Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
25 ClassImp(TSelectorList);
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 
55 Bool_t TSelectorList::CheckDuplicateName(TObject *obj)
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 
77 void TSelectorList::AddFirst(TObject *obj)
78 {
79  UnsetDirectory(obj);
80  if (CheckDuplicateName(obj))
81  THashList::AddFirst(obj);
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// Add at the start of the list
86 
87 void TSelectorList::AddFirst(TObject *obj, Option_t *opt)
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 
97 void TSelectorList::AddLast(TObject *obj)
98 {
99  UnsetDirectory(obj);
100  if (CheckDuplicateName(obj))
101  THashList::AddLast(obj);
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Add at the end of the list
106 
107 void TSelectorList::AddLast(TObject *obj, Option_t *opt)
108 {
109  UnsetDirectory(obj);
110  if (CheckDuplicateName(obj))
111  THashList::AddLast(obj, opt);
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 /// Add to the list.
116 
117 void TSelectorList::AddAt(TObject *obj, Int_t idx)
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 
137 void TSelectorList::AddAfter(TObjLink *after, TObject *obj)
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 
157 void TSelectorList::AddBefore(TObjLink *before, TObject *obj)
158 {
159  UnsetDirectory(obj);
160  if (CheckDuplicateName(obj))
161  THashList::AddBefore(before, obj);
162 }