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