Introduce the digits parameter class which is supposed to store digits information...
[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();
242 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
abaf1f1d 243
244}
625f5260 245
17eee78a 246//_____________________________________________________________________________
247void AliTRDdigitsManager::ResetArrays()
248{
249 //
250 // Reset the data arrays
251 //
252
486c2339 253 if (fDigits)
b65e5048 254 {
255 fDigits->Delete();
256 delete fDigits;
257 }
b65e5048 258 if (fHasSDigits)
259 {
486c2339 260 fDigits = new TObjArray(fDets);
261 for (Int_t index = 0; index < fDets; index++)
966f6939 262 {
263 fDigits->AddAt(new AliTRDarraySignal(),index);
264 }
b65e5048 265 }
486c2339 266 else
267 {
268 fDigits = new TObjArray(fDets);
269 for (Int_t index = 0; index < fDets; index++)
966f6939 270 {
271 fDigits->AddAt(new AliTRDarrayADC(),index);
272 }
486c2339 273 }
274
275 for (Int_t iDict = 0; iDict < kNDict; iDict++)
b65e5048 276 {
486c2339 277 if (fDict[iDict])
b65e5048 278 {
486c2339 279 fDict[iDict]->Delete();
280 delete fDict[iDict];
966f6939 281 fDict[iDict] = NULL;
b65e5048 282 }
283 }
b65e5048 284 if (fUseDictionaries)
285 {
b65e5048 286 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 287 {
288 fDict[iDict] = new TObjArray(fDets);
289 for (Int_t index = 0; index < fDets; index++)
290 {
291 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),index);
292 }
293 }
b65e5048 294 }
486c2339 295
966f6939 296 if (fSignalIndexes)
b65e5048 297 {
486c2339 298 fSignalIndexes->Delete();
299 delete fSignalIndexes;
b65e5048 300 }
486c2339 301 fSignalIndexes = new TObjArray(fDets);
302 for (Int_t i = 0; i < fDets; i++)
966f6939 303 {
304 fSignalIndexes->AddLast(new AliTRDSignalIndex());
305 }
306
486c2339 307}
308
309//_____________________________________________________________________________
310void AliTRDdigitsManager::ResetArrays(Int_t det)
311{
a4c334b6 312 //
313 // Reset the data arrays
314 //
486c2339 315
77ad13f4 316 Int_t recoDet = fRawRec ? 0 : det;
317
318 RemoveDigits(recoDet);
319 RemoveDictionaries(recoDet);
320 RemoveIndexes(recoDet);
486c2339 321
322 if (fHasSDigits)
966f6939 323 {
324 fDigits->AddAt(new AliTRDarraySignal(),recoDet);
325 }
486c2339 326 else
966f6939 327 {
328 fDigits->AddAt(new AliTRDarrayADC(),recoDet);
329 }
6f1e466d 330
486c2339 331 if (fUseDictionaries)
332 {
333 for (Int_t iDict = 0; iDict < kNDict; iDict++)
966f6939 334 {
335 fDict[iDict]->AddAt(new AliTRDarrayDictionary(),recoDet);
336 }
486c2339 337 }
338
77ad13f4 339 fSignalIndexes->AddAt(new AliTRDSignalIndex(),recoDet);
966f6939 340
6f1e466d 341}
342
343//_____________________________________________________________________________
b65e5048 344Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
16bf9884 345{
346 //
347 // Returns the amplitude of a digit
348 //
349
486c2339 350 if (!GetDigits(det)) return 0;
b65e5048 351
da43c135 352 return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
16bf9884 353
354}
b65e5048 355
16bf9884 356//_____________________________________________________________________________
b65e5048 357UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
d739fd4e 358{
c10bf383 359 //
360 // Returns the pad status for the requested pad
361 //
d739fd4e 362
486c2339 363 if (!GetDigits(det)) return 0;
d739fd4e 364
b65e5048 365 return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
366
d739fd4e 367}
368
369//_____________________________________________________________________________
77ad13f4 370Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)
855bfffd 371{
372 //
373 // Creates the tree and branches for the digits and the dictionary
374 //
375
b65e5048 376 Int_t buffersize = 64000;
377 Bool_t status = kTRUE;
855bfffd 378
b65e5048 379 if (tree)
380 {
381 fTree = tree;
382 }
855bfffd 383
abaf1f1d 384 // Make the branch for the digits
b65e5048 385 if (fDigits)
386 {
966f6939 387 if (fHasSDigits)
b65e5048 388 {
389 const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0);
390 if (kDigits)
391 {
392 if (!fTree) return kFALSE;
393 AliDebug(1,"Making branch for SDigits!\n");
966f6939 394 TBranch *branch = fTree->GetBranch("TRDdigits");
395 if (!branch)
396 {
397 fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
398 }
b65e5048 399 AliDebug(1,"Making branch TRDdigits\n");
400 }
401 else
402 {
403 status = kFALSE;
404 }
405 }
406
966f6939 407 if (!fHasSDigits)
b65e5048 408 {
409 const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
410 if (kDigits)
411 {
412 if (!fTree) return kFALSE;
413 AliDebug(1,"Making branch for Digits!\n");
966f6939 414 TBranch *branch = fTree->GetBranch("TRDdigits");
415 if (!branch)
416 {
417 fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
418 }
b65e5048 419 AliDebug(1,"Making branch TRDdigits\n");
420 }
421 else
422 {
423 status = kFALSE;
424 }
425 }
426
966f6939 427 }
b65e5048 428 else
429 {
966f6939 430
6f1e466d 431 status = kFALSE;
966f6939 432
6f1e466d 433 }
b65e5048 434
435 if (fUseDictionaries)
436 {
437 // Make the branches for the dictionaries
438 for (Int_t iDict = 0; iDict < kNDict; iDict++)
439 {
440 Char_t branchname[15];
441 sprintf(branchname,"TRDdictionary%d",iDict);
442 if (fDict[iDict])
443 {
444 const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
445 if (kDictionary)
446 {
447 if (!fTree) return kFALSE;
448 AliDebug(2,"Making branch for dictionary!\n");
966f6939 449 TBranch *branch = fTree->GetBranch(branchname);
450 if (!branch)
451 {
452 fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
453 }
b65e5048 454 AliDebug(1,Form("Making branch %s\n",branchname));
455 }
456 else
457 {
458 status = kFALSE;
459 }
460 }
461 else
462 {
463 status = kFALSE;
464 }
001be664 465 }
abaf1f1d 466 }
966f6939 467
468 if (fDigitsParam)
469 {
470 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
471 if (!fTree) return kFALSE;
472 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
473 if (!branch)
474 {
475 fTree->Branch("TRDdigitsParam","AliTRDdigitsParam",&kDigitsParam,buffersize,99);
476 }
477 AliDebug(1,"Making branch AliTRDdigitsParam\n");
478 }
479
6f1e466d 480 return status;
481
482}
483
484//_____________________________________________________________________________
77ad13f4 485Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
6f1e466d 486{
8230f242 487 //
488 // Reads the digit information from the input file
489 //
6f1e466d 490
491 Bool_t status = kTRUE;
492
b65e5048 493 if (tree)
494 {
495 fTree = tree;
496 }
497
498 if (!fDigits)
499 {
500 AliDebug(1,"Create the data arrays.\n");
501 CreateArrays();
502 }
503
966f6939 504 status = LoadArrayDigits();
b65e5048 505
506 if (fUseDictionaries)
507 {
966f6939 508 status = LoadArrayDict();
509 if (status == kFALSE)
b65e5048 510 {
966f6939 511 fUseDictionaries = kFALSE;
512 AliWarning("Unable to load dict arrays. Will not use them.\n");
513 }
514 }
515
516 if (!LoadDigitsParam()) {
517 AliWarning("Could not read digits parameter.");
518 if (fDigitsParam) {
519 delete fDigitsParam;
b65e5048 520 }
966f6939 521 AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
522 ,AliTRDSimParam::Instance()->GetNTimeBins()));
523 fDigitsParam = new AliTRDdigitsParam();
524 fDigitsParam->SetNTimeBins(AliTRDSimParam::Instance()->GetNTimeBins());
525 }
6f1e466d 526
966f6939 527 return status;
6f1e466d 528
529}
530
531//_____________________________________________________________________________
532Bool_t AliTRDdigitsManager::WriteDigits()
533{
534 //
535 // Writes out the TRD-digits and the dictionaries
536 //
537
966f6939 538 if (!StoreArrayDigits())
b65e5048 539 {
966f6939 540 AliError("Error while storing digits\n");
b65e5048 541 return kFALSE;
6f1e466d 542 }
6f1e466d 543
b65e5048 544 if (fUseDictionaries)
545 {
966f6939 546 if (!StoreArrayDict())
b65e5048 547 {
966f6939 548 AliError("Error while storing dictionaries in branch\n");
549 return kFALSE;
b65e5048 550 }
551 }
552
abaf1f1d 553 // Write the new tree to the output file
b65e5048 554 fTree->AutoSave();
abaf1f1d 555
6f1e466d 556 return kTRUE;
557
558}
9d0b222b 559
560//_____________________________________________________________________________
b65e5048 561AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
562 , Int_t col
563 , Int_t time
564 , Int_t det) const
9d0b222b 565{
566 //
567 // Creates a single digit object
568 //
569
b65e5048 570 Int_t digits[4];
9d0b222b 571 Int_t amp[1];
572
573 digits[0] = det;
574 digits[1] = row;
575 digits[2] = col;
576 digits[3] = time;
577
b65e5048 578 amp[0] = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
9d0b222b 579
625f5260 580 return (new AliTRDdigit(digits,amp));
9d0b222b 581
582}
583
584//_____________________________________________________________________________
585Int_t AliTRDdigitsManager::GetTrack(Int_t track
b65e5048 586 , Int_t row
587 , Int_t col
588 , Int_t time
793ff80c 589 , Int_t det) const
9d0b222b 590{
591 //
592 // Returns the MC-track numbers from the dictionary.
593 //
594
b65e5048 595 if ((track < 0) || (track >= kNDict))
596 {
597 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
598 return -1;
599 }
9d0b222b 600
b65e5048 601 if (fUseDictionaries == kFALSE)
602 {
603 return -1;
604 }
625f5260 605
b65e5048 606 // Array contains index+1 to allow data compression--->Changed
607 return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
9d0b222b 608
609}
610
b65e5048 611//________________________________________________________________________________
612AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 613{
614 //
615 // Returns the digits array for one detector
616 //
617
486c2339 618 Int_t RecoDet = fRawRec ? 0 : det;
619
b65e5048 620 if (!fDigits)
621 {
622 return 0x0;
623 }
625f5260 624
b65e5048 625 if (!fHasSDigits)
626 {
486c2339 627 ((AliTRDarrayADC *) fDigits->At(RecoDet))->SetNdet(det);
628 return (AliTRDarrayADC *) fDigits->At(RecoDet);
b65e5048 629 }
630 else
631 {
632 AliDebug(2,"ERROR IN DATA TYPE!!!!");
633 return 0x0;
634 }
dd9a6ee3 635
636}
637
638//_____________________________________________________________________________
b65e5048 639AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
dd9a6ee3 640{
641 //
b65e5048 642 // Returns the sdigits array for one detector
dd9a6ee3 643 //
644
486c2339 645 Int_t RecoDet = fRawRec ? 0 : det;
646
b65e5048 647 if (!fDigits)
648 {
649 // AliDebug(1,"NO FDIGITS!");
650 return 0x0;
651 }
652
653 if (fHasSDigits)
654 {
486c2339 655 ((AliTRDarraySignal *) fDigits->At(RecoDet))->SetNdet(det);
656 return (AliTRDarraySignal *) fDigits->At(RecoDet);
b65e5048 657 }
658 else
659 {
660 AliDebug(2,"ERROR IN DATA TYPE!!!!");
661 return 0x0;
662 }
663
664}
665
666//_____________________________________________________________________________
667AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
668 , Int_t i) const
669{
670 //
671 // Returns the dictionary for one detector
672 //
625f5260 673
486c2339 674 Int_t RecoDet = fRawRec ? 0 : det;
675
b65e5048 676 if (fUseDictionaries == kFALSE)
677 {
678 return 0x0;
679 }
dd9a6ee3 680
486c2339 681 ((AliTRDarrayDictionary *) fDigits->At(RecoDet))->SetNdet(det);
682 return (AliTRDarrayDictionary *) fDict[i]->At(RecoDet);
b65e5048 683
dd9a6ee3 684}
685
686//_____________________________________________________________________________
77ad13f4 687Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
dd9a6ee3 688{
689 //
690 // Returns the MC-track numbers from the dictionary for a given digit
691 //
692
b65e5048 693 Int_t row = digit->GetRow();
694 Int_t col = digit->GetCol();
695 Int_t time = digit->GetTime();
696 Int_t det = digit->GetDetector();
dd9a6ee3 697
698 return GetTrack(track,row,col,time,det);
699
700}
ca21baaa 701
702//_____________________________________________________________________________
703AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det)
704{
705 //
706 // Returns indexes of active pads
707 //
708
486c2339 709 Int_t RecoDet = fRawRec ? 0 : det;
710
711 return (AliTRDSignalIndex *) fSignalIndexes->At(RecoDet);
ca21baaa 712
713}
714
715//_____________________________________________________________________________
716void AliTRDdigitsManager::RemoveDigits(Int_t det)
717{
b65e5048 718 //
719 // Clear memory at det for Digits
720 //
ca21baaa 721
486c2339 722 Int_t RecoDet = fRawRec ? 0 : det;
723
724 if (fDigits->At(RecoDet))
b65e5048 725 {
b37bf997 726 if (fHasSDigits)
727 {
486c2339 728 AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(RecoDet);
b37bf997 729 delete arr;
730 }
731 else
732 {
486c2339 733 AliTRDarrayADC *arr = (AliTRDarrayADC *) fDigits->RemoveAt(RecoDet);
b37bf997 734 delete arr;
735 }
b65e5048 736 }
ca21baaa 737
738}
739
740//_____________________________________________________________________________
741void AliTRDdigitsManager::RemoveDictionaries(Int_t det)
742{
743 //
744 // Clear memory
745 //
625f5260 746
486c2339 747 Int_t RecoDet = fRawRec ? 0 : det;
748
b65e5048 749 if (fUseDictionaries == kFALSE)
750 {
751 return;
752 }
ca21baaa 753
b65e5048 754 for (Int_t i = 0; i < kNDict; i++)
755 {
486c2339 756 if (fDict[i]->At(RecoDet))
b65e5048 757 {
486c2339 758 AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(RecoDet);
b37bf997 759 delete arr;
b65e5048 760 }
761 }
ca21baaa 762
763}
764
765//_____________________________________________________________________________
486c2339 766void AliTRDdigitsManager::RemoveIndexes(Int_t det)
767{
768 //
769 // Clear memory
770 //
771
772 Int_t RecoDet = fRawRec ? 0 : det;
773
774 if (fSignalIndexes->At(RecoDet))
775 {
776 AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(RecoDet);
777 delete arr;
778 }
779
780}
781
486c2339 782//_____________________________________________________________________________
ca21baaa 783void AliTRDdigitsManager::ClearIndexes(Int_t det)
784{
785 //
786 // Clear memory
787 //
486c2339 788
789 Int_t RecoDet = fRawRec ? 0 : det;
625f5260 790
486c2339 791 ((AliTRDSignalIndex *) fSignalIndexes->At(RecoDet))->ClearAll();
ca21baaa 792
625f5260 793}
ca21baaa 794
795//_____________________________________________________________________________
796Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
797{
798 //
799 // Build the list of indices
800 //
801
b65e5048 802 Int_t nRows = 0;
803 Int_t nCols = 0;
ca21baaa 804 Int_t nTbins = 0;
805
b65e5048 806 AliTRDgeometry geom;
807 AliTRDarrayADC *digits = 0x0;
625f5260 808
b65e5048 809 if (fHasSDigits)
810 {
811 return kFALSE;
812 }
813 else
814 {
815 digits = (AliTRDarrayADC *) GetDigits(det);
816 }
625f5260 817
966f6939 818 // digits should be expanded by now!!!
b65e5048 819 if (digits->GetNtime() > 0)
820 {
821 digits->Expand();
822 nRows = digits->GetNrow();
823 nCols = digits->GetNcol();
824 nTbins = digits->GetNtime();
825
826 AliTRDSignalIndex *indexes = GetIndexes(det);
827 indexes->SetSM(geom.GetSector(det));
828 indexes->SetStack(geom.GetStack(det));
829 indexes->SetLayer(geom.GetLayer(det));
830 indexes->SetDetNumber(det);
831
832 if (indexes->IsAllocated() == kFALSE)
833 {
834 indexes->Allocate(nRows,nCols,nTbins);
835 }
625f5260 836
b65e5048 837 for (Int_t ir = 0; ir < nRows; ir++)
838 {
839 for (Int_t ic = 0; ic < nCols; ic++)
840 {
841 for (Int_t it = 0; it < nTbins; it++)
842 {
da43c135 843 Int_t isig = digits->GetDataBits(ir,ic,it);
b65e5048 844 if (isig > 0)
845 {
ae63fafc 846 indexes->AddIndexRC(ir,ic);
b65e5048 847 }
848 } // tbins
849 } // cols
850 } // rows
851
852 } // if GetNtime
853 else
854 {
855 return kFALSE;
856 }
857
858 return kTRUE;
625f5260 859
b65e5048 860}
625f5260 861
b65e5048 862//_____________________________________________________________________________
966f6939 863Bool_t AliTRDdigitsManager::LoadArrayDigits()
b65e5048 864{
865 //
966f6939 866 // Loads the (s-)digits arrays for all detectors
b65e5048 867 //
868
966f6939 869 if (!fTree)
b65e5048 870 {
871 AliError("Digits tree is not defined\n");
872 return kFALSE;
ca21baaa 873 }
625f5260 874
966f6939 875 Bool_t status = kTRUE;
876
b65e5048 877 // Get the branch
966f6939 878 TBranch *branch = fTree->GetBranch("TRDdigits");
879 if (!branch)
b65e5048 880 {
966f6939 881 AliError("Branch TRDdigits is not defined\n");
b65e5048 882 return kFALSE;
883 }
625f5260 884
b65e5048 885 // Loop through all detectors and read them from the tree
486c2339 886 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 887 {
966f6939 888 if (fHasSDigits)
b65e5048 889 {
966f6939 890 AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 891 if (!dataArray)
892 {
893 status = kFALSE;
894 break;
895 }
966f6939 896 branch->SetAddress(&dataArray);
897 branch->GetEntry(iDet);
b65e5048 898 }
899 else
900 {
966f6939 901 AliTRDarrayADC *dataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 902 if (!dataArray)
903 {
904 status = kFALSE;
966f6939 905 break;
b65e5048 906 }
966f6939 907 branch->SetAddress(&dataArray);
908 branch->GetEntry(iDet);
b65e5048 909 }
910 }
625f5260 911
b65e5048 912 return status;
913
914}
915
916//________________________________________________________________________________________________
966f6939 917Bool_t AliTRDdigitsManager::LoadArrayDict()
b65e5048 918{
919 //
966f6939 920 // Loads dictionary arrays for all detectors
b65e5048 921 //
922
966f6939 923 if (!fTree)
924 {
925 AliError("Digits tree is not defined\n");
926 return kFALSE;
927 }
928
929 Bool_t status = kTRUE;
930
931 for (Int_t iDict = 0; iDict < kNDict; iDict++)
932 {
933
934 // Get the branch
935 Char_t branchname[15];
936 sprintf(branchname,"TRDdictionary%d",iDict);
937 TBranch *branch = fTree->GetBranch(branchname);
938 if (!branch)
939 {
940 AliError(Form("Branch %s is not defined\n",branchname));
941 return kFALSE;
942 }
943
944 // Loop through all detectors and read them from the tree
945 for (Int_t iDet = 0; iDet < fDets; iDet++)
946 {
947 AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
948 if (!dataArray)
949 {
950 status = kFALSE;
951 break;
952 }
953 branch->SetAddress(&dataArray);
954 branch->GetEntry(iDet);
955 }
956
957 }
958
959 return status;
960
961}
962
963//_____________________________________________________________________________
964Bool_t AliTRDdigitsManager::LoadDigitsParam()
965{
966 //
967 // Loads the digits parameter object from the digits tree
968 //
b65e5048 969
966f6939 970 if (!fTree)
b65e5048 971 {
972 AliError("Digits tree is not defined\n");
973 return kFALSE;
974 }
975
976 // Get the branch
966f6939 977 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
978 if (!branch)
b65e5048 979 {
966f6939 980 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 981 return kFALSE;
982 }
983
966f6939 984 // Read the parameter object
985 AliTRDdigitsParam *digitsParam = fDigitsParam;
986 if (!digitsParam)
b65e5048 987 {
966f6939 988 return kFALSE;
b65e5048 989 }
990
966f6939 991 branch->SetAddress(&digitsParam);
992 branch->GetEntry();
993
994 return kTRUE;
b65e5048 995
996}
997
998//_____________________________________________________________________________
966f6939 999Bool_t AliTRDdigitsManager::StoreArrayDigits()
b65e5048 1000{
1001 //
966f6939 1002 // Stores the digit arrays for all detectors
b65e5048 1003 //
1004
b65e5048 1005 if (!fTree)
1006 {
1007 AliError("Digits tree is not defined\n");
1008 return kFALSE;
1009 }
1010
1011 // Get the branch
966f6939 1012 TBranch *branch = fTree->GetBranch("TRDdigits");
1013 if (!branch)
b65e5048 1014 {
966f6939 1015 AliError("Branch TRDdigits is not defined\n");
b65e5048 1016 return kFALSE;
1017 }
1018
1019 // Loop through all detectors and fill them into the tree
1020 Bool_t status = kTRUE;
486c2339 1021 for (Int_t iDet = 0; iDet < fDets; iDet++)
b65e5048 1022 {
1023 if (fHasSDigits)
1024 {
966f6939 1025 const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
b65e5048 1026 if (!kDataArray)
1027 {
1028 status = kFALSE;
1029 break;
1030 }
966f6939 1031 branch->SetAddress(&kDataArray);
1032 branch->Fill();
b65e5048 1033 }
1034 else
1035 {
966f6939 1036 const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) fDigits->At(iDet);
b65e5048 1037 if (!kDataArray)
1038 {
1039 status = kFALSE;
1040 break;
1041 }
966f6939 1042 branch->SetAddress(&kDataArray);
1043 branch->Fill();
b65e5048 1044 }
1045 }
1046
1047 return status;
1048
1049}
1050
1051//_____________________________________________________________________________
966f6939 1052Bool_t AliTRDdigitsManager::StoreArrayDict()
b65e5048 1053{
1054 //
966f6939 1055 // Stores the dictionary arrays for all detectors
b65e5048 1056 //
1057
966f6939 1058 if (!fTree)
1059 {
1060 AliError("Digits tree is not defined\n");
1061 return kFALSE;
1062 }
1063
1064 Bool_t status = kTRUE;
1065
1066 for (Int_t iDict = 0; iDict < kNDict; iDict++)
1067 {
1068
1069 // Get the branch
1070 Char_t branchname[15];
1071 sprintf(branchname,"TRDdictionary%d",iDict);
1072 TBranch *branch = fTree->GetBranch(branchname);
1073 if (!branch)
1074 {
1075 AliError(Form("Branch %s is not defined\n",branchname));
1076 return kFALSE;
1077 }
1078
1079 // Loop through all detectors and fill them into the tree
1080 for (Int_t iDet = 0; iDet < fDets; iDet++)
1081 {
1082 const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) fDict[iDict]->At(iDet);
1083 if (!kDataArray)
1084 {
1085 status = kFALSE;
1086 break;
1087 }
1088 branch->SetAddress(&kDataArray);
1089 branch->Fill();
1090 }
1091
1092 }
1093
1094 return status;
1095
1096}
1097
1098//_____________________________________________________________________________
1099Bool_t AliTRDdigitsManager::StoreDigitsParam()
1100{
1101 //
1102 // Stores the digits parameter object from the digits tree
1103 //
b65e5048 1104
1105 if (!fTree)
1106 {
1107 AliError("Digits tree is not defined\n");
1108 return kFALSE;
1109 }
1110
1111 // Get the branch
966f6939 1112 TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1113 if (!branch)
b65e5048 1114 {
966f6939 1115 AliError("Branch TRDdigitsParam is not defined\n");
b65e5048 1116 return kFALSE;
1117 }
1118
966f6939 1119 // Fill the digits object in the tree
1120 const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1121 if (!kDigitsParam)
b65e5048 1122 {
966f6939 1123 return kFALSE;
b65e5048 1124 }
966f6939 1125 branch->SetAddress(&kDigitsParam);
1126 branch->Fill();
b65e5048 1127
966f6939 1128 return kTRUE;
ca21baaa 1129
1130}
966f6939 1131