]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderDate.cxx
Compiler Warning removed
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDate.cxx
CommitLineData
16048fcf 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 date event and providing
19// information about digits
20//
21///////////////////////////////////////////////////////////////////////////////
22
23#include "AliRawReaderDate.h"
24#ifdef ALI_DATE
25#include "event.h"
26#endif
27
28ClassImp(AliRawReaderDate)
29
30
31AliRawReaderDate::AliRawReaderDate(
32#ifdef ALI_DATE
33 void* event
34#else
35 void* /* event */
36#endif
37)
38{
39// create an object to read digits from the given date event
40
41#ifdef ALI_DATE
42 fEvent = (eventHeaderStruct*) event;
43 fSubEvent = NULL;
44 fPosition = fEnd = NULL;
45#else
46 Fatal("AliRawReaderDate", "this class was compiled without DATE");
47#endif
48}
49
50AliRawReaderDate::AliRawReaderDate(const AliRawReaderDate& rawReader) :
51 AliRawReader(rawReader)
52{
53// copy constructor
54
55 fEvent = rawReader.fEvent;
56 fSubEvent = rawReader.fSubEvent;
57 fPosition = rawReader.fPosition;
58 fEnd = rawReader.fEnd;
59}
60
61AliRawReaderDate& AliRawReaderDate::operator = (const AliRawReaderDate&
62 rawReader)
63{
64// assignment operator
65
66 this->~AliRawReaderDate();
67 new(this) AliRawReaderDate(rawReader);
68 return *this;
69}
70
71
72UInt_t AliRawReaderDate::GetType() const
73{
74// get the type from the event header
75
76#ifdef ALI_DATE
77 if (!fEvent) return 0;
78 return fEvent->eventType;
79#else
80 return 0;
81#endif
82}
83
84UInt_t AliRawReaderDate::GetRunNumber() const
85{
86// get the run number from the event header
87
88#ifdef ALI_DATE
89 if (!fEvent) return 0;
90 return fEvent->eventRunNb;
91#else
92 return 0;
93#endif
94}
95
96const UInt_t* AliRawReaderDate::GetEventId() const
97{
98// get the event id from the event header
99
100#ifdef ALI_DATE
101 if (!fEvent) return NULL;
102 return fEvent->eventId;
103#else
104 return NULL;
105#endif
106}
107
108const UInt_t* AliRawReaderDate::GetTriggerPattern() const
109{
110// get the trigger pattern from the event header
111
112#ifdef ALI_DATE
113 if (!fEvent) return NULL;
114 return fEvent->eventTriggerPattern;
115#else
116 return NULL;
117#endif
118}
119
120const UInt_t* AliRawReaderDate::GetDetectorPattern() const
121{
122// get the detector pattern from the event header
123
124#ifdef ALI_DATE
125 if (!fEvent) return NULL;
126 return fEvent->eventDetectorPattern;
127#else
128 return NULL;
129#endif
130}
131
132const UInt_t* AliRawReaderDate::GetAttributes() const
133{
134// get the type attributes from the event header
135
136#ifdef ALI_DATE
137 if (!fEvent) return NULL;
138 return fEvent->eventTypeAttribute;
139#else
140 return NULL;
141#endif
142}
143
144UInt_t AliRawReaderDate::GetGDCId() const
145{
146// get the GDC Id from the event header
147
148#ifdef ALI_DATE
149 if (!fEvent) return 0;
150 return fEvent->eventGdcId;
151#else
152 return 0;
153#endif
154}
155
156
157Bool_t AliRawReaderDate::ReadMiniHeader()
158{
159// read a mini header at the current position
160// returns kFALSE if the mini header could not be read
161
b4857df7 162 fErrorCode = 0;
163
16048fcf 164#ifdef ALI_DATE
165 if (!fEvent) return kFALSE;
b4857df7 166 // check whether there are sub events
167 if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
168
16048fcf 169 do {
b4857df7 170 // skip payload (if event was not selected)
171 if (fCount > 0) fPosition += fCount;
172
173 // get the first or the next sub event if at the end of a sub event
174 if (!fSubEvent || (fPosition >= fEnd)) {
175
176 // check for end of event data
177 if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE;
16048fcf 178 if (fSubEvent) {
179 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) +
180 fSubEvent->eventSize);
181 } else {
16048fcf 182 fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
183 fEvent->eventHeadSize);
184 }
b4857df7 185
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;
194 return kFALSE;
195 }
196
16048fcf 197 fCount = 0;
198 fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize +
199 sizeof(equipmentHeaderStruct);
200 fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
201 }
b4857df7 202
203 // continue with the next sub event if no data left in the payload
204 if (fPosition >= fEnd) continue;
205
206 // check that there are enough bytes left for the mini header
16048fcf 207 if (fPosition + sizeof(AliMiniHeader) > fEnd) {
b4857df7 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);
214 fCount = 0;
215 fPosition = fEnd;
216 fErrorCode = kErrNoMiniHeader;
217 continue;
16048fcf 218 }
b4857df7 219
220 // "read" and check the mini header
16048fcf 221 fMiniHeader = (AliMiniHeader*) fPosition;
222 fPosition += sizeof(AliMiniHeader);
72dd1d4f 223 if (!CheckMiniHeader()) {
b4857df7 224 Error("ReadMiniHeader", "wrong magic word in mini header!");
72dd1d4f 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);
230 fCount = 0;
231 fPosition = fEnd;
b4857df7 232 fErrorCode = kErrMiniMagic;
72dd1d4f 233 continue;
234 }
16048fcf 235 fCount = fMiniHeader->fSize;
b4857df7 236
237 // check consistency of data size in the mini header and in the sub event
238 if (fPosition + fCount > fEnd) {
16048fcf 239 Error("ReadMiniHeader", "size in mini header exceeds event size!");
03c6d9a3 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);
245 fCount = 0;
246 fPosition = fEnd;
b4857df7 247 fErrorCode = kErrSize;
03c6d9a3 248 continue;
16048fcf 249 }
b4857df7 250
16048fcf 251 } while (!IsSelected());
b4857df7 252
16048fcf 253 return kTRUE;
254#else
255 return kFALSE;
256#endif
257}
258
259Bool_t AliRawReaderDate::ReadNextData(UChar_t*& data)
260{
261// reads the next payload at the current position
262// returns kFALSE if the data could not be read
263
b4857df7 264 fErrorCode = 0;
16048fcf 265 while (fCount == 0) {
266 if (!ReadMiniHeader()) return kFALSE;
267 }
268 data = fPosition;
269 fPosition += fCount;
270 fCount = 0;
271 return kTRUE;
272}
273
274Bool_t AliRawReaderDate::ReadNext(UChar_t* data, Int_t size)
275{
276// reads the next block of data at the current position
277// returns kFALSE if the data could not be read
278
b4857df7 279 fErrorCode = 0;
16048fcf 280 if (fPosition + size > fEnd) {
281 Error("ReadNext", "could not read data!");
b4857df7 282 fErrorCode = kErrOutOfBounds;
16048fcf 283 return kFALSE;
284 }
285 memcpy(data, fPosition, size);
286 fPosition += size;
287 fCount -= size;
288 return kTRUE;
289}
290
291
292Bool_t AliRawReaderDate::Reset()
293{
294// reset the current position to the beginning of the event
295
296#ifdef ALI_DATE
297 fSubEvent = NULL;
298#endif
299 fCount = 0;
300 fPosition = fEnd = NULL;
301 return kTRUE;
302}
b4857df7 303
304
305Int_t AliRawReaderDate::CheckData() const
306{
307// check the consistency of the data
308
309#ifdef ALI_DATE
310 if (!fEvent) return 0;
311 // check whether there are sub events
312 if (fEvent->eventSize <= fEvent->eventHeadSize) return 0;
313
314 eventHeaderStruct* subEvent = NULL;
315 UChar_t* position = 0;
316 UChar_t* end = 0;
be50fca2 317 Int_t result = 0;
b4857df7 318
319 while (kTRUE) {
320 // get the first or the next sub event if at the end of a sub event
321 if (!subEvent || (position >= end)) {
322
323 // check for end of event data
be50fca2 324 if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
b4857df7 325 if (subEvent) {
326 subEvent = (eventHeaderStruct*) (((UChar_t*)subEvent) +
327 subEvent->eventSize);
328 } else {
329 subEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) +
330 fEvent->eventHeadSize);
331 }
332
333 // check the magic word of the sub event
be50fca2 334 if (subEvent->eventMagic != EVENT_MAGIC_NUMBER) {
335 result |= kErrMagic;
336 return result;
337 }
b4857df7 338
339 position = ((UChar_t*)subEvent) + subEvent->eventHeadSize +
340 sizeof(equipmentHeaderStruct);
341 end = ((UChar_t*)subEvent) + subEvent->eventSize;
342 }
343
344 // continue with the next sub event if no data left in the payload
345 if (position >= end) continue;
346
347 // check that there are enough bytes left for the mini header
be50fca2 348 if (position + sizeof(AliMiniHeader) > end) {
349 result |= kErrNoMiniHeader;
350 position = end;
351 continue;
352 }
b4857df7 353
354 // "read" and check the mini header
355 AliMiniHeader* miniHeader = (AliMiniHeader*) position;
356 position += sizeof(AliMiniHeader);
be50fca2 357 if (!CheckMiniHeader(miniHeader)){
358 result |= kErrMiniMagic;
359 position = end;
360 continue;
361 }
b4857df7 362
363 // check consistency of data size in the mini header and in the sub event
be50fca2 364 if (position + miniHeader->fSize > end) result |= kErrSize;
b4857df7 365 position += miniHeader->fSize;
366 };
367
368#endif
369 return 0;
370}