Logo ROOT  
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 
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 }
TSelectorList::AddAt
void AddAt(TObject *obj, Int_t idx)
Add to the list.
Definition: TSelectorList.cxx:117
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TMethodCall::SetParam
void SetParam(Long_t l)
Add a long method parameter.
Definition: TMethodCall.cxx:603
THashList::AddAfter
void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Definition: THashList.cxx:143
ClassImp
#define ClassImp(name)
Definition: Rtypes.h:364
TSelectorList.h
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:890
bool
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
THashList::AddBefore
void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
Definition: THashList.cxx:121
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TSelectorList::AddAfter
void AddAfter(const TObject *after, TObject *obj)
Add to the list.
Definition: TSelectorList.cxx:127
TSelectorList::AddLast
void AddLast(TObject *obj)
Add at the end of the list.
Definition: TSelectorList.cxx:97
THashList::FindObject
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:262
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
THashList::AddLast
void AddLast(TObject *obj)
Add object at the end of the list.
Definition: THashList.cxx:95
TMethodCall::IsValid
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
Definition: TMethodCall.cxx:373
Long_t
long Long_t
Definition: RtypesCore.h:54
org
#define org(otri, vertexptr)
Definition: triangle.c:1037
TMethodCall::InitWithPrototype
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
Definition: TMethodCall.cxx:339
TMethodCall::Execute
void Execute(const char *, const char *, int *=0)
Execute method on this object with the given parameter string, e.g.
Definition: TMethodCall.h:64
TSelectorList::AddBefore
void AddBefore(const TObject *before, TObject *obj)
Add to the list.
Definition: TSelectorList.cxx:147
TSelectorList::AddFirst
void AddFirst(TObject *obj)
Add at the start of the list.
Definition: TSelectorList.cxx:77
TObject
Definition: TObject.h:37
TSelectorList
Definition: TSelectorList.h:31
THashList::AddAt
void AddAt(TObject *obj, Int_t idx)
Insert object at location idx in the list.
Definition: THashList.cxx:165
TMethodCall
Definition: TMethodCall.h:37
THashList::AddFirst
void AddFirst(TObject *obj)
Add object at the beginning of the list.
Definition: THashList.cxx:69
TSelectorList::CheckDuplicateName
Bool_t CheckDuplicateName(TObject *obj)
Check for duplicate object names in the list.
Definition: TSelectorList.cxx:55
TSelectorList::UnsetDirectory
Bool_t UnsetDirectory(TObject *obj)
If the class of obj has the SetDirectory(TDirectory*) method call it to unset the directory assiciati...
Definition: TSelectorList.cxx:33
int
TMethodCall.h