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 fFile = TFile::Open(fileName);
36 if (!fFile || !fFile->IsOpen()) {
37 Error("AliRawReaderRoot", "could not open file %s", fileName);
40 TTree* tree = (TTree*) fFile->Get("RAW");
42 Error("AliRawReaderRoot", "no raw data tree found");
45 TBranch* branch = tree->GetBranch("rawevent");
47 Error("AliRawReaderRoot", "no raw data branch found");
51 fEvent = new AliRawEvent;
52 branch->SetAddress(&fEvent);
53 if (branch->GetEntry(eventNumber) <= 0) {
54 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
64 fPosition = fEnd = NULL;
67 AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
69 // create an object to read digits from the given raw event
80 fPosition = fEnd = NULL;
83 AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
84 AliRawReader(rawReader)
89 fEvent = rawReader.fEvent;
91 fSubEventIndex = rawReader.fSubEventIndex;
92 fSubEvent = rawReader.fSubEvent;
93 fRawData = rawReader.fRawData;
94 fMiniHeader = rawReader.fMiniHeader;
96 fCount = rawReader.fCount;
97 fPosition = rawReader.fPosition;
98 fEnd = rawReader.fEnd;
101 AliRawReaderRoot& AliRawReaderRoot::operator = (const AliRawReaderRoot&
104 // assignment operator
106 this->~AliRawReaderRoot();
107 new(this) AliRawReaderRoot(rawReader);
111 AliRawReaderRoot::~AliRawReaderRoot()
113 // delete objects and close root file
116 if (fEvent) delete fEvent;
123 UInt_t AliRawReaderRoot::GetType() const
125 // get the type from the event header
127 if (!fEvent) return 0;
128 return fEvent->GetHeader()->GetType();
131 UInt_t AliRawReaderRoot::GetRunNumber() const
133 // get the run number from the event header
135 if (!fEvent) return 0;
136 return fEvent->GetHeader()->GetRunNumber();
139 const UInt_t* AliRawReaderRoot::GetEventId() const
141 // get the event id from the event header
143 if (!fEvent) return NULL;
144 return fEvent->GetHeader()->GetId();
147 const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
149 // get the trigger pattern from the event header
151 if (!fEvent) return NULL;
152 return fEvent->GetHeader()->GetTriggerPattern();
155 const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
157 // get the detector pattern from the event header
159 if (!fEvent) return NULL;
160 return fEvent->GetHeader()->GetDetectorPattern();
163 const UInt_t* AliRawReaderRoot::GetAttributes() const
165 // get the type attributes from the event header
167 if (!fEvent) return NULL;
168 return fEvent->GetHeader()->GetTypeAttribute();
171 UInt_t AliRawReaderRoot::GetGDCId() const
173 // get the GDC Id from the event header
175 if (!fEvent) return 0;
176 return fEvent->GetHeader()->GetGDCId();
180 Bool_t AliRawReaderRoot::ReadMiniHeader()
182 // read a mini header at the current position
183 // returns kFALSE if the mini header could not be read
185 if (!fEvent) return kFALSE;
187 if (fCount > 0) fPosition += fCount; // skip payload if event was not selected
188 if (!fSubEvent || (fPosition >= fEnd)) { // new sub event
189 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
190 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
191 fRawData = fSubEvent->GetRawData();
193 fPosition = (UChar_t*) fRawData->GetBuffer();
194 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
196 if (fPosition >= fEnd) continue; // no data left in the payload
197 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
198 Error("ReadMiniHeader", "could not read data!");
201 fMiniHeader = (AliMiniHeader*) fPosition;
202 fPosition += sizeof(AliMiniHeader);
204 fCount = fMiniHeader->fSize;
205 if (fPosition + fCount > fEnd) { // check data size in mini header and sub event
206 Error("ReadMiniHeader", "size in mini header exceeds event size!");
207 fMiniHeader->fSize = fCount = fEnd - fPosition;
209 } while (!IsSelected());
213 Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
215 // reads the next payload at the current position
216 // returns kFALSE if the data could not be read
218 while (fCount == 0) {
219 if (!ReadMiniHeader()) return kFALSE;
227 Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
229 // reads the next block of data at the current position
230 // returns kFALSE if the data could not be read
232 if (fPosition + size > fEnd) {
233 Error("ReadNext", "could not read data!");
236 memcpy(data, fPosition, size);
243 Bool_t AliRawReaderRoot::Reset()
245 // reset the current position to the beginning of the event
253 fPosition = fEnd = NULL;