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"
24 #include "AliRawEvent.h"
27 ClassImp(AliRawReaderRoot)
30 AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber)
32 // create an object to read digits from the given input file for the
33 // event with the given number
35 TDirectory* dir = gDirectory;
36 fFile = TFile::Open(fileName);
38 if (!fFile || !fFile->IsOpen()) {
39 Error("AliRawReaderRoot", "could not open file %s", fileName);
42 TTree* tree = (TTree*) fFile->Get("RAW");
44 Error("AliRawReaderRoot", "no raw data tree found");
47 TBranch* branch = tree->GetBranch("rawevent");
49 Error("AliRawReaderRoot", "no raw data branch found");
53 fEvent = new AliRawEvent;
54 branch->SetAddress(&fEvent);
55 if (branch->GetEntry(eventNumber) <= 0) {
56 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
66 fPosition = fEnd = NULL;
69 AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
71 // create an object to read digits from the given raw event
82 fPosition = fEnd = NULL;
85 AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
86 AliRawReader(rawReader)
91 fEvent = rawReader.fEvent;
93 fSubEventIndex = rawReader.fSubEventIndex;
94 fSubEvent = rawReader.fSubEvent;
95 fRawData = rawReader.fRawData;
96 fMiniHeader = rawReader.fMiniHeader;
98 fCount = rawReader.fCount;
99 fPosition = rawReader.fPosition;
100 fEnd = rawReader.fEnd;
103 AliRawReaderRoot& AliRawReaderRoot::operator = (const AliRawReaderRoot&
106 // assignment operator
108 this->~AliRawReaderRoot();
109 new(this) AliRawReaderRoot(rawReader);
113 AliRawReaderRoot::~AliRawReaderRoot()
115 // delete objects and close root file
118 if (fEvent) delete fEvent;
125 UInt_t AliRawReaderRoot::GetType() const
127 // get the type from the event header
129 if (!fEvent) return 0;
130 return fEvent->GetHeader()->GetType();
133 UInt_t AliRawReaderRoot::GetRunNumber() const
135 // get the run number from the event header
137 if (!fEvent) return 0;
138 return fEvent->GetHeader()->GetRunNumber();
141 const UInt_t* AliRawReaderRoot::GetEventId() const
143 // get the event id from the event header
145 if (!fEvent) return NULL;
146 return fEvent->GetHeader()->GetId();
149 const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
151 // get the trigger pattern from the event header
153 if (!fEvent) return NULL;
154 return fEvent->GetHeader()->GetTriggerPattern();
157 const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
159 // get the detector pattern from the event header
161 if (!fEvent) return NULL;
162 return fEvent->GetHeader()->GetDetectorPattern();
165 const UInt_t* AliRawReaderRoot::GetAttributes() const
167 // get the type attributes from the event header
169 if (!fEvent) return NULL;
170 return fEvent->GetHeader()->GetTypeAttribute();
173 UInt_t AliRawReaderRoot::GetGDCId() const
175 // get the GDC Id from the event header
177 if (!fEvent) return 0;
178 return fEvent->GetHeader()->GetGDCId();
182 Bool_t AliRawReaderRoot::ReadMiniHeader()
184 // read a mini header at the current position
185 // returns kFALSE if the mini header could not be read
187 if (!fEvent) return kFALSE;
189 if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
190 if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
191 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
192 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
193 fRawData = fSubEvent->GetRawData();
195 fPosition = (UChar_t*) fRawData->GetBuffer();
196 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
198 if (fPosition >= fEnd) continue; // no data left in the payload
199 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
200 Error("ReadMiniHeader", "could not read data!");
203 fMiniHeader = (AliMiniHeader*) fPosition;
204 fPosition += sizeof(AliMiniHeader);
205 if (!CheckMiniHeader()) {
206 Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
207 fSubEvent->GetHeader()->Dump();
212 fCount = fMiniHeader->fSize;
213 if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
214 Error("ReadMiniHeader", "size in mini header exceeds event size!");
215 Warning("ReadMiniHeader", "skipping %d bytes", fEnd - fPosition);
216 fSubEvent->GetHeader()->Dump();
221 } while (!IsSelected());
225 Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
227 // reads the next payload at the current position
228 // returns kFALSE if the data could not be read
230 while (fCount == 0) {
231 if (!ReadMiniHeader()) return kFALSE;
239 Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
241 // reads the next block of data at the current position
242 // returns kFALSE if the data could not be read
244 if (fPosition + size > fEnd) {
245 Error("ReadNext", "could not read data!");
248 memcpy(data, fPosition, size);
255 Bool_t AliRawReaderRoot::Reset()
257 // reset the current position to the beginning of the event
265 fPosition = fEnd = NULL;