]>
Commit | Line | Data |
---|---|---|
ce351cca | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | /// \class AliMUONVStore | |
19 | /// | |
20 | /// A store is a container, which can be searched for (using FindObject methods), | |
21 | /// iterated upon (using CreateIterator() method), and into which you can | |
22 | /// add objects (using Add) | |
23 | /// | |
24 | /// In addition, a store can be connected to a TTree. | |
25 | /// | |
26 | /// The general way of dealing with I/O for MUON is a two stage process : | |
27 | /// | |
28 | /// 1) first get a TTree pointer using the AliLoader mechanism (this is AliRoot | |
29 | /// general) | |
30 | /// | |
31 | /// 2) connect that TTree to a MUON (virtual) data container using | |
32 | /// the container's Connect(TTree&) method (this is MUON specific) | |
33 | /// | |
34 | /// Example for reading digits for nevents | |
35 | /// | |
36 | /// \code | |
37 | /// | |
38 | /// AliMUONVDigitStore* digitStore(0x0); | |
39 | /// | |
40 | /// AliLoader* loader = ... ( get loader from somewhere, e.g. AliRunLoader::GetDetectorLoader()); | |
41 | /// loader->LoadDigits("READ"); // load digits | |
42 | /// | |
43 | /// for ( Int_t i = 0; i < nevents; ++i ) | |
44 | /// { | |
45 | /// TTree* treeD = loader->TreeD(); // get the tree | |
46 | /// if (!digitStore) digitStore = static_cast<AliMUONVDigitStore*> | |
47 | /// (AliMUONVDigitStore::CreateStore(*treeD,"Digit")); // creates a container for digits | |
48 | /// (concrete class is given by the tree itself) | |
49 | /// digitStore->Connect(*treeD); | |
50 | /// treeD->GetEvent(0); // actual reading of the data | |
51 | /// | |
52 | /// the digitStore is now filled and ready to be used | |
53 | /// .... | |
54 | /// | |
55 | /// digitStore->Clear(); // reset once used | |
56 | /// } | |
57 | /// | |
58 | /// \endcode | |
59 | /// | |
60 | /// Please note that for reading data, you do *not* need to know the concrete | |
61 | /// container class, as it is given to you by the TTree | |
62 | /// | |
63 | /// Example for writing digits | |
64 | /// | |
65 | /// \code | |
66 | /// | |
67 | /// get the loader and do a loader->LoadDigits("RECREATE" or "UPDATE") | |
68 | /// (generally done by the framework itself) | |
69 | /// | |
70 | /// AliMUONVDigitStore* digitStore = new AliMUONDigitStoreV1 | |
71 | /// // for writing, must decide on the concrete store class to use | |
72 | /// | |
73 | /// for ( Int_t i = 0; i < nevents; ++i ) | |
74 | /// { | |
75 | /// TTree* treeD = loader->TreeD(); | |
76 | /// digitStore->Connect(*treeD); | |
77 | /// | |
78 | /// ... put some digits in the digitStore | |
79 | /// | |
80 | /// treeD->Fill(); | |
81 | /// | |
82 | /// loader->WriteDigits("OVERWRITE"); | |
83 | /// } | |
84 | /// | |
85 | /// delete digitStore; | |
86 | /// | |
87 | /// loader->UnloadDigits(); | |
88 | /// | |
89 | /// \endcode | |
90 | /// | |
91 | /// In the write case, one *must* specify a concrete class for the container | |
92 | /// | |
93 | ||
94 | #include "AliMUONVStore.h" | |
95 | ||
96 | #include "AliMUONTreeManager.h" | |
97 | #include "AliLog.h" | |
98 | ||
99 | #include <TRegexp.h> | |
100 | #include <TClass.h> | |
101 | ||
102 | /// \cond CLASSIMP | |
103 | ClassImp(AliMUONVStore) | |
104 | /// \endcond | |
105 | ||
106 | //_____________________________________________________________________________ | |
107 | AliMUONVStore::AliMUONVStore() : TObject() | |
108 | { | |
109 | /// ctor | |
110 | } | |
111 | ||
112 | //_____________________________________________________________________________ | |
113 | AliMUONVStore::~AliMUONVStore() | |
114 | { | |
115 | /// dtor | |
116 | } | |
117 | ||
118 | //_____________________________________________________________________________ | |
119 | Bool_t | |
120 | AliMUONVStore::Connect(TTree&, Bool_t) const | |
121 | { | |
122 | /// Connect to a Ttree | |
123 | AliError("Not implemented"); | |
124 | return kFALSE; | |
125 | } | |
126 | ||
127 | //_____________________________________________________________________________ | |
128 | AliMUONVStore* | |
129 | AliMUONVStore::Create(TTree& tree, const char* what) | |
130 | { | |
131 | /// Create a store from a tree. Forwarded to AliMUONTreeManager::CreateStore | |
132 | AliMUONTreeManager tman; | |
133 | ||
134 | TObject* o = tman.CreateObject(tree,what);; | |
135 | if (o) | |
136 | { | |
137 | AliMUONVStore* c = dynamic_cast<AliMUONVStore*>(o); | |
138 | if (!c) | |
139 | { | |
140 | AliErrorClass(Form("Object of class %s cannot be cast to an AliMUONVStore", | |
141 | o->ClassName())); | |
142 | } | |
143 | return c; | |
144 | } | |
145 | return 0x0; | |
146 | } | |
147 | ||
148 | //_____________________________________________________________________________ | |
149 | TObject* | |
150 | AliMUONVStore::FindObject(Int_t, Int_t) const | |
151 | { | |
152 | /// Find an object using 2 identifiers | |
153 | AliError("Not implemented"); | |
154 | return 0; | |
155 | } | |
156 | ||
157 | //_____________________________________________________________________________ | |
158 | TObject* | |
159 | AliMUONVStore::FindObject(Int_t,Int_t, Int_t) const | |
160 | { | |
161 | /// Find an object using 3 identifiers | |
162 | AliError("Not implemented"); | |
163 | return 0; | |
164 | } | |
165 | ||
166 | //_____________________________________________________________________________ | |
167 | TObject* | |
168 | AliMUONVStore::FindObject(Int_t, Int_t, Int_t, Int_t) const | |
169 | { | |
170 | /// Find an object using 4 identifiers | |
171 | AliError("Not implemented"); | |
172 | return 0; | |
173 | } | |
174 | ||
175 | //______________________________________________________________________________ | |
176 | TObject* | |
177 | AliMUONVStore::FindObject(const char *name) const | |
178 | { | |
179 | // Find an object in this collection using its name. Requires a sequential | |
180 | // scan till the object has been found. Returns 0 if object with specified | |
181 | // name is not found. | |
182 | ||
183 | TIter next(CreateIterator()); | |
184 | TObject *obj; | |
185 | ||
186 | while ((obj = next())) | |
187 | if (!strcmp(name, obj->GetName())) return obj; | |
188 | return 0; | |
189 | } | |
190 | ||
191 | //______________________________________________________________________________ | |
192 | TObject* | |
193 | AliMUONVStore::FindObject(const TObject *obj) const | |
194 | { | |
195 | // Find an object in this store using the object's IsEqual() | |
196 | // member function. Requires a sequential scan till the object has | |
197 | // been found. Returns 0 if object is not found. | |
198 | // Typically this function is overridden by a more efficient version | |
199 | // in concrete collection classes (e.g. THashTable). | |
200 | ||
201 | TIter next(CreateIterator()); | |
202 | TObject *ob; | |
203 | ||
204 | while ((ob = next())) | |
205 | if (ob->IsEqual(obj)) return ob; | |
206 | return 0; | |
207 | } | |
208 | ||
209 | //_____________________________________________________________________________ | |
210 | TObject* | |
211 | AliMUONVStore::FindObject(UInt_t uniqueID) const | |
212 | { | |
213 | /// Generic find method. Should be overriden by derived class if it can | |
214 | /// be made more efficient there. | |
215 | ||
216 | AliDebug(1,Form("uniqueID=%u",uniqueID)); | |
217 | ||
218 | TIter next(CreateIterator()); | |
219 | TObject* o; | |
220 | while ( ( o = next() ) ) | |
221 | { | |
222 | if ( o->GetUniqueID() == uniqueID ) return o; | |
223 | } | |
224 | return 0x0; | |
225 | } | |
226 | ||
227 | //______________________________________________________________________________ | |
228 | Int_t | |
229 | AliMUONVStore::GetSize(Int_t /*i*/) const | |
230 | { | |
231 | /// Number of objects store for "i", whatever that can means | |
232 | AliError("Not implemented"); | |
233 | return 0; | |
234 | } | |
235 | ||
236 | //______________________________________________________________________________ | |
237 | void | |
238 | AliMUONVStore::Print(Option_t *wildcard) const | |
239 | { | |
240 | // Print all objects in this store. | |
241 | // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects | |
242 | // with names matching xxx*. | |
243 | ||
244 | if (!wildcard) wildcard = ""; | |
245 | TRegexp re(wildcard, kTRUE); | |
246 | Int_t nch = strlen(wildcard); | |
247 | TIter next(CreateIterator()); | |
248 | TObject *object; | |
249 | ||
250 | while ((object = next())) { | |
251 | TString s = object->GetName(); | |
252 | if (nch && s != wildcard && s.Index(re) == kNPOS) continue; | |
253 | object->Print(); | |
254 | } | |
255 | } | |
256 | ||
257 | //_____________________________________________________________________________ | |
258 | void | |
259 | AliMUONVStore::Print(Option_t *wildcard, Option_t *option) const | |
260 | { | |
261 | // Print all objects in this store, passing option to the | |
262 | // objects Print() method. | |
263 | // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects | |
264 | // with names matching xxx*. | |
265 | ||
266 | if (!wildcard) wildcard = ""; | |
267 | TRegexp re(wildcard, kTRUE); | |
268 | Int_t nch = strlen(wildcard); | |
269 | TIter next(CreateIterator()); | |
270 | TObject *object; | |
271 | ||
272 | while ((object = next())) { | |
273 | TString s = object->GetName(); | |
274 | if (nch && s != wildcard && s.Index(re) == kNPOS) continue; | |
275 | object->Print(option); | |
276 | } | |
277 | } | |
278 |