Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TSelectorList.cxx
Go to the documentation of this file.
1// @(#)root/cont:$Id$
2// Author: Fons Rademakers 10/08/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/** \class TSelectorList
13\ingroup tree
14
15A TList derived class that makes sure that objects added to it
16are not linked to the currently open file (like histograms,
17eventlists and trees). Also it makes sure the name of the added
18object is unique. This class is used in the TSelector for the
19output list.
20*/
21
22#include "TSelectorList.h"
23#include "TMethodCall.h"
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// If the class of obj has the SetDirectory(TDirectory*) method
28/// call it to unset the directory association. The objects in the
29/// selector list or owned by the list and not by the directory that
30/// was active when they were created. Returns true in case of success.
31
33{
34 if (!obj || !obj->IsA())
35 return false;
36
37 TMethodCall callEnv;
38 callEnv.InitWithPrototype(obj->IsA(), "SetDirectory", "TDirectory*");
39 if (!callEnv.IsValid())
40 return false;
41
42 callEnv.SetParam((Longptr_t) nullptr);
43 callEnv.Execute(obj);
44
45 return true;
46}
47
48////////////////////////////////////////////////////////////////////////////////
49/// Check for duplicate object names in the list. If an object with
50/// the same name is added then the merge function will fail that will
51/// look up objects in different output lists by name. Returns true
52/// in case name is unique.
53
55{
56 if (!obj)
57 return false;
58
59 TObject *org = FindObject(obj->GetName());
60 if (org == obj) {
61 Error("CheckDuplicateName","object with name: %s already in the list",obj->GetName());
62 return false;
63 }
64
65 if (org) {
66 Error("CheckDuplicateName","an object with the same name: %s is already in the list",obj->GetName());
67 return false;
68 }
69
70 return true;
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Add at the start of the list
75
82
83////////////////////////////////////////////////////////////////////////////////
84/// Add at the start of the list
85
87{
88 UnsetDirectory(obj);
89 if (CheckDuplicateName(obj))
90 THashList::AddFirst(obj, opt);
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Add at the end of the list
95
97{
98 UnsetDirectory(obj);
99 if (CheckDuplicateName(obj))
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// Add at the end of the list
105
107{
108 UnsetDirectory(obj);
109 if (CheckDuplicateName(obj))
110 THashList::AddLast(obj, opt);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Add to the list.
115
117{
118 UnsetDirectory(obj);
119 if (CheckDuplicateName(obj))
120 THashList::AddAt(obj, idx);
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Add to the list, with options.
125
127{
128 UnsetDirectory(obj);
129 if (CheckDuplicateName(obj))
130 THashList::AddAt(obj, idx, opt);
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Add to the list.
135
137{
138 UnsetDirectory(obj);
139 if (CheckDuplicateName(obj))
140 THashList::AddAfter(after, obj);
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Add to the list.
145
147{
148 UnsetDirectory(obj);
149 if (CheckDuplicateName(obj))
150 THashList::AddAfter(after, obj);
151}
152
153////////////////////////////////////////////////////////////////////////////////
154/// Add to the list, with options.
155
156void TSelectorList::AddAfter(const TObject *after, TObject *obj, Option_t *opt)
157{
158 UnsetDirectory(obj);
159 if (CheckDuplicateName(obj))
160 THashList::AddAfter(after, obj, opt);
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Add to the list, with options.
165
167{
168 UnsetDirectory(obj);
169 if (CheckDuplicateName(obj))
170 THashList::AddAfter(after, obj, opt);
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Add to the list.
175
176void TSelectorList::AddBefore(const TObject *before, TObject *obj)
177{
178 UnsetDirectory(obj);
179 if (CheckDuplicateName(obj))
180 THashList::AddBefore(before, obj);
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Add to the list.
185
187{
188 UnsetDirectory(obj);
189 if (CheckDuplicateName(obj))
190 THashList::AddBefore(before, obj);
191}
192
193////////////////////////////////////////////////////////////////////////////////
194/// Add to the list, with options.
195
196void TSelectorList::AddBefore(const TObject *before, TObject *obj, Option_t *opt)
197{
198 UnsetDirectory(obj);
199 if (CheckDuplicateName(obj))
200 THashList::AddBefore(before, obj, opt);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Add to the list, with options.
205
207{
208 UnsetDirectory(obj);
209 if (CheckDuplicateName(obj))
210 THashList::AddBefore(before, obj, opt);
211}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
Definition RtypesCore.h:89
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void AddBefore(const TObject *before, TObject *obj) override
Insert object before object before in the list.
void AddFirst(TObject *obj) override
Add object at the beginning of the list.
Definition THashList.cxx:68
void AddAfter(const TObject *after, TObject *obj) override
Insert object after object after in the list.
void AddAt(TObject *obj, Int_t idx) override
Insert object at location idx in the list.
TObject * FindObject(const char *name) const override
Find object using its name.
void AddLast(TObject *obj) override
Add object at the end of the list.
Definition THashList.cxx:94
Method or function calling interface.
Definition TMethodCall.h:37
void Execute(const char *, const char *, int *=nullptr) override
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
void SetParam(Long_t l)
Add a long method parameter.
Mother of all ROOT objects.
Definition TObject.h:42
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:462
virtual TClass * IsA() const
Definition TObject.h:248
void AddBefore(const TObject *before, TObject *obj) override
Add to the list.
void AddFirst(TObject *obj) override
Add at the start of the list.
void AddAt(TObject *obj, Int_t idx) override
Add to the list.
void AddLast(TObject *obj) override
Add at the end of the list.
void AddAfter(const TObject *after, TObject *obj) override
Add to the list.
bool UnsetDirectory(TObject *obj)
If the class of obj has the SetDirectory(TDirectory*) method call it to unset the directory associati...
bool CheckDuplicateName(TObject *obj)
Check for duplicate object names in the list.