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 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // This is the base class for reading raw data and providing
19 // information about digits
21 // The derived classes, which operate on concrete raw data formats,
23 // - ReadHeader to read the next (data/equipment) header
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
28 // Sequential access to the raw data is provided by the methods
29 // ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
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.
36 ///////////////////////////////////////////////////////////////////////////////
38 #include "AliRawReader.h"
41 ClassImp(AliRawReader)
44 AliRawReader::AliRawReader() :
47 fSelectEquipmentType(-1),
48 fSelectMinEquipmentId(-1),
49 fSelectMaxEquipmentId(-1),
53 // default constructor: initialize data members
57 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
59 fHeader(rawReader.fHeader),
60 fCount(rawReader.fCount),
61 fSelectEquipmentType(rawReader.fSelectEquipmentType),
62 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
63 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
64 fSkipInvalid(rawReader.fSkipInvalid),
71 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
73 // assignment operator
75 fHeader = rawReader.fHeader;
76 fCount = rawReader.fCount;
78 fSelectEquipmentType = rawReader.fSelectEquipmentType;
79 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
80 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
81 fSkipInvalid = rawReader.fSkipInvalid;
83 fErrorCode = rawReader.fErrorCode;
89 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
91 // read only data of the detector with the given ID and in the given
92 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
93 // no selection is applied if a value < 0 is used.
95 fSelectEquipmentType = 0;
96 if (minDDLID < 0) minDDLID = 0;
97 fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
98 if (maxDDLID < 0) maxDDLID = 0xFF;
99 fSelectMaxEquipmentId = (detectorID << 8) + maxDDLID;
102 void AliRawReader::SelectEquipment(Int_t equipmentType,
103 Int_t minEquipmentId, Int_t maxEquipmentId)
105 // read only data of the equipment with the given type and in the given
106 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
107 // no selection is applied if a value < 0 is used.
109 fSelectEquipmentType = equipmentType;
110 fSelectMinEquipmentId = minEquipmentId;
111 fSelectMaxEquipmentId = maxEquipmentId;
114 Bool_t AliRawReader::IsSelected() const
116 // apply the selection (if any)
118 if (fSkipInvalid && !IsValid()) return kFALSE;
120 if (fSelectEquipmentType >= 0) {
121 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
122 if ((fSelectMinEquipmentId >= 0) &&
123 (GetEquipmentId() < fSelectMinEquipmentId))
125 if ((fSelectMaxEquipmentId >= 0) &&
126 (GetEquipmentId() > fSelectMaxEquipmentId))
134 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
136 // reads the next 4 bytes at the current position
137 // returns kFALSE if the data could not be read
139 while (fCount == 0) {
140 if (!ReadHeader()) return kFALSE;
142 if (fCount < (Int_t) sizeof(data)) {
144 "too few data left (%d bytes) to read an UInt_t!", fCount);
147 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
148 Error("ReadNextInt", "could not read data!");
154 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
156 // reads the next 2 bytes at the current position
157 // returns kFALSE if the data could not be read
159 while (fCount == 0) {
160 if (!ReadHeader()) return kFALSE;
162 if (fCount < (Int_t) sizeof(data)) {
163 Error("ReadNextShort",
164 "too few data left (%d bytes) to read an UShort_t!", fCount);
167 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
168 Error("ReadNextShort", "could not read data!");
174 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
176 // reads the next 1 byte at the current stream position
177 // returns kFALSE if the data could not be read
179 while (fCount == 0) {
180 if (!ReadHeader()) return kFALSE;
182 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
183 Error("ReadNextChar", "could not read data!");
190 Int_t AliRawReader::CheckData() const
192 // check the consistency of the data
193 // derived classes should overwrite the default method which returns 0 (no err)
199 void AliRawReader::DumpData(Int_t limit)
201 // print the raw data
202 // if limit is not negative, only the first and last "limit" lines of raw data
207 Error("DumpData", "no header");
211 " type = %d run = %d ", GetType(), GetRunNumber());
213 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
215 printf("event = -------- --------\n");
217 if (GetTriggerPattern()) {
218 printf(" trigger = %8.8x %8.8x ",
219 GetTriggerPattern()[1], GetTriggerPattern()[0]);
221 printf(" trigger = -------- -------- ");
223 if (GetDetectorPattern()) {
224 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
226 printf("detector = --------\n");
228 if (GetAttributes()) {
229 printf(" attributes = %8.8x %8.8x %8.8x ",
230 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
232 printf(" attributes = -------- -------- -------- ");
234 printf("GDC = %d\n", GetGDCId());
238 printf("-------------------------------------------------------------------------------\n");
239 printf("LDC = %d\n", GetLDCId());
241 printf("equipment:\n"
242 " size = %d type = %d id = %d\n",
243 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
244 if (GetEquipmentAttributes()) {
245 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
246 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
248 printf(" attributes = -------- -------- -------- ");
250 printf("element size = %d\n", GetEquipmentElementSize());
252 printf("data header:\n"
253 " size = %d version = %d valid = %d compression = %d\n",
254 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
257 if (limit == 0) continue;
259 Int_t size = GetDataSize();
261 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
267 for (Int_t n = 0; n < size; n++) {
268 if (!ReadNextChar(byte)) {
269 Error("DumpData", "couldn't read byte number %d\n", n);
273 printf("%8.8x %s\n", n-pos, line);
274 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
277 if ((limit > 0) && (n/max == limit)) {
278 Int_t nContinue = ((size-1)/max+1-limit) * max;
280 printf(" [skipping %d bytes]\n", nContinue-n);
286 Int_t offset = pos/4;
287 if ((byte > 0x20) && (byte < 0x7f)) {
288 line[pos+offset] = byte;
290 line[pos+offset] = '.';
293 sprintf(hex, "%2.2x", byte);
294 line[max+max/4+3+2*pos+offset] = hex[0];
295 line[max+max/4+4+2*pos+offset] = hex[1];
299 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
302 } while (ReadHeader());