]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Coding conventions
[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 //  AliTRDdataArray objects.                                                 //
22 //                                                                           //
23 ///////////////////////////////////////////////////////////////////////////////
24
25 #include <Riostream.h>
26  
27 #include <TROOT.h>
28 #include <TTree.h>                                                              
29 #include <TFile.h>
30
31 #include "AliRun.h"
32
33 #include "AliTRDdigitsManager.h"
34 #include "AliTRDsegmentArray.h"
35 #include "AliTRDdataArrayI.h"
36 #include "AliTRDdigit.h"
37 #include "AliTRDgeometry.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():TObject()
48 {
49   //
50   // Default constructor
51   //
52
53   fIsRaw   = kFALSE;
54   fEvent   = 0;
55   fDebug   = 0;
56   fSDigits = 0;
57
58   fTree    = NULL;
59   fDigits  = NULL;
60   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
61     fDictionary[iDict] = NULL;
62   }
63
64 }
65
66 //_____________________________________________________________________________
67 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
68 :TObject(m)
69 {
70   //
71   // AliTRDdigitsManager copy constructor
72   //
73
74   ((AliTRDdigitsManager &) m).Copy(*this);
75
76 }
77
78 //_____________________________________________________________________________
79 AliTRDdigitsManager::~AliTRDdigitsManager()
80 {
81   //
82   // AliTRDdigitsManager destructor
83   //
84
85   if (fDigits) {
86     fDigits->Delete();
87     delete fDigits;
88     fDigits = NULL;
89   }
90
91   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
92     fDictionary[iDict]->Delete();
93     delete fDictionary[iDict];
94     fDictionary[iDict] = NULL;
95   }
96
97 }
98
99 //_____________________________________________________________________________
100 void AliTRDdigitsManager::Copy(TObject &m) const
101 {
102   //
103   // Copy function
104   //
105
106   ((AliTRDdigitsManager &) m).fIsRaw   = fIsRaw;
107   ((AliTRDdigitsManager &) m).fEvent   = fEvent;
108   ((AliTRDdigitsManager &) m).fDebug   = fDebug;
109   ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
110
111   TObject::Copy(m);
112
113 }
114
115 //_____________________________________________________________________________
116 void AliTRDdigitsManager::CreateArrays()
117 {
118   //
119   // Create the data arrays
120   //
121
122   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
123
124   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
125     fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
126                                                ,AliTRDgeometry::Ndet());
127   }
128
129 }
130 //_____________________________________________________________________________
131 void AliTRDdigitsManager::ResetArrays()
132 {
133   //
134   // Reset the data arrays
135   //
136
137   if (fDigits) {
138     delete fDigits;
139   }
140   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
141
142   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
143     if (fDictionary[iDict]) {  
144       delete fDictionary[iDict];
145     }
146     fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
147                                                ,AliTRDgeometry::Ndet());
148   }
149
150 }
151
152 //_____________________________________________________________________________
153 void AliTRDdigitsManager::SetRaw()
154 {
155   //
156   // Switch on the raw digits flag
157   //
158
159   fIsRaw = kTRUE;
160
161   fDigits->SetBit(AliTRDdigit::RawDigit());
162   
163 }
164
165 //_____________________________________________________________________________
166 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
167                                        , Int_t det) const
168 {
169   //
170   // Returns the amplitude of a digit
171   //
172
173   return ((Short_t) GetDigits(det)->GetData(row,col,time));
174
175 }
176  
177 //_____________________________________________________________________________
178 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
179 {
180   //
181   // Creates the tree and branches for the digits and the dictionary
182   //
183
184   Int_t buffersize = 64000;
185
186   Bool_t status = kTRUE;
187
188   if (tree) {
189     fTree = tree;
190   }
191
192   // Make the branch for the digits
193   if (fDigits) {
194     const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
195     if (kDigits) {
196       if (!fTree) return kFALSE;
197       TBranch* branch = fTree->GetBranch("TRDdigits");
198       if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
199                                  &kDigits,buffersize,99);
200       if (fDebug > 0) {
201         printf("<AliTRDdigitsManager::MakeBranch> ");
202         printf("Making branch TRDdigits\n");
203       }
204     }
205     else {
206       status = kFALSE;
207     }
208   }
209   else {
210     status = kFALSE;
211   }
212
213   // Make the branches for the dictionaries
214   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
215     Char_t branchname[15];
216     sprintf(branchname,"TRDdictionary%d",iDict);
217     if (fDictionary[iDict]) {
218       const AliTRDdataArray *kDictionary = 
219               (AliTRDdataArray *) fDictionary[iDict]->At(0);
220       if (kDictionary) {
221         if (!fTree) return kFALSE;
222         TBranch* branch = fTree->GetBranch(branchname);
223         if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
224                                    &kDictionary,buffersize,99);
225         if (fDebug > 0) {
226           printf("<AliTRDdigitsManager::MakeBranch> ");
227           printf("Making branch %s\n",branchname);
228         }
229       }
230       else {
231         status = kFALSE;
232       }
233     }
234     else {
235       status = kFALSE;
236     }
237   }
238
239   return status;
240
241 }
242
243 //_____________________________________________________________________________
244 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
245 {
246   //
247   // Reads the digit information from the input file
248   //
249
250   Bool_t status = kTRUE;
251
252   if (tree) {
253
254     fTree = tree;
255
256   }
257
258   if (!fDigits) {
259     if (fDebug > 0) {
260       printf("<AliTRDdigitsManager::ReadDigits> ");
261       printf("Create the data arrays.\n");
262     }
263     CreateArrays();
264   }
265
266   status = fDigits->LoadArray("TRDdigits",fTree);
267
268   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
269     Char_t branchname[15];
270     sprintf(branchname,"TRDdictionary%d",iDict);
271     status = fDictionary[iDict]->LoadArray(branchname,fTree);
272   }  
273
274   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
275     fIsRaw = kTRUE;
276   }
277   else {
278     fIsRaw = kFALSE;
279   }
280
281   return kTRUE;
282
283 }
284
285 //_____________________________________________________________________________
286 Bool_t AliTRDdigitsManager::WriteDigits()
287 {
288   //
289   // Writes out the TRD-digits and the dictionaries
290   //
291
292   // Store the contents of the segment array in the tree
293   if (!fDigits->StoreArray("TRDdigits",fTree)) {
294     printf("<AliTRDdigitsManager::WriteDigits> ");
295     printf("Error while storing digits in branch TRDdigits\n");
296     return kFALSE;
297   }
298   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
299     Char_t branchname[15];
300     sprintf(branchname,"TRDdictionary%d",iDict);
301     if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
302       printf("<AliTRDdigitsManager::WriteDigits> ");
303       printf("Error while storing dictionary in branch %s\n",branchname);
304       return kFALSE;
305     }
306   }
307
308   // Write the new tree to the output file
309   //fTree->Write();
310   fTree->AutoSave();  // Modification by Jiri
311
312   return kTRUE;
313
314 }
315
316 //_____________________________________________________________________________
317 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
318                                          , Int_t time, Int_t det) const
319 {
320   // 
321   // Creates a single digit object 
322   //
323
324   Int_t digits[4];
325   Int_t amp[1];
326
327   digits[0] = det;
328   digits[1] = row;
329   digits[2] = col;
330   digits[3] = time;
331
332   amp[0]    = GetDigits(det)->GetData(row,col,time);
333   
334   return (new AliTRDdigit(fIsRaw,digits,amp));
335
336 }
337
338 //_____________________________________________________________________________
339 Int_t AliTRDdigitsManager::GetTrack(Int_t track
340                                   , Int_t row, Int_t col, Int_t time
341                                   , Int_t det) const
342 {
343   // 
344   // Returns the MC-track numbers from the dictionary.
345   //
346
347   if ((track < 0) || (track >= kNDict)) {
348     TObject::Error("GetTracks"
349                   ,"track %d out of bounds (size: %d, this: 0x%08x)"
350                   ,track,kNDict,this);
351     return -1;
352   }
353
354   // Array contains index+1 to allow data compression
355   return (GetDictionary(det,track)->GetData(row,col,time) - 1);
356
357 }
358
359 //_____________________________________________________________________________
360 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
361 {
362   //
363   // Returns the digits array for one detector
364   //
365
366   return (AliTRDdataArrayI *) fDigits->At(det);
367
368 }
369
370 //_____________________________________________________________________________
371 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
372 {
373   //
374   // Returns the dictionary for one detector
375   //
376
377   return (AliTRDdataArrayI *) fDictionary[i]->At(det);
378
379 }
380
381 //_____________________________________________________________________________
382 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
383 {
384   // 
385   // Returns the MC-track numbers from the dictionary for a given digit
386   //
387
388   Int_t row  = Digit->GetRow();
389   Int_t col  = Digit->GetCol();
390   Int_t time = Digit->GetTime();
391   Int_t det  = Digit->GetDetector();
392
393   return GetTrack(track,row,col,time,det);
394
395 }
396
397 //_____________________________________________________________________________
398 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
399 {
400   //
401   // Assignment operator
402   //
403
404   if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
405   return *this;
406
407 }