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