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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // This is a class for reading a raw data from a root file and providing
19 // information about digits
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliRawReaderRoot.h"
26 ClassImp(AliRawReaderRoot)
29 AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber)
31 // create an object to read digits from the given input file for the
32 // event with the given number
34 fFile = TFile::Open(fileName);
35 if (!fFile || !fFile->IsOpen()) {
36 Error("AliRawReaderRoot", "could not open file %s", fileName);
39 TTree* tree = (TTree*) fFile->Get("RAW");
41 Error("AliRawReaderRoot", "no raw data tree found");
44 TBranch* branch = tree->GetBranch("rawevent");
46 Error("AliRawReaderRoot", "no raw data branch found");
50 fEvent = new AliRawEvent;
51 branch->SetAddress(&fEvent);
52 if (branch->GetEntry(eventNumber) <= 0) {
53 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
63 fPosition = fEnd = NULL;
66 AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
68 // create an object to read digits from the given raw event
79 fPosition = fEnd = NULL;
82 AliRawReaderRoot::~AliRawReaderRoot()
84 // delete objects and close root file
87 if (fEvent) delete fEvent;
94 UInt_t AliRawReaderRoot::GetType()
96 // get the type from the event header
98 if (!fEvent) return 0;
99 return fEvent->GetHeader()->GetType();
102 UInt_t AliRawReaderRoot::GetRunNumber()
104 // get the run number from the event header
106 if (!fEvent) return 0;
107 return fEvent->GetHeader()->GetRunNumber();
110 const UInt_t* AliRawReaderRoot::GetEventId()
112 // get the event id from the event header
114 if (!fEvent) return NULL;
115 return fEvent->GetHeader()->GetId();
118 const UInt_t* AliRawReaderRoot::GetTriggerPattern()
120 // get the trigger pattern from the event header
122 if (!fEvent) return NULL;
123 return fEvent->GetHeader()->GetTriggerPattern();
126 const UInt_t* AliRawReaderRoot::GetDetectorPattern()
128 // get the detector pattern from the event header
130 if (!fEvent) return NULL;
131 return fEvent->GetHeader()->GetDetectorPattern();
134 const UInt_t* AliRawReaderRoot::GetAttributes()
136 // get the type attributes from the event header
138 if (!fEvent) return NULL;
139 return fEvent->GetHeader()->GetTypeAttribute();
142 UInt_t AliRawReaderRoot::GetGDCId()
144 // get the GDC Id from the event header
146 if (!fEvent) return 0;
147 return fEvent->GetHeader()->GetGDCId();
151 Bool_t AliRawReaderRoot::ReadMiniHeader()
153 // read a mini header at the current position
154 // returns kFALSE if the mini header could not be read
156 if (!fEvent) return kFALSE;
158 if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
159 if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
160 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
161 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
162 fRawData = fSubEvent->GetRawData();
164 fPosition = (UChar_t*) fRawData->GetBuffer();
165 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
167 if (fPosition >= fEnd) continue; // no data left in the payload
168 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
169 Error("ReadMiniHeader", "could not read data!");
172 fMiniHeader = (AliMiniHeader*) fPosition;
173 fPosition += sizeof(AliMiniHeader);
175 fCount = fMiniHeader->fSize;
176 if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
177 Error("ReadMiniHeader", "size in mini header exceeds event size!");
178 fMiniHeader->fSize = fCount = fEnd - fPosition;
180 } while (!IsSelected());
184 Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
186 // reads the next payload at the current position
187 // returns kFALSE if the data could not be read
189 while (fCount == 0) {
190 if (!ReadMiniHeader()) return kFALSE;
198 Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
200 // reads the next block of data at the current position
201 // returns kFALSE if the data could not be read
203 if (fPosition + size > fEnd) {
204 Error("ReadNext", "could not read data!");
207 memcpy(data, fPosition, size);
214 Bool_t AliRawReaderRoot::Reset()
216 // reset the current position to the beginning of the event
224 fPosition = fEnd = NULL;