]>
Commit | Line | Data |
---|---|---|
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 | /* | |
17 | $Log$ | |
18 | Revision 1.12 2002/02/12 16:06:45 cblume | |
19 | Remove delete fTree | |
20 | ||
21 | Revision 1.11 2001/11/19 08:44:08 cblume | |
22 | Fix bugs reported by Rene | |
23 | ||
24 | Revision 1.10 2001/08/30 09:31:22 hristov | |
25 | The operator[] is replaced by At() or AddAt() in case of TObjArray. | |
26 | ||
27 | Revision 1.9 2001/07/27 13:03:15 hristov | |
28 | Default Branch split level set to 99 | |
29 | ||
30 | Revision 1.8 2001/01/26 19:56:57 hristov | |
31 | Major upgrade of AliRoot code | |
32 | ||
33 | Revision 1.7 2000/11/20 08:56:07 cblume | |
34 | Cleanup of data arrays | |
35 | ||
36 | Revision 1.6 2000/11/01 14:53:21 cblume | |
37 | Merge with TRD-develop | |
38 | ||
39 | Revision 1.1.4.3 2000/10/06 16:49:46 cblume | |
40 | Made Getters const | |
41 | ||
42 | Revision 1.1.4.2 2000/10/04 16:34:58 cblume | |
43 | Replace include files by forward declarations | |
44 | ||
45 | Revision 1.5 2000/06/09 11:10:07 cblume | |
46 | Compiler warnings and coding conventions, next round | |
47 | ||
48 | Revision 1.4 2000/06/08 18:32:58 cblume | |
49 | Make code compliant to coding conventions | |
50 | ||
51 | Revision 1.3 2000/06/07 16:27:01 cblume | |
52 | Try to remove compiler warnings on Sun and HP | |
53 | ||
54 | Revision 1.2 2000/05/08 16:17:27 cblume | |
55 | Merge TRD-develop | |
56 | ||
57 | Revision 1.1.4.1 2000/05/08 14:55:03 cblume | |
58 | Bug fixes | |
59 | ||
60 | Revision 1.1 2000/02/28 19:02:56 cblume | |
61 | Add new TRD classes | |
62 | ||
63 | */ | |
64 | ||
65 | /////////////////////////////////////////////////////////////////////////////// | |
66 | // // | |
67 | // Alice segment manager base class // | |
68 | // // | |
69 | /////////////////////////////////////////////////////////////////////////////// | |
70 | ||
71 | #include <TROOT.h> | |
72 | #include <TTree.h> | |
73 | #include <TClonesArray.h> | |
74 | #include <TDirectory.h> | |
75 | #include <TError.h> | |
76 | #include <TClass.h> | |
77 | ||
78 | #include "AliTRDarrayI.h" | |
79 | #include "AliTRDsegmentID.h" | |
80 | #include "AliTRDsegmentArrayBase.h" | |
81 | ||
82 | ClassImp(AliTRDsegmentArrayBase) | |
83 | ||
84 | //_____________________________________________________________________________ | |
85 | AliTRDsegmentArrayBase::AliTRDsegmentArrayBase():TNamed() | |
86 | { | |
87 | // | |
88 | // AliTRDsegmentArrayBase default constructor | |
89 | // | |
90 | ||
91 | fNSegment = 0; | |
92 | fSegment = 0; | |
93 | fTreeIndex = 0; | |
94 | fTree = 0; | |
95 | fClass = 0; | |
96 | fBranch = 0; | |
97 | ||
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(Text_t *classname, Int_t n) | |
102 | { | |
103 | // | |
104 | // Create an array of objects of <classname>. The class must inherit from | |
105 | // AliTRDsegmentID. The second argument sets the number of entries in | |
106 | // the array. | |
107 | // | |
108 | ||
109 | fNSegment = 0; | |
110 | fSegment = 0; | |
111 | fTreeIndex = 0; | |
112 | fTree = 0; | |
113 | fClass = 0; | |
114 | fBranch = 0; | |
115 | ||
116 | SetClass(classname); | |
117 | ||
118 | if (MakeArray(n) == kFALSE) { | |
119 | Error("AliTRDsegmentArrayBase","Cannot allocate %d segments in memory",n); | |
120 | return; | |
121 | } | |
122 | ||
123 | } | |
124 | ||
125 | //_____________________________________________________________________________ | |
126 | AliTRDsegmentArrayBase::AliTRDsegmentArrayBase(const AliTRDsegmentArrayBase &a) | |
127 | { | |
128 | // | |
129 | // AliTRDsegmentArrayBase copy constructor | |
130 | // | |
131 | ||
132 | ((AliTRDsegmentArrayBase &) a).Copy(*this); | |
133 | ||
134 | } | |
135 | ||
136 | //_____________________________________________________________________________ | |
137 | AliTRDsegmentArrayBase::~AliTRDsegmentArrayBase() | |
138 | { | |
139 | // | |
140 | // AliTRDsegmentArrayBase destructor | |
141 | // | |
142 | ||
143 | if (fNSegment){ | |
144 | fSegment->Delete(); | |
145 | delete fSegment; | |
146 | } | |
147 | ||
148 | //if (fTree) delete fTree; | |
149 | if (fTreeIndex) delete fTreeIndex; | |
150 | ||
151 | } | |
152 | ||
153 | //_____________________________________________________________________________ | |
154 | AliTRDsegmentArrayBase &AliTRDsegmentArrayBase | |
155 | ::operator=(const AliTRDsegmentArrayBase &a) | |
156 | { | |
157 | // | |
158 | // Assignment operator | |
159 | // | |
160 | ||
161 | if (this != &a) ((AliTRDsegmentArrayBase &) a).Copy(*this); | |
162 | return *this; | |
163 | ||
164 | } | |
165 | ||
166 | //_____________________________________________________________________________ | |
167 | void AliTRDsegmentArrayBase::Copy(TObject &a) | |
168 | { | |
169 | // | |
170 | // Copy function | |
171 | // | |
172 | ||
173 | TNamed::Copy(a); | |
174 | ||
175 | fSegment->Copy(*((AliTRDsegmentArrayBase &) a).fSegment); | |
176 | fTreeIndex->Copy(*((AliTRDsegmentArrayBase &) a).fTreeIndex); | |
177 | fClass->Copy(*((AliTRDsegmentArrayBase &) a).fClass); | |
178 | ||
179 | ((AliTRDsegmentArrayBase &) a).fNSegment = fNSegment; | |
180 | ||
181 | } | |
182 | ||
183 | //_____________________________________________________________________________ | |
184 | Bool_t AliTRDsegmentArrayBase::SetClass(Text_t *classname) | |
185 | { | |
186 | // | |
187 | // Sets the classname of the stored object | |
188 | // | |
189 | ||
190 | if (fTree != 0) { | |
191 | delete fTree; | |
192 | fTree = 0; | |
193 | fBranch = 0; | |
194 | delete fTreeIndex; | |
195 | fTreeIndex = 0; | |
196 | } | |
197 | if (fSegment != 0) { | |
198 | fSegment->Delete(); | |
199 | delete fSegment; | |
200 | fSegment = 0; | |
201 | } | |
202 | ||
203 | if (!gROOT) ::Fatal("AliTRDsegmentArrayBase::AliTRDsegmentArrayBase" | |
204 | ,"ROOT system not initialized"); | |
205 | ||
206 | fClass = gROOT->GetClass(classname); | |
207 | if (!fClass) { | |
208 | Error("AliTRDsegmentArrayBase","%s is not a valid class name",classname); | |
209 | return kFALSE; | |
210 | } | |
211 | if (!fClass->InheritsFrom(AliTRDsegmentID::Class())) { | |
212 | Error("AliTRDsegmentArrayBase" | |
213 | ,"%s does not inherit from AliTRDsegmentID",classname); | |
214 | return kFALSE; | |
215 | } | |
216 | ||
217 | return kTRUE; | |
218 | ||
219 | } | |
220 | ||
221 | //_____________________________________________________________________________ | |
222 | AliTRDsegmentID *AliTRDsegmentArrayBase::NewSegment() | |
223 | { | |
224 | // | |
225 | // Create a new object according to the class information | |
226 | // | |
227 | ||
228 | if (fClass == 0) return 0; | |
229 | ||
230 | AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New(); | |
231 | if (segment == 0) return 0; | |
232 | ||
233 | return segment; | |
234 | ||
235 | } | |
236 | ||
237 | //_____________________________________________________________________________ | |
238 | Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment) | |
239 | { | |
240 | // | |
241 | // Add a segment to the array | |
242 | // | |
243 | ||
244 | if (segment == 0) return kFALSE; | |
245 | if (fSegment == 0) return kFALSE; | |
246 | if (fClass == 0) return kFALSE; | |
247 | ||
248 | if (!(segment->IsA()->InheritsFrom(fClass))) { | |
249 | Error("AliTRDsegmentArrayBase","added class %s is not of proper type", | |
250 | segment->IsA()->GetName()); | |
251 | return kFALSE; | |
252 | } | |
253 | ||
254 | fSegment->AddAt(segment,segment->GetID()); | |
255 | fNSegment = fSegment->GetLast() + 1; | |
256 | ||
257 | return kTRUE; | |
258 | ||
259 | } | |
260 | ||
261 | //_____________________________________________________________________________ | |
262 | AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index) | |
263 | { | |
264 | // | |
265 | // Add a segment to the array | |
266 | // | |
267 | ||
268 | if (fSegment == 0) return 0; | |
269 | if (fClass == 0) return 0; | |
270 | ||
271 | AliTRDsegmentID *segment = NewSegment(); | |
272 | if (segment == 0) return 0; | |
273 | ||
274 | fSegment->AddAt(segment,index); | |
275 | segment->SetID(index); | |
276 | fNSegment = fSegment->GetLast() + 1; | |
277 | ||
278 | return segment; | |
279 | ||
280 | } | |
281 | ||
282 | //_____________________________________________________________________________ | |
283 | Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n) | |
284 | { | |
285 | // | |
286 | // Create an array of pointers to the segments | |
287 | // | |
288 | ||
289 | if (fSegment) { | |
290 | fSegment->Delete(); | |
291 | delete fSegment; | |
292 | } | |
293 | if (fTreeIndex) delete fTreeIndex; | |
294 | ||
295 | fSegment = new TObjArray(n); | |
296 | fTreeIndex = new AliTRDarrayI(); | |
297 | fTreeIndex->Set(n); | |
298 | fNSegment = n; | |
299 | if ((fSegment) && (fTreeIndex)) | |
300 | return kTRUE; | |
301 | else | |
302 | return kFALSE; | |
303 | ||
304 | } | |
305 | ||
306 | //_____________________________________________________________________________ | |
307 | void AliTRDsegmentArrayBase::ClearSegment(Int_t index) | |
308 | { | |
309 | // | |
310 | // Remove a segment from the active memory | |
311 | // | |
312 | ||
313 | //PH if ((*fSegment)[index]){ | |
314 | //PH delete (*fSegment)[index]; // because problem with deleting TClonesArray | |
315 | //PH fSegment->RemoveAt(index); | |
316 | //PH } | |
317 | if (fSegment->At(index)){ | |
318 | delete fSegment->RemoveAt(index); | |
319 | } | |
320 | ||
321 | } | |
322 | ||
323 | //_____________________________________________________________________________ | |
324 | void AliTRDsegmentArrayBase::MakeTree(char *file) | |
325 | { | |
326 | // | |
327 | // Create a tree for the segment | |
328 | // | |
329 | ||
330 | AliTRDsegmentID *psegment = NewSegment(); | |
331 | ||
332 | if (fTree) delete fTree; | |
333 | fTree = new TTree("Segment Tree","Tree with segments"); | |
334 | ||
335 | fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000); | |
336 | if (file) | |
337 | fBranch->SetFile(file); | |
338 | ||
339 | delete psegment; | |
340 | ||
341 | } | |
342 | ||
343 | //_____________________________________________________________________________ | |
344 | Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName) | |
345 | { | |
346 | // | |
347 | // Connect a tree from current directory | |
348 | // | |
349 | ||
350 | if (fTree){ | |
351 | delete fTree; | |
352 | fTree = 0; | |
353 | fBranch = 0; | |
354 | } | |
355 | ||
356 | fTree = (TTree*) gDirectory->Get(treeName); | |
357 | if (fTree == 0) return kFALSE; | |
358 | fBranch = fTree->GetBranch("Segment"); | |
359 | if (fBranch == 0) return kFALSE; | |
360 | ||
361 | MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries()))); | |
362 | ||
363 | return kTRUE; | |
364 | ||
365 | } | |
366 | ||
367 | //_____________________________________________________________________________ | |
368 | AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index) | |
369 | { | |
370 | // | |
371 | // Load a segment with index <index> into the memory | |
372 | // | |
373 | ||
374 | if (fTreeIndex == 0) MakeDictionary(3000); | |
375 | ||
376 | // First try to load dictionary | |
377 | if (fTreeIndex == 0) return 0; | |
378 | if (fBranch == 0) return 0; | |
379 | if (index > fTreeIndex->fN) return 0; | |
380 | //PH AliTRDsegmentID *s = (AliTRDsegmentID*) (*fSegment)[index]; | |
381 | AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index); | |
382 | if (s == 0) s = NewSegment(); | |
383 | s->SetID(index); | |
384 | ||
385 | if (s != 0) { | |
386 | Int_t treeIndex = (*fTreeIndex)[index]; | |
387 | if (treeIndex < 1) | |
388 | return 0; | |
389 | else | |
390 | treeIndex--; | |
391 | fBranch->SetAddress(&s); | |
392 | fTree->GetEvent(treeIndex); | |
393 | //PH (*fSegment)[index] = (TObject*) s; | |
394 | fSegment->AddAt((TObject*) s, index); | |
395 | } | |
396 | else | |
397 | return 0; | |
398 | ||
399 | return s; | |
400 | ||
401 | } | |
402 | ||
403 | //_____________________________________________________________________________ | |
404 | AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index) | |
405 | { | |
406 | // | |
407 | // Load a segment at position <index> in the tree into the memory | |
408 | // | |
409 | ||
410 | if (fBranch == 0) return 0; | |
411 | if (index > fTree->GetEntries()) return 0; | |
412 | ||
413 | AliTRDsegmentID *s = NewSegment(); | |
414 | if (s) { | |
415 | fBranch->SetAddress(&s); | |
416 | fTree->GetEvent(index); | |
417 | } | |
418 | else | |
419 | return 0; | |
420 | ||
421 | Int_t nindex = s->GetID(); | |
422 | ClearSegment(nindex); | |
423 | //PH (*fSegment)[nindex] = (TObject *) s; | |
424 | fSegment->AddAt((TObject *) s, nindex); | |
425 | ||
426 | return s; | |
427 | ||
428 | } | |
429 | ||
430 | //_____________________________________________________________________________ | |
431 | void AliTRDsegmentArrayBase::StoreSegment(Int_t index) | |
432 | { | |
433 | // | |
434 | // Make a segment persistent | |
435 | // | |
436 | ||
437 | const AliTRDsegmentID *kSegment = (*this)[index]; | |
438 | if (kSegment == 0) return; | |
439 | if (fTree == 0) MakeTree(); | |
440 | fBranch->SetAddress(&kSegment); | |
441 | fTree->Fill(); | |
442 | ||
443 | } | |
444 | ||
445 | //_____________________________________________________________________________ | |
446 | Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size) | |
447 | { | |
448 | // | |
449 | // Create an index table for the tree | |
450 | // | |
451 | ||
452 | if (size < 1) return kFALSE; | |
453 | if (fTreeIndex) delete fTreeIndex; | |
454 | ||
455 | fTreeIndex = new AliTRDarrayI(); | |
456 | fTreeIndex->Set(size); | |
457 | ||
458 | AliTRDsegmentID segment; | |
459 | AliTRDsegmentID *psegment = &segment; | |
460 | ||
461 | fBranch->SetAddress(&psegment); | |
462 | TBranch *brindix = fTree->GetBranch("fSegmentID"); | |
463 | ||
464 | Int_t nevent = (Int_t) fTree->GetEntries(); | |
465 | for (Int_t i = 0; i < nevent; i++){ | |
466 | brindix->GetEvent(i); | |
467 | Int_t treeIndex = segment.GetID(); | |
468 | if (fTreeIndex->fN < treeIndex) | |
469 | fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1); | |
470 | (*fTreeIndex)[treeIndex] = i + 1; | |
471 | } | |
472 | ||
473 | return kTRUE; | |
474 | ||
475 | } | |
476 | ||
477 | //_____________________________________________________________________________ | |
478 | const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const | |
479 | { | |
480 | // | |
481 | // Returns a segment with the given index <i> | |
482 | // | |
483 | ||
484 | if ((i < 0) || (i >= fNSegment)) return 0; | |
485 | return (AliTRDsegmentID *) fSegment->At(i); | |
486 | ||
487 | } | |
488 | ||
489 | //_____________________________________________________________________________ | |
490 | const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const | |
491 | { | |
492 | // | |
493 | // Returns a segment with the given index <i> | |
494 | // | |
495 | ||
496 | if ((i < 0) || (i >= fNSegment)) return 0; | |
497 | //PH return (AliTRDsegmentID *)((*fSegment)[i]); | |
498 | return (AliTRDsegmentID *) fSegment->At(i); | |
499 | ||
500 | } |