]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderRoot.cxx
get tables from the aliroot directory if they are not in the current one
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
CommitLineData
04fa961a 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16///////////////////////////////////////////////////////////////////////////////
17//
18// This is a class for reading a raw data from a root file and providing
19// information about digits
20//
21///////////////////////////////////////////////////////////////////////////////
22
23#include "AliRawReaderRoot.h"
42d20574 24#include "AliRawEvent.h"
04fa961a 25
26
27ClassImp(AliRawReaderRoot)
28
29
30AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber)
31{
32// create an object to read digits from the given input file for the
33// event with the given number
34
be50fca2 35 fEvent = NULL;
03c6d9a3 36 TDirectory* dir = gDirectory;
04fa961a 37 fFile = TFile::Open(fileName);
03c6d9a3 38 dir->cd();
04fa961a 39 if (!fFile || !fFile->IsOpen()) {
40 Error("AliRawReaderRoot", "could not open file %s", fileName);
41 return;
42 }
43 TTree* tree = (TTree*) fFile->Get("RAW");
44 if (!tree) {
45 Error("AliRawReaderRoot", "no raw data tree found");
46 return;
47 }
48 TBranch* branch = tree->GetBranch("rawevent");
49 if (!branch) {
50 Error("AliRawReaderRoot", "no raw data branch found");
51 return;
52 }
53
54 fEvent = new AliRawEvent;
55 branch->SetAddress(&fEvent);
56 if (branch->GetEntry(eventNumber) <= 0) {
57 Error("AliRawReaderRoot", "no event with number %d found", eventNumber);
58 return;
59 }
60
61 fSubEventIndex = 0;
62 fSubEvent = NULL;
63 fRawData = NULL;
64 fMiniHeader = NULL;
65
66 fCount = 0;
67 fPosition = fEnd = NULL;
68}
69
70AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event)
71{
72// create an object to read digits from the given raw event
73
74 fFile = NULL;
75 fEvent = event;
76
77 fSubEventIndex = 0;
78 fSubEvent = NULL;
79 fRawData = NULL;
42d20574 80 fMiniHeader = NULL;
04fa961a 81
82 fCount = 0;
83 fPosition = fEnd = NULL;
84}
85
42d20574 86AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
87 AliRawReader(rawReader)
88{
89// copy constructor
90
91 fFile = NULL;
92 fEvent = rawReader.fEvent;
93
94 fSubEventIndex = rawReader.fSubEventIndex;
95 fSubEvent = rawReader.fSubEvent;
96 fRawData = rawReader.fRawData;
97 fMiniHeader = rawReader.fMiniHeader;
98
99 fCount = rawReader.fCount;
100 fPosition = rawReader.fPosition;
101 fEnd = rawReader.fEnd;
102}
103
104AliRawReaderRoot& AliRawReaderRoot::operator = (const AliRawReaderRoot&
105 rawReader)
106{
107// assignment operator
108
109 this->~AliRawReaderRoot();
110 new(this) AliRawReaderRoot(rawReader);
111 return *this;
112}
113
04fa961a 114AliRawReaderRoot::~AliRawReaderRoot()
115{
116// delete objects and close root file
117
118 if (fFile) {
119 if (fEvent) delete fEvent;
120 fFile->Close();
121 delete fFile;
122 }
123}
124
125
42d20574 126UInt_t AliRawReaderRoot::GetType() const
04fa961a 127{
128// get the type from the event header
129
130 if (!fEvent) return 0;
131 return fEvent->GetHeader()->GetType();
132}
133
42d20574 134UInt_t AliRawReaderRoot::GetRunNumber() const
04fa961a 135{
136// get the run number from the event header
137
138 if (!fEvent) return 0;
139 return fEvent->GetHeader()->GetRunNumber();
140}
141
42d20574 142const UInt_t* AliRawReaderRoot::GetEventId() const
04fa961a 143{
144// get the event id from the event header
145
146 if (!fEvent) return NULL;
147 return fEvent->GetHeader()->GetId();
148}
149
42d20574 150const UInt_t* AliRawReaderRoot::GetTriggerPattern() const
04fa961a 151{
152// get the trigger pattern from the event header
153
154 if (!fEvent) return NULL;
155 return fEvent->GetHeader()->GetTriggerPattern();
156}
157
42d20574 158const UInt_t* AliRawReaderRoot::GetDetectorPattern() const
04fa961a 159{
160// get the detector pattern from the event header
161
162 if (!fEvent) return NULL;
163 return fEvent->GetHeader()->GetDetectorPattern();
164}
165
42d20574 166const UInt_t* AliRawReaderRoot::GetAttributes() const
04fa961a 167{
168// get the type attributes from the event header
169
170 if (!fEvent) return NULL;
171 return fEvent->GetHeader()->GetTypeAttribute();
172}
173
c946ab02 174UInt_t AliRawReaderRoot::GetLDCId() const
175{
176// get the LDC Id from the event header
177
178 if (!fEvent || !fEvent->GetSubEvent(fSubEventIndex)) return 0;
179 return fEvent->GetSubEvent(fSubEventIndex)->GetHeader()->GetLDCId();
180}
181
42d20574 182UInt_t AliRawReaderRoot::GetGDCId() const
04fa961a 183{
184// get the GDC Id from the event header
185
186 if (!fEvent) return 0;
187 return fEvent->GetHeader()->GetGDCId();
188}
189
190
c946ab02 191Int_t AliRawReaderRoot::GetEquipmentSize() const
192{
193// get the size of the equipment
194
195 if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
196 return fEvent->GetEquipmentHeader()->GetEquipmentSize();
197}
198
199Int_t AliRawReaderRoot::GetEquipmentType() const
200{
201// get the type from the equipment header
202
203 if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
204 return fEvent->GetEquipmentHeader()->GetEquipmentType();
205}
206
207Int_t AliRawReaderRoot::GetEquipmentId() const
208{
209// get the ID from the equipment header
210
211 if (!fEvent || !fEvent->GetEquipmentHeader()) return -1;
212 return fEvent->GetEquipmentHeader()->GetId();
213}
214
215const UInt_t* AliRawReaderRoot::GetEquipmentAttributes() const
216{
217// get the attributes from the equipment header
218
219 if (!fEvent || !fEvent->GetEquipmentHeader()) return NULL;
220 return fEvent->GetEquipmentHeader()->GetTypeAttribute();
221}
222
223Int_t AliRawReaderRoot::GetEquipmentElementSize() const
224{
225// get the basic element size from the equipment header
226
227 if (!fEvent || !fEvent->GetEquipmentHeader()) return 0;
228 return fEvent->GetEquipmentHeader()->GetBasicSizeType();
229}
230
231
232Bool_t AliRawReaderRoot::ReadHeader()
04fa961a 233{
234// read a mini header at the current position
235// returns kFALSE if the mini header could not be read
236
b4857df7 237 fErrorCode = 0;
04fa961a 238 if (!fEvent) return kFALSE;
b4857df7 239
04fa961a 240 do {
b4857df7 241 // skip payload (if event was not selected)
242 if (fCount > 0) fPosition += fCount;
243
244 // get the first or the next sub event if at the end of a sub event
245 if (!fSubEvent || (fPosition >= fEnd)) {
246
247 // check for end of event data
04fa961a 248 if (fSubEventIndex >= fEvent->GetNSubEvents()) return kFALSE;
249 fSubEvent = fEvent->GetSubEvent(fSubEventIndex++);
b4857df7 250
251 // check the magic word of the sub event
252 if (!fSubEvent->GetHeader()->IsValid()) {
c946ab02 253 Error("ReadHeader", "wrong magic number in sub event!");
b4857df7 254 fSubEvent->GetHeader()->Dump();
255 fErrorCode = kErrMagic;
256 return kFALSE;
257 }
258
04fa961a 259 fRawData = fSubEvent->GetRawData();
260 fCount = 0;
261 fPosition = (UChar_t*) fRawData->GetBuffer();
262 fEnd = ((UChar_t*) fRawData->GetBuffer()) + fRawData->GetSize();
263 }
b4857df7 264
265 // continue with the next sub event if no data left in the payload
266 if (fPosition >= fEnd) continue;
267
268 // check that there are enough bytes left for the mini header
04fa961a 269 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
c946ab02 270 Error("ReadHeader", "could not read mini header data!");
271 Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
b4857df7 272 fSubEvent->GetHeader()->Dump();
273 fCount = 0;
274 fPosition = fEnd;
275 fErrorCode = kErrNoMiniHeader;
276 continue;
04fa961a 277 }
b4857df7 278
279 // "read" and check the mini header
04fa961a 280 fMiniHeader = (AliMiniHeader*) fPosition;
281 fPosition += sizeof(AliMiniHeader);
72dd1d4f 282 if (!CheckMiniHeader()) {
c946ab02 283 Error("ReadHeader", "wrong magic word in mini header!");
284 Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
72dd1d4f 285 fSubEvent->GetHeader()->Dump();
286 fCount = 0;
287 fPosition = fEnd;
b4857df7 288 fErrorCode = kErrMiniMagic;
72dd1d4f 289 continue;
290 }
04fa961a 291 fCount = fMiniHeader->fSize;
b4857df7 292
293 // check consistency of data size in the mini header and in the sub event
294 if (fPosition + fCount > fEnd) {
c946ab02 295 Error("ReadHeader", "size in mini header exceeds event size!");
296 Warning("ReadHeader", "skipping %d bytes", fEnd - fPosition);
03c6d9a3 297 fSubEvent->GetHeader()->Dump();
298 fCount = 0;
299 fPosition = fEnd;
b4857df7 300 fErrorCode = kErrSize;
03c6d9a3 301 continue;
04fa961a 302 }
b4857df7 303
04fa961a 304 } while (!IsSelected());
b4857df7 305
04fa961a 306 return kTRUE;
307}
308
309Bool_t AliRawReaderRoot::ReadNextData(UChar_t*& data)
310{
311// reads the next payload at the current position
312// returns kFALSE if the data could not be read
313
b4857df7 314 fErrorCode = 0;
04fa961a 315 while (fCount == 0) {
c946ab02 316 if (!ReadHeader()) return kFALSE;
04fa961a 317 }
318 data = fPosition;
319 fPosition += fCount;
320 fCount = 0;
321 return kTRUE;
322}
323
324Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
325{
326// reads the next block of data at the current position
327// returns kFALSE if the data could not be read
328
b4857df7 329 fErrorCode = 0;
04fa961a 330 if (fPosition + size > fEnd) {
331 Error("ReadNext", "could not read data!");
b4857df7 332 fErrorCode = kErrOutOfBounds;
04fa961a 333 return kFALSE;
334 }
335 memcpy(data, fPosition, size);
336 fPosition += size;
337 fCount -= size;
338 return kTRUE;
339}
340
341
342Bool_t AliRawReaderRoot::Reset()
343{
344// reset the current position to the beginning of the event
345
346 fSubEventIndex = 0;
347 fSubEvent = NULL;
348 fRawData = NULL;
349 fMiniHeader = NULL;
350
351 fCount = 0;
352 fPosition = fEnd = NULL;
353 return kTRUE;
354}
355
b4857df7 356
357Int_t AliRawReaderRoot::CheckData() const
358{
359// check the consistency of the data
360
361 if (!fEvent) return 0;
362
363 AliRawEvent* subEvent = NULL;
364 Int_t subEventIndex = 0;
365 UChar_t* position = 0;
366 UChar_t* end = 0;
be50fca2 367 Int_t result = 0;
b4857df7 368
369 while (kTRUE) {
370 // get the first or the next sub event if at the end of a sub event
371 if (!subEvent || (position >= end)) {
372
373 // check for end of event data
be50fca2 374 if (subEventIndex >= fEvent->GetNSubEvents()) return result;
b4857df7 375 subEvent = fEvent->GetSubEvent(subEventIndex++);
376
377 // check the magic word of the sub event
be50fca2 378 if (!fSubEvent->GetHeader()->IsValid()) {
379 result |= kErrMagic;
380 return result;
381 }
b4857df7 382
383 AliRawData* rawData = subEvent->GetRawData();
384 position = (UChar_t*) rawData->GetBuffer();
385 end = ((UChar_t*) rawData->GetBuffer()) + rawData->GetSize();
386 }
387
388 // continue with the next sub event if no data left in the payload
389 if (position >= end) continue;
390
391 // check that there are enough bytes left for the mini header
be50fca2 392 if (position + sizeof(AliMiniHeader) > end) {
393 result |= kErrNoMiniHeader;
394 position = end;
395 continue;
396 }
b4857df7 397
398 // "read" and check the mini header
399 AliMiniHeader* miniHeader = (AliMiniHeader*) position;
400 position += sizeof(AliMiniHeader);
be50fca2 401 if (!CheckMiniHeader(miniHeader)) {
402 result |= kErrMiniMagic;
403 position = end;
404 continue;
405 }
b4857df7 406
407 // check consistency of data size in the mini header and in the sub event
be50fca2 408 if (position + miniHeader->fSize > end) result |= kErrSize;
b4857df7 409 position += miniHeader->fSize;
410 };
fd0de2e2 411
412 return result;
b4857df7 413}