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