]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderDate.cxx
Compiler Warning removed
[u/mrichter/AliRoot.git] / RAW / AliRawReaderDate.cxx
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
28 ClassImp(AliRawReaderDate)
29
30
31 AliRawReaderDate::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
50 AliRawReaderDate::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
61 AliRawReaderDate& 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
72 UInt_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
84 UInt_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
96 const 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
108 const 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
120 const 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
132 const 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
144 UInt_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
157 Bool_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
162   fErrorCode = 0;
163
164 #ifdef ALI_DATE
165   if (!fEvent) return kFALSE;
166   // check whether there are sub events
167   if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE;
168
169   do {
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;
178       if (fSubEvent) {
179         fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) + 
180                                           fSubEvent->eventSize);
181       } else {
182         fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) + 
183                                           fEvent->eventHeadSize);
184       }
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
197       fCount = 0;
198       fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize + 
199         sizeof(equipmentHeaderStruct);
200       fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
201     }
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
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);
214       fCount = 0;
215       fPosition = fEnd;
216       fErrorCode = kErrNoMiniHeader;
217       continue;
218     }
219
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);
230       fCount = 0;
231       fPosition = fEnd;
232       fErrorCode = kErrMiniMagic;
233       continue;
234     }
235     fCount = fMiniHeader->fSize;
236
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);
245       fCount = 0;
246       fPosition = fEnd;
247       fErrorCode = kErrSize;
248       continue;
249     }
250
251   } while (!IsSelected());
252
253   return kTRUE;
254 #else
255   return kFALSE;
256 #endif
257 }
258
259 Bool_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
264   fErrorCode = 0;
265   while (fCount == 0) {
266     if (!ReadMiniHeader()) return kFALSE;
267   }
268   data = fPosition;
269   fPosition += fCount;  
270   fCount = 0;
271   return kTRUE;
272 }
273
274 Bool_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
279   fErrorCode = 0;
280   if (fPosition + size > fEnd) {
281     Error("ReadNext", "could not read data!");
282     fErrorCode = kErrOutOfBounds;
283     return kFALSE;
284   }
285   memcpy(data, fPosition, size);
286   fPosition += size;
287   fCount -= size;
288   return kTRUE;
289 }
290
291
292 Bool_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 }
303
304
305 Int_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;
317   Int_t result = 0;
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
324       if (position >= ((UChar_t*)fEvent)+fEvent->eventSize) return result;
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
334       if (subEvent->eventMagic != EVENT_MAGIC_NUMBER) {
335         result |= kErrMagic;
336         return result;
337       }
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
348     if (position + sizeof(AliMiniHeader) > end) {
349       result |= kErrNoMiniHeader;
350       position = end;
351       continue;
352     }
353
354     // "read" and check the mini header
355     AliMiniHeader* miniHeader = (AliMiniHeader*) position;
356     position += sizeof(AliMiniHeader);
357     if (!CheckMiniHeader(miniHeader)){
358       result |= kErrMiniMagic;
359       position = end;
360       continue;
361     }
362
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;
366   };
367
368 #endif
369   return 0;
370 }