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