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