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