Changed timebin 0 to be the one closest to the readout
[u/mrichter/AliRoot.git] / TRD / AliTRDdigitsManager.cxx
CommitLineData
6f1e466d 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$
94de3818 18Revision 1.5 2000/06/09 11:10:07 cblume
19Compiler warnings and coding conventions, next round
20
dd9a6ee3 21Revision 1.4 2000/06/08 18:32:58 cblume
22Make code compliant to coding conventions
23
8230f242 24Revision 1.3 2000/06/07 16:27:01 cblume
25Try to remove compiler warnings on Sun and HP
26
9d0b222b 27Revision 1.2 2000/05/08 16:17:27 cblume
28Merge TRD-develop
29
6f1e466d 30Revision 1.1.2.1 2000/05/08 14:44:01 cblume
31Add 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
94de3818 42#include <TTree.h>
43
6f1e466d 44#include "AliRun.h"
45
46#include "AliTRDdigitsManager.h"
47#include "AliTRDconst.h"
48
49ClassImp(AliTRDdigitsManager)
50
51//_____________________________________________________________________________
52AliTRDdigitsManager::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//_____________________________________________________________________________
dd9a6ee3 69AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
8230f242 70{
71 //
72 // AliTRDdigitsManager copy constructor
73 //
74
dd9a6ee3 75 ((AliTRDdigitsManager &) m).Copy(*this);
8230f242 76
77}
78
79//_____________________________________________________________________________
6f1e466d 80AliTRDdigitsManager::~AliTRDdigitsManager()
81{
8230f242 82 //
83 // AliTRDdigitsManager destructor
84 //
6f1e466d 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//_____________________________________________________________________________
dd9a6ee3 99void AliTRDdigitsManager::Copy(TObject &m)
8230f242 100{
101 //
102 // Copy function
103 //
104
dd9a6ee3 105 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
8230f242 106
107 TObject::Copy(m);
108
109}
110
111//_____________________________________________________________________________
6f1e466d 112void AliTRDdigitsManager::SetRaw()
113{
114
115 fIsRaw = kTRUE;
116
117 fDigits->SetBit(kRawDigit);
118
119}
120
121//_____________________________________________________________________________
122Bool_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) {
8230f242 136 const AliTRDdataArrayI *kDigits =
6f1e466d 137 (AliTRDdataArrayI *) fDigits->At(0);
8230f242 138 if (kDigits) {
139 gAlice->TreeD()->Branch("TRDdigits",kDigits->IsA()->GetName()
140 ,&kDigits,buffersize,1);
6f1e466d 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]) {
8230f242 158 const AliTRDdataArrayI *kDictionary =
6f1e466d 159 (AliTRDdataArrayI *) fDictionary[iDict]->At(0);
8230f242 160 if (kDictionary) {
161 gAlice->TreeD()->Branch(branchname,kDictionary->IsA()->GetName()
162 ,&kDictionary,buffersize,1);
6f1e466d 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//_____________________________________________________________________________
185Bool_t AliTRDdigitsManager::ReadDigits()
186{
8230f242 187 //
188 // Reads the digit information from the input file
189 //
6f1e466d 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//_____________________________________________________________________________
213Bool_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}
9d0b222b 243
244//_____________________________________________________________________________
245AliTRDdigit *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//_____________________________________________________________________________
267Int_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
dd9a6ee3 287//_____________________________________________________________________________
288AliTRDdataArrayI *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//_____________________________________________________________________________
299AliTRDdataArrayI *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//_____________________________________________________________________________
310Int_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//_____________________________________________________________________________
326AliTRDdigitsManager &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}