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 date event and providing
19 // information about digits
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliRawReaderDate.h"
28 ClassImp(AliRawReaderDate)
31 AliRawReaderDate::AliRawReaderDate(
39 // create an object to read digits from the given date event
42 fEvent = (eventHeaderStruct*) event;
44 fPosition = fEnd = NULL;
46 Fatal("AliRawReaderDate", "this class was compiled without DATE");
50 AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
51 AliRawReader(rawReader)
55 fEvent = rawReader.fEvent;
56 fSubEvent = rawReader.fSubEvent;
57 fPosition = rawReader.fPosition;
58 fEnd = rawReader.fEnd;
61 AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate&
64 // assignment operator
66 this->~AliRawReaderDate();
67 new(this) AliRawReaderDate(rawReader);
72 UInt_t AliRawReaderDate::GetType() const
74 // get the type from the event header
77 if (!fEvent) return 0;
78 return fEvent->eventType;
84 UInt_t AliRawReaderDate::GetRunNumber() const
86 // get the run number from the event header
89 if (!fEvent) return 0;
90 return fEvent->eventRunNb;
96 const UInt_t* AliRawReaderDate::GetEventId() const
98 // get the event id from the event header
101 if (!fEvent) return NULL;
102 return fEvent->eventId;
108 const UInt_t* AliRawReaderDate::GetTriggerPattern() const
110 // get the trigger pattern from the event header
113 if (!fEvent) return NULL;
114 return fEvent->eventTriggerPattern;
120 const UInt_t* AliRawReaderDate::GetDetectorPattern() const
122 // get the detector pattern from the event header
125 if (!fEvent) return NULL;
126 return fEvent->eventDetectorPattern;
132 const UInt_t* AliRawReaderDate::GetAttributes() const
134 // get the type attributes from the event header
137 if (!fEvent) return NULL;
138 return fEvent->eventTypeAttribute;
144 UInt_t AliRawReaderDate::GetGDCId() const
146 // get the GDC Id from the event header
149 if (!fEvent) return 0;
150 return fEvent->eventGdcId;
157 Bool_t AliRawReaderDate::ReadMiniHeader()
159 // read a mini header at the current position
160 // returns kFALSE if the mini header could not be read
165 if (!fEvent) return kFALSE;
166 // check whether there are sub events
167 if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
170 // skip payload (if event was not selected)
171 if (fCount > 0) fPosition += fCount;
173 // get the first or the next sub event if at the end of a sub event
174 if (!fSubEvent || (fPosition >= fEnd)) {
176 // check for end of event data
177 if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE;
179 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) +
180 fSubEvent->eventSize);
182 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
183 fEvent->eventHeadSize);
186 // check the magic word of the sub event
187 if (fSubEvent->eventMagic != EVENT_MAGIC_NUMBER) {
188 Error("ReadMiniHeader", "wrong magic number in sub event!\n"
189 " run: %d event: %d %d LDC: %d GDC: %d\n",
190 fSubEvent->eventRunNb,
191 fSubEvent->eventId[0], fSubEvent->eventId[1],
192 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
193 fErrorCode = kErrMagic;
198 fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize +
199 sizeof(equipmentHeaderStruct);
200 fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
203 // continue with the next sub event if no data left in the payload
204 if (fPosition >= fEnd) continue;
206 // check that there are enough bytes left for the mini header
207 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
208 Error("ReadMiniHeader", "could not read mini header data!");
209 Warning("ReadMiniHeader", "skipping %d bytes\n"
210 " run: %d event: %d %d LDC: %d GDC: %d\n",
211 fEnd - fPosition, fSubEvent->eventRunNb,
212 fSubEvent->eventId[0], fSubEvent->eventId[1],
213 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
216 fErrorCode = kErrNoMiniHeader;
220 // "read" and check the mini header
221 fMiniHeader = (AliMiniHeader*) fPosition;
222 fPosition += sizeof(AliMiniHeader);
223 if (!CheckMiniHeader()) {
224 Error("ReadMiniHeader", "wrong magic word in mini header!");
225 Warning("ReadMiniHeader", "skipping %d bytes\n"
226 " run: %d event: %d %d LDC: %d GDC: %d\n",
227 fEnd - fPosition, fSubEvent->eventRunNb,
228 fSubEvent->eventId[0], fSubEvent->eventId[1],
229 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
232 fErrorCode = kErrMiniMagic;
235 fCount = fMiniHeader->fSize;
237 // check consistency of data size in the mini header and in the sub event
238 if (fPosition + fCount > fEnd) {
239 Error("ReadMiniHeader", "size in mini header exceeds event size!");
240 Warning("ReadMiniHeader", "skipping %d bytes\n"
241 " run: %d event: %d %d LDC: %d GDC: %d\n",
242 fEnd - fPosition, fSubEvent->eventRunNb,
243 fSubEvent->eventId[0], fSubEvent->eventId[1],
244 fSubEvent->eventLdcId, fSubEvent->eventGdcId);
247 fErrorCode = kErrSize;
251 } while (!IsSelected());
259 Bool_t AliRawReaderDate::ReadNextData(UChar_t*& data)
261 // reads the next payload at the current position
262 // returns kFALSE if the data could not be read
265 while (fCount == 0) {
266 if (!ReadMiniHeader()) return kFALSE;
274 Bool_t AliRawReaderDate::ReadNext(UChar_t* data, Int_t size)
276 // reads the next block of data at the current position
277 // returns kFALSE if the data could not be read
280 if (fPosition + size > fEnd) {
281 Error("ReadNext", "could not read data!");
282 fErrorCode = kErrOutOfBounds;
285 memcpy(data, fPosition, size);
292 Bool_t AliRawReaderDate::Reset()
294 // reset the current position to the beginning of the event
300 fPosition = fEnd = NULL;
305 Int_t AliRawReaderDate::CheckData() const
307 // check the consistency of the data
310 if (!fEvent) return 0;
311 // check whether there are sub events
312 if (fEvent->eventSize <= fEvent->eventHeadSize) return 0;
314 eventHeaderStruct* subEvent = NULL;
315 UChar_t* position = 0;
320 // get the first or the next sub event if at the end of a sub event
321 if (!subEvent || (position >= end)) {
323 // check for end of event data
324 if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
326 subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) +
327 subEvent->eventSize);
329 subEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
330 fEvent->eventHeadSize);
333 // check the magic word of the sub event
334 if (subEvent->eventMagic != EVENT_MAGIC_NUMBER) {
339 position = ((UChar_t*)subEvent) + subEvent->eventHeadSize +
340 sizeof(equipmentHeaderStruct);
341 end = ((UChar_t*)subEvent) + subEvent->eventSize;
344 // continue with the next sub event if no data left in the payload
345 if (position >= end) continue;
347 // check that there are enough bytes left for the mini header
348 if (position + sizeof(AliMiniHeader) > end) {
349 result |= kErrNoMiniHeader;
354 // "read" and check the mini header
355 AliMiniHeader* miniHeader = (AliMiniHeader*) position;
356 position += sizeof(AliMiniHeader);
357 if (!CheckMiniHeader(miniHeader)){
358 result |= kErrMiniMagic;
363 // check consistency of data size in the mini header and in the sub event
364 if (position + miniHeader->fSize > end) result |= kErrSize;
365 position += miniHeader->fSize;