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 <Riostream.h>
40 #include "AliRawReader.h"
44 ClassImp(AliRawReader)
47 AliRawReader::AliRawReader() :
48 fEquipmentIdsIn(NULL),
49 fEquipmentIdsOut(NULL),
50 fRequireHeader(kTRUE),
53 fSelectEquipmentType(-1),
54 fSelectMinEquipmentId(-1),
55 fSelectMaxEquipmentId(-1),
60 fErrorLogs("AliRawDataErrorLog",100)
62 // default constructor: initialize data members
65 Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName)
67 // Open the mapping file
68 // and load the mapping data
69 ifstream input(fileName);
70 if (input.is_open()) {
71 Warning("AliRawReader","Equipment ID mapping file is found !");
72 const Int_t kMaxDDL = 256;
73 fEquipmentIdsIn = new TArrayI(kMaxDDL);
74 fEquipmentIdsOut = new TArrayI(kMaxDDL);
75 Int_t equipIn, equipOut;
77 while (input >> equipIn >> equipOut) {
78 if (nIds >= kMaxDDL) {
79 Error("AliRawReader","Too many equipment Id mappings found ! Truncating the list !");
82 fEquipmentIdsIn->AddAt(equipIn,nIds);
83 fEquipmentIdsOut->AddAt(equipOut,nIds);
86 fEquipmentIdsIn->Set(nIds);
87 fEquipmentIdsOut->Set(nIds);
92 Error("AliRawReader","equipment id map file is not found ! Skipping the mapping !");
97 AliRawReader::AliRawReader(const AliRawReader& rawReader) :
99 fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
100 fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
101 fRequireHeader(rawReader.fRequireHeader),
102 fHeader(rawReader.fHeader),
103 fCount(rawReader.fCount),
104 fSelectEquipmentType(rawReader.fSelectEquipmentType),
105 fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
106 fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
107 fSkipInvalid(rawReader.fSkipInvalid),
108 fSelectEventType(rawReader.fSelectEventType),
111 fErrorLogs("AliRawDataErrorLog",100)
116 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
118 // assignment operator
119 fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
120 fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
122 fHeader = rawReader.fHeader;
123 fCount = rawReader.fCount;
125 fSelectEquipmentType = rawReader.fSelectEquipmentType;
126 fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
127 fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
128 fSkipInvalid = rawReader.fSkipInvalid;
129 fSelectEventType = rawReader.fSelectEventType;
131 fErrorCode = rawReader.fErrorCode;
133 fEventNumber = rawReader.fEventNumber;
134 fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
139 AliRawReader::~AliRawReader()
142 // delete the mapping arrays if
144 if (fEquipmentIdsIn) delete fEquipmentIdsIn;
145 if (fEquipmentIdsOut) delete fEquipmentIdsOut;
149 Int_t AliRawReader::GetMappedEquipmentId() const
151 if (!fEquipmentIdsIn || !fEquipmentIdsOut) {
152 Error("AliRawReader","equipment Ids mapping is not initialized !");
153 return GetEquipmentId();
155 Int_t equipmentId = GetEquipmentId();
156 for(Int_t iId = 0; iId < fEquipmentIdsIn->GetSize(); iId++) {
157 if (equipmentId == fEquipmentIdsIn->At(iId)) {
158 equipmentId = fEquipmentIdsOut->At(iId);
165 Int_t AliRawReader::GetDetectorID() const
167 // Get the detector ID
168 // The list of detector IDs
169 // can be found in AliDAQ.h
171 if (fEquipmentIdsIn && fEquipmentIdsIn)
172 equipmentId = GetMappedEquipmentId();
174 equipmentId = GetEquipmentId();
176 if (equipmentId >= 0) {
178 return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
184 Int_t AliRawReader::GetDDLID() const
186 // Get the DDL ID (within one sub-detector)
187 // The list of detector IDs
188 // can be found in AliDAQ.h
190 if (fEquipmentIdsIn && fEquipmentIdsIn)
191 equipmentId = GetMappedEquipmentId();
193 equipmentId = GetEquipmentId();
195 if (equipmentId >= 0) {
197 AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
204 void AliRawReader::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID)
206 // read only data of the detector with the given name and in the given
207 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
208 // no selection is applied if a value < 0 is used.
209 Int_t detectorID = AliDAQ::DetectorID(detectorName);
211 Select(detectorID,minDDLID,maxDDLID);
214 void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
216 // read only data of the detector with the given ID and in the given
217 // range of DDLs (minDDLID <= DDLID <= maxDDLID).
218 // no selection is applied if a value < 0 is used.
220 fSelectEquipmentType = -1;
223 fSelectMinEquipmentId = AliDAQ::DdlIDOffset(detectorID);
225 fSelectMinEquipmentId = AliDAQ::DdlID(detectorID,minDDLID);
228 fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,AliDAQ::NumberOfDdls(detectorID)-1);
230 fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,maxDDLID);
233 void AliRawReader::SelectEquipment(Int_t equipmentType,
234 Int_t minEquipmentId, Int_t maxEquipmentId)
236 // read only data of the equipment with the given type and in the given
237 // range of IDs (minEquipmentId <= EquipmentId <= maxEquipmentId).
238 // no selection is applied if a value < 0 is used.
240 fSelectEquipmentType = equipmentType;
241 fSelectMinEquipmentId = minEquipmentId;
242 fSelectMaxEquipmentId = maxEquipmentId;
245 void AliRawReader::SelectEvents(Int_t type)
247 // read only events with the given type.
248 // no selection is applied if a value < 0 is used.
250 fSelectEventType = type;
253 Bool_t AliRawReader::IsSelected() const
255 // apply the selection (if any)
257 if (fSkipInvalid && !IsValid()) return kFALSE;
259 if (fSelectEquipmentType >= 0)
260 if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
263 if (fEquipmentIdsIn && fEquipmentIdsIn)
264 equipmentId = GetMappedEquipmentId();
266 equipmentId = GetEquipmentId();
268 if ((fSelectMinEquipmentId >= 0) &&
269 (equipmentId < fSelectMinEquipmentId))
271 if ((fSelectMaxEquipmentId >= 0) &&
272 (equipmentId > fSelectMaxEquipmentId))
278 Bool_t AliRawReader::IsEventSelected() const
280 // apply the event selection (if any)
282 if (fSelectEventType >= 0) {
283 if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
290 Bool_t AliRawReader::ReadNextInt(UInt_t& data)
292 // reads the next 4 bytes at the current position
293 // returns kFALSE if the data could not be read
295 while (fCount == 0) {
296 if (!ReadHeader()) return kFALSE;
298 if (fCount < (Int_t) sizeof(data)) {
300 "too few data left (%d bytes) to read an UInt_t!", fCount);
303 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
304 Error("ReadNextInt", "could not read data!");
310 Bool_t AliRawReader::ReadNextShort(UShort_t& data)
312 // reads the next 2 bytes at the current position
313 // returns kFALSE if the data could not be read
315 while (fCount == 0) {
316 if (!ReadHeader()) return kFALSE;
318 if (fCount < (Int_t) sizeof(data)) {
319 Error("ReadNextShort",
320 "too few data left (%d bytes) to read an UShort_t!", fCount);
323 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
324 Error("ReadNextShort", "could not read data!");
330 Bool_t AliRawReader::ReadNextChar(UChar_t& data)
332 // reads the next 1 byte at the current stream position
333 // returns kFALSE if the data could not be read
335 while (fCount == 0) {
336 if (!ReadHeader()) return kFALSE;
338 if (!ReadNext((UChar_t*) &data, sizeof(data))) {
339 Error("ReadNextChar", "could not read data!");
346 Int_t AliRawReader::CheckData() const
348 // check the consistency of the data
349 // derived classes should overwrite the default method which returns 0 (no err)
355 void AliRawReader::DumpData(Int_t limit)
357 // print the raw data
358 // if limit is not negative, only the first and last "limit" lines of raw data
363 Error("DumpData", "no header");
367 " type = %d run = %d ", GetType(), GetRunNumber());
369 printf("event = %8.8x %8.8x\n", GetEventId()[1], GetEventId()[0]);
371 printf("event = -------- --------\n");
373 if (GetTriggerPattern()) {
374 printf(" trigger = %8.8x %8.8x ",
375 GetTriggerPattern()[1], GetTriggerPattern()[0]);
377 printf(" trigger = -------- -------- ");
379 if (GetDetectorPattern()) {
380 printf("detector = %8.8x\n", GetDetectorPattern()[0]);
382 printf("detector = --------\n");
384 if (GetAttributes()) {
385 printf(" attributes = %8.8x %8.8x %8.8x ",
386 GetAttributes()[2], GetAttributes()[1], GetAttributes()[0]);
388 printf(" attributes = -------- -------- -------- ");
390 printf("GDC = %d\n", GetGDCId());
394 printf("-------------------------------------------------------------------------------\n");
395 printf("LDC = %d\n", GetLDCId());
397 printf("equipment:\n"
398 " size = %d type = %d id = %d\n",
399 GetEquipmentSize(), GetEquipmentType(), GetEquipmentId());
400 if (GetEquipmentAttributes()) {
401 printf(" attributes = %8.8x %8.8x %8.8x ", GetEquipmentAttributes()[2],
402 GetEquipmentAttributes()[1], GetEquipmentAttributes()[0]);
404 printf(" attributes = -------- -------- -------- ");
406 printf("element size = %d\n", GetEquipmentElementSize());
408 printf("data header:\n"
409 " size = %d version = %d valid = %d compression = %d\n",
410 GetDataSize(), GetVersion(), IsValid(), IsCompressed());
413 if (limit == 0) continue;
415 Int_t size = GetDataSize();
417 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
423 for (Int_t n = 0; n < size; n++) {
424 if (!ReadNextChar(byte)) {
425 Error("DumpData", "couldn't read byte number %d\n", n);
429 printf("%8.8x %s\n", n-pos, line);
430 for (Int_t i = 0; i < 70; i++) line[i] = ' ';
433 if ((limit > 0) && (n/max == limit)) {
434 Int_t nContinue = ((size-1)/max+1-limit) * max;
436 printf(" [skipping %d bytes]\n", nContinue-n);
442 Int_t offset = pos/4;
443 if ((byte > 0x20) && (byte < 0x7f)) {
444 line[pos+offset] = byte;
446 line[pos+offset] = '.';
449 sprintf(hex, "%2.2x", byte);
450 line[max+max/4+3+2*pos+offset] = hex[0];
451 line[max+max/4+4+2*pos+offset] = hex[1];
455 if (pos > 0) printf("%8.8x %s\n", size-pos, line);
458 } while (ReadHeader());
461 void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
465 // Add a raw data error message to the list
466 // of raw-data decoding errors
467 if (fEventNumber < 0) {
468 AliError("No events have read so far! Impossible to add a raw data error log!");
471 Int_t ddlId = GetDDLID();
473 AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!");
477 Int_t prevEventNumber = -1;
478 Int_t prevDdlId = -1;
479 Int_t prevErrorCode = -1;
480 AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last();
482 prevEventNumber = prevLog->GetEventNumber();
483 prevDdlId = prevLog->GetDdlID();
484 prevErrorCode = prevLog->GetErrorCode();
487 if ((prevEventNumber != fEventNumber) ||
488 (prevDdlId != ddlId) ||
489 (prevErrorCode != code)) {
490 new (fErrorLogs[fErrorLogs.GetEntriesFast()])
491 AliRawDataErrorLog(fEventNumber,
498 if (prevLog) prevLog->AddCount();