coverity defects fixed
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
CommitLineData
6f1e466d 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$ */
6f1e466d 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Manages the digits and the track dictionary in the form of //
b65e5048 21// TObjArray objects //
6f1e466d 22// //
23///////////////////////////////////////////////////////////////////////////////
6244debe 24
793ff80c 25#include <TTree.h>
77ad13f4 26
2745a409 27#include "AliLog.h"
77ad13f4 28
6f1e466d 29#include "AliTRDdigitsManager.h"
b65e5048 30#include "AliTRDarrayDictionary.h"
31#include "AliTRDarrayADC.h"
32#include "AliTRDarraySignal.h"
793ff80c 33#include "AliTRDdigit.h"
966f6939 34#include "AliTRDdigitsParam.h"
35#include "AliTRDSimParam.h"
793ff80c 36#include "AliTRDgeometry.h"
ca21baaa 37#include "AliTRDSignalIndex.h"
38
6f1e466d 39ClassImp(AliTRDdigitsManager)
40
41//_____________________________________________________________________________
793ff80c 42
43 // Number of track dictionary arrays
44 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
45
46//_____________________________________________________________________________
3d0c7d6d 47AliTRDdigitsManager::AliTRDdigitsManager(Bool_t rawRec)
2745a409 48 :TObject()
49 ,fEvent(0)
50 ,fTree(0)
b65e5048 51 ,fDigits(0)
625f5260 52 ,fHasSDigits(0)
ca21baaa 53 ,fSignalIndexes(NULL)
001be664 54 ,fUseDictionaries(kTRUE)
486c2339 55 ,fDets(AliTRDgeometry::Ndet())
3d0c7d6d 56 ,fRawRec(rawRec)
966f6939 57 ,fDigitsParam(0)
6f1e466d 58{
59 //
60 // Default constructor
61 //
486c2339 62
966f6939 63 if (fRawRec)
486c2339 64 {
966f6939 65 fDets = 1;
66 fRawRec = kTRUE;
486c2339 67 }
6f1e466d 68
b65e5048 69 for (Int_t iDict = 0; iDict < kNDict; iDict++)
70 {
71 fDict[iDict] = NULL;
966f6939 72 }
73
6f1e466d 74}
75
76//_____________________________________________________________________________
dd9a6ee3 77AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
2745a409 78 :TObject(m)
79 ,fEvent(m.fEvent)
80 ,fTree(0)
b65e5048 81 ,fDigits(0)
625f5260 82 ,fHasSDigits(m.fHasSDigits)
ca21baaa 83 ,fSignalIndexes(NULL)
001be664 84 ,fUseDictionaries(kTRUE)
486c2339 85 ,fDets(m.fDets)
86 ,fRawRec(m.fRawRec)
966f6939 87 ,fDigitsParam(NULL)
8230f242 88{
89 //
90 // AliTRDdigitsManager copy constructor
91 //
92
8230f242 93}
94
95//_____________________________________________________________________________
6f1e466d 96AliTRDdigitsManager::~AliTRDdigitsManager()
97{
8230f242 98 //
99 // AliTRDdigitsManager destructor
100 //
6f1e466d 101
b37bf997 102
b65e5048 103 if (fDigits)
104 {
105 fDigits->Delete();
106 delete fDigits;
107 fDigits = NULL;
108 }
6f1e466d 109
b65e5048 110 for (Int_t iDict = 0; iDict < kNDict; iDict++)
111 {
486c2339 112 if(fDict[iDict])
113 {
114 fDict[iDict]->Delete();
115 delete fDict[iDict];
116 fDict[iDict] = NULL;
117 }
b65e5048 118 }
6f1e466d 119
b65e5048 120 if (fSignalIndexes)
121 {
122 fSignalIndexes->Delete();
123 delete fSignalIndexes;
124 fSignalIndexes = NULL;
125 }
ca21baaa 126
966f6939 127 if (fDigitsParam)
128 {
129 delete fDigitsParam;
130 fDigitsParam = NULL;
131 }
132
6f1e466d 133}
134
135//_____________________________________________________________________________
2745a409 136AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
137{
138 //
139 // Assignment operator
140 //
141
b65e5048 142 if (this != &m)
143 {
144 ((AliTRDdigitsManager &) m).Copy(*this);
145 }
625f5260 146
2745a409 147 return *this;
148
149}
150
151//_____________________________________________________________________________
e0d47c25 152void AliTRDdigitsManager::Copy(TObject &m) const
8230f242 153{
154 //
155 // Copy function
156 //
157
625f5260 158 ((AliTRDdigitsManager &) m).fEvent = fEvent;
159 ((AliTRDdigitsManager &) m).fHasSDigits = fHasSDigits;
966f6939 160 ((AliTRDdigitsManager &) m).fDigits = NULL;
161 for(Int_t i = 0; i < kNDict; i++)
b65e5048 162 {
966f6939 163 ((AliTRDdigitsManager &) m).fDict[i] = NULL;
b65e5048 164 }
966f6939 165 ((AliTRDdigitsManager &) m).fSignalIndexes = NULL;
001be664 166 ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
486c2339 167 ((AliTRDdigitsManager &) m).fDets = fDets;
966f6939 168 ((AliTRDdigitsManager &) m).fRawRec = fRawRec;
169 ((AliTRDdigitsManager &) m).fDigitsParam = NULL;
001be664 170
8230f242 171 TObject::Copy(m);
172
173}
174
175//_____________________________________________________________________________
abaf1f1d 176void AliTRDdigitsManager::CreateArrays()
177{
178 //
179 // Create the data arrays
180 //
181
b65e5048 182 if (fHasSDigits)
183 {
966f6939 184 if (fDigits)
b65e5048 185 {
186 fDigits->Delete();
187 delete fDigits;
188 }
486c2339 189 fDigits = new TObjArray(fDets);
190 for (Int_t index = 0; index < fDets; index++)
966f6939 191 {
192 fDigits->AddAt(new AliTRDarraySignal(),index);
193 }
b65e5048 194 }
195 else
196 {
966f6939 197 if (fDigits)
b65e5048 198 {
199 fDigits->Delete();
200 delete fDigits;
201 }
486c2339 202 fDigits = new TObjArray(fDets);
966f6939 203 for (Int_t index = 0; index < fDets; index++)
204 {
205 fDigits->AddAt(new AliTRDarrayADC(),index);
206 }
b65e5048 207 }
208
209 if (fUseDictionaries)
210 {
b65e5048 211 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 212 {
213 if (fDict[iDict])
214 {
215 fDict[iDict]->Delete();
216 delete fDict[iDict];
217 }
218 fDict[iDict] = new TObjArray(fDets);
219 for (Int_t index = 0; index < fDets; index++)
220 {
221 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
222 }
223 }
001be664 224 }
486c2339 225
966f6939 226 if (fSignalIndexes)
b65e5048 227 {
486c2339 228 fSignalIndexes->Delete();
229 delete fSignalIndexes;
230 }
231 fSignalIndexes = new TObjArray(fDets);
966f6939 232 for (Int_t i = 0; i < fDets; i++)
233 {
234 fSignalIndexes->AddLast(new AliTRDSignalIndex());
235 }
236
237 if (fDigitsParam)
238 {
239 delete fDigitsParam;
240 }
241 fDigitsParam = new AliTRDdigitsParam();
abaf1f1d 242
243}
625f5260 244
17eee78a 245//_____________________________________________________________________________
534529cb 246void AliTRDdigitsManager::ClearArrays(Int_t det)
247{
248 //
249 // Reset the data arrays
250 //
251
252 Int_t recoDet = fRawRec ? 0 : det;
253
254 if (fHasSDigits)
255 {
256 ((AliTRDarraySignal*)fDigits->At(recoDet))->Reset();
257 }
258 else
259 {
260 ((AliTRDarrayADC*)fDigits->At(recoDet))->ConditionalReset((AliTRDSignalIndex*)fSignalIndexes->At(recoDet));
261 }
262
263 if (fUseDictionaries)
264 {
265 for (Int_t iDict = 0; iDict < kNDict; iDict++)
266 {
267 ((AliTRDarrayDictionary*)fDict[iDict]->At(recoDet))->Reset();
268 }
269 }
270
271 ((AliTRDSignalIndex*)fSignalIndexes->At(recoDet))->ResetContent();
272
273}
274
275//_____________________________________________________________________________
b65e5048 276Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
16bf9884 277{
278 //
279 // Returns the amplitude of a digit
280 //
281
486c2339 282 if (!GetDigits(det)) return 0;
b65e5048 283
da43c135 284 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
16bf9884 285
286}
b65e5048 287
16bf9884 288//_____________________________________________________________________________
b65e5048 289UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
d739fd4e 290{
c10bf383 291 //
292 // Returns the pad status for the requested pad
293 //
d739fd4e 294
486c2339 295 if (!GetDigits(det)) return 0;
d739fd4e 296
b65e5048 297 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
298
d739fd4e 299}
300
301//_____________________________________________________________________________
77ad13f4 302Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
855bfffd 303{
304 //
305 // Creates the tree and branches for the digits and the dictionary
306 //
307
b65e5048 308 Int_t buffersize = 64000;
309 Bool_t status = kTRUE;
855bfffd 310
b65e5048 311 if (tree)
312 {
313 fTree = tree;
314 }
855bfffd 315
abaf1f1d 316 // Make the branch for the digits
b65e5048 317 if (fDigits)
318 {
966f6939 319 if (fHasSDigits)
b65e5048 320 {
321 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
322 if (kDigits)
323 {
324 if (!fTree) return kFALSE;
325 AliDebug(1,"Making branch for SDigits!\n");
966f6939 326 TBranch *branch = fTree->GetBranch("TRDdigits");
327 if (!branch)
328 {
329 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
330 }
b65e5048 331 AliDebug(1,"Making branch TRDdigits\n");
332 }
333 else
334 {
335 status = kFALSE;
336 }
337 }
338
966f6939 339 if (!fHasSDigits)
b65e5048 340 {
341 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
342 if (kDigits)
343 {
344 if (!fTree) return kFALSE;
345 AliDebug(1,"Making branch for Digits!\n");
966f6939 346 TBranch *branch = fTree->GetBranch("TRDdigits");
347 if (!branch)
348 {
349 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
350 }
b65e5048 351 AliDebug(1,"Making branch TRDdigits\n");
352 }
353 else
354 {
355 status = kFALSE;
356 }
357 }
358
966f6939 359 }
b65e5048 360 else
361 {
966f6939 362
6f1e466d 363 status = kFALSE;
966f6939 364
6f1e466d 365 }
b65e5048 366
367 if (fUseDictionaries)
368 {
369 // Make the branches for the dictionaries
370 for (Int_t iDict = 0; iDict < kNDict; iDict++)
371 {
372 Char_t branchname[15];
373 sprintf(branchname,"TRDdictionary%d",iDict);
374 if (fDict[iDict])
375 {
376 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
377 if (kDictionary)
378 {
379 if (!fTree) return kFALSE;
380 AliDebug(2,"Making branch for dictionary!\n");
966f6939 381 TBranch *branch = fTree->GetBranch(branchname);
382 if (!branch)
383 {
384 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
385 }
b65e5048 386 AliDebug(1,Form("Making branch %s\n",branchname));
387 }
388 else
389 {
390 status = kFALSE;
391 }
392 }
393 else
394 {
395 status = kFALSE;
396 }
001be664 397 }
abaf1f1d 398 }
966f6939 399
400 if (fDigitsParam)
401 {
402 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
403 if (!fTree) return kFALSE;
404 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
405 if (!branch)
406 {
407 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
408 }
409 AliDebug(1,"Making branch AliTRDdigitsParam\n");
410 }
411
6f1e466d 412 return status;
413
414}
415
416//_____________________________________________________________________________
77ad13f4 417Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
6f1e466d 418{
8230f242 419 //
420 // Reads the digit information from the input file
421 //
6f1e466d 422
423 Bool_t status = kTRUE;
424
b65e5048 425 if (tree)
426 {
427 fTree = tree;
428 }
429
430 if (!fDigits)
431 {
432 AliDebug(1,"Create the data arrays.\n");
433 CreateArrays();
434 }
435
966f6939 436 status = LoadArrayDigits();
b65e5048 437
438 if (fUseDictionaries)
439 {
966f6939 440 status = LoadArrayDict();
441 if (status == kFALSE)
b65e5048 442 {
966f6939 443 fUseDictionaries = kFALSE;
444 AliWarning("Unable to load dict arrays. Will not use them.\n");
445 }
446 }
447
448 if (!LoadDigitsParam()) {
449 AliWarning("Could not read digits parameter.");
450 if (fDigitsParam) {
451 delete fDigitsParam;
b65e5048 452 }
966f6939 453 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
454 ,AliTRDSimParam::Instance()->GetNTimeBins()));
455 fDigitsParam = new AliTRDdigitsParam();
a0446ff1 456 fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
457 fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
966f6939 458 }
6f1e466d 459
966f6939 460 return status;
6f1e466d 461
462}
463
464//_____________________________________________________________________________
465Bool_t AliTRDdigitsManager::WriteDigits()
466{
467 //
5896bc23 468 // Writes out the TRD-digits, the dictionaries and the digitsPaam
6f1e466d 469 //
470
966f6939 471 if (!StoreArrayDigits())
b65e5048 472 {
966f6939 473 AliError("Error while storing digits\n");
b65e5048 474 return kFALSE;
6f1e466d 475 }
6f1e466d 476
b65e5048 477 if (fUseDictionaries)
478 {
966f6939 479 if (!StoreArrayDict())
b65e5048 480 {
966f6939 481 AliError("Error while storing dictionaries in branch\n");
482 return kFALSE;
b65e5048 483 }
484 }
5896bc23 485
486 if (!StoreDigitsParam())
487 {
488 AliError("Error while storing digitsParam\n");
489 return kFALSE;
490 }
b65e5048 491
abaf1f1d 492 // Write the new tree to the output file
b65e5048 493 fTree->AutoSave();
abaf1f1d 494
6f1e466d 495 return kTRUE;
496
497}
9d0b222b 498
499//_____________________________________________________________________________
b65e5048 500AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
501 , Int_t col
502 , Int_t time
503 , Int_t det) const
9d0b222b 504{
505 //
506 // Creates a single digit object
507 //
508
b65e5048 509 Int_t digits[4];
9d0b222b 510 Int_t amp[1];
511
512 digits[0] = det;
513 digits[1] = row;
514 digits[2] = col;
515 digits[3] = time;
516
b65e5048 517 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
9d0b222b 518
625f5260 519 return (new AliTRDdigit(digits,amp));
9d0b222b 520
521}
522
523//_____________________________________________________________________________
524Int_t AliTRDdigitsManager::GetTrack(Int_t track
b65e5048 525 , Int_t row
526 , Int_t col
527 , Int_t time
793ff80c 528 , Int_t det) const
9d0b222b 529{
530 //
531 // Returns the MC-track numbers from the dictionary.
532 //
533
b65e5048 534 if ((track < 0) || (track >= kNDict))
535 {
20a6e9c2 536 AliError(Form("track %d out of bounds (size: %d, this: 0x%p)",track,kNDict,this));
b65e5048 537 return -1;
538 }
9d0b222b 539
b65e5048 540 if (fUseDictionaries == kFALSE)
541 {
542 return -1;
543 }
625f5260 544
b65e5048 545 // Array contains index+1 to allow data compression--->Changed
546 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
9d0b222b 547
548}
549
b65e5048 550//________________________________________________________________________________
551AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 552{
553 //
554 // Returns the digits array for one detector
555 //
556
4f5f1ae2 557 Int_t recoDet = fRawRec ? 0 : det;
486c2339 558
b65e5048 559 if (!fDigits)
560 {
561 return 0x0;
562 }
625f5260 563
b65e5048 564 if (!fHasSDigits)
565 {
4f5f1ae2 566 ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
567 return (AliTRDarrayADC *) fDigits->At(recoDet);
b65e5048 568 }
569 else
570 {
571 AliDebug(2,"ERROR IN DATA TYPE!!!!");
572 return 0x0;
573 }
dd9a6ee3 574
575}
576
577//_____________________________________________________________________________
b65e5048 578AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
dd9a6ee3 579{
580 //
b65e5048 581 // Returns the sdigits array for one detector
dd9a6ee3 582 //
583
4f5f1ae2 584 Int_t recoDet = fRawRec ? 0 : det;
486c2339 585
b65e5048 586 if (!fDigits)
587 {
588 // AliDebug(1,"NO FDIGITS!");
589 return 0x0;
590 }
591
592 if (fHasSDigits)
593 {
4f5f1ae2 594 ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
595 return (AliTRDarraySignal *) fDigits->At(recoDet);
b65e5048 596 }
597 else
598 {
599 AliDebug(2,"ERROR IN DATA TYPE!!!!");
600 return 0x0;
601 }
602
603}
604
605//_____________________________________________________________________________
606AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
607 , Int_t i) const
608{
609 //
610 // Returns the dictionary for one detector
611 //
625f5260 612
4f5f1ae2 613 Int_t recoDet = fRawRec ? 0 : det;
486c2339 614
b65e5048 615 if (fUseDictionaries == kFALSE)
616 {
617 return 0x0;
618 }
dd9a6ee3 619
4f5f1ae2 620 ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
621 return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
b65e5048 622
dd9a6ee3 623}
624
625//_____________________________________________________________________________
77ad13f4 626Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
dd9a6ee3 627{
628 //
629 // Returns the MC-track numbers from the dictionary for a given digit
630 //
631
b65e5048 632 Int_t row = digit->GetRow();
633 Int_t col = digit->GetCol();
634 Int_t time = digit->GetTime();
635 Int_t det = digit->GetDetector();
dd9a6ee3 636
637 return GetTrack(track,row,col,time,det);
638
639}
ca21baaa 640
641//_____________________________________________________________________________
642AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
643{
644 //
645 // Returns indexes of active pads
646 //
647
4f5f1ae2 648 Int_t recoDet = fRawRec ? 0 : det;
486c2339 649
4f5f1ae2 650 return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
ca21baaa 651
652}
653
654//_____________________________________________________________________________
655void AliTRDdigitsManager::RemoveDigits(Int_t det)
656{
b65e5048 657 //
658 // Clear memory at det for Digits
659 //
ca21baaa 660
4f5f1ae2 661 Int_t recoDet = fRawRec ? 0 : det;
486c2339 662
4f5f1ae2 663 if (fDigits->At(recoDet))
b65e5048 664 {
b37bf997 665 if (fHasSDigits)
666 {
4f5f1ae2 667 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
b37bf997 668 delete arr;
669 }
670 else
671 {
4f5f1ae2 672 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(recoDet);
b37bf997 673 delete arr;
674 }
b65e5048 675 }
ca21baaa 676
677}
678
679//_____________________________________________________________________________
680void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
681{
682 //
683 // Clear memory
684 //
625f5260 685
4f5f1ae2 686 Int_t recoDet = fRawRec ? 0 : det;
486c2339 687
b65e5048 688 if (fUseDictionaries == kFALSE)
689 {
690 return;
691 }
ca21baaa 692
b65e5048 693 for (Int_t i = 0; i < kNDict; i++)
694 {
4f5f1ae2 695 if (fDict[i]->At(recoDet))
b65e5048 696 {
4f5f1ae2 697 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
b37bf997 698 delete arr;
b65e5048 699 }
700 }
ca21baaa 701
702}
703
704//_____________________________________________________________________________
486c2339 705void AliTRDdigitsManager::RemoveIndexes(Int_t det)
706{
707 //
708 // Clear memory
709 //
710
4f5f1ae2 711 Int_t recoDet = fRawRec ? 0 : det;
486c2339 712
4f5f1ae2 713 if (fSignalIndexes->At(recoDet))
486c2339 714 {
4f5f1ae2 715 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(recoDet);
486c2339 716 delete arr;
717 }
718
719}
720
486c2339 721//_____________________________________________________________________________
ca21baaa 722void AliTRDdigitsManager::ClearIndexes(Int_t det)
723{
724 //
725 // Clear memory
726 //
486c2339 727
4f5f1ae2 728 Int_t recoDet = fRawRec ? 0 : det;
625f5260 729
4f5f1ae2 730 ((AliTRDSignalIndex *) fSignalIndexes->At(recoDet))->ClearAll();
ca21baaa 731
625f5260 732}
ca21baaa 733
734//_____________________________________________________________________________
735Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
736{
737 //
738 // Build the list of indices
739 //
740
b65e5048 741 Int_t nRows = 0;
742 Int_t nCols = 0;
ca21baaa 743 Int_t nTbins = 0;
744
b65e5048 745 AliTRDgeometry geom;
746 AliTRDarrayADC *digits = 0x0;
625f5260 747
b65e5048 748 if (fHasSDigits)
749 {
750 return kFALSE;
751 }
752 else
753 {
754 digits = (AliTRDarrayADC *) GetDigits(det);
755 }
625f5260 756
966f6939 757 // digits should be expanded by now!!!
b65e5048 758 if (digits->GetNtime() > 0)
759 {
760 digits->Expand();
761 nRows = digits->GetNrow();
762 nCols = digits->GetNcol();
763 nTbins = digits->GetNtime();
764
765 AliTRDSignalIndex *indexes = GetIndexes(det);
766 indexes->SetSM(geom.GetSector(det));
767 indexes->SetStack(geom.GetStack(det));
768 indexes->SetLayer(geom.GetLayer(det));
769 indexes->SetDetNumber(det);
770
771 if (indexes->IsAllocated() == kFALSE)
772 {
773 indexes->Allocate(nRows,nCols,nTbins);
774 }
625f5260 775
b65e5048 776 for (Int_t ir = 0; ir < nRows; ir++)
777 {
778 for (Int_t ic = 0; ic < nCols; ic++)
779 {
780 for (Int_t it = 0; it < nTbins; it++)
781 {
da43c135 782 Int_t isig = digits->GetDataBits(ir,ic,it);
b65e5048 783 if (isig > 0)
784 {
ae63fafc 785 indexes->AddIndexRC(ir,ic);
b65e5048 786 }
787 } // tbins
788 } // cols
789 } // rows
790
791 } // if GetNtime
792 else
793 {
794 return kFALSE;
795 }
796
797 return kTRUE;
625f5260 798
b65e5048 799}
625f5260 800
b65e5048 801//_____________________________________________________________________________
966f6939 802Bool_t AliTRDdigitsManager::LoadArrayDigits()
b65e5048 803{
804 //
966f6939 805 // Loads the (s-)digits arrays for all detectors
b65e5048 806 //
807
966f6939 808 if (!fTree)
b65e5048 809 {
810 AliError("Digits tree is not defined\n");
811 return kFALSE;
ca21baaa 812 }
625f5260 813
966f6939 814 Bool_t status = kTRUE;
815
b65e5048 816 // Get the branch
966f6939 817 TBranch *branch = fTree->GetBranch("TRDdigits");
818 if (!branch)
b65e5048 819 {
966f6939 820 AliError("Branch TRDdigits is not defined\n");
b65e5048 821 return kFALSE;
822 }
625f5260 823
b65e5048 824 // Loop through all detectors and read them from the tree
486c2339 825 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 826 {
966f6939 827 if (fHasSDigits)
b65e5048 828 {
966f6939 829 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 830 if (!dataArray)
831 {
832 status = kFALSE;
833 break;
834 }
966f6939 835 branch->SetAddress(&dataArray);
836 branch->GetEntry(iDet);
b65e5048 837 }
838 else
839 {
966f6939 840 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 841 if (!dataArray)
842 {
843 status = kFALSE;
966f6939 844 break;
b65e5048 845 }
966f6939 846 branch->SetAddress(&dataArray);
847 branch->GetEntry(iDet);
b65e5048 848 }
849 }
625f5260 850
b65e5048 851 return status;
852
853}
854
855//________________________________________________________________________________________________
966f6939 856Bool_t AliTRDdigitsManager::LoadArrayDict()
b65e5048 857{
858 //
966f6939 859 // Loads dictionary arrays for all detectors
b65e5048 860 //
861
966f6939 862 if (!fTree)
863 {
864 AliError("Digits tree is not defined\n");
865 return kFALSE;
866 }
867
868 Bool_t status = kTRUE;
869
870 for (Int_t iDict = 0; iDict < kNDict; iDict++)
871 {
872
873 // Get the branch
874 Char_t branchname[15];
875 sprintf(branchname,"TRDdictionary%d",iDict);
876 TBranch *branch = fTree->GetBranch(branchname);
877 if (!branch)
878 {
879 AliError(Form("Branch %s is not defined\n",branchname));
880 return kFALSE;
881 }
882
883 // Loop through all detectors and read them from the tree
884 for (Int_t iDet = 0; iDet < fDets; iDet++)
885 {
886 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
887 if (!dataArray)
888 {
889 status = kFALSE;
890 break;
891 }
892 branch->SetAddress(&dataArray);
893 branch->GetEntry(iDet);
894 }
895
896 }
897
898 return status;
899
900}
901
902//_____________________________________________________________________________
903Bool_t AliTRDdigitsManager::LoadDigitsParam()
904{
905 //
906 // Loads the digits parameter object from the digits tree
907 //
b65e5048 908
966f6939 909 if (!fTree)
b65e5048 910 {
911 AliError("Digits tree is not defined\n");
912 return kFALSE;
913 }
914
915 // Get the branch
966f6939 916 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
917 if (!branch)
b65e5048 918 {
966f6939 919 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 920 return kFALSE;
921 }
922
966f6939 923 // Read the parameter object
924 AliTRDdigitsParam *digitsParam = fDigitsParam;
925 if (!digitsParam)
b65e5048 926 {
966f6939 927 return kFALSE;
b65e5048 928 }
929
966f6939 930 branch->SetAddress(&digitsParam);
931 branch->GetEntry();
932
933 return kTRUE;
b65e5048 934
935}
936
937//_____________________________________________________________________________
966f6939 938Bool_t AliTRDdigitsManager::StoreArrayDigits()
b65e5048 939{
940 //
966f6939 941 // Stores the digit arrays for all detectors
b65e5048 942 //
943
b65e5048 944 if (!fTree)
945 {
946 AliError("Digits tree is not defined\n");
947 return kFALSE;
948 }
949
950 // Get the branch
966f6939 951 TBranch *branch = fTree->GetBranch("TRDdigits");
952 if (!branch)
b65e5048 953 {
966f6939 954 AliError("Branch TRDdigits is not defined\n");
b65e5048 955 return kFALSE;
956 }
957
958 // Loop through all detectors and fill them into the tree
959 Bool_t status = kTRUE;
486c2339 960 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 961 {
962 if (fHasSDigits)
963 {
966f6939 964 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 965 if (!kDataArray)
966 {
967 status = kFALSE;
968 break;
969 }
966f6939 970 branch->SetAddress(&kDataArray);
971 branch->Fill();
b65e5048 972 }
973 else
974 {
966f6939 975 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 976 if (!kDataArray)
977 {
978 status = kFALSE;
979 break;
980 }
966f6939 981 branch->SetAddress(&kDataArray);
982 branch->Fill();
b65e5048 983 }
984 }
985
986 return status;
987
988}
989
990//_____________________________________________________________________________
966f6939 991Bool_t AliTRDdigitsManager::StoreArrayDict()
b65e5048 992{
993 //
966f6939 994 // Stores the dictionary arrays for all detectors
b65e5048 995 //
996
966f6939 997 if (!fTree)
998 {
999 AliError("Digits tree is not defined\n");
1000 return kFALSE;
1001 }
1002
1003 Bool_t status = kTRUE;
1004
1005 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1006 {
1007
1008 // Get the branch
1009 Char_t branchname[15];
1010 sprintf(branchname,"TRDdictionary%d",iDict);
1011 TBranch *branch = fTree->GetBranch(branchname);
1012 if (!branch)
1013 {
1014 AliError(Form("Branch %s is not defined\n",branchname));
1015 return kFALSE;
1016 }
1017
1018 // Loop through all detectors and fill them into the tree
1019 for (Int_t iDet = 0; iDet < fDets; iDet++)
1020 {
1021 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1022 if (!kDataArray)
1023 {
1024 status = kFALSE;
1025 break;
1026 }
1027 branch->SetAddress(&kDataArray);
1028 branch->Fill();
1029 }
1030
1031 }
1032
1033 return status;
1034
1035}
1036
1037//_____________________________________________________________________________
1038Bool_t AliTRDdigitsManager::StoreDigitsParam()
1039{
1040 //
1041 // Stores the digits parameter object from the digits tree
1042 //
b65e5048 1043
1044 if (!fTree)
1045 {
1046 AliError("Digits tree is not defined\n");
1047 return kFALSE;
1048 }
1049
1050 // Get the branch
966f6939 1051 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1052 if (!branch)
b65e5048 1053 {
966f6939 1054 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 1055 return kFALSE;
1056 }
1057
966f6939 1058 // Fill the digits object in the tree
1059 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1060 if (!kDigitsParam)
b65e5048 1061 {
966f6939 1062 return kFALSE;
b65e5048 1063 }
966f6939 1064 branch->SetAddress(&kDigitsParam);
1065 branch->Fill();
b65e5048 1066
966f6939 1067 return kTRUE;
ca21baaa 1068
1069}
966f6939 1070