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