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() :
48 fSelectEquipmentType(-1),
49 fSelectMinEquipmentId(-1),
50 fSelectMaxEquipmentId(-1),
54 // default constructor: initialize data members
58 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
60 fHeader(rawReader.fHeader),
61 fCount(rawReader.fCount),
62 fSelectEquipmentType(rawReader.fSelectEquipmentType),
63 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
64 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
65 fSkipInvalid(rawReader.fSkipInvalid),
72 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
74 // assignment operator
76 fHeader = rawReader.fHeader;
77 fCount = rawReader.fCount;
79 fSelectEquipmentType = rawReader.fSelectEquipmentType;
80 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
81 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
82 fSkipInvalid = rawReader.fSkipInvalid;
84 fErrorCode = rawReader.fErrorCode;
90 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
92 // read only data of the detector with the given ID and in the given
93 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
94 // no selection is applied if a value < 0 is used.
96 fSelectEquipmentType = 0;
97 if (minDDLID < 0) minDDLID = 0;
98 fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
99 if (maxDDLID < 0) maxDDLID = 0xFF;
100 fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
103 void AliRawReader::SelectEquipment(Int_t equipmentType,
104 Int_t minEquipmentId, Int_t maxEquipmentId)
106 // read only data of the equipment with the given type and in the given
107 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
108 // no selection is applied if a value < 0 is used.
110 fSelectEquipmentType = equipmentType;
111 fSelectMinEquipmentId = minEquipmentId;
112 fSelectMaxEquipmentId = maxEquipmentId;
115 Bool_t AliRawReader::IsSelected() const
117 // apply the selection (if any)
119 if (fSkipInvalid && !IsValid()) return kFALSE;
121 if (fSelectEquipmentType >= 0) {
122 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
123 if ((fSelectMinEquipmentId >= 0) &&
124 (GetEquipmentId() < fSelectMinEquipmentId))
126 if ((fSelectMaxEquipmentId >= 0) &&
127 (GetEquipmentId() > fSelectMaxEquipmentId))
135 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
137 // reads the next 4 bytes at the current position
138 // returns kFALSE if the data could not be read
140 while (fCount == 0) {
141 if (!ReadHeader()) return kFALSE;
143 if (fCount < (Int_t) sizeof(data)) {
145 "too few data left (%d bytes) to read an UInt_t!", fCount);
148 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
149 Error("ReadNextInt", "could not read data!");
155 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
157 // reads the next 2 bytes at the current position
158 // returns kFALSE if the data could not be read
160 while (fCount == 0) {
161 if (!ReadHeader()) return kFALSE;
163 if (fCount < (Int_t) sizeof(data)) {
164 Error("ReadNextShort",
165 "too few data left (%d bytes) to read an UShort_t!", fCount);
168 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
169 Error("ReadNextShort", "could not read data!");
175 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
177 // reads the next 1 byte at the current stream position
178 // returns kFALSE if the data could not be read
180 while (fCount == 0) {
181 if (!ReadHeader()) return kFALSE;
183 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
184 Error("ReadNextChar", "could not read data!");
191 Int_t AliRawReader::CheckData() const
193 // check the consistency of the data
194 // derived classes should overwrite the default method which returns 0 (no err)
200 void AliRawReader::DumpData(Int_t limit)
202 // print the raw data
203 // if limit is not negative, only the first and last "limit" lines of raw data
208 Error("DumpData", "no header");
212 " type = %d run = %d ", GetType(), GetRunNumber());
214 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
216 printf("event = -------- --------\n");
218 if (GetTriggerPattern()) {
219 printf(" trigger = %8.8x %8.8x ",
220 GetTriggerPattern()[1], GetTriggerPattern()[0]);
222 printf(" trigger = -------- -------- ");
224 if (GetDetectorPattern()) {
225 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
227 printf("detector = --------\n");
229 if (GetAttributes()) {
230 printf(" attributes = %8.8x %8.8x %8.8x ",
231 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
233 printf(" attributes = -------- -------- -------- ");
235 printf("GDC = %d\n", GetGDCId());
239 printf("-------------------------------------------------------------------------------\n");
240 printf("LDC = %d\n", GetLDCId());
242 printf("equipment:\n"
243 " size = %d type = %d id = %d\n",
244 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
245 if (GetEquipmentAttributes()) {
246 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
247 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
249 printf(" attributes = -------- -------- -------- ");
251 printf("element size = %d\n", GetEquipmentElementSize());
253 printf("data header:\n"
254 " size = %d version = %d valid = %d compression = %d\n",
255 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
258 if (limit == 0) continue;
260 Int_t size = GetDataSize();
262 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
268 for (Int_t n = 0; n < size; n++) {
269 if (!ReadNextChar(byte)) {
270 Error("DumpData", "couldn't read byte number %d\n", n);
274 printf("%8.8x %s\n", n-pos, line);
275 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
278 if ((limit > 0) && (n/max == limit)) {
279 Int_t nContinue = ((size-1)/max+1-limit) * max;
281 printf(" [skipping %d bytes]\n", nContinue-n);
287 Int_t offset = pos/4;
288 if ((byte > 0x20) && (byte < 0x7f)) {
289 line[pos+offset] = byte;
291 line[pos+offset] = '.';
294 sprintf(hex, "%2.2x", byte);
295 line[max+max/4+3+2*pos+offset] = hex[0];
296 line[max+max/4+4+2*pos+offset] = hex[1];
300 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
303 } while (ReadHeader());