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