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