]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderDate.cxx
protection against wrong magic word
[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 #ifdef ALI_DATE
163   if (!fEvent) return kFALSE;
164   do {
165     if (fCount > 0) fPosition += fCount;      // skip payload if event was not selected
166     if (!fSubEvent || (fPosition >= fEnd)) {  // new sub event
167       if (fPosition >= ((UChar_t*)fEvent)+fEvent->eventSize) return kFALSE;  // end of data
168       if (fSubEvent) {
169         fSubEvent = (eventHeaderStruct*) (((UChar_t*)fSubEvent) + 
170                                           fSubEvent->eventSize);
171       } else {
172         if (fEvent->eventSize <= fEvent->eventHeadSize) return kFALSE; // no sub events
173         fSubEvent = (eventHeaderStruct*) (((UChar_t*)fEvent) + 
174                                           fEvent->eventHeadSize);
175       }
176       fCount = 0;
177       fPosition = ((UChar_t*)fSubEvent) + fSubEvent->eventHeadSize + 
178         sizeof(equipmentHeaderStruct);
179       fEnd = ((UChar_t*)fSubEvent) + fSubEvent->eventSize;
180     }
181     if (fPosition >= fEnd) continue;          // no data left in the payload
182     if (fPosition + sizeof(AliMiniHeader) > fEnd) {
183       Error("ReadMiniHeader", "could not read data!");
184       return kFALSE;
185     }
186     fMiniHeader = (AliMiniHeader*) fPosition;
187     fPosition += sizeof(AliMiniHeader);
188     if (!CheckMiniHeader()) {
189       Warning("ReadMiniHeader", "skipping %d bytes\n"
190               " run: %d  event: %d %d  LDC: %d  GDC: %d\n", 
191               fEnd - fPosition, fSubEvent->eventRunNb, 
192               fSubEvent->eventId[0], fSubEvent->eventId[1],
193               fSubEvent->eventLdcId, fSubEvent->eventGdcId);
194       fCount = 0;
195       fPosition = fEnd;
196       continue;
197     }
198     fCount = fMiniHeader->fSize;
199     if (fPosition + fCount > fEnd) {  // check data size in mini header and sub event
200       Error("ReadMiniHeader", "size in mini header exceeds event size!");
201       Warning("ReadMiniHeader", "skipping %d bytes\n"
202               " run: %d  event: %d %d  LDC: %d  GDC: %d\n", 
203               fEnd - fPosition, fSubEvent->eventRunNb, 
204               fSubEvent->eventId[0], fSubEvent->eventId[1],
205               fSubEvent->eventLdcId, fSubEvent->eventGdcId);
206       fCount = 0;
207       fPosition = fEnd;
208       continue;
209     }
210   } while (!IsSelected());
211   return kTRUE;
212 #else
213   return kFALSE;
214 #endif
215 }
216
217 Bool_t AliRawReaderDate::ReadNextData(UChar_t*& data)
218 {
219 // reads the next payload at the current position
220 // returns kFALSE if the data could not be read
221
222   while (fCount == 0) {
223     if (!ReadMiniHeader()) return kFALSE;
224   }
225   data = fPosition;
226   fPosition += fCount;  
227   fCount = 0;
228   return kTRUE;
229 }
230
231 Bool_t AliRawReaderDate::ReadNext(UChar_t* data, Int_t size)
232 {
233 // reads the next block of data at the current position
234 // returns kFALSE if the data could not be read
235
236   if (fPosition + size > fEnd) {
237     Error("ReadNext", "could not read data!");
238     return kFALSE;
239   }
240   memcpy(data, fPosition, size);
241   fPosition += size;
242   fCount -= size;
243   return kTRUE;
244 }
245
246
247 Bool_t AliRawReaderDate::Reset()
248 {
249 // reset the current position to the beginning of the event
250
251 #ifdef ALI_DATE
252   fSubEvent = NULL;
253 #endif
254   fCount = 0;
255   fPosition = fEnd = NULL;
256   return kTRUE;
257 }