Merge with TRD-develop
[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$
793ff80c 18Revision 1.1.2.5 2000/10/17 02:27:34 cblume
19Get rid of global constants
20
21Revision 1.1.2.4 2000/10/15 23:40:01 cblume
22Remove AliTRDconst
23
24Revision 1.1.2.3 2000/10/06 16:49:46 cblume
25Made Getters const
26
27Revision 1.1.2.2 2000/10/04 16:34:58 cblume
28Replace include files by forward declarations
29
94de3818 30Revision 1.5 2000/06/09 11:10:07 cblume
31Compiler warnings and coding conventions, next round
32
dd9a6ee3 33Revision 1.4 2000/06/08 18:32:58 cblume
34Make code compliant to coding conventions
35
8230f242 36Revision 1.3 2000/06/07 16:27:01 cblume
37Try to remove compiler warnings on Sun and HP
38
9d0b222b 39Revision 1.2 2000/05/08 16:17:27 cblume
40Merge TRD-develop
41
6f1e466d 42Revision 1.1.2.1 2000/05/08 14:44:01 cblume
43Add 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///////////////////////////////////////////////////////////////////////////////
793ff80c 53
54#include <TTree.h>
94de3818 55
6f1e466d 56#include "AliRun.h"
57
58#include "AliTRDdigitsManager.h"
793ff80c 59#include "AliTRDsegmentArray.h"
60#include "AliTRDdataArrayI.h"
61#include "AliTRDdigit.h"
62#include "AliTRDgeometry.h"
6f1e466d 63
64ClassImp(AliTRDdigitsManager)
65
66//_____________________________________________________________________________
793ff80c 67
68 // Number of track dictionary arrays
69 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
70
71//_____________________________________________________________________________
6f1e466d 72AliTRDdigitsManager::AliTRDdigitsManager():TObject()
73{
74 //
75 // Default constructor
76 //
77
78 fIsRaw = kFALSE;
79
793ff80c 80 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
6f1e466d 81
82 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
793ff80c 83 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
84 ,AliTRDgeometry::Ndet());
6f1e466d 85 }
86
87}
88
89//_____________________________________________________________________________
dd9a6ee3 90AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
8230f242 91{
92 //
93 // AliTRDdigitsManager copy constructor
94 //
95
dd9a6ee3 96 ((AliTRDdigitsManager &) m).Copy(*this);
8230f242 97
98}
99
100//_____________________________________________________________________________
6f1e466d 101AliTRDdigitsManager::~AliTRDdigitsManager()
102{
8230f242 103 //
104 // AliTRDdigitsManager destructor
105 //
6f1e466d 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//_____________________________________________________________________________
dd9a6ee3 120void AliTRDdigitsManager::Copy(TObject &m)
8230f242 121{
122 //
123 // Copy function
124 //
125
dd9a6ee3 126 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
8230f242 127
128 TObject::Copy(m);
129
130}
131
132//_____________________________________________________________________________
6f1e466d 133void AliTRDdigitsManager::SetRaw()
134{
135
136 fIsRaw = kTRUE;
137
793ff80c 138 fDigits->SetBit(AliTRDdigit::RawDigit());
6f1e466d 139
140}
141
142//_____________________________________________________________________________
143Bool_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) {
8230f242 157 const AliTRDdataArrayI *kDigits =
6f1e466d 158 (AliTRDdataArrayI *) fDigits->At(0);
8230f242 159 if (kDigits) {
160 gAlice->TreeD()->Branch("TRDdigits",kDigits->IsA()->GetName()
161 ,&kDigits,buffersize,1);
6f1e466d 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]) {
8230f242 179 const AliTRDdataArrayI *kDictionary =
6f1e466d 180 (AliTRDdataArrayI *) fDictionary[iDict]->At(0);
8230f242 181 if (kDictionary) {
182 gAlice->TreeD()->Branch(branchname,kDictionary->IsA()->GetName()
183 ,&kDictionary,buffersize,1);
6f1e466d 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//_____________________________________________________________________________
206Bool_t AliTRDdigitsManager::ReadDigits()
207{
8230f242 208 //
209 // Reads the digit information from the input file
210 //
6f1e466d 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
793ff80c 222 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
6f1e466d 223 fIsRaw = kTRUE;
224 }
225 else {
226 fIsRaw = kFALSE;
227 }
228
229 return kTRUE;
230
231}
232
233//_____________________________________________________________________________
234Bool_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}
9d0b222b 264
265//_____________________________________________________________________________
266AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 267 , Int_t time, Int_t det) const
9d0b222b 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//_____________________________________________________________________________
288Int_t AliTRDdigitsManager::GetTrack(Int_t track
289 , Int_t row, Int_t col, Int_t time
793ff80c 290 , Int_t det) const
9d0b222b 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
dd9a6ee3 308//_____________________________________________________________________________
793ff80c 309AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 310{
311 //
312 // Returns the digits array for one detector
313 //
314
315 return (AliTRDdataArrayI *) fDigits->At(det);
316
317}
318
319//_____________________________________________________________________________
793ff80c 320AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 321{
322 //
323 // Returns the dictionary for one detector
324 //
325
326 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
327
328}
329
330//_____________________________________________________________________________
793ff80c 331Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 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//_____________________________________________________________________________
347AliTRDdigitsManager &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}