]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDdigitsManager.cxx
Add PPR macros
[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 /*
17 $Log$
18 Revision 1.8  2000/11/01 15:20:13  cblume
19 Change AliTRDdataArrayI to AliTRDdataArray in MakeBranch()
20
21 Revision 1.7  2000/11/01 14:53:20  cblume
22 Merge with TRD-develop
23
24 Revision 1.1.2.5  2000/10/17 02:27:34  cblume
25 Get rid of global constants
26
27 Revision 1.1.2.4  2000/10/15 23:40:01  cblume
28 Remove AliTRDconst
29
30 Revision 1.1.2.3  2000/10/06 16:49:46  cblume
31 Made Getters const
32
33 Revision 1.1.2.2  2000/10/04 16:34:58  cblume
34 Replace include files by forward declarations
35
36 Revision 1.5  2000/06/09 11:10:07  cblume
37 Compiler warnings and coding conventions, next round
38
39 Revision 1.4  2000/06/08 18:32:58  cblume
40 Make code compliant to coding conventions
41
42 Revision 1.3  2000/06/07 16:27:01  cblume
43 Try to remove compiler warnings on Sun and HP
44
45 Revision 1.2  2000/05/08 16:17:27  cblume
46 Merge TRD-develop
47
48 Revision 1.1.2.1  2000/05/08 14:44:01  cblume
49 Add new class AliTRDdigitsManager
50
51 */
52
53 ///////////////////////////////////////////////////////////////////////////////
54 //                                                                           //
55 //  Manages the digits and the track dictionary in the form of               //
56 //  AliTRDdataArray objects.                                                 //
57 //                                                                           //
58 ///////////////////////////////////////////////////////////////////////////////
59  
60 #include <TTree.h>                                                              
61
62 #include "AliRun.h"
63
64 #include "AliTRDdigitsManager.h"
65 #include "AliTRDsegmentArray.h"
66 #include "AliTRDdataArrayI.h"
67 #include "AliTRDdigit.h"
68 #include "AliTRDgeometry.h"
69
70 ClassImp(AliTRDdigitsManager)
71
72 //_____________________________________________________________________________
73
74   // Number of track dictionary arrays
75   const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
76
77 //_____________________________________________________________________________
78 AliTRDdigitsManager::AliTRDdigitsManager():TObject()
79 {
80   //
81   // Default constructor
82   //
83
84   fIsRaw = kFALSE;
85
86   fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
87
88   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
89     fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
90                                                ,AliTRDgeometry::Ndet());
91   }
92
93 }
94
95 //_____________________________________________________________________________
96 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
97 {
98   //
99   // AliTRDdigitsManager copy constructor
100   //
101
102   ((AliTRDdigitsManager &) m).Copy(*this);
103
104 }
105
106 //_____________________________________________________________________________
107 AliTRDdigitsManager::~AliTRDdigitsManager()
108 {
109   //
110   // AliTRDdigitsManager destructor
111   //
112
113   if (fDigits) {
114     fDigits->Delete();
115     delete fDigits;
116   }
117
118   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
119     fDictionary[iDict]->Delete();
120     delete fDictionary[iDict];
121   }
122
123 }
124
125 //_____________________________________________________________________________
126 void AliTRDdigitsManager::Copy(TObject &m)
127 {
128   //
129   // Copy function
130   //
131
132   ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
133
134   TObject::Copy(m);
135
136 }
137
138 //_____________________________________________________________________________
139 void AliTRDdigitsManager::SetRaw()
140 {
141
142   fIsRaw = kTRUE;
143
144   fDigits->SetBit(AliTRDdigit::RawDigit());
145   
146 }
147
148 //_____________________________________________________________________________
149 Bool_t AliTRDdigitsManager::MakeBranch()
150 {
151   //
152   // Creates the branches for the digits and the dictionary in the digits tree
153   //
154
155   Int_t buffersize = 64000;
156
157   Bool_t status = kTRUE;
158
159   if (gAlice->TreeD()) {
160
161     // Make the branch for the digits
162     if (fDigits) {
163       //const AliTRDdataArrayI *kDigits = 
164       //     (AliTRDdataArrayI *) fDigits->At(0);
165       const AliTRDdataArray *kDigits = 
166            (AliTRDdataArray *) fDigits->At(0);
167       if (kDigits) {
168         gAlice->TreeD()->Branch("TRDdigits",kDigits->IsA()->GetName()
169                                            ,&kDigits,buffersize,1);
170         printf("AliTRDdigitsManager::MakeBranch -- ");
171         printf("Making branch TRDdigits\n");
172       }
173       else {
174         status = kFALSE;
175       }
176     }
177     else {
178       status = kFALSE;
179     }
180
181     // Make the branches for the dictionaries
182     for (Int_t iDict = 0; iDict < kNDict; iDict++) {
183       Char_t branchname[15];
184       sprintf(branchname,"TRDdictionary%d",iDict);
185       if (fDictionary[iDict]) {
186         //const AliTRDdataArrayI *kDictionary = 
187         //     (AliTRDdataArrayI *) fDictionary[iDict]->At(0);
188         const AliTRDdataArray *kDictionary = 
189              (AliTRDdataArray *) fDictionary[iDict]->At(0);
190         if (kDictionary) {
191           gAlice->TreeD()->Branch(branchname,kDictionary->IsA()->GetName()
192                                             ,&kDictionary,buffersize,1);
193           printf("AliTRDdigitsManager::MakeBranch -- ");
194           printf("Making branch %s\n",branchname);
195         }
196         else {
197           status = kFALSE;
198         }
199       }
200       else {
201         status = kFALSE;
202       }
203     }
204
205   }
206   else {
207     status = kFALSE;
208   }
209
210   return status;
211
212 }
213
214 //_____________________________________________________________________________
215 Bool_t AliTRDdigitsManager::ReadDigits()
216 {
217   //
218   // Reads the digit information from the input file
219   //
220
221   Bool_t status = kTRUE;
222
223   status = fDigits->LoadArray("TRDdigits");
224
225   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
226     Char_t branchname[15];
227     sprintf(branchname,"TRDdictionary%d",iDict);
228     status = fDictionary[iDict]->LoadArray(branchname);
229   }  
230
231   if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
232     fIsRaw = kTRUE;
233   }
234   else {
235     fIsRaw = kFALSE;
236   }
237
238   return kTRUE;
239
240 }
241
242 //_____________________________________________________________________________
243 Bool_t AliTRDdigitsManager::WriteDigits()
244 {
245   //
246   // Writes out the TRD-digits and the dictionaries
247   //
248
249   // Create the branches
250   if (!(gAlice->TreeD()->GetBranch("TRDdigits"))) { 
251     if (!MakeBranch()) return kFALSE;
252   }
253
254   // Store the contents of the segment array in the tree
255   if (!fDigits->StoreArray("TRDdigits")) {
256     printf("AliTRDdigitsManager::WriteDigits -- ");
257     printf("Error while storing digits in branch TRDdigits\n");
258     return kFALSE;
259   }
260   for (Int_t iDict = 0; iDict < kNDict; iDict++) {
261     Char_t branchname[15];
262     sprintf(branchname,"TRDdictionary%d",iDict);
263     if (!fDictionary[iDict]->StoreArray(branchname)) {
264       printf("AliTRDdigitsManager::WriteDigits -- ");
265       printf("Error while storing dictionary in branch %s\n",branchname);
266       return kFALSE;
267     }
268   }
269
270   return kTRUE;
271
272 }
273
274 //_____________________________________________________________________________
275 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
276                                          , Int_t time, Int_t det) const
277 {
278   // 
279   // Creates a single digit object 
280   //
281
282   Int_t digits[4];
283   Int_t amp[1];
284
285   digits[0] = det;
286   digits[1] = row;
287   digits[2] = col;
288   digits[3] = time;
289
290   amp[0]    = GetDigits(det)->GetData(row,col,time);
291   
292   return (new AliTRDdigit(fIsRaw,digits,amp));
293
294 }
295
296 //_____________________________________________________________________________
297 Int_t AliTRDdigitsManager::GetTrack(Int_t track
298                                   , Int_t row, Int_t col, Int_t time
299                                   , Int_t det) const
300 {
301   // 
302   // Returns the MC-track numbers from the dictionary.
303   //
304
305   if ((track < 0) || (track >= kNDict)) {
306     TObject::Error("GetTracks"
307                   ,"track %d out of bounds (size: %d, this: 0x%08x)"
308                   ,track,kNDict,this);
309     return -1;
310   }
311
312   // Array contains index+1 to allow data compression
313   return (GetDictionary(det,track)->GetData(row,col,time) - 1);
314
315 }
316
317 //_____________________________________________________________________________
318 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
319 {
320   //
321   // Returns the digits array for one detector
322   //
323
324   return (AliTRDdataArrayI *) fDigits->At(det);
325
326 }
327
328 //_____________________________________________________________________________
329 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
330 {
331   //
332   // Returns the dictionary for one detector
333   //
334
335   return (AliTRDdataArrayI *) fDictionary[i]->At(det);
336
337 }
338
339 //_____________________________________________________________________________
340 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
341 {
342   // 
343   // Returns the MC-track numbers from the dictionary for a given digit
344   //
345
346   Int_t row  = Digit->GetRow();
347   Int_t col  = Digit->GetCol();
348   Int_t time = Digit->GetTime();
349   Int_t det  = Digit->GetDetector();
350
351   return GetTrack(track,row,col,time,det);
352
353 }
354
355 //_____________________________________________________________________________
356 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
357 {
358   //
359   // Assignment operator
360   //
361
362   if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
363   return *this;
364
365 }