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