]>
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 | ||
190 | if (fClass == 0) return 0; | |
191 | ||
192 | AliTRDsegmentID *segment = (AliTRDsegmentID *) fClass->New(); | |
8230f242 | 193 | |
2745a409 | 194 | if (segment == 0) { |
195 | return 0; | |
196 | } | |
197 | else { | |
198 | return segment; | |
199 | } | |
8230f242 | 200 | |
f7336fa3 | 201 | } |
202 | ||
6f1e466d | 203 | //_____________________________________________________________________________ |
f7336fa3 | 204 | Bool_t AliTRDsegmentArrayBase::AddSegment(AliTRDsegmentID *segment) |
205 | { | |
206 | // | |
8230f242 | 207 | // Add a segment to the array |
f7336fa3 | 208 | // |
8230f242 | 209 | |
210 | if (segment == 0) return kFALSE; | |
211 | if (fSegment == 0) return kFALSE; | |
212 | if (fClass == 0) return kFALSE; | |
213 | ||
214 | if (!(segment->IsA()->InheritsFrom(fClass))) { | |
2745a409 | 215 | AliError(Form("added class %s is not of proper type" |
216 | ,segment->IsA()->GetName())); | |
8230f242 | 217 | return kFALSE; |
f7336fa3 | 218 | } |
8230f242 | 219 | |
f7336fa3 | 220 | fSegment->AddAt(segment,segment->GetID()); |
8230f242 | 221 | fNSegment = fSegment->GetLast() + 1; |
222 | ||
f7336fa3 | 223 | return kTRUE; |
8230f242 | 224 | |
f7336fa3 | 225 | } |
226 | ||
6f1e466d | 227 | //_____________________________________________________________________________ |
f7336fa3 | 228 | AliTRDsegmentID * AliTRDsegmentArrayBase::AddSegment(Int_t index) |
229 | { | |
230 | // | |
8230f242 | 231 | // Add a segment to the array |
f7336fa3 | 232 | // |
8230f242 | 233 | |
234 | if (fSegment == 0) return 0; | |
235 | if (fClass == 0) return 0; | |
236 | ||
237 | AliTRDsegmentID *segment = NewSegment(); | |
238 | if (segment == 0) return 0; | |
239 | ||
f7336fa3 | 240 | fSegment->AddAt(segment,index); |
241 | segment->SetID(index); | |
8230f242 | 242 | fNSegment = fSegment->GetLast() + 1; |
243 | ||
f7336fa3 | 244 | return segment; |
8230f242 | 245 | |
f7336fa3 | 246 | } |
247 | ||
6f1e466d | 248 | //_____________________________________________________________________________ |
f7336fa3 | 249 | Bool_t AliTRDsegmentArrayBase::MakeArray(Int_t n) |
250 | { | |
251 | // | |
8230f242 | 252 | // Create an array of pointers to the segments |
f7336fa3 | 253 | // |
8230f242 | 254 | |
f7336fa3 | 255 | if (fSegment) { |
256 | fSegment->Delete(); | |
257 | delete fSegment; | |
258 | } | |
8230f242 | 259 | if (fTreeIndex) delete fTreeIndex; |
260 | ||
261 | fSegment = new TObjArray(n); | |
fa6b9ac3 | 262 | fTreeIndex = new AliTRDarrayI(); |
f7336fa3 | 263 | fTreeIndex->Set(n); |
8230f242 | 264 | fNSegment = n; |
2745a409 | 265 | if ((fSegment) && (fTreeIndex)) { |
8230f242 | 266 | return kTRUE; |
2745a409 | 267 | } |
268 | else { | |
8230f242 | 269 | return kFALSE; |
2745a409 | 270 | } |
8230f242 | 271 | |
f7336fa3 | 272 | } |
273 | ||
6f1e466d | 274 | //_____________________________________________________________________________ |
f7336fa3 | 275 | void AliTRDsegmentArrayBase::ClearSegment(Int_t index) |
276 | { | |
277 | // | |
8230f242 | 278 | // Remove a segment from the active memory |
f7336fa3 | 279 | // |
8230f242 | 280 | |
2745a409 | 281 | if (fSegment->At(index)) { |
350743f0 | 282 | delete fSegment->RemoveAt(index); |
f7336fa3 | 283 | } |
8230f242 | 284 | |
f7336fa3 | 285 | } |
286 | ||
6f1e466d | 287 | //_____________________________________________________________________________ |
2ab0c725 | 288 | void AliTRDsegmentArrayBase::MakeTree(char *file) |
f7336fa3 | 289 | { |
8230f242 | 290 | // |
291 | // Create a tree for the segment | |
292 | // | |
293 | ||
294 | AliTRDsegmentID *psegment = NewSegment(); | |
295 | ||
f7336fa3 | 296 | if (fTree) delete fTree; |
8230f242 | 297 | fTree = new TTree("Segment Tree","Tree with segments"); |
298 | ||
d0f40f23 | 299 | fBranch = fTree->Branch("Segment",psegment->IsA()->GetName(),&psegment,64000); |
2745a409 | 300 | if (file) { |
301 | fBranch->SetFile(file); | |
302 | } | |
8230f242 | 303 | |
f7336fa3 | 304 | delete psegment; |
8230f242 | 305 | |
f7336fa3 | 306 | } |
307 | ||
6f1e466d | 308 | //_____________________________________________________________________________ |
f7336fa3 | 309 | Bool_t AliTRDsegmentArrayBase::ConnectTree(const char * treeName) |
310 | { | |
8230f242 | 311 | // |
312 | // Connect a tree from current directory | |
313 | // | |
314 | ||
2745a409 | 315 | if (fTree) { |
f7336fa3 | 316 | delete fTree; |
8230f242 | 317 | fTree = 0; |
f7336fa3 | 318 | fBranch = 0; |
319 | } | |
8230f242 | 320 | |
321 | fTree = (TTree*) gDirectory->Get(treeName); | |
322 | if (fTree == 0) return kFALSE; | |
f7336fa3 | 323 | fBranch = fTree->GetBranch("Segment"); |
8230f242 | 324 | if (fBranch == 0) return kFALSE; |
325 | ||
f7336fa3 | 326 | MakeDictionary(TMath::Max(fNSegment,Int_t(fTree->GetEntries()))); |
8230f242 | 327 | |
f7336fa3 | 328 | return kTRUE; |
8230f242 | 329 | |
f7336fa3 | 330 | } |
331 | ||
6f1e466d | 332 | //_____________________________________________________________________________ |
f7336fa3 | 333 | AliTRDsegmentID *AliTRDsegmentArrayBase::LoadSegment(Int_t index) |
334 | { | |
335 | // | |
8230f242 | 336 | // Load a segment with index <index> into the memory |
f7336fa3 | 337 | // |
8230f242 | 338 | |
339 | if (fTreeIndex == 0) MakeDictionary(3000); | |
340 | ||
341 | // First try to load dictionary | |
342 | if (fTreeIndex == 0) return 0; | |
343 | if (fBranch == 0) return 0; | |
344 | if (index > fTreeIndex->fN) return 0; | |
2745a409 | 345 | |
350743f0 | 346 | AliTRDsegmentID *s = (AliTRDsegmentID*) fSegment->At(index); |
8230f242 | 347 | if (s == 0) s = NewSegment(); |
f7336fa3 | 348 | s->SetID(index); |
f7336fa3 | 349 | |
8230f242 | 350 | if (s != 0) { |
351 | Int_t treeIndex = (*fTreeIndex)[index]; | |
2745a409 | 352 | if (treeIndex < 1) { |
8230f242 | 353 | return 0; |
2745a409 | 354 | } |
355 | else { | |
356 | treeIndex--; | |
357 | } | |
f7336fa3 | 358 | fBranch->SetAddress(&s); |
359 | fTree->GetEvent(treeIndex); | |
350743f0 | 360 | fSegment->AddAt((TObject*) s, index); |
f7336fa3 | 361 | } |
2745a409 | 362 | else { |
f7336fa3 | 363 | return 0; |
2745a409 | 364 | } |
8230f242 | 365 | |
f7336fa3 | 366 | return s; |
8230f242 | 367 | |
f7336fa3 | 368 | } |
6f1e466d | 369 | |
370 | //_____________________________________________________________________________ | |
f7336fa3 | 371 | AliTRDsegmentID *AliTRDsegmentArrayBase::LoadEntry(Int_t index) |
372 | { | |
373 | // | |
8230f242 | 374 | // Load a segment at position <index> in the tree into the memory |
f7336fa3 | 375 | // |
8230f242 | 376 | |
377 | if (fBranch == 0) return 0; | |
378 | if (index > fTree->GetEntries()) return 0; | |
379 | ||
380 | AliTRDsegmentID *s = NewSegment(); | |
f7336fa3 | 381 | if (s) { |
382 | fBranch->SetAddress(&s); | |
383 | fTree->GetEvent(index); | |
384 | } | |
2745a409 | 385 | else { |
f7336fa3 | 386 | return 0; |
2745a409 | 387 | } |
8230f242 | 388 | |
f7336fa3 | 389 | Int_t nindex = s->GetID(); |
390 | ClearSegment(nindex); | |
350743f0 | 391 | fSegment->AddAt((TObject *) s, nindex); |
8230f242 | 392 | |
f7336fa3 | 393 | return s; |
8230f242 | 394 | |
f7336fa3 | 395 | } |
396 | ||
8230f242 | 397 | //_____________________________________________________________________________ |
f7336fa3 | 398 | void AliTRDsegmentArrayBase::StoreSegment(Int_t index) |
399 | { | |
400 | // | |
8230f242 | 401 | // Make a segment persistent |
f7336fa3 | 402 | // |
8230f242 | 403 | |
404 | const AliTRDsegmentID *kSegment = (*this)[index]; | |
405 | if (kSegment == 0) return; | |
406 | if (fTree == 0) MakeTree(); | |
407 | fBranch->SetAddress(&kSegment); | |
f7336fa3 | 408 | fTree->Fill(); |
8230f242 | 409 | |
f7336fa3 | 410 | } |
411 | ||
6f1e466d | 412 | //_____________________________________________________________________________ |
f7336fa3 | 413 | Bool_t AliTRDsegmentArrayBase::MakeDictionary(Int_t size) |
414 | { | |
415 | // | |
8230f242 | 416 | // Create an index table for the tree |
f7336fa3 | 417 | // |
8230f242 | 418 | |
419 | if (size < 1) return kFALSE; | |
f7336fa3 | 420 | if (fTreeIndex) delete fTreeIndex; |
8230f242 | 421 | |
f7336fa3 | 422 | fTreeIndex = new AliTRDarrayI(); |
423 | fTreeIndex->Set(size); | |
424 | ||
8230f242 | 425 | AliTRDsegmentID segment; |
426 | AliTRDsegmentID *psegment = &segment; | |
427 | ||
f7336fa3 | 428 | fBranch->SetAddress(&psegment); |
8230f242 | 429 | TBranch *brindix = fTree->GetBranch("fSegmentID"); |
430 | ||
431 | Int_t nevent = (Int_t) fTree->GetEntries(); | |
432 | for (Int_t i = 0; i < nevent; i++){ | |
f7336fa3 | 433 | brindix->GetEvent(i); |
8230f242 | 434 | Int_t treeIndex = segment.GetID(); |
435 | if (fTreeIndex->fN < treeIndex) | |
436 | fTreeIndex->Expand(Int_t (Float_t(treeIndex) * 1.5) + 1); | |
437 | (*fTreeIndex)[treeIndex] = i + 1; | |
f7336fa3 | 438 | } |
8230f242 | 439 | |
f7336fa3 | 440 | return kTRUE; |
8230f242 | 441 | |
f7336fa3 | 442 | } |
9d0b222b | 443 | |
444 | //_____________________________________________________________________________ | |
0a29d0f1 | 445 | const AliTRDsegmentID * AliTRDsegmentArrayBase::operator[](Int_t i) const |
9d0b222b | 446 | { |
447 | // | |
8230f242 | 448 | // Returns a segment with the given index <i> |
9d0b222b | 449 | // |
8230f242 | 450 | |
451 | if ((i < 0) || (i >= fNSegment)) return 0; | |
452 | return (AliTRDsegmentID *) fSegment->At(i); | |
453 | ||
9d0b222b | 454 | } |
455 | ||
456 | //_____________________________________________________________________________ | |
793ff80c | 457 | const AliTRDsegmentID *AliTRDsegmentArrayBase::At(Int_t i) const |
9d0b222b | 458 | { |
459 | // | |
8230f242 | 460 | // Returns a segment with the given index <i> |
9d0b222b | 461 | // |
8230f242 | 462 | |
463 | if ((i < 0) || (i >= fNSegment)) return 0; | |
350743f0 | 464 | return (AliTRDsegmentID *) fSegment->At(i); |
8230f242 | 465 | |
9d0b222b | 466 | } |