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