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