1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This is the base class for reading raw data.
22 /// The derived classes, which operate on concrete raw data formats,
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
29 /// Sequential access to the raw data is provided by the methods
30 /// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
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.
37 ///////////////////////////////////////////////////////////////////////////////
39 #include "AliRawReader.h"
42 ClassImp(AliRawReader)
45 AliRawReader::AliRawReader() :
46 fRequireHeader(kTRUE),
49 fSelectEquipmentType(-1),
50 fSelectMinEquipmentId(-1),
51 fSelectMaxEquipmentId(-1),
56 // default constructor: initialize data members
60 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
62 fRequireHeader(rawReader.fRequireHeader),
63 fHeader(rawReader.fHeader),
64 fCount(rawReader.fCount),
65 fSelectEquipmentType(rawReader.fSelectEquipmentType),
66 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
67 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
68 fSkipInvalid(rawReader.fSkipInvalid),
69 fSelectEventType(rawReader.fSelectEventType),
76 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
78 // assignment operator
80 fHeader = rawReader.fHeader;
81 fCount = rawReader.fCount;
83 fSelectEquipmentType = rawReader.fSelectEquipmentType;
84 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
85 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
86 fSkipInvalid = rawReader.fSkipInvalid;
87 fSelectEventType = rawReader.fSelectEventType;
89 fErrorCode = rawReader.fErrorCode;
95 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
97 // read only data of the detector with the given ID and in the given
98 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
99 // no selection is applied if a value < 0 is used.
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;
108 void AliRawReader::SelectEquipment(Int_t equipmentType,
109 Int_t minEquipmentId, Int_t maxEquipmentId)
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.
115 fSelectEquipmentType = equipmentType;
116 fSelectMinEquipmentId = minEquipmentId;
117 fSelectMaxEquipmentId = maxEquipmentId;
120 void AliRawReader::SelectEvents(Int_t type)
122 // read only events with the given type.
123 // no selection is applied if a value < 0 is used.
125 fSelectEventType = type;
128 Bool_t AliRawReader::IsSelected() const
130 // apply the selection (if any)
132 if (fSkipInvalid && !IsValid()) return kFALSE;
134 if (fSelectEquipmentType >= 0) {
135 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
136 if ((fSelectMinEquipmentId >= 0) &&
137 (GetEquipmentId() < fSelectMinEquipmentId))
139 if ((fSelectMaxEquipmentId >= 0) &&
140 (GetEquipmentId() > fSelectMaxEquipmentId))
147 Bool_t AliRawReader::IsEventSelected() const
149 // apply the event selection (if any)
151 if (fSelectEventType >= 0) {
152 if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
159 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
161 // reads the next 4 bytes at the current position
162 // returns kFALSE if the data could not be read
164 while (fCount == 0) {
165 if (!ReadHeader()) return kFALSE;
167 if (fCount < (Int_t) sizeof(data)) {
169 "too few data left (%d bytes) to read an UInt_t!", fCount);
172 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
173 Error("ReadNextInt", "could not read data!");
179 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
181 // reads the next 2 bytes at the current position
182 // returns kFALSE if the data could not be read
184 while (fCount == 0) {
185 if (!ReadHeader()) return kFALSE;
187 if (fCount < (Int_t) sizeof(data)) {
188 Error("ReadNextShort",
189 "too few data left (%d bytes) to read an UShort_t!", fCount);
192 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
193 Error("ReadNextShort", "could not read data!");
199 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
201 // reads the next 1 byte at the current stream position
202 // returns kFALSE if the data could not be read
204 while (fCount == 0) {
205 if (!ReadHeader()) return kFALSE;
207 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
208 Error("ReadNextChar", "could not read data!");
215 Int_t AliRawReader::CheckData() const
217 // check the consistency of the data
218 // derived classes should overwrite the default method which returns 0 (no err)
224 void AliRawReader::DumpData(Int_t limit)
226 // print the raw data
227 // if limit is not negative, only the first and last "limit" lines of raw data
232 Error("DumpData", "no header");
236 " type = %d run = %d ", GetType(), GetRunNumber());
238 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
240 printf("event = -------- --------\n");
242 if (GetTriggerPattern()) {
243 printf(" trigger = %8.8x %8.8x ",
244 GetTriggerPattern()[1], GetTriggerPattern()[0]);
246 printf(" trigger = -------- -------- ");
248 if (GetDetectorPattern()) {
249 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
251 printf("detector = --------\n");
253 if (GetAttributes()) {
254 printf(" attributes = %8.8x %8.8x %8.8x ",
255 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
257 printf(" attributes = -------- -------- -------- ");
259 printf("GDC = %d\n", GetGDCId());
263 printf("-------------------------------------------------------------------------------\n");
264 printf("LDC = %d\n", GetLDCId());
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]);
273 printf(" attributes = -------- -------- -------- ");
275 printf("element size = %d\n", GetEquipmentElementSize());
277 printf("data header:\n"
278 " size = %d version = %d valid = %d compression = %d\n",
279 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
282 if (limit == 0) continue;
284 Int_t size = GetDataSize();
286 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
292 for (Int_t n = 0; n < size; n++) {
293 if (!ReadNextChar(byte)) {
294 Error("DumpData", "couldn't read byte number %d\n", n);
298 printf("%8.8x %s\n", n-pos, line);
299 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
302 if ((limit > 0) && (n/max == limit)) {
303 Int_t nContinue = ((size-1)/max+1-limit) * max;
305 printf(" [skipping %d bytes]\n", nContinue-n);
311 Int_t offset = pos/4;
312 if ((byte > 0x20) && (byte < 0x7f)) {
313 line[pos+offset] = byte;
315 line[pos+offset] = '.';
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];
324 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
327 } while (ReadHeader());