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
36 TDirectory* dir = gDirectory;
37 fFile = TFile::Open(fileName);
39 if (!fFile || !fFile->IsOpen()) {
40 Error("AliRawReaderRoot", "could not open file %s", fileName);
43 TTree* tree = (TTree*) fFile->Get("RAW");
45 Error("AliRawReaderRoot", "no raw data tree found");
48 TBranch* branch = tree->GetBranch("rawevent");
50 Error("AliRawReaderRoot", "no raw data branch found");
54 fEvent = new AliRawEvent;
55 branch->SetAddress(&fEvent);
56 if (branch->GetEntry(eventNumber) <= 0) {
57 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
67 fPosition = fEnd = NULL;
70 AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
72 // create an object to read digits from the given raw event
83 fPosition = fEnd = NULL;
86 AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
87 AliRawReader(rawReader)
92 fEvent = rawReader.fEvent;
94 fSubEventIndex = rawReader.fSubEventIndex;
95 fSubEvent = rawReader.fSubEvent;
96 fRawData = rawReader.fRawData;
97 fHeader = rawReader.fHeader;
99 fCount = rawReader.fCount;
100 fPosition = rawReader.fPosition;
101 fEnd = rawReader.fEnd;
104 AliRawReaderRoot& AliRawReaderRoot::operator = (const AliRawReaderRoot&
107 // assignment operator
109 this->~AliRawReaderRoot();
110 new(this) AliRawReaderRoot(rawReader);
114 AliRawReaderRoot::~AliRawReaderRoot()
116 // delete objects and close root file
119 if (fEvent) delete fEvent;
126 UInt_t AliRawReaderRoot::GetType() const
128 // get the type from the event header
130 if (!fEvent) return 0;
131 return fEvent->GetHeader()->GetType();
134 UInt_t AliRawReaderRoot::GetRunNumber() const
136 // get the run number from the event header
138 if (!fEvent) return 0;
139 return fEvent->GetHeader()->GetRunNumber();
142 const UInt_t* AliRawReaderRoot::GetEventId() const
144 // get the event id from the event header
146 if (!fEvent) return NULL;
147 return fEvent->GetHeader()->GetId();
150 const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
152 // get the trigger pattern from the event header
154 if (!fEvent) return NULL;
155 return fEvent->GetHeader()->GetTriggerPattern();
158 const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
160 // get the detector pattern from the event header
162 if (!fEvent) return NULL;
163 return fEvent->GetHeader()->GetDetectorPattern();
166 const UInt_t* AliRawReaderRoot::GetAttributes() const
168 // get the type attributes from the event header
170 if (!fEvent) return NULL;
171 return fEvent->GetHeader()->GetTypeAttribute();
174 UInt_t AliRawReaderRoot::GetLDCId() const
176 // get the LDC Id from the event header
178 if (!fEvent || !fEvent->GetSubEvent(fSubEventIndex)) return 0;
179 return fEvent->GetSubEvent(fSubEventIndex)->GetHeader()->GetLDCId();
182 UInt_t AliRawReaderRoot::GetGDCId() const
184 // get the GDC Id from the event header
186 if (!fEvent) return 0;
187 return fEvent->GetHeader()->GetGDCId();
191 Int_t AliRawReaderRoot::GetEquipmentSize() const
193 // get the size of the equipment
195 if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
196 return fEvent->GetEquipmentHeader()->GetEquipmentSize();
199 Int_t AliRawReaderRoot::GetEquipmentType() const
201 // get the type from the equipment header
203 if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
204 return fEvent->GetEquipmentHeader()->GetEquipmentType();
207 Int_t AliRawReaderRoot::GetEquipmentId() const
209 // get the ID from the equipment header
211 if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
212 return fEvent->GetEquipmentHeader()->GetId();
215 const UInt_t* AliRawReaderRoot::GetEquipmentAttributes() const
217 // get the attributes from the equipment header
219 if (!fEvent || !fEvent->GetEquipmentHeader()) return NULL;
220 return fEvent->GetEquipmentHeader()->GetTypeAttribute();
223 Int_t AliRawReaderRoot::GetEquipmentElementSize() const
225 // get the basic element size from the equipment header
227 if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
228 return fEvent->GetEquipmentHeader()->GetBasicSizeType();
232 Bool_t AliRawReaderRoot::ReadHeader()
234 // read a data header at the current position
235 // returns kFALSE if the data header could not be read
238 if (!fEvent) return kFALSE;
241 // skip payload (if event was not selected)
242 if (fCount > 0) fPosition += fCount;
244 // get the first or the next sub event if at the end of a sub event
245 if (!fSubEvent || (fPosition >= fEnd)) {
247 // check for end of event data
248 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
249 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
251 // check the magic word of the sub event
252 if (!fSubEvent->GetHeader()->IsValid()) {
253 Error("ReadHeader", "wrong magic number in sub event!");
254 fSubEvent->GetHeader()->Dump();
255 fErrorCode = kErrMagic;
259 fRawData = fSubEvent->GetRawData();
261 fPosition = (UChar_t*) fRawData->GetBuffer();
262 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
265 // continue with the next sub event if no data left in the payload
266 if (fPosition >= fEnd) continue;
268 // check that there are enough bytes left for the data header
269 if (fPosition + sizeof(AliRawDataHeader) > fEnd) {
270 Error("ReadHeader", "could not read data header!");
271 Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
272 fSubEvent->GetHeader()->Dump();
275 fErrorCode = kErrNoDataHeader;
279 // "read" the data header
280 fHeader = (AliRawDataHeader*) fPosition;
281 fPosition += sizeof(AliRawDataHeader);
282 if (fHeader->fSize != 0xFFFFFFFF) {
283 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
285 fCount = fEnd - fPosition;
288 // check consistency of data size in the header and in the sub event
289 if (fPosition + fCount > fEnd) {
290 Error("ReadHeader", "size in data header exceeds event size!");
291 Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
292 fSubEvent->GetHeader()->Dump();
295 fErrorCode = kErrSize;
299 } while (!IsSelected());
304 Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
306 // reads the next payload at the current position
307 // returns kFALSE if the data could not be read
310 while (fCount == 0) {
311 if (!ReadHeader()) return kFALSE;
319 Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
321 // reads the next block of data at the current position
322 // returns kFALSE if the data could not be read
325 if (fPosition + size > fEnd) {
326 Error("ReadNext", "could not read data!");
327 fErrorCode = kErrOutOfBounds;
330 memcpy(data, fPosition, size);
337 Bool_t AliRawReaderRoot::Reset()
339 // reset the current position to the beginning of the event
347 fPosition = fEnd = NULL;
352 Int_t AliRawReaderRoot::CheckData() const
354 // check the consistency of the data
356 if (!fEvent) return 0;
358 AliRawEvent* subEvent = NULL;
359 Int_t subEventIndex = 0;
360 UChar_t* position = 0;
365 // get the first or the next sub event if at the end of a sub event
366 if (!subEvent || (position >= end)) {
368 // check for end of event data
369 if (subEventIndex >= fEvent->GetNSubEvents()) return result;
370 subEvent = fEvent->GetSubEvent(subEventIndex++);
372 // check the magic word of the sub event
373 if (!fSubEvent->GetHeader()->IsValid()) {
378 AliRawData* rawData = subEvent->GetRawData();
379 position = (UChar_t*) rawData->GetBuffer();
380 end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize();
383 // continue with the next sub event if no data left in the payload
384 if (position >= end) continue;
386 // check that there are enough bytes left for the data header
387 if (position + sizeof(AliRawDataHeader) > end) {
388 result |= kErrNoDataHeader;
393 // check consistency of data size in the header and in the sub event
394 AliRawDataHeader* header = (AliRawDataHeader*) position;
395 if (fHeader->fSize != 0xFFFFFFFF) {
396 if (position + header->fSize > end) {
400 position += header->fSize;