]>
Commit | Line | Data |
---|---|---|
a6e7b125 | 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 | ||
bea6b2a4 | 16 | /* $Id$ */ |
17 | ||
a6e7b125 | 18 | /////////////////////////////////////////////////////////////////////////////// |
bea6b2a4 | 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 | /// | |
a6e7b125 | 37 | /////////////////////////////////////////////////////////////////////////////// |
38 | ||
39 | #include "AliRawReader.h" | |
40 | ||
8de97894 | 41 | |
a6e7b125 | 42 | ClassImp(AliRawReader) |
43 | ||
44 | ||
c946ab02 | 45 | AliRawReader::AliRawReader() : |
39f9963f | 46 | fHeader(NULL), |
c946ab02 | 47 | fCount(0), |
f224de6c | 48 | fSelectEquipmentType(-1), |
49 | fSelectMinEquipmentId(-1), | |
50 | fSelectMaxEquipmentId(-1), | |
39f9963f | 51 | fSkipInvalid(kFALSE), |
dd9a70fe | 52 | fSelectEventType(-1), |
c946ab02 | 53 | fErrorCode(0) |
a6e7b125 | 54 | { |
42d20574 | 55 | // default constructor: initialize data members |
56 | ||
a6e7b125 | 57 | } |
58 | ||
42d20574 | 59 | AliRawReader::AliRawReader(const AliRawReader& rawReader) : |
c946ab02 | 60 | TObject(rawReader), |
39f9963f | 61 | fHeader(rawReader.fHeader), |
c946ab02 | 62 | fCount(rawReader.fCount), |
f224de6c | 63 | fSelectEquipmentType(rawReader.fSelectEquipmentType), |
64 | fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId), | |
65 | fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId), | |
39f9963f | 66 | fSkipInvalid(rawReader.fSkipInvalid), |
dd9a70fe | 67 | fSelectEventType(rawReader.fSelectEventType), |
c946ab02 | 68 | fErrorCode(0) |
42d20574 | 69 | { |
70 | // copy constructor | |
71 | ||
42d20574 | 72 | } |
73 | ||
74 | AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader) | |
75 | { | |
76 | // assignment operator | |
77 | ||
39f9963f | 78 | fHeader = rawReader.fHeader; |
42d20574 | 79 | fCount = rawReader.fCount; |
80 | ||
39f9963f | 81 | fSelectEquipmentType = rawReader.fSelectEquipmentType; |
82 | fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId; | |
83 | fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId; | |
84 | fSkipInvalid = rawReader.fSkipInvalid; | |
dd9a70fe | 85 | fSelectEventType = rawReader.fSelectEventType; |
42d20574 | 86 | |
b4857df7 | 87 | fErrorCode = rawReader.fErrorCode; |
88 | ||
42d20574 | 89 | return *this; |
90 | } | |
91 | ||
8de97894 | 92 | |
93 | void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID) | |
a6e7b125 | 94 | { |
8de97894 | 95 | // read only data of the detector with the given ID and in the given |
f224de6c | 96 | // range of DDLs (minDDLID <= DDLID <= maxDDLID). |
8de97894 | 97 | // no selection is applied if a value < 0 is used. |
a6e7b125 | 98 | |
39f9963f | 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; | |
8de97894 | 104 | } |
a6e7b125 | 105 | |
f224de6c | 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 | ||
dd9a70fe | 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 | ||
42d20574 | 126 | Bool_t AliRawReader::IsSelected() const |
a6e7b125 | 127 | { |
8de97894 | 128 | // apply the selection (if any) |
129 | ||
39f9963f | 130 | if (fSkipInvalid && !IsValid()) return kFALSE; |
f224de6c | 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 | ||
8de97894 | 142 | return kTRUE; |
a6e7b125 | 143 | } |
144 | ||
dd9a70fe | 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 | ||
a6e7b125 | 156 | |
a6e7b125 | 157 | Bool_t AliRawReader::ReadNextInt(UInt_t& data) |
158 | { | |
8de97894 | 159 | // reads the next 4 bytes at the current position |
160 | // returns kFALSE if the data could not be read | |
a6e7b125 | 161 | |
162 | while (fCount == 0) { | |
c946ab02 | 163 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 164 | } |
8de97894 | 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))) { | |
a6e7b125 | 171 | Error("ReadNextInt", "could not read data!"); |
172 | return kFALSE; | |
173 | } | |
a6e7b125 | 174 | return kTRUE; |
175 | } | |
176 | ||
177 | Bool_t AliRawReader::ReadNextShort(UShort_t& data) | |
178 | { | |
8de97894 | 179 | // reads the next 2 bytes at the current position |
180 | // returns kFALSE if the data could not be read | |
a6e7b125 | 181 | |
182 | while (fCount == 0) { | |
c946ab02 | 183 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 184 | } |
8de97894 | 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))) { | |
a6e7b125 | 191 | Error("ReadNextShort", "could not read data!"); |
192 | return kFALSE; | |
193 | } | |
a6e7b125 | 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 | |
8de97894 | 200 | // returns kFALSE if the data could not be read |
a6e7b125 | 201 | |
202 | while (fCount == 0) { | |
c946ab02 | 203 | if (!ReadHeader()) return kFALSE; |
a6e7b125 | 204 | } |
8de97894 | 205 | if (!ReadNext((UChar_t*) &data, sizeof(data))) { |
a6e7b125 | 206 | Error("ReadNextChar", "could not read data!"); |
207 | return kFALSE; | |
208 | } | |
a6e7b125 | 209 | return kTRUE; |
210 | } | |
211 | ||
b4857df7 | 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 | ||
509a7696 | 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 | ||
39f9963f | 275 | printf("data header:\n" |
276 | " size = %d version = %d valid = %d compression = %d\n", | |
277 | GetDataSize(), GetVersion(), IsValid(), IsCompressed()); | |
509a7696 | 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 | } |