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