]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Introduce chamber wise NTimeBins and ADCbaseline to digitsParam
[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
243 }
244
245 //_____________________________________________________________________________
246 void 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 //_____________________________________________________________________________
276 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
277 {
278   //
279   // Returns the amplitude of a digit
280   //
281
282   if (!GetDigits(det)) return 0;
283   
284   return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataBits(row,col,time));
285
286 }
287
288 //_____________________________________________________________________________
289 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
290 {
291   //
292   // Returns the pad status for the requested pad
293   //
294         
295   if (!GetDigits(det)) return 0;
296
297   return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
298  
299 }
300
301 //_____________________________________________________________________________
302 Bool_t AliTRDdigitsManager::MakeBranch(TTree * const tree)  
303 {
304   //
305   // Creates the tree and branches for the digits and the dictionary
306   //
307
308   Int_t  buffersize = 64000;
309   Bool_t status     = kTRUE;
310
311   if (tree) 
312     {
313       fTree = tree;
314     }
315
316   // Make the branch for the digits
317   if (fDigits) 
318     {
319       if (fHasSDigits)
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");
326               TBranch *branch = fTree->GetBranch("TRDdigits");
327               if (!branch)
328                 {
329                   fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
330                 }
331               AliDebug(1,"Making branch TRDdigits\n");
332             }
333           else 
334             {
335               status = kFALSE;
336             }
337         }
338
339       if (!fHasSDigits)
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");
346               TBranch *branch = fTree->GetBranch("TRDdigits");
347               if (!branch) 
348                 {
349                   fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
350                 }
351               AliDebug(1,"Making branch TRDdigits\n");        
352             }
353           else 
354             {
355               status = kFALSE;
356             }
357         }
358
359     }
360   else
361     {
362
363       status = kFALSE;
364
365     }
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");
381                   TBranch *branch = fTree->GetBranch(branchname);
382                   if (!branch) 
383                     {
384                       fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
385                     }
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             }
397         }
398     }
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
412   return status;
413
414 }
415
416 //_____________________________________________________________________________
417 Bool_t AliTRDdigitsManager::ReadDigits(TTree * const tree)
418 {
419   //
420   // Reads the digit information from the input file
421   //
422
423   Bool_t status = kTRUE;
424
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
436   status = LoadArrayDigits();
437
438   if (fUseDictionaries) 
439     {
440       status = LoadArrayDict();
441       if (status == kFALSE) 
442         {
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;
452     }
453     AliWarning(Form("Create default version of digits parameter (NTimeBin=%d).\n"
454                    ,AliTRDSimParam::Instance()->GetNTimeBins()));
455     fDigitsParam = new AliTRDdigitsParam();
456     fDigitsParam->SetNTimeBinsAll(AliTRDSimParam::Instance()->GetNTimeBins());
457     fDigitsParam->SetADCbaselineAll(AliTRDSimParam::Instance()->GetADCbaseline());
458   }
459
460   return status;
461
462 }
463
464 //_____________________________________________________________________________
465 Bool_t AliTRDdigitsManager::WriteDigits()
466 {
467   //
468   // Writes out the TRD-digits, the dictionaries and the digitsPaam
469   //
470
471   if (!StoreArrayDigits())
472     {
473       AliError("Error while storing digits\n");
474       return kFALSE;
475     }
476
477   if (fUseDictionaries) 
478     {
479       if (!StoreArrayDict())
480         {
481           AliError("Error while storing dictionaries in branch\n");
482           return kFALSE;
483         }
484     }
485
486   if (!StoreDigitsParam())
487     {
488       AliError("Error while storing digitsParam\n");
489       return kFALSE;
490     }
491   
492   // Write the new tree to the output file
493   fTree->AutoSave();
494
495   return kTRUE;
496
497 }
498
499 //_____________________________________________________________________________
500 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row
501                                          , Int_t col
502                                          , Int_t time
503                                          , Int_t det) const
504 {
505   // 
506   // Creates a single digit object 
507   //
508
509   Int_t digits[4]; 
510   Int_t amp[1];
511
512   digits[0] = det;
513   digits[1] = row;
514   digits[2] = col;
515   digits[3] = time;
516
517   amp[0]    = ((AliTRDarrayADC *) GetDigits(det))->GetData(row,col,time);
518   
519   return (new AliTRDdigit(digits,amp));
520
521 }
522
523 //_____________________________________________________________________________
524 Int_t AliTRDdigitsManager::GetTrack(Int_t track
525                                   , Int_t row
526                                   , Int_t col
527                                   , Int_t time
528                                   , Int_t det) const
529 {
530   // 
531   // Returns the MC-track numbers from the dictionary.
532   //
533
534   if ((track < 0) || (track >= kNDict)) 
535     {
536       AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)",track,kNDict,this));
537       return -1;
538     }
539
540   if (fUseDictionaries == kFALSE) 
541     {
542       return -1;
543     }
544
545   // Array contains index+1 to allow data compression--->Changed
546   return (((AliTRDarrayDictionary *) GetDictionary(det,track))->GetData(row,col,time) );
547
548 }
549
550 //________________________________________________________________________________
551 AliTRDarrayADC *AliTRDdigitsManager::GetDigits(Int_t det) const
552 {
553   //
554   // Returns the digits array for one detector
555   //
556
557   Int_t recoDet = fRawRec ? 0 : det;
558
559   if (!fDigits)   
560     {
561       return 0x0;
562     }
563
564   if (!fHasSDigits)
565     {
566       ((AliTRDarrayADC *) fDigits->At(recoDet))->SetNdet(det);
567       return (AliTRDarrayADC *) fDigits->At(recoDet); 
568     }
569   else
570     {
571       AliDebug(2,"ERROR IN DATA TYPE!!!!");
572       return 0x0;
573     }
574
575 }
576
577 //_____________________________________________________________________________
578 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
579 {
580   //
581   // Returns the sdigits array for one detector
582   //
583
584   Int_t recoDet = fRawRec ? 0 : det;
585
586   if (!fDigits)   
587     {
588       //      AliDebug(1,"NO FDIGITS!");        
589       return 0x0;
590     }
591
592   if (fHasSDigits)
593     {
594       ((AliTRDarraySignal *) fDigits->At(recoDet))->SetNdet(det);
595       return (AliTRDarraySignal *) fDigits->At(recoDet);
596     }
597   else
598     {
599       AliDebug(2,"ERROR IN DATA TYPE!!!!");
600       return 0x0;
601     }
602
603 }
604
605 //_____________________________________________________________________________
606 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
607                                                         , Int_t i) const
608 {
609   //
610   // Returns the dictionary for one detector
611   //
612
613   Int_t recoDet = fRawRec ? 0 : det;
614
615   if (fUseDictionaries == kFALSE)
616     {
617       return 0x0;
618     }
619
620   ((AliTRDarrayDictionary *) fDigits->At(recoDet))->SetNdet(det);
621   return (AliTRDarrayDictionary *) fDict[i]->At(recoDet);
622   
623 }
624
625 //_____________________________________________________________________________
626 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit * const digit) const
627 {
628   // 
629   // Returns the MC-track numbers from the dictionary for a given digit
630   //
631
632   Int_t row  = digit->GetRow();
633   Int_t col  = digit->GetCol();
634   Int_t time = digit->GetTime();
635   Int_t det  = digit->GetDetector();
636
637   return GetTrack(track,row,col,time,det);
638
639 }
640
641 //_____________________________________________________________________________
642 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
643 {
644   // 
645   // Returns indexes of active pads
646   //
647
648   Int_t recoDet = fRawRec ? 0 : det;
649
650   return (AliTRDSignalIndex *) fSignalIndexes->At(recoDet);
651
652 }
653
654 //_____________________________________________________________________________
655 void AliTRDdigitsManager::RemoveDigits(Int_t det) 
656 {
657    // 
658    // Clear memory at det for Digits
659    //
660
661   Int_t recoDet = fRawRec ? 0 : det;
662
663   if (fDigits->At(recoDet))
664     {
665       if (fHasSDigits) 
666         {
667           AliTRDarraySignal *arr = (AliTRDarraySignal *) fDigits->RemoveAt(recoDet);
668           delete arr;
669         }
670       else 
671         {
672           AliTRDarrayADC    *arr = (AliTRDarrayADC *)    fDigits->RemoveAt(recoDet);
673           delete arr;
674         }
675     }
676
677 }
678
679 //_____________________________________________________________________________
680 void AliTRDdigitsManager::RemoveDictionaries(Int_t det) 
681 {
682   // 
683   // Clear memory
684   //
685
686   Int_t recoDet = fRawRec ? 0 : det;
687
688   if (fUseDictionaries == kFALSE) 
689     {
690       return;
691     }
692
693   for (Int_t i = 0; i < kNDict; i++) 
694     {
695       if (fDict[i]->At(recoDet))
696         {
697           AliTRDarrayDictionary *arr = (AliTRDarrayDictionary *) fDict[i]->RemoveAt(recoDet);
698           delete arr;
699         }
700     }
701
702 }
703
704 //_____________________________________________________________________________
705 void AliTRDdigitsManager::RemoveIndexes(Int_t det) 
706 {
707    // 
708    // Clear memory
709    //
710
711   Int_t recoDet = fRawRec ? 0 : det;
712
713   if (fSignalIndexes->At(recoDet))
714     {
715       AliTRDSignalIndex *arr = (AliTRDSignalIndex *) fSignalIndexes->RemoveAt(recoDet);
716       delete arr;
717     }
718
719 }
720
721 //_____________________________________________________________________________
722 void AliTRDdigitsManager::ClearIndexes(Int_t det) 
723 {
724   // 
725   // Clear memory
726   //
727   
728   Int_t recoDet = fRawRec ? 0 : det;
729
730   ((AliTRDSignalIndex *) fSignalIndexes->At(recoDet))->ClearAll();  
731
732 }
733
734 //_____________________________________________________________________________
735 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
736 {
737   //
738   // Build the list of indices
739   //
740
741   Int_t nRows  = 0;
742   Int_t nCols  = 0;
743   Int_t nTbins = 0;
744
745   AliTRDgeometry  geom;
746   AliTRDarrayADC *digits = 0x0;
747
748   if (fHasSDigits) 
749     {
750       return kFALSE;
751     }
752   else 
753     {
754       digits = (AliTRDarrayADC *) GetDigits(det);
755     }
756
757   // digits should be expanded by now!!!
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         }
775
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                 {         
782                   Int_t isig = digits->GetDataBits(ir,ic,it);
783                   if (isig > 0) 
784                     {
785                       indexes->AddIndexRC(ir,ic);           
786                     }
787                 } // tbins
788             } // cols
789         } // rows
790
791     } // if GetNtime
792   else 
793     {
794       return kFALSE;
795     }
796   
797   return kTRUE;
798
799 }
800
801 //_____________________________________________________________________________
802 Bool_t AliTRDdigitsManager::LoadArrayDigits()
803 {
804   //
805   // Loads the (s-)digits arrays for all detectors
806   //
807
808   if (!fTree) 
809     {
810       AliError("Digits tree is not defined\n");
811       return kFALSE;
812     }
813
814   Bool_t status = kTRUE;
815
816   // Get the branch
817   TBranch *branch = fTree->GetBranch("TRDdigits");
818   if (!branch) 
819     {
820       AliError("Branch TRDdigits is not defined\n");
821       return kFALSE;
822     }
823
824   // Loop through all detectors and read them from the tree
825   for (Int_t iDet = 0; iDet < fDets; iDet++) 
826     {
827       if (fHasSDigits)
828         {
829           AliTRDarraySignal *dataArray = (AliTRDarraySignal *) fDigits->At(iDet);
830           if (!dataArray) 
831             {
832               status = kFALSE;
833               break;    
834             }
835           branch->SetAddress(&dataArray);
836           branch->GetEntry(iDet);
837         }
838       else
839         {
840           AliTRDarrayADC    *dataArray = (AliTRDarrayADC *)    fDigits->At(iDet);
841           if (!dataArray) 
842             {
843               status = kFALSE;
844               break;
845             }
846           branch->SetAddress(&dataArray);
847           branch->GetEntry(iDet);
848         }
849     }
850
851   return status;
852
853 }
854
855 //________________________________________________________________________________________________
856 Bool_t AliTRDdigitsManager::LoadArrayDict()
857 {
858   //
859   // Loads dictionary arrays for all detectors
860   //
861
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 //_____________________________________________________________________________
903 Bool_t AliTRDdigitsManager::LoadDigitsParam()
904 {
905   //
906   // Loads the digits parameter object from the digits tree
907   //
908
909   if (!fTree) 
910     {
911       AliError("Digits tree is not defined\n");
912       return kFALSE;
913     }
914
915   // Get the branch
916   TBranch *branch = fTree->GetBranch("TRDdigitsParam");
917   if (!branch) 
918     {
919       AliError("Branch TRDdigitsParam is not defined\n");
920       return kFALSE;
921     }
922
923   // Read the parameter object
924   AliTRDdigitsParam *digitsParam = fDigitsParam;
925   if (!digitsParam)
926     {
927       return kFALSE;
928     }
929
930   branch->SetAddress(&digitsParam);
931   branch->GetEntry();
932
933   return kTRUE;
934
935 }
936
937 //_____________________________________________________________________________
938 Bool_t AliTRDdigitsManager::StoreArrayDigits()
939 {
940   //
941   // Stores the digit arrays for all detectors
942   //
943
944   if (!fTree) 
945     {
946       AliError("Digits tree is not defined\n");
947       return kFALSE;
948     }
949
950   // Get the branch
951   TBranch *branch = fTree->GetBranch("TRDdigits");
952   if (!branch) 
953     {
954       AliError("Branch TRDdigits is not defined\n");
955       return kFALSE;
956     }
957
958   // Loop through all detectors and fill them into the tree
959   Bool_t status = kTRUE;
960   for (Int_t iDet = 0; iDet < fDets; iDet++) 
961     {
962       if (fHasSDigits)
963         {
964           const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) fDigits->At(iDet);
965           if (!kDataArray) 
966             {
967               status = kFALSE;
968               break;
969             }
970           branch->SetAddress(&kDataArray);
971           branch->Fill();
972         }
973       else
974         {
975           const AliTRDarrayADC    *kDataArray = (AliTRDarrayADC *)    fDigits->At(iDet); 
976           if (!kDataArray) 
977             {
978               status = kFALSE;
979               break;
980             }
981           branch->SetAddress(&kDataArray);
982           branch->Fill();
983         }
984     }
985
986   return status;
987
988 }
989
990 //_____________________________________________________________________________
991 Bool_t AliTRDdigitsManager::StoreArrayDict()
992 {
993   //
994   // Stores the dictionary arrays for all detectors
995   //
996
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 //_____________________________________________________________________________
1038 Bool_t AliTRDdigitsManager::StoreDigitsParam()
1039 {
1040   //
1041   // Stores the digits parameter object from the digits tree
1042   //
1043
1044   if (!fTree) 
1045     {
1046       AliError("Digits tree is not defined\n");
1047       return kFALSE;
1048     }
1049
1050   // Get the branch
1051   TBranch *branch = fTree->GetBranch("TRDdigitsParam");
1052   if (!branch) 
1053     {
1054       AliError("Branch TRDdigitsParam is not defined\n");
1055       return kFALSE;
1056     }
1057
1058   // Fill the digits object in the tree
1059   const AliTRDdigitsParam *kDigitsParam = fDigitsParam;
1060   if (!kDigitsParam)
1061     {
1062       return kFALSE;
1063     }
1064   branch->SetAddress(&kDigitsParam);
1065   branch->Fill();
1066
1067   return kTRUE;
1068
1069 }
1070