]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TRD/AliTRDdigitsManager.cxx
Added a prototection to prevent deleting the run loader in case the getter is inoked...
[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
88cb7938 16/* $Id$ */
6f1e466d 17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// Manages the digits and the track dictionary in the form of //
21// AliTRDdataArray objects. //
22// //
23///////////////////////////////////////////////////////////////////////////////
6244debe 24
a2cb5b3d 25#include <Riostream.h>
793ff80c 26
2ab0c725 27#include <TROOT.h>
793ff80c 28#include <TTree.h>
2ab0c725 29#include <TFile.h>
94de3818 30
6f1e466d 31#include "AliRun.h"
32
33#include "AliTRDdigitsManager.h"
793ff80c 34#include "AliTRDsegmentArray.h"
35#include "AliTRDdataArrayI.h"
36#include "AliTRDdigit.h"
37#include "AliTRDgeometry.h"
9e1a0ddb 38#include "AliTRD.h"
6f1e466d 39
40ClassImp(AliTRDdigitsManager)
41
793ff80c 42//_____________________________________________________________________________
43
44 // Number of track dictionary arrays
45 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
46
6f1e466d 47//_____________________________________________________________________________
48AliTRDdigitsManager::AliTRDdigitsManager():TObject()
49{
50 //
51 // Default constructor
52 //
53
abaf1f1d 54 fIsRaw = kFALSE;
55 fEvent = 0;
855bfffd 56 fDebug = 0;
abaf1f1d 57 fSDigits = 0;
6f1e466d 58
abaf1f1d 59 fTree = NULL;
60 fDigits = NULL;
6f1e466d 61 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
abaf1f1d 62 fDictionary[iDict] = NULL;
6f1e466d 63 }
64
65}
66
8230f242 67//_____________________________________________________________________________
dd9a6ee3 68AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
73ae7b59 69:TObject(m)
8230f242 70{
71 //
72 // AliTRDdigitsManager copy constructor
73 //
74
dd9a6ee3 75 ((AliTRDdigitsManager &) m).Copy(*this);
8230f242 76
77}
78
6f1e466d 79//_____________________________________________________________________________
80AliTRDdigitsManager::~AliTRDdigitsManager()
81{
8230f242 82 //
83 // AliTRDdigitsManager destructor
84 //
6f1e466d 85
86 if (fDigits) {
87 fDigits->Delete();
88 delete fDigits;
abaf1f1d 89 fDigits = NULL;
6f1e466d 90 }
91
92 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
93 fDictionary[iDict]->Delete();
94 delete fDictionary[iDict];
abaf1f1d 95 fDictionary[iDict] = NULL;
6f1e466d 96 }
97
98}
99
8230f242 100//_____________________________________________________________________________
dd9a6ee3 101void AliTRDdigitsManager::Copy(TObject &m)
8230f242 102{
103 //
104 // Copy function
105 //
106
abaf1f1d 107 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
108 ((AliTRDdigitsManager &) m).fEvent = fEvent;
855bfffd 109 ((AliTRDdigitsManager &) m).fDebug = fDebug;
abaf1f1d 110 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
8230f242 111
112 TObject::Copy(m);
113
114}
115
abaf1f1d 116//_____________________________________________________________________________
117void AliTRDdigitsManager::CreateArrays()
118{
119 //
120 // Create the data arrays
121 //
122
123 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
124
125 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
126 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
127 ,AliTRDgeometry::Ndet());
128 }
129
17eee78a 130}
131//_____________________________________________________________________________
132void AliTRDdigitsManager::ResetArrays()
133{
134 //
135 // Reset the data arrays
136 //
137
138 if (fDigits) {
139 delete fDigits;
140 }
141 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
142
143 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
144 if (fDictionary[iDict]) {
145 delete fDictionary[iDict];
146 }
147 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
148 ,AliTRDgeometry::Ndet());
149 }
150
abaf1f1d 151}
152
6f1e466d 153//_____________________________________________________________________________
154void AliTRDdigitsManager::SetRaw()
155{
0a29d0f1 156 //
157 // Switch on the raw digits flag
158 //
6f1e466d 159
160 fIsRaw = kTRUE;
161
793ff80c 162 fDigits->SetBit(AliTRDdigit::RawDigit());
6f1e466d 163
164}
165
16bf9884 166//_____________________________________________________________________________
167Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
168 , Int_t det) const
169{
170 //
171 // Returns the amplitude of a digit
172 //
173
174 return ((Short_t) GetDigits(det)->GetData(row,col,time));
175
176}
177
6f1e466d 178//_____________________________________________________________________________
88cb7938 179Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
855bfffd 180{
181 //
182 // Creates the tree and branches for the digits and the dictionary
183 //
184
185 Int_t buffersize = 64000;
186
187 Bool_t status = kTRUE;
188
189 AliTRD *trd = (AliTRD *) gAlice->GetDetector("TRD") ;
190
191 if (tree) {
192 fTree = tree;
193 }
194
abaf1f1d 195 // Make the branch for the digits
196 if (fDigits) {
197 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
198 if (kDigits) {
199 trd->MakeBranchInTree(fTree,"TRDdigits",kDigits->IsA()->GetName()
88cb7938 200 ,&kDigits,buffersize,99);
855bfffd 201 if (fDebug > 0) {
202 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 203 printf("Making branch TRDdigits\n");
204 }
6f1e466d 205 }
206 else {
207 status = kFALSE;
208 }
abaf1f1d 209 }
210 else {
211 status = kFALSE;
212 }
6f1e466d 213
abaf1f1d 214 // Make the branches for the dictionaries
215 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
216 Char_t branchname[15];
217 sprintf(branchname,"TRDdictionary%d",iDict);
218 if (fDictionary[iDict]) {
219 const AliTRDdataArray *kDictionary =
220 (AliTRDdataArray *) fDictionary[iDict]->At(0);
221 if (kDictionary) {
222 trd->MakeBranchInTree(fTree,branchname,kDictionary->IsA()->GetName()
88cb7938 223 ,&kDictionary,buffersize,99);
855bfffd 224 if (fDebug > 0) {
225 printf("<AliTRDdigitsManager::MakeBranch> ");
6f1e466d 226 printf("Making branch %s\n",branchname);
6244debe 227 }
6f1e466d 228 }
229 else {
230 status = kFALSE;
231 }
232 }
abaf1f1d 233 else {
234 status = kFALSE;
235 }
6f1e466d 236 }
237
238 return status;
239
240}
241
242//_____________________________________________________________________________
855bfffd 243Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
6f1e466d 244{
8230f242 245 //
246 // Reads the digit information from the input file
247 //
6f1e466d 248
249 Bool_t status = kTRUE;
250
855bfffd 251 if (tree) {
252
253 fTree = tree;
254
abaf1f1d 255 }
256
257 if (!fDigits) {
855bfffd 258 if (fDebug > 0) {
259 printf("<AliTRDdigitsManager::ReadDigits> ");
abaf1f1d 260 printf("Create the data arrays.\n");
261 }
262 CreateArrays();
263 }
264
265 status = fDigits->LoadArray("TRDdigits",fTree);
6f1e466d 266
267 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
268 Char_t branchname[15];
269 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 270 status = fDictionary[iDict]->LoadArray(branchname,fTree);
6f1e466d 271 }
272
793ff80c 273 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
6f1e466d 274 fIsRaw = kTRUE;
275 }
276 else {
277 fIsRaw = kFALSE;
278 }
279
280 return kTRUE;
281
282}
283
284//_____________________________________________________________________________
285Bool_t AliTRDdigitsManager::WriteDigits()
286{
287 //
288 // Writes out the TRD-digits and the dictionaries
289 //
290
6f1e466d 291 // Store the contents of the segment array in the tree
abaf1f1d 292 if (!fDigits->StoreArray("TRDdigits",fTree)) {
855bfffd 293 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 294 printf("Error while storing digits in branch TRDdigits\n");
295 return kFALSE;
296 }
297 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
298 Char_t branchname[15];
299 sprintf(branchname,"TRDdictionary%d",iDict);
abaf1f1d 300 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
855bfffd 301 printf("<AliTRDdigitsManager::WriteDigits> ");
6f1e466d 302 printf("Error while storing dictionary in branch %s\n",branchname);
303 return kFALSE;
304 }
305 }
306
abaf1f1d 307 // Write the new tree to the output file
8e64dd77 308 //fTree->Write();
309 fTree->AutoSave(); // Modification by Jiri
abaf1f1d 310
6f1e466d 311 return kTRUE;
312
313}
9d0b222b 314
315//_____________________________________________________________________________
316AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
793ff80c 317 , Int_t time, Int_t det) const
9d0b222b 318{
319 //
320 // Creates a single digit object
321 //
322
323 Int_t digits[4];
324 Int_t amp[1];
325
326 digits[0] = det;
327 digits[1] = row;
328 digits[2] = col;
329 digits[3] = time;
330
331 amp[0] = GetDigits(det)->GetData(row,col,time);
332
333 return (new AliTRDdigit(fIsRaw,digits,amp));
334
335}
336
337//_____________________________________________________________________________
338Int_t AliTRDdigitsManager::GetTrack(Int_t track
339 , Int_t row, Int_t col, Int_t time
793ff80c 340 , Int_t det) const
9d0b222b 341{
342 //
343 // Returns the MC-track numbers from the dictionary.
344 //
345
346 if ((track < 0) || (track >= kNDict)) {
347 TObject::Error("GetTracks"
348 ,"track %d out of bounds (size: %d, this: 0x%08x)"
349 ,track,kNDict,this);
350 return -1;
351 }
352
353 // Array contains index+1 to allow data compression
354 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
355
356}
357
dd9a6ee3 358//_____________________________________________________________________________
793ff80c 359AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
dd9a6ee3 360{
361 //
362 // Returns the digits array for one detector
363 //
364
365 return (AliTRDdataArrayI *) fDigits->At(det);
366
367}
368
369//_____________________________________________________________________________
793ff80c 370AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
dd9a6ee3 371{
372 //
373 // Returns the dictionary for one detector
374 //
375
376 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
377
378}
379
380//_____________________________________________________________________________
793ff80c 381Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
dd9a6ee3 382{
383 //
384 // Returns the MC-track numbers from the dictionary for a given digit
385 //
386
387 Int_t row = Digit->GetRow();
388 Int_t col = Digit->GetCol();
389 Int_t time = Digit->GetTime();
390 Int_t det = Digit->GetDetector();
391
392 return GetTrack(track,row,col,time,det);
393
394}
395
396//_____________________________________________________________________________
397AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
398{
399 //
400 // Assignment operator
401 //
402
403 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
404 return *this;
405
406}