]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReader.cxx
Fix in raw data headers processing in AliMDC. Removing wrong equipment size in versio...
[u/mrichter/AliRoot.git] / RAW / AliRawReader.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 /* $Id$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 ///
20 /// This is the base class for reading raw data.
21 ///
22 /// The derived classes, which operate on concrete raw data formats,
23 /// should implement
24 /// - ReadHeader to read the next (data/equipment) header
25 /// - ReadNextData to read the next raw data block (=1 DDL)
26 /// - ReadNext to read a given number of bytes
27 /// - several getters like GetType
28 ///
29 /// Sequential access to the raw data is provided by the methods
30 /// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
31 ///
32 /// If only data from a specific detector (and a given range of DDL numbers)
33 /// should be read, this can be achieved by the Select method.
34 /// Several getters provide information about the current event and the
35 /// current type of raw data.
36 ///
37 ///////////////////////////////////////////////////////////////////////////////
38
39 #include "AliRawReader.h"
40
41
42 ClassImp(AliRawReader)
43
44
45 AliRawReader::AliRawReader() :
46   fHeader(NULL),
47   fCount(0),
48   fSelectEquipmentType(-1),
49   fSelectMinEquipmentId(-1),
50   fSelectMaxEquipmentId(-1),
51   fSkipInvalid(kFALSE),
52   fSelectEventType(-1),
53   fErrorCode(0)
54 {
55 // default constructor: initialize data members
56
57 }
58
59 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
60   TObject(rawReader),
61   fHeader(rawReader.fHeader),
62   fCount(rawReader.fCount),
63   fSelectEquipmentType(rawReader.fSelectEquipmentType),
64   fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
65   fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
66   fSkipInvalid(rawReader.fSkipInvalid),
67   fSelectEventType(rawReader.fSelectEventType),
68   fErrorCode(0)
69 {
70 // copy constructor
71
72 }
73
74 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
75 {
76 // assignment operator
77
78   fHeader = rawReader.fHeader;
79   fCount = rawReader.fCount;
80
81   fSelectEquipmentType = rawReader.fSelectEquipmentType;
82   fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
83   fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
84   fSkipInvalid = rawReader.fSkipInvalid;
85   fSelectEventType = rawReader.fSelectEventType;
86
87   fErrorCode = rawReader.fErrorCode;
88
89   return *this;
90 }
91
92
93 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
94 {
95 // read only data of the detector with the given ID and in the given
96 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
97 // no selection is applied if a value < 0 is used.
98
99   fSelectEquipmentType = 0;
100   if (minDDLID < 0) minDDLID = 0;
101   fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
102   if (maxDDLID < 0) maxDDLID = 0xFF;
103   fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
104 }
105
106 void AliRawReader::SelectEquipment(Int_t equipmentType, 
107                                    Int_t minEquipmentId, Int_t maxEquipmentId)
108 {
109 // read only data of the equipment with the given type and in the given
110 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
111 // no selection is applied if a value < 0 is used.
112
113   fSelectEquipmentType = equipmentType;
114   fSelectMinEquipmentId = minEquipmentId;
115   fSelectMaxEquipmentId = maxEquipmentId;
116 }
117
118 void AliRawReader::SelectEvents(Int_t type)
119 {
120 // read only events with the given type.
121 // no selection is applied if a value < 0 is used.
122
123   fSelectEventType = type;
124 }
125
126 Bool_t AliRawReader::IsSelected() const
127 {
128 // apply the selection (if any)
129
130   if (fSkipInvalid && !IsValid()) return kFALSE;
131
132   if (fSelectEquipmentType >= 0) {
133     if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
134     if ((fSelectMinEquipmentId >= 0) && 
135         (GetEquipmentId() < fSelectMinEquipmentId))
136       return kFALSE;
137     if ((fSelectMaxEquipmentId >= 0) && 
138         (GetEquipmentId() > fSelectMaxEquipmentId))
139       return kFALSE;
140   }
141
142   return kTRUE;
143 }
144
145 Bool_t AliRawReader::IsEventSelected() const
146 {
147 // apply the event selection (if any)
148
149   if (fSelectEventType >= 0) {
150     if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
151   }
152
153   return kTRUE;
154 }
155
156
157 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
158 {
159 // reads the next 4 bytes at the current position
160 // returns kFALSE if the data could not be read
161
162   while (fCount == 0) {
163     if (!ReadHeader()) return kFALSE;
164   }
165   if (fCount < (Int_t) sizeof(data)) {
166     Error("ReadNextInt", 
167           "too few data left (%d bytes) to read an UInt_t!", fCount);
168     return kFALSE;
169   }
170   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
171     Error("ReadNextInt", "could not read data!");
172     return kFALSE;
173   }
174   return kTRUE;
175 }
176
177 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
178 {
179 // reads the next 2 bytes at the current position
180 // returns kFALSE if the data could not be read
181
182   while (fCount == 0) {
183     if (!ReadHeader()) return kFALSE;
184   }
185   if (fCount < (Int_t) sizeof(data)) {
186     Error("ReadNextShort", 
187           "too few data left (%d bytes) to read an UShort_t!", fCount);
188     return kFALSE;
189   }
190   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
191     Error("ReadNextShort", "could not read data!");
192     return kFALSE;
193   }
194   return kTRUE;
195 }
196
197 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
198 {
199 // reads the next 1 byte at the current stream position
200 // returns kFALSE if the data could not be read
201
202   while (fCount == 0) {
203     if (!ReadHeader()) return kFALSE;
204   }
205   if (!ReadNext((UChar_t*) &data, sizeof(data))) {
206     Error("ReadNextChar", "could not read data!");
207     return kFALSE;
208   }
209   return kTRUE;
210 }
211
212
213 Int_t AliRawReader::CheckData() const
214 {
215 // check the consistency of the data
216 // derived classes should overwrite the default method which returns 0 (no err)
217
218   return 0;
219 }
220
221
222 void AliRawReader::DumpData(Int_t limit)
223 {
224 // print the raw data
225 // if limit is not negative, only the first and last "limit" lines of raw data
226 // are printed
227
228   Reset();
229   if (!ReadHeader()) {
230     Error("DumpData", "no header");
231     return;
232   }
233   printf("header:\n"
234          " type = %d  run = %d  ", GetType(), GetRunNumber());
235   if (GetEventId()) {
236     printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
237   } else {
238     printf("event = -------- --------\n");
239   }
240   if (GetTriggerPattern()) {
241     printf(" trigger = %8.8x %8.8x  ",
242            GetTriggerPattern()[1], GetTriggerPattern()[0]);
243   } else {
244     printf(" trigger = -------- --------  ");
245   }
246   if (GetDetectorPattern()) {
247     printf("detector = %8.8x\n", GetDetectorPattern()[0]);
248   } else {
249     printf("detector = --------\n");
250   }
251   if (GetAttributes()) {
252     printf(" attributes = %8.8x %8.8x %8.8x  ",
253            GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
254   } else {
255     printf(" attributes = -------- -------- --------  ");
256   }
257   printf("GDC = %d\n", GetGDCId());
258   printf("\n");
259
260   do {
261     printf("-------------------------------------------------------------------------------\n");
262     printf("LDC = %d\n", GetLDCId());
263
264     printf("equipment:\n"
265            " size = %d  type = %d  id = %d\n",
266            GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
267     if (GetEquipmentAttributes()) {
268       printf(" attributes = %8.8x %8.8x %8.8x  ", GetEquipmentAttributes()[2],
269              GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
270     } else {
271       printf(" attributes = -------- -------- --------  ");
272     }
273     printf("element size = %d\n", GetEquipmentElementSize());
274
275     printf("data header:\n"
276            " size = %d  version = %d  valid = %d  compression = %d\n",
277            GetDataSize(), GetVersion(), IsValid(), IsCompressed());
278
279     printf("\n");
280     if (limit == 0) continue;
281
282     Int_t size = GetDataSize();
283     char line[70];
284     for (Int_t i = 0; i < 70; i++) line[i] = ' ';
285     line[69] = '\0';
286     Int_t pos = 0;
287     Int_t max = 16;
288     UChar_t byte;
289
290     for (Int_t n = 0; n < size; n++) {
291       if (!ReadNextChar(byte)) {
292         Error("DumpData", "couldn't read byte number %d\n", n);
293         break;
294       }
295       if (pos >= max) {
296         printf("%8.8x  %s\n", n-pos, line);
297         for (Int_t i = 0; i < 70; i++) line[i] = ' ';
298         line[69] = '\0';
299         pos = 0;
300         if ((limit > 0) && (n/max == limit)) {
301           Int_t nContinue = ((size-1)/max+1-limit) * max;
302           if (nContinue > n) {
303             printf(" [skipping %d bytes]\n", nContinue-n);
304             n = nContinue-1;
305             continue;
306           }
307         }
308       }
309       Int_t offset = pos/4;
310       if ((byte > 0x20) && (byte < 0x7f)) {
311         line[pos+offset] = byte;
312       } else {
313         line[pos+offset] = '.';
314       }
315       char hex[3];
316       sprintf(hex, "%2.2x", byte);
317       line[max+max/4+3+2*pos+offset] = hex[0];
318       line[max+max/4+4+2*pos+offset] = hex[1];
319       pos++;
320     }
321
322     if (pos > 0) printf("%8.8x  %s\n", size-pos, line);
323     printf("\n");
324            
325   } while (ReadHeader());
326 }