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