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),
55 // default constructor: initialize data members
59 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
61 fHeader(rawReader.fHeader),
62 fCount(rawReader.fCount),
63 fSelectEquipmentType(rawReader.fSelectEquipmentType),
64 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
65 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
66 fSkipInvalid(rawReader.fSkipInvalid),
67 fSelectEventType(rawReader.fSelectEventType),
74 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
76 // assignment operator
78 fHeader = rawReader.fHeader;
79 fCount = rawReader.fCount;
81 fSelectEquipmentType = rawReader.fSelectEquipmentType;
82 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
83 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
84 fSkipInvalid = rawReader.fSkipInvalid;
85 fSelectEventType = rawReader.fSelectEventType;
87 fErrorCode = rawReader.fErrorCode;
93 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
95 // read only data of the detector with the given ID and in the given
96 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
97 // no selection is applied if a value < 0 is used.
99 fSelectEquipmentType = 0;
100 if (minDDLID < 0) minDDLID = 0;
101 fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
102 if (maxDDLID < 0) maxDDLID = 0xFF;
103 fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
106 void AliRawReader::SelectEquipment(Int_t equipmentType,
107 Int_t minEquipmentId, Int_t maxEquipmentId)
109 // read only data of the equipment with the given type and in the given
110 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
111 // no selection is applied if a value < 0 is used.
113 fSelectEquipmentType = equipmentType;
114 fSelectMinEquipmentId = minEquipmentId;
115 fSelectMaxEquipmentId = maxEquipmentId;
118 void AliRawReader::SelectEvents(Int_t type)
120 // read only events with the given type.
121 // no selection is applied if a value < 0 is used.
123 fSelectEventType = type;
126 Bool_t AliRawReader::IsSelected() const
128 // apply the selection (if any)
130 if (fSkipInvalid && !IsValid()) return kFALSE;
132 if (fSelectEquipmentType >= 0) {
133 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
134 if ((fSelectMinEquipmentId >= 0) &&
135 (GetEquipmentId() < fSelectMinEquipmentId))
137 if ((fSelectMaxEquipmentId >= 0) &&
138 (GetEquipmentId() > fSelectMaxEquipmentId))
145 Bool_t AliRawReader::IsEventSelected() const
147 // apply the event selection (if any)
149 if (fSelectEventType >= 0) {
150 if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
157 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
159 // reads the next 4 bytes at the current position
160 // returns kFALSE if the data could not be read
162 while (fCount == 0) {
163 if (!ReadHeader()) return kFALSE;
165 if (fCount < (Int_t) sizeof(data)) {
167 "too few data left (%d bytes) to read an UInt_t!", fCount);
170 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
171 Error("ReadNextInt", "could not read data!");
177 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
179 // reads the next 2 bytes at the current position
180 // returns kFALSE if the data could not be read
182 while (fCount == 0) {
183 if (!ReadHeader()) return kFALSE;
185 if (fCount < (Int_t) sizeof(data)) {
186 Error("ReadNextShort",
187 "too few data left (%d bytes) to read an UShort_t!", fCount);
190 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
191 Error("ReadNextShort", "could not read data!");
197 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
199 // reads the next 1 byte at the current stream position
200 // returns kFALSE if the data could not be read
202 while (fCount == 0) {
203 if (!ReadHeader()) return kFALSE;
205 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
206 Error("ReadNextChar", "could not read data!");
213 Int_t AliRawReader::CheckData() const
215 // check the consistency of the data
216 // derived classes should overwrite the default method which returns 0 (no err)
222 void AliRawReader::DumpData(Int_t limit)
224 // print the raw data
225 // if limit is not negative, only the first and last "limit" lines of raw data
230 Error("DumpData", "no header");
234 " type = %d run = %d ", GetType(), GetRunNumber());
236 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
238 printf("event = -------- --------\n");
240 if (GetTriggerPattern()) {
241 printf(" trigger = %8.8x %8.8x ",
242 GetTriggerPattern()[1], GetTriggerPattern()[0]);
244 printf(" trigger = -------- -------- ");
246 if (GetDetectorPattern()) {
247 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
249 printf("detector = --------\n");
251 if (GetAttributes()) {
252 printf(" attributes = %8.8x %8.8x %8.8x ",
253 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
255 printf(" attributes = -------- -------- -------- ");
257 printf("GDC = %d\n", GetGDCId());
261 printf("-------------------------------------------------------------------------------\n");
262 printf("LDC = %d\n", GetLDCId());
264 printf("equipment:\n"
265 " size = %d type = %d id = %d\n",
266 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
267 if (GetEquipmentAttributes()) {
268 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
269 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
271 printf(" attributes = -------- -------- -------- ");
273 printf("element size = %d\n", GetEquipmentElementSize());
275 printf("data header:\n"
276 " size = %d version = %d valid = %d compression = %d\n",
277 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
280 if (limit == 0) continue;
282 Int_t size = GetDataSize();
284 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
290 for (Int_t n = 0; n < size; n++) {
291 if (!ReadNextChar(byte)) {
292 Error("DumpData", "couldn't read byte number %d\n", n);
296 printf("%8.8x %s\n", n-pos, line);
297 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
300 if ((limit > 0) && (n/max == limit)) {
301 Int_t nContinue = ((size-1)/max+1-limit) * max;
303 printf(" [skipping %d bytes]\n", nContinue-n);
309 Int_t offset = pos/4;
310 if ((byte > 0x20) && (byte < 0x7f)) {
311 line[pos+offset] = byte;
313 line[pos+offset] = '.';
316 sprintf(hex, "%2.2x", byte);
317 line[max+max/4+3+2*pos+offset] = hex[0];
318 line[max+max/4+4+2*pos+offset] = hex[1];
322 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
325 } while (ReadHeader());