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