]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONVStore.cxx
Consolidating definitions of FindObject methods (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONVStore.cxx
CommitLineData
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
103ClassImp(AliMUONVStore)
104/// \endcond
105
106//_____________________________________________________________________________
107AliMUONVStore::AliMUONVStore() : TObject()
108{
109 /// ctor
110}
111
112//_____________________________________________________________________________
113AliMUONVStore::~AliMUONVStore()
114{
115 /// dtor
116}
117
118//_____________________________________________________________________________
119Bool_t
120AliMUONVStore::Connect(TTree&, Bool_t) const
121{
122 /// Connect to a Ttree
123 AliError("Not implemented");
124 return kFALSE;
125}
126
127//_____________________________________________________________________________
128AliMUONVStore*
129AliMUONVStore::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//_____________________________________________________________________________
149TObject*
150AliMUONVStore::FindObject(Int_t, Int_t) const
151{
152 /// Find an object using 2 identifiers
153 AliError("Not implemented");
154 return 0;
155}
156
ce351cca 157//______________________________________________________________________________
158TObject*
159AliMUONVStore::FindObject(const char *name) const
160{
161 // Find an object in this collection using its name. Requires a sequential
162 // scan till the object has been found. Returns 0 if object with specified
163 // name is not found.
164
165 TIter next(CreateIterator());
166 TObject *obj;
167
168 while ((obj = next()))
169 if (!strcmp(name, obj->GetName())) return obj;
170 return 0;
171}
172
173//______________________________________________________________________________
174TObject*
175AliMUONVStore::FindObject(const TObject *obj) const
176{
177 // Find an object in this store using the object's IsEqual()
178 // member function. Requires a sequential scan till the object has
179 // been found. Returns 0 if object is not found.
180 // Typically this function is overridden by a more efficient version
2ed392cf 181 // in concrete collection classes.
ce351cca 182
183 TIter next(CreateIterator());
184 TObject *ob;
185
186 while ((ob = next()))
187 if (ob->IsEqual(obj)) return ob;
188 return 0;
189}
190
191//_____________________________________________________________________________
192TObject*
193AliMUONVStore::FindObject(UInt_t uniqueID) const
194{
195 /// Generic find method. Should be overriden by derived class if it can
196 /// be made more efficient there.
197
198 AliDebug(1,Form("uniqueID=%u",uniqueID));
199
200 TIter next(CreateIterator());
201 TObject* o;
202 while ( ( o = next() ) )
203 {
204 if ( o->GetUniqueID() == uniqueID ) return o;
205 }
206 return 0x0;
207}
208
209//______________________________________________________________________________
210Int_t
211AliMUONVStore::GetSize(Int_t /*i*/) const
212{
213 /// Number of objects store for "i", whatever that can means
214 AliError("Not implemented");
215 return 0;
216}
217
218//______________________________________________________________________________
219void
220AliMUONVStore::Print(Option_t *wildcard) const
221{
222 // Print all objects in this store.
223 // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects
224 // with names matching xxx*.
225
226 if (!wildcard) wildcard = "";
227 TRegexp re(wildcard, kTRUE);
228 Int_t nch = strlen(wildcard);
229 TIter next(CreateIterator());
230 TObject *object;
231
232 while ((object = next())) {
233 TString s = object->GetName();
234 if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
235 object->Print();
236 }
237}
238
239//_____________________________________________________________________________
240void
241AliMUONVStore::Print(Option_t *wildcard, Option_t *option) const
242{
243 // Print all objects in this store, passing option to the
244 // objects Print() method.
245 // Wildcarding is supported, e.g. wildcard="xxx*" prints only objects
246 // with names matching xxx*.
247
248 if (!wildcard) wildcard = "";
249 TRegexp re(wildcard, kTRUE);
250 Int_t nch = strlen(wildcard);
251 TIter next(CreateIterator());
252 TObject *object;
253
254 while ((object = next())) {
255 TString s = object->GetName();
256 if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
257 object->Print(option);
258 }
259}
260