Logo ROOT   6.10/09
Reference Guide
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 
15 A TList derived class that makes sure that objects added to it
16 are not linked to the currently open file (like histograms,
17 eventlists and trees). Also it makes sure the name of the added
18 object is unique. This class is used in the TSelector for the
19 output list.
20 */
21 
22 #include "TSelectorList.h"
23 #include "TMethodCall.h"
24 
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 /// If the class of obj has the SetDirectory(TDirectory*) method
29 /// call it to unset the directory assiciation. The objects in the
30 /// selector list or owned by the list and not by the directory that
31 /// was active when they were created. Returns true in case of success.
32 
33 Bool_t TSelectorList::UnsetDirectory(TObject *obj)
34 {
35  if (!obj || !obj->IsA())
36  return kFALSE;
37 
38  TMethodCall callEnv;
39  callEnv.InitWithPrototype(obj->IsA(), "SetDirectory", "TDirectory*");
40  if (!callEnv.IsValid())
41  return kFALSE;
42 
43  callEnv.SetParam((Long_t) 0);
44  callEnv.Execute(obj);
45 
46  return kTRUE;
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// Check for duplicate object names in the list. If an object with
51 /// the same name is added then the merge function will fail that will
52 /// look up objects in different output lists by name. Returns true
53 /// in case name is unique.
54 
56 {
57  if (!obj)
58  return kFALSE;
59 
60  TObject *org = FindObject(obj->GetName());
61  if (org == obj) {
62  Error("CheckDuplicateName","object with name: %s already in the list",obj->GetName());
63  return kFALSE;
64  }
65 
66  if (org) {
67  Error("CheckDuplicateName","an object with the same name: %s is already in the list",obj->GetName());
68  return kFALSE;
69  }
70 
71  return kTRUE;
72 }
73 
74 ////////////////////////////////////////////////////////////////////////////////
75 /// Add at the start of the list
76 
78 {
79  UnsetDirectory(obj);
80  if (CheckDuplicateName(obj))
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Add at the start of the list
86 
88 {
89  UnsetDirectory(obj);
90  if (CheckDuplicateName(obj))
91  THashList::AddFirst(obj, opt);
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// Add at the end of the list
96 
98 {
99  UnsetDirectory(obj);
100  if (CheckDuplicateName(obj))
101  THashList::AddLast(obj);
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Add at the end of the list
106 
108 {
109  UnsetDirectory(obj);
110  if (CheckDuplicateName(obj))
111  THashList::AddLast(obj, opt);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Add to the list.
116 
118 {
119  UnsetDirectory(obj);
120  if (CheckDuplicateName(obj))
121  THashList::AddAt(obj, idx);
122 }
123 
124 ////////////////////////////////////////////////////////////////////////////////
125 /// Add to the list.
126 
127 void TSelectorList::AddAfter(const TObject *after, TObject *obj)
128 {
129  UnsetDirectory(obj);
130  if (CheckDuplicateName(obj))
131  THashList::AddAfter(after, obj);
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// Add to the list.
136 
138 {
139  UnsetDirectory(obj);
140  if (CheckDuplicateName(obj))
141  THashList::AddAfter(after, obj);
142 }
143 
144 ////////////////////////////////////////////////////////////////////////////////
145 /// Add to the list.
146 
147 void TSelectorList::AddBefore(const TObject *before, TObject *obj)
148 {
149  UnsetDirectory(obj);
150  if (CheckDuplicateName(obj))
151  THashList::AddBefore(before, obj);
152 }
153 
154 ////////////////////////////////////////////////////////////////////////////////
155 /// Add to the list.
156 
158 {
159  UnsetDirectory(obj);
160  if (CheckDuplicateName(obj))
161  THashList::AddBefore(before, obj);
162 }
void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: THashList.cxx:68
void AddAt(TObject *obj, Int_t idx)
Add to the list.
void AddLast(TObject *obj)
Add object at the end of the list.
Definition: THashList.cxx:90
void AddBefore(const TObject *before, TObject *obj)
Add to the list.
const char Option_t
Definition: RtypesCore.h:62
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
Bool_t CheckDuplicateName(TObject *obj)
Check for duplicate object names in the list.
Bool_t UnsetDirectory(TObject *obj)
If the class of obj has the SetDirectory(TDirectory*) method call it to unset the directory assiciati...
Method or function calling interface.
Definition: TMethodCall.h:37
void AddFirst(TObject *obj)
Add at the start of the list.
void AddAt(TObject *obj, Int_t idx)
Insert object at location idx in the list.
Definition: THashList.cxx:148
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:873
void AddLast(TObject *obj)
Add at the end of the list.
void AddAfter(const TObject *after, TObject *obj)
Add to the list.
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: THashList.cxx:130
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.
const Bool_t kFALSE
Definition: RtypesCore.h:92
long Long_t
Definition: RtypesCore.h:50
#define ClassImp(name)
Definition: Rtypes.h:336
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: THashList.cxx:112
#define org(otri, vertexptr)
Definition: triangle.c:1037
Mother of all ROOT objects.
Definition: TObject.h:37
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
A TList derived class that makes sure that objects added to it are not linked to the currently open f...
Definition: TSelectorList.h:31
void SetParam(Long_t l)
Add a long method parameter.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364
const Bool_t kTRUE
Definition: RtypesCore.h:91