1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Manages the digits and the track dictionary in the form of //
21 // AliTRDdataArray objects. //
23 ///////////////////////////////////////////////////////////////////////////////
25 #include <Riostream.h>
34 #include "AliTRDdigitsManager.h"
35 #include "AliTRDsegmentArray.h"
36 #include "AliTRDdataArrayI.h"
37 #include "AliTRDdigit.h"
38 #include "AliTRDgeometry.h"
40 ClassImp(AliTRDdigitsManager)
42 //_____________________________________________________________________________
44 // Number of track dictionary arrays
45 const Int_t AliTRDdigitsManager::fgkNDict = kNDict;
47 //_____________________________________________________________________________
48 AliTRDdigitsManager::AliTRDdigitsManager()
57 // Default constructor
60 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
61 fDictionary[iDict] = NULL;
66 //_____________________________________________________________________________
67 AliTRDdigitsManager::AliTRDdigitsManager(const AliTRDdigitsManager &m)
76 // AliTRDdigitsManager copy constructor
81 //_____________________________________________________________________________
82 AliTRDdigitsManager::~AliTRDdigitsManager()
85 // AliTRDdigitsManager destructor
94 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
95 fDictionary[iDict]->Delete();
96 delete fDictionary[iDict];
97 fDictionary[iDict] = NULL;
102 //_____________________________________________________________________________
103 AliTRDdigitsManager &AliTRDdigitsManager::operator=(const AliTRDdigitsManager &m)
106 // Assignment operator
109 if (this != &m) ((AliTRDdigitsManager &) m).Copy(*this);
114 //_____________________________________________________________________________
115 void AliTRDdigitsManager::Copy(TObject &m) const
121 ((AliTRDdigitsManager &) m).fIsRaw = fIsRaw;
122 ((AliTRDdigitsManager &) m).fEvent = fEvent;
123 ((AliTRDdigitsManager &) m).fSDigits = fSDigits;
129 //_____________________________________________________________________________
130 void AliTRDdigitsManager::CreateArrays()
133 // Create the data arrays
136 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
138 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
139 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
140 ,AliTRDgeometry::Ndet());
144 //_____________________________________________________________________________
145 void AliTRDdigitsManager::ResetArrays()
148 // Reset the data arrays
154 fDigits = new AliTRDsegmentArray("AliTRDdataArrayI",AliTRDgeometry::Ndet());
156 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
157 if (fDictionary[iDict]) {
158 delete fDictionary[iDict];
160 fDictionary[iDict] = new AliTRDsegmentArray("AliTRDdataArrayI"
161 ,AliTRDgeometry::Ndet());
166 //_____________________________________________________________________________
167 void AliTRDdigitsManager::SetRaw()
170 // Switch on the raw digits flag
175 fDigits->SetBit(AliTRDdigit::RawDigit());
179 //_____________________________________________________________________________
180 Short_t AliTRDdigitsManager::GetDigitAmp(Int_t row, Int_t col,Int_t time
184 // Returns the amplitude of a digit
187 if (!GetDigits(det)) return 0;
188 return ((Short_t) GetDigits(det)->GetData(row,col,time));
192 //_____________________________________________________________________________
193 Bool_t AliTRDdigitsManager::MakeBranch(TTree *tree)
196 // Creates the tree and branches for the digits and the dictionary
199 Int_t buffersize = 64000;
201 Bool_t status = kTRUE;
207 // Make the branch for the digits
209 const AliTRDdataArray *kDigits = (AliTRDdataArray *) fDigits->At(0);
211 if (!fTree) return kFALSE;
212 TBranch* branch = fTree->GetBranch("TRDdigits");
213 if (!branch) fTree->Branch("TRDdigits",kDigits->IsA()->GetName(),
214 &kDigits,buffersize,99);
215 AliDebug(1,"Making branch TRDdigits\n");
225 // Make the branches for the dictionaries
226 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
227 Char_t branchname[15];
228 sprintf(branchname,"TRDdictionary%d",iDict);
229 if (fDictionary[iDict]) {
230 const AliTRDdataArray *kDictionary =
231 (AliTRDdataArray *) fDictionary[iDict]->At(0);
233 if (!fTree) return kFALSE;
234 TBranch* branch = fTree->GetBranch(branchname);
235 if (!branch) fTree->Branch(branchname,kDictionary->IsA()->GetName(),
236 &kDictionary,buffersize,99);
237 AliDebug(1,Form("Making branch %s\n",branchname));
252 //_____________________________________________________________________________
253 Bool_t AliTRDdigitsManager::ReadDigits(TTree *tree)
256 // Reads the digit information from the input file
259 Bool_t status = kTRUE;
268 AliDebug(1,"Create the data arrays.\n");
272 status = fDigits->LoadArray("TRDdigits",fTree);
274 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
275 Char_t branchname[15];
276 sprintf(branchname,"TRDdictionary%d",iDict);
277 status = fDictionary[iDict]->LoadArray(branchname,fTree);
280 if (fDigits->TestBit(AliTRDdigit::RawDigit())) {
291 //_____________________________________________________________________________
292 Bool_t AliTRDdigitsManager::WriteDigits()
295 // Writes out the TRD-digits and the dictionaries
298 // Store the contents of the segment array in the tree
299 if (!fDigits->StoreArray("TRDdigits",fTree)) {
300 AliError("Error while storing digits in branch TRDdigits\n");
303 for (Int_t iDict = 0; iDict < kNDict; iDict++) {
304 Char_t branchname[15];
305 sprintf(branchname,"TRDdictionary%d",iDict);
306 if (!fDictionary[iDict]->StoreArray(branchname,fTree)) {
307 AliError(Form("Error while storing dictionary in branch %s\n",branchname));
312 // Write the new tree to the output file
313 fTree->AutoSave(); // Modification by Jiri
319 //_____________________________________________________________________________
320 AliTRDdigit *AliTRDdigitsManager::GetDigit(Int_t row, Int_t col
321 , Int_t time, Int_t det) const
324 // Creates a single digit object
335 amp[0] = GetDigits(det)->GetData(row,col,time);
337 return (new AliTRDdigit(fIsRaw,digits,amp));
341 //_____________________________________________________________________________
342 Int_t AliTRDdigitsManager::GetTrack(Int_t track
343 , Int_t row, Int_t col, Int_t time
347 // Returns the MC-track numbers from the dictionary.
350 if ((track < 0) || (track >= kNDict)) {
351 AliError(Form("track %d out of bounds (size: %d, this: 0x%08x)"
352 ,track,kNDict,this));
356 // Array contains index+1 to allow data compression
357 return (GetDictionary(det,track)->GetData(row,col,time) - 1);
361 //_____________________________________________________________________________
362 AliTRDdataArrayI *AliTRDdigitsManager::GetDigits(Int_t det) const
365 // Returns the digits array for one detector
368 if (!fDigits) return 0x0;
369 return (AliTRDdataArrayI *) fDigits->At(det);
373 //_____________________________________________________________________________
374 AliTRDdataArrayI *AliTRDdigitsManager::GetDictionary(Int_t det, Int_t i) const
377 // Returns the dictionary for one detector
380 return (AliTRDdataArrayI *) fDictionary[i]->At(det);
384 //_____________________________________________________________________________
385 Int_t AliTRDdigitsManager::GetTrack(Int_t track, AliTRDdigit *Digit) const
388 // Returns the MC-track numbers from the dictionary for a given digit
391 Int_t row = Digit->GetRow();
392 Int_t col = Digit->GetCol();
393 Int_t time = Digit->GetTime();
394 Int_t det = Digit->GetDetector();
396 return GetTrack(track,row,col,time,det);