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