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