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 (mini or 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 fSelectDetectorID(-1),
50 fSelectEquipmentType(-1),
51 fSelectMinEquipmentId(-1),
52 fSelectMaxEquipmentId(-1),
55 // default constructor: initialize data members
59 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
61 fMiniHeader(rawReader.fMiniHeader),
62 fCount(rawReader.fCount),
63 fSelectDetectorID(rawReader.fSelectDetectorID),
64 fSelectMinDDLID(rawReader.fSelectMinDDLID),
65 fSelectMaxDDLID(rawReader.fSelectMaxDDLID),
66 fSelectEquipmentType(rawReader.fSelectEquipmentType),
67 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
68 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
75 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
77 // assignment operator
79 fMiniHeader = rawReader.fMiniHeader;
80 fCount = rawReader.fCount;
82 fSelectDetectorID = rawReader.fSelectDetectorID;
83 fSelectMinDDLID = rawReader.fSelectMinDDLID;
84 fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
86 fErrorCode = rawReader.fErrorCode;
92 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
94 // read only data of the detector with the given ID and in the given
95 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
96 // no selection is applied if a value < 0 is used.
98 fSelectDetectorID = detectorID;
99 fSelectMinDDLID = minDDLID;
100 fSelectMaxDDLID = 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 (fSelectDetectorID >= 0) {
120 if (!fMiniHeader) return kFALSE;
121 if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
122 if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
124 if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID > fSelectMaxDDLID))
128 if (fSelectEquipmentType >= 0) {
129 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
130 if ((fSelectMinEquipmentId >= 0) &&
131 (GetEquipmentId() < fSelectMinEquipmentId))
133 if ((fSelectMaxEquipmentId >= 0) &&
134 (GetEquipmentId() > fSelectMaxEquipmentId))
142 Bool_t AliRawReader::CheckMiniHeader(AliMiniHeader* miniHeader) const
144 // check the magic number of the mini header
146 if (!miniHeader) miniHeader = fMiniHeader;
147 if (!miniHeader) return kFALSE;
148 UInt_t magicWord = miniHeader->fMagicWord[2]*65536 +
149 miniHeader->fMagicWord[1]*256 + miniHeader->fMagicWord[0];
150 if (magicWord != AliMiniHeader::kMagicWord) {
156 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
158 // reads the next 4 bytes at the current position
159 // returns kFALSE if the data could not be read
161 while (fCount == 0) {
162 if (!ReadHeader()) return kFALSE;
164 if (fCount < (Int_t) sizeof(data)) {
166 "too few data left (%d bytes) to read an UInt_t!", fCount);
169 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
170 Error("ReadNextInt", "could not read data!");
176 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
178 // reads the next 2 bytes at the current position
179 // returns kFALSE if the data could not be read
181 while (fCount == 0) {
182 if (!ReadHeader()) return kFALSE;
184 if (fCount < (Int_t) sizeof(data)) {
185 Error("ReadNextShort",
186 "too few data left (%d bytes) to read an UShort_t!", fCount);
189 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
190 Error("ReadNextShort", "could not read data!");
196 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
198 // reads the next 1 byte at the current stream position
199 // returns kFALSE if the data could not be read
201 while (fCount == 0) {
202 if (!ReadHeader()) return kFALSE;
204 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
205 Error("ReadNextChar", "could not read data!");
212 Int_t AliRawReader::CheckData() const
214 // check the consistency of the data
215 // derived classes should overwrite the default method which returns 0 (no err)
221 void AliRawReader::DumpData(Int_t limit)
223 // print the raw data
224 // if limit is not negative, only the first and last "limit" lines of raw data
229 Error("DumpData", "no header");
233 " type = %d run = %d ", GetType(), GetRunNumber());
235 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
237 printf("event = -------- --------\n");
239 if (GetTriggerPattern()) {
240 printf(" trigger = %8.8x %8.8x ",
241 GetTriggerPattern()[1], GetTriggerPattern()[0]);
243 printf(" trigger = -------- -------- ");
245 if (GetDetectorPattern()) {
246 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
248 printf("detector = --------\n");
250 if (GetAttributes()) {
251 printf(" attributes = %8.8x %8.8x %8.8x ",
252 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
254 printf(" attributes = -------- -------- -------- ");
256 printf("GDC = %d\n", GetGDCId());
260 printf("-------------------------------------------------------------------------------\n");
261 printf("LDC = %d\n", GetLDCId());
263 printf("equipment:\n"
264 " size = %d type = %d id = %d\n",
265 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
266 if (GetEquipmentAttributes()) {
267 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
268 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
270 printf(" attributes = -------- -------- -------- ");
272 printf("element size = %d\n", GetEquipmentElementSize());
274 printf("mini header:\n"
275 " size = %d detector = %d DDL = %d\n"
276 " version = %d compression = %d\n",
277 GetDataSize(), GetDetectorID(), GetDDLID(),
278 GetVersion(), IsCompressed());
281 if (limit == 0) continue;
283 Int_t size = GetDataSize();
285 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
291 for (Int_t n = 0; n < size; n++) {
292 if (!ReadNextChar(byte)) {
293 Error("DumpData", "couldn't read byte number %d\n", n);
297 printf("%8.8x %s\n", n-pos, line);
298 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
301 if ((limit > 0) && (n/max == limit)) {
302 Int_t nContinue = ((size-1)/max+1-limit) * max;
304 printf(" [skipping %d bytes]\n", nContinue-n);
310 Int_t offset = pos/4;
311 if ((byte > 0x20) && (byte < 0x7f)) {
312 line[pos+offset] = byte;
314 line[pos+offset] = '.';
317 sprintf(hex, "%2.2x", byte);
318 line[max+max/4+3+2*pos+offset] = hex[0];
319 line[max+max/4+4+2*pos+offset] = hex[1];
323 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
326 } while (ReadHeader());