Line data Source code
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 : //-----------------------------------------------------------------------------
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 : ///
94 : //-----------------------------------------------------------------------------
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
105 18 : ClassImp(AliMUONVStore)
106 : /// \endcond
107 :
108 : //_____________________________________________________________________________
109 113 : AliMUONVStore::AliMUONVStore() : TObject()
110 339 : {
111 : /// ctor
112 113 : }
113 :
114 : //_____________________________________________________________________________
115 : AliMUONVStore::~AliMUONVStore()
116 0 : {
117 : /// dtor
118 186 : }
119 :
120 : //_____________________________________________________________________________
121 : Bool_t
122 : AliMUONVStore::Connect(TTree&, Bool_t) const
123 : {
124 : /// Connect to a Ttree
125 0 : AliError("Not implemented");
126 0 : return kFALSE;
127 : }
128 :
129 : //_____________________________________________________________________________
130 : AliMUONVStore*
131 : AliMUONVStore::Create(TTree& tree, const char* what)
132 : {
133 : /// Create a store from a tree. Forwarded to AliMUONTreeManager::CreateStore
134 46 : AliMUONTreeManager tman;
135 :
136 23 : TObject* o = tman.CreateObject(tree,what);;
137 23 : if (o)
138 : {
139 69 : AliMUONVStore* c = dynamic_cast<AliMUONVStore*>(o);
140 23 : if (!c)
141 : {
142 0 : AliErrorClass(Form("Object of class %s cannot be cast to an AliMUONVStore",
143 : o->ClassName()));
144 : }
145 : return c;
146 : }
147 0 : return 0x0;
148 23 : }
149 :
150 : //_____________________________________________________________________________
151 : TObject*
152 : AliMUONVStore::FindObject(Int_t, Int_t) const
153 : {
154 : /// Find an object using 2 identifiers
155 0 : AliError("(Int_t,Int_t) : Not implemented");
156 0 : return 0;
157 : }
158 :
159 : //______________________________________________________________________________
160 : TObject*
161 : AliMUONVStore::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 0 : TIter next(CreateIterator());
168 : TObject *obj;
169 :
170 0 : while ((obj = next()))
171 0 : if (!strcmp(name, obj->GetName())) return obj;
172 0 : return 0;
173 0 : }
174 :
175 : //______________________________________________________________________________
176 : TObject*
177 : AliMUONVStore::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
183 : // in concrete collection classes.
184 :
185 0 : TIter next(CreateIterator());
186 : TObject *ob;
187 :
188 0 : while ((ob = next()))
189 0 : if (ob->IsEqual(obj)) return ob;
190 0 : return 0;
191 0 : }
192 :
193 : //_____________________________________________________________________________
194 : TObject*
195 : AliMUONVStore::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 0 : AliDebug(1,Form("uniqueID=%u",uniqueID));
201 :
202 0 : TIter next(CreateIterator());
203 : TObject* o;
204 0 : while ( ( o = next() ) )
205 : {
206 0 : if ( o->GetUniqueID() == uniqueID ) return o;
207 : }
208 0 : return 0x0;
209 0 : }
210 :
211 : //______________________________________________________________________________
212 : Int_t
213 : AliMUONVStore::GetSize(Int_t /*i*/) const
214 : {
215 : /// Number of objects store for "i", whatever that can means
216 0 : AliError("Not implemented");
217 0 : return 0;
218 : }
219 :
220 : //______________________________________________________________________________
221 : void
222 : AliMUONVStore::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 16 : if (!wildcard) wildcard = "";
229 8 : TRegexp re(wildcard, kTRUE);
230 16 : Int_t nch = strlen(wildcard);
231 16 : TIter next(CreateIterator());
232 : TObject *object;
233 :
234 352 : while ((object = next())) {
235 328 : TString s = object->GetName();
236 164 : if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
237 164 : object->Print();
238 328 : }
239 8 : }
240 :
241 : //_____________________________________________________________________________
242 : void
243 : AliMUONVStore::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 4 : if (!wildcard) wildcard = "";
251 2 : TRegexp re(wildcard, kTRUE);
252 4 : Int_t nch = strlen(wildcard);
253 4 : TIter next(CreateIterator());
254 : TObject *object;
255 :
256 6 : while ((object = next())) {
257 0 : TString s = object->GetName();
258 0 : if (nch && s != wildcard && s.Index(re) == kNPOS) continue;
259 0 : object->Print(option);
260 0 : }
261 2 : }
262 :
|