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