]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Introduce new digits structures by Hermes with ZS in digitzer stage
[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 <Riostream.h> 
26 #include <TROOT.h>
27 #include <TTree.h>                                                              
28 #include <TFile.h>
29 #include "AliRun.h"
30 #include "AliLog.h"
31 #include "AliTRDdigitsManager.h"
32 #include "AliTRDarrayDictionary.h"
33 #include "AliTRDarrayADC.h"
34 #include "AliTRDarraySignal.h"
35 #include "AliTRDdigit.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()
48   :TObject()
49   ,fEvent(0)
50   ,fTree(0)
51   ,fDigits(0) 
52   ,fHasSDigits(0)
53   ,fSignalIndexes(NULL)
54   ,fUseDictionaries(kTRUE)
55   ,fTreeD(0)
56   ,fBranch(0)
57 {
58   //
59   // Default constructor
60   //
61
62   for (Int_t iDict = 0; iDict < kNDict; iDict++) 
63     {
64       fDict[iDict] = NULL;
65     }
66   
67   fSignalIndexes = new TObjArray(AliTRDgeometry::Ndet());
68   
69 }
70
71 //_____________________________________________________________________________
72 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
73   :TObject(m)
74   ,fEvent(m.fEvent)
75   ,fTree(0)
76   ,fDigits(0) 
77   ,fHasSDigits(m.fHasSDigits)
78   ,fSignalIndexes(NULL)
79   ,fUseDictionaries(kTRUE)
80   ,fTreeD(m.fTree)
81   ,fBranch(m.fBranch)
82 {
83   //
84   // AliTRDdigitsManager copy constructor
85   //
86
87 }
88
89 //_____________________________________________________________________________
90 AliTRDdigitsManager::~AliTRDdigitsManager()
91 {
92   //
93   // AliTRDdigitsManager destructor
94   //
95
96   if (fDigits) 
97     {
98       fDigits->Delete();
99       delete fDigits;
100       fDigits = NULL;
101     }
102
103   for (Int_t iDict = 0; iDict < kNDict; iDict++) 
104     {
105       fDict[iDict]->Delete();
106       delete fDict[iDict];
107       fDict[iDict] = NULL;
108     }
109
110   if (fSignalIndexes) 
111     {
112       fSignalIndexes->Delete();
113       delete fSignalIndexes;
114       fSignalIndexes = NULL;
115     }
116
117 }
118
119 //_____________________________________________________________________________
120 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
121 {
122   //
123   // Assignment operator
124   //
125
126   if (this != &m) 
127     {
128       ((AliTRDdigitsManager &) m).Copy(*this);
129     }
130
131   return *this;
132
133 }
134
135 //_____________________________________________________________________________
136 void AliTRDdigitsManager::Copy(TObject &m) const
137 {
138   //
139   // Copy function
140   //
141
142   ((AliTRDdigitsManager &) m).fEvent           = fEvent;
143   ((AliTRDdigitsManager &) m).fHasSDigits      = fHasSDigits;
144   ((AliTRDdigitsManager &) m).fDigits   = fDigits;
145   for(Int_t i=0; i<kNDict; i++)
146     {
147       ((AliTRDdigitsManager &) m).fDict[i]  = fDict[i];
148     }
149   ((AliTRDdigitsManager &) m).fSignalIndexes   = fSignalIndexes;
150   ((AliTRDdigitsManager &) m).fUseDictionaries = fUseDictionaries;
151
152   TObject::Copy(m);
153
154 }
155
156 //_____________________________________________________________________________
157 void AliTRDdigitsManager::CreateArrays()
158 {
159   //
160   // Create the data arrays
161   //
162
163   if (fHasSDigits) 
164     {
165       if(fDigits)                                        
166         {                                                   
167           fDigits->Delete();                                
168           delete fDigits;                                   
169         }                                                    
170       fDigits = new TObjArray(AliTRDgeometry::Ndet());
171       for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
172         {
173           AliTRDarraySignal *chamber= new AliTRDarraySignal();
174           chamber->SetNdet(index);
175           fDigits->AddAt(chamber,index);
176         } 
177     }
178   else 
179     {
180       if(fDigits)                                          
181         {                                                    
182           fDigits->Delete();                                
183           delete fDigits;                                   
184         }                                                   
185       fDigits = new TObjArray(AliTRDgeometry::Ndet());    
186       for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
187         {
188           AliTRDarrayADC *chamber= new AliTRDarrayADC();                                                 
189           chamber->SetNdet(index);
190           fDigits->AddAt(chamber,index);
191         }       
192     }
193
194   if (fUseDictionaries) 
195     {
196       for(Int_t iDict = 0; iDict < kNDict; iDict++)
197         if(fDict[iDict])                                           
198           {
199             fDict[iDict]->Delete();                                
200             delete fDict[iDict];                                    
201           }
202       for(Int_t iDict = 0; iDict < kNDict; iDict++)
203         {
204           fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());    
205         }
206
207       for (Int_t iDict = 0; iDict < kNDict; iDict++)
208         {
209           for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
210             {
211               AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();
212               dictio->SetNdet(index);
213               fDict[iDict]->AddAt(dictio,index);
214             } 
215         }
216     }
217
218   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) 
219     {
220       fSignalIndexes->AddLast(new AliTRDSignalIndex());
221     } 
222
223 }
224
225 //_____________________________________________________________________________
226 void AliTRDdigitsManager::ResetArrays()
227 {
228   //
229   // Reset the data arrays
230   //
231
232   if (fDigits) 
233     {
234       fDigits->Delete();
235       delete fDigits;
236     }
237
238   for (Int_t iDict = 0; iDict < kNDict; iDict++)          
239     {                                                        
240       if (fDict[iDict])                                
241         {                                                    
242           fDict[iDict]->Delete();                      
243           delete fDict[iDict];                        
244         }
245     }
246
247   if (fHasSDigits)
248     {
249       fDigits = new TObjArray(AliTRDgeometry::Ndet());     
250       for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
251         {
252           AliTRDarraySignal *chamber= new AliTRDarraySignal();
253           chamber->SetNdet(index);
254           fDigits->AddAt(chamber,index);
255         } 
256     }
257   else 
258     {
259       fDigits = new TObjArray(AliTRDgeometry::Ndet());      
260       for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
261         {
262           AliTRDarrayADC *chamber= new AliTRDarrayADC();
263           chamber->SetNdet(index);
264           fDigits->AddAt(chamber,index);
265         }
266     }
267   
268   if (fUseDictionaries) 
269     {
270       for(Int_t iDict = 0; iDict < kNDict; iDict++)
271         {
272           fDict[iDict] = new TObjArray(AliTRDgeometry::Ndet());  
273         }
274       for (Int_t iDict = 0; iDict < kNDict; iDict++)
275         {
276           for (Int_t index = 0; index < AliTRDgeometry::Ndet(); index++) 
277             {
278               AliTRDarrayDictionary *dictio= new AliTRDarrayDictionary();   
279               dictio->SetNdet(index);                                       
280               fDict[iDict]->AddAt(dictio,index);                            
281             }
282         }
283     }
284
285   for (Int_t i = 0; i < AliTRDgeometry::Ndet(); i++) 
286     {
287       AliTRDSignalIndex *idx = (AliTRDSignalIndex *) fSignalIndexes->At(i);
288       if (idx) idx->Reset();
289     }
290
291 }
292
293 //_____________________________________________________________________________
294 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time, Int_t det) const
295 {
296   //
297   // Returns the amplitude of a digit
298   //
299
300   if (!GetDigits(det)) 
301     {
302       return 0;
303     }
304   
305   return ((Short_t) ((AliTRDarrayADC *) GetDigits(det))->GetDataB(row,col,time));
306
307 }
308
309 //_____________________________________________________________________________
310 UChar_t AliTRDdigitsManager::GetPadStatus(Int_t row, Int_t col, Int_t time, Int_t det) const
311 {
312   //
313   // Returns the pad status for the requested pad
314   //
315         
316   if (!GetDigits(det)) 
317     {
318       return 0;
319     }
320
321   return ((UChar_t) ((AliTRDarrayADC *) GetDigits(det))->GetPadStatus(row,col,time));
322  
323 }
324
325 //_____________________________________________________________________________
326 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)  
327 {
328   //
329   // Creates the tree and branches for the digits and the dictionary
330   //
331
332   Int_t  buffersize = 64000;
333   Bool_t status     = kTRUE;
334
335   if (tree) 
336     {
337       fTree = tree;
338     }
339
340   // Make the branch for the digits
341   if (fDigits) 
342     {
343       if(fHasSDigits)
344         {
345           const AliTRDarraySignal *kDigits = (AliTRDarraySignal *) fDigits->At(0); 
346           if (kDigits) 
347             {
348               if (!fTree) return kFALSE;
349               AliDebug(1,"Making branch for SDigits!\n");
350               TBranch* branch = fTree->GetBranch("TRDdigits");
351               if (!branch) fTree->Branch("TRDdigits","AliTRDarraySignal",&kDigits,buffersize,99);
352               AliDebug(1,"Making branch TRDdigits\n");
353             }
354           else 
355             {
356               status = kFALSE;
357             }
358         }
359
360       if(!fHasSDigits)
361         {
362           const AliTRDarrayADC *kDigits = (AliTRDarrayADC *) fDigits->At(0);
363           if (kDigits) 
364             {
365               if (!fTree) return kFALSE;
366               AliDebug(1,"Making branch for Digits!\n");
367               TBranch* branch = fTree->GetBranch("TRDdigits");
368               if (!branch) fTree->Branch("TRDdigits","AliTRDarrayADC",&kDigits,buffersize,99);
369               AliDebug(1,"Making branch TRDdigits\n");        
370             }
371           else 
372             {
373               status = kFALSE;
374             }
375         }
376
377     }    
378   else
379     {
380       status = kFALSE;
381     }
382   
383   if (fUseDictionaries) 
384     {
385       // Make the branches for the dictionaries
386       for (Int_t iDict = 0; iDict < kNDict; iDict++) 
387         {
388           Char_t branchname[15];
389           sprintf(branchname,"TRDdictionary%d",iDict); 
390           if (fDict[iDict]) 
391             {
392               const AliTRDarrayDictionary *kDictionary = (AliTRDarrayDictionary *) fDict[iDict]->At(0);
393               if (kDictionary) 
394                 {
395                   if (!fTree) return kFALSE;
396                   AliDebug(2,"Making branch for dictionary!\n");
397                   TBranch* branch = fTree->GetBranch(branchname);
398                   if (!branch) fTree->Branch(branchname,"AliTRDarrayDictionary",&kDictionary,buffersize,99);
399                   AliDebug(1,Form("Making branch %s\n",branchname));
400                 }
401               else 
402                 {
403                   status = kFALSE;
404                 }
405             }
406           else 
407             {
408               status = kFALSE;
409             }
410         }
411     }
412   
413   return status;
414
415 }
416
417 //_____________________________________________________________________________
418 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
419 {
420   //
421   // Reads the digit information from the input file
422   //
423
424   Bool_t status = kTRUE;
425
426   if (tree) 
427     {
428       fTree = tree;
429     }
430
431   if (!fDigits) 
432     {
433       AliDebug(1,"Create the data arrays.\n");
434       CreateArrays();
435     }
436
437   status = LoadArray(fDigits,"TRDdigits",fTree);
438
439   if (fUseDictionaries) 
440     {
441       for (Int_t iDict = 0; iDict < kNDict; iDict++) 
442         {
443           Char_t branchname[15];
444           sprintf(branchname,"TRDdictionary%d",iDict);
445           status = LoadArrayDict(fDict[iDict],branchname,fTree);
446           if (status == kFALSE) 
447             {
448               fUseDictionaries = kFALSE;
449               AliWarning("Unable to load dict arrays. Will not use them.\n");
450               break;
451             }
452         }  
453     }
454
455   return kTRUE;
456
457 }
458
459 //_____________________________________________________________________________
460 Bool_t AliTRDdigitsManager::WriteDigits()
461 {
462   //
463   // Writes out the TRD-digits and the dictionaries
464   //
465
466   // Store the contents of the detector array in the tree
467
468   if (!StoreArray(fDigits,"TRDdigits",fTree))
469     {
470       AliError("Error while storing digits in branch TRDdigits\n");
471       return kFALSE;
472     }
473
474   if (fUseDictionaries) 
475     {
476       for (Int_t iDict = 0; iDict < kNDict; iDict++)
477         {
478           Char_t branchname[15];
479           sprintf(branchname,"TRDdictionary%d",iDict);
480           if (!StoreArrayDict(fDict[iDict],branchname,fTree)) 
481             {
482               AliError(Form("Error while storing dictionary in branch %s\n",branchname));
483               return kFALSE;
484             }
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   if (!fDigits)   
554     {
555       return 0x0;
556     }
557
558   if (!fHasSDigits)
559     {
560       return (AliTRDarrayADC *) fDigits->At(det); 
561     }
562   else
563     {
564       AliDebug(2,"ERROR IN DATA TYPE!!!!");
565       return 0x0;
566     }
567
568 }
569
570 //_____________________________________________________________________________
571 AliTRDarraySignal *AliTRDdigitsManager::GetSDigits(Int_t det) const
572 {
573   //
574   // Returns the sdigits array for one detector
575   //
576
577   if (!fDigits)   
578     {
579       //      AliDebug(1,"NO FDIGITS!");        
580       return 0x0;
581     }
582
583   if (fHasSDigits)
584     {
585       return (AliTRDarraySignal *) fDigits->At(det);
586     }
587   else
588     {
589       AliDebug(2,"ERROR IN DATA TYPE!!!!");
590       return 0x0;
591     }
592
593 }
594
595 //_____________________________________________________________________________
596 AliTRDarrayDictionary *AliTRDdigitsManager::GetDictionary(Int_t det
597                                                         , Int_t i) const
598 {
599   //
600   // Returns the dictionary for one detector
601   //
602
603   if (fUseDictionaries == kFALSE)
604     {
605       return 0x0;
606     }
607
608   return (AliTRDarrayDictionary *) fDict[i]->At(det);
609   
610 }
611
612 //_____________________________________________________________________________
613 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *digit) const
614 {
615   // 
616   // Returns the MC-track numbers from the dictionary for a given digit
617   //
618
619   Int_t row  = digit->GetRow();
620   Int_t col  = digit->GetCol();
621   Int_t time = digit->GetTime();
622   Int_t det  = digit->GetDetector();
623
624   return GetTrack(track,row,col,time,det);
625
626 }
627
628 //_____________________________________________________________________________
629 AliTRDSignalIndex *AliTRDdigitsManager::GetIndexes(Int_t det) 
630 {
631   // 
632   // Returns indexes of active pads
633   //
634
635   return (AliTRDSignalIndex *) fSignalIndexes->At(det);
636
637 }
638
639 //_____________________________________________________________________________
640 void AliTRDdigitsManager::RemoveDigits(Int_t det) 
641 {
642    // 
643    // Clear memory at det for Digits
644    //
645
646   if (fDigits->At(det))
647     {
648       fDigits->RemoveAt(det);
649     }
650
651 }
652
653 //_____________________________________________________________________________
654 void AliTRDdigitsManager::RemoveDictionaries(Int_t det) 
655 {
656   // 
657   // Clear memory
658   //
659
660   if (fUseDictionaries == kFALSE) 
661     {
662       return;
663     }
664
665   for (Int_t i = 0; i < kNDict; i++) 
666     {
667       if (fDict[i]->At(det))
668         {
669           fDict[i]->RemoveAt(det);
670         }
671     }
672
673 }
674
675 //_____________________________________________________________________________
676 void AliTRDdigitsManager::ClearIndexes(Int_t det) 
677 {
678   // 
679   // Clear memory
680   //
681
682   ((AliTRDSignalIndex *) fSignalIndexes->At(det))->ClearAll();  
683
684 }
685
686 //_____________________________________________________________________________
687 Bool_t AliTRDdigitsManager::BuildIndexes(Int_t det)
688 {
689   //
690   // Build the list of indices
691   //
692
693   Int_t nRows  = 0;
694   Int_t nCols  = 0;
695   Int_t nTbins = 0;
696
697   AliTRDgeometry  geom;
698   AliTRDarrayADC *digits = 0x0;
699
700   if (fHasSDigits) 
701     {
702       return kFALSE;
703     }
704   else 
705     {
706       digits = (AliTRDarrayADC *) GetDigits(det);
707     }
708
709   //digits should be expanded by now!!!
710   if (digits->GetNtime() > 0) 
711     {      
712       digits->Expand(); 
713       nRows  = digits->GetNrow();
714       nCols  = digits->GetNcol();
715       nTbins = digits->GetNtime();
716       
717       AliTRDSignalIndex *indexes = GetIndexes(det);
718       indexes->SetSM(geom.GetSector(det));
719       indexes->SetStack(geom.GetStack(det));
720       indexes->SetLayer(geom.GetLayer(det));
721       indexes->SetDetNumber(det);
722
723       if (indexes->IsAllocated() == kFALSE)
724         {
725           indexes->Allocate(nRows,nCols,nTbins);
726         }
727
728       for (Int_t ir = 0; ir < nRows; ir++) 
729         {
730           for (Int_t ic = 0; ic < nCols; ic++) 
731             {
732               for (Int_t it = 0; it < nTbins; it++)
733                 {         
734                   Int_t isig = digits->GetDataB(ir,ic,it);
735                   if (isig > 0) 
736                     {
737                       indexes->AddIndexTBin(ir,ic,it);      
738                     }
739                 } // tbins
740             } // cols
741         } // rows
742
743     } // if GetNtime
744   else 
745     {
746       return kFALSE;
747     }
748   
749   return kTRUE;
750
751 }
752
753 //_____________________________________________________________________________
754 Bool_t AliTRDdigitsManager::LoadArray(TObjArray *object
755                                     , const Char_t *branchname
756                                     , TTree *tree)
757 {
758   //
759   // Loads all detectors of the array from the branch <branchname> of
760   // the digits tree <tree>
761   // Adapted from code of the class AliTRDsegmentArray
762   //
763
764   fTreeD = tree;
765
766   if (!fTreeD) 
767     {
768       AliError("Digits tree is not defined\n");
769       return kFALSE;
770     }
771
772   // Get the branch
773   fBranch = fTreeD->GetBranch(branchname);
774   if (!fBranch) 
775     {
776       AliError(Form("Branch %s is not defined\n",branchname));
777       return kFALSE;
778     }
779
780   // Loop through all detectors and read them from the tree
781   Bool_t status = kTRUE;
782   for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
783     {
784       if(fHasSDigits)
785         {
786           AliTRDarraySignal *dataArray = (AliTRDarraySignal *) object->At(iDet);
787           if (!dataArray) 
788             {
789               status = kFALSE;
790               break;    
791             }
792
793           fBranch->SetAddress(&dataArray);
794           fBranch->GetEntry(iDet);
795         }
796       else
797         {
798           AliTRDarrayADC *dataArray = (AliTRDarrayADC *) object->At(iDet);
799           if (!dataArray) 
800             {
801               status = kFALSE;
802               break;    
803             }
804           fBranch->SetAddress(&dataArray);
805           fBranch->GetEntry(iDet);
806         }
807     }
808
809   return status;
810
811 }
812
813 //________________________________________________________________________________________________
814 Bool_t AliTRDdigitsManager::LoadArrayDict(TObjArray *object
815                                         , const Char_t *branchname
816                                         , TTree *tree)
817 {
818   //
819   // Loads all detectors of the array from the branch <branchname> of
820   // the dictionary tree <tree>
821   // Adapted from code of the class AliTRDsegmentArray
822   //
823
824   fTreeD = tree;
825
826   if (!fTreeD) 
827     {
828       AliError("Digits tree is not defined\n");
829       return kFALSE;
830     }
831
832   // Get the branch
833   fBranch = fTreeD->GetBranch(branchname);
834   if (!fBranch) 
835     {
836       AliError(Form("Branch %s is not defined\n",branchname));
837       return kFALSE;
838     }
839
840   // Loop through all detectors and read them from the tree
841   Bool_t status = kTRUE;
842   for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
843     {
844       AliTRDarrayDictionary *dataArray = (AliTRDarrayDictionary *) object->At(iDet);
845       if (!dataArray) 
846         {
847           status = kFALSE;
848           break;    
849         }
850       fBranch->SetAddress(&dataArray);
851       fBranch->GetEntry(iDet);
852     }
853
854   return status;
855
856 }
857
858 //_____________________________________________________________________________
859 Bool_t AliTRDdigitsManager::StoreArray(TObjArray *array1
860                                      , const Char_t *branchname
861                                      , TTree *tree)
862 {
863   //
864   // Stores all the detectors of the array in the branch <branchname> of 
865   // the digits tree <tree>
866   // Adapted from code of the class AliTRDsegmentArray
867   //
868
869   fTree = tree;
870
871   if (!fTree) 
872     {
873       AliError("Digits tree is not defined\n");
874       return kFALSE;
875     }
876
877   // Get the branch
878   fBranch = fTree->GetBranch(branchname);
879   if (!fBranch) 
880     {
881       AliError(Form("Branch %s is not defined\n",branchname));
882       return kFALSE;
883     }
884
885   // Loop through all detectors and fill them into the tree
886   Bool_t status = kTRUE;
887   for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
888     {
889       if (fHasSDigits)
890         {
891           const AliTRDarraySignal *kDataArray = (AliTRDarraySignal *) array1->At(iDet);
892           if (!kDataArray) 
893             {
894               status = kFALSE;
895               break;
896             }
897           fBranch->SetAddress(&kDataArray);
898           fBranch->Fill();
899         }
900       else
901         {
902           const AliTRDarrayADC *kDataArray = (AliTRDarrayADC *) array1->At(iDet); 
903           if (!kDataArray) 
904             {
905               status = kFALSE;
906               break;
907             }
908           fBranch->SetAddress(&kDataArray);
909           fBranch->Fill();
910         }
911     }
912
913   return status;
914
915 }
916
917 //_____________________________________________________________________________
918 Bool_t AliTRDdigitsManager::StoreArrayDict(TObjArray *array3
919                                          , const Char_t *branchname
920                                          , TTree *tree)
921 {
922   //
923   // Stores all the dictionary arrays of the detectors of the array in the branch <branchname> of 
924   // the dictionary tree <tree>
925   // Adapted from code of the class AliTRDsegmentArray
926   //
927
928   //  AliDebug(1,"Storing Arrays of Dictionary");
929   fTree = tree;
930
931   if (!fTree) 
932     {
933       AliError("Digits tree is not defined\n");
934       return kFALSE;
935     }
936
937   // Get the branch
938   fBranch = fTree->GetBranch(branchname);
939   if (!fBranch) 
940     {
941       AliError(Form("Branch %s is not defined\n",branchname));
942       return kFALSE;
943     }
944
945   // Loop through all detectors and fill them into the tree
946   Bool_t status = kTRUE;
947   for (Int_t iDet = 0; iDet < AliTRDgeometry::Ndet(); iDet++) 
948     {
949       const AliTRDarrayDictionary *kDataArray = (AliTRDarrayDictionary *) array3->At(iDet);
950       if (!kDataArray) 
951         {
952           status = kFALSE;
953           break;
954         }
955       fBranch->SetAddress(&kDataArray);
956       fBranch->Fill();
957     }
958
959   return status;
960
961 }