* provided "as is" without express or implied warranty. *
**************************************************************************/
+/* $Id$ */
+
///////////////////////////////////////////////////////////////////////////////
-//
-// This is the base class for reading raw data and providing
-// information about digits
-//
-// The derived classes, which operate on concrete raw data formats,
-// should implement
-// - ReadHeader to read the next (mini or equipment) header
-// - ReadNextData to read the next raw data block (=1 DDL)
-// - ReadNext to read a given number of bytes
-// - several getters like GetType
-//
-// Sequential access to the raw data is provided by the methods
-// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
-//
-// If only data from a specific detector (and a given range of DDL numbers)
-// should be read, this can be achieved by the Select method.
-// Several getter provide information about the current event and the
-// current type of raw data.
-//
+///
+/// This is the base class for reading raw data.
+///
+/// The derived classes, which operate on concrete raw data formats,
+/// should implement
+/// - ReadHeader to read the next (data/equipment) header
+/// - ReadNextData to read the next raw data block (=1 DDL)
+/// - ReadNext to read a given number of bytes
+/// - several getters like GetType
+///
+/// Sequential access to the raw data is provided by the methods
+/// ReadHeader, ReadNextData, ReadNextInt, ReadNextShort, ReadNextChar
+///
+/// If only data from a specific detector (and a given range of DDL numbers)
+/// should be read, this can be achieved by the Select method.
+/// Several getters provide information about the current event and the
+/// current type of raw data.
+///
///////////////////////////////////////////////////////////////////////////////
+#include <Riostream.h>
#include "AliRawReader.h"
-
+#include "AliDAQ.h"
+#include "AliLog.h"
ClassImp(AliRawReader)
AliRawReader::AliRawReader() :
- fMiniHeader(NULL),
+ fEquipmentIdsIn(NULL),
+ fEquipmentIdsOut(NULL),
+ fRequireHeader(kTRUE),
+ fHeader(NULL),
fCount(0),
- fSelectDetectorID(-1),
- fSelectMinDDLID(-1),
- fSelectMaxDDLID(-1),
fSelectEquipmentType(-1),
fSelectMinEquipmentId(-1),
fSelectMaxEquipmentId(-1),
- fErrorCode(0)
+ fSkipInvalid(kFALSE),
+ fSelectEventType(-1),
+ fErrorCode(0),
+ fEventNumber(-1),
+ fErrorLogs("AliRawDataErrorLog",100),
+ fHeaderSwapped(NULL)
{
// default constructor: initialize data members
+// Allocate the swapped header in case of Mac
+#ifndef R__BYTESWAP
+ fHeaderSwapped=new AliRawDataHeader();
+#endif
+}
+Bool_t AliRawReader::LoadEquipmentIdsMap(const char *fileName)
+{
+ // Open the mapping file
+ // and load the mapping data
+ ifstream input(fileName);
+ if (input.is_open()) {
+ Warning("AliRawReader","Equipment ID mapping file is found !");
+ const Int_t kMaxDDL = 256;
+ fEquipmentIdsIn = new TArrayI(kMaxDDL);
+ fEquipmentIdsOut = new TArrayI(kMaxDDL);
+ Int_t equipIn, equipOut;
+ Int_t nIds = 0;
+ while (input >> equipIn >> equipOut) {
+ if (nIds >= kMaxDDL) {
+ Error("AliRawReader","Too many equipment Id mappings found ! Truncating the list !");
+ break;
+ }
+ fEquipmentIdsIn->AddAt(equipIn,nIds);
+ fEquipmentIdsOut->AddAt(equipOut,nIds);
+ nIds++;
+ }
+ fEquipmentIdsIn->Set(nIds);
+ fEquipmentIdsOut->Set(nIds);
+ input.close();
+ return kTRUE;
+ }
+ else {
+ Error("AliRawReader","equipment id map file is not found ! Skipping the mapping !");
+ return kFALSE;
+ }
}
AliRawReader::AliRawReader(const AliRawReader& rawReader) :
TObject(rawReader),
- fMiniHeader(rawReader.fMiniHeader),
+ fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
+ fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
+ fRequireHeader(rawReader.fRequireHeader),
+ fHeader(rawReader.fHeader),
fCount(rawReader.fCount),
- fSelectDetectorID(rawReader.fSelectDetectorID),
- fSelectMinDDLID(rawReader.fSelectMinDDLID),
- fSelectMaxDDLID(rawReader.fSelectMaxDDLID),
fSelectEquipmentType(rawReader.fSelectEquipmentType),
fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
- fErrorCode(0)
+ fSkipInvalid(rawReader.fSkipInvalid),
+ fSelectEventType(rawReader.fSelectEventType),
+ fErrorCode(0),
+ fEventNumber(-1),
+ fErrorLogs("AliRawDataErrorLog",100),
+ fHeaderSwapped(NULL)
{
// copy constructor
-
+// Allocate the swapped header in case of Mac
+#ifndef R__BYTESWAP
+ fHeaderSwapped=new AliRawDataHeader(*rawReader.fHeaderSwapped);
+#endif
}
AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
{
// assignment operator
+ fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
+ fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
- fMiniHeader = rawReader.fMiniHeader;
+ fHeader = rawReader.fHeader;
fCount = rawReader.fCount;
- fSelectDetectorID = rawReader.fSelectDetectorID;
- fSelectMinDDLID = rawReader.fSelectMinDDLID;
- fSelectMaxDDLID = rawReader.fSelectMaxDDLID;
+ fSelectEquipmentType = rawReader.fSelectEquipmentType;
+ fSelectMinEquipmentId = rawReader.fSelectMinEquipmentId;
+ fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
+ fSkipInvalid = rawReader.fSkipInvalid;
+ fSelectEventType = rawReader.fSelectEventType;
fErrorCode = rawReader.fErrorCode;
+ fEventNumber = rawReader.fEventNumber;
+ fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
+
return *this;
}
+AliRawReader::~AliRawReader()
+{
+ // destructor
+ // delete the mapping arrays if
+ // initialized
+ if (fEquipmentIdsIn) delete fEquipmentIdsIn;
+ if (fEquipmentIdsOut) delete fEquipmentIdsOut;
+ fErrorLogs.Delete();
+ if (fHeaderSwapped) delete fHeaderSwapped;
+}
+
+Int_t AliRawReader::GetMappedEquipmentId() const
+{
+ if (!fEquipmentIdsIn || !fEquipmentIdsOut) {
+ Error("AliRawReader","equipment Ids mapping is not initialized !");
+ return GetEquipmentId();
+ }
+ Int_t equipmentId = GetEquipmentId();
+ for(Int_t iId = 0; iId < fEquipmentIdsIn->GetSize(); iId++) {
+ if (equipmentId == fEquipmentIdsIn->At(iId)) {
+ equipmentId = fEquipmentIdsOut->At(iId);
+ break;
+ }
+ }
+ return equipmentId;
+}
+
+Int_t AliRawReader::GetDetectorID() const
+{
+ // Get the detector ID
+ // The list of detector IDs
+ // can be found in AliDAQ.h
+ Int_t equipmentId;
+ if (fEquipmentIdsIn && fEquipmentIdsIn)
+ equipmentId = GetMappedEquipmentId();
+ else
+ equipmentId = GetEquipmentId();
+
+ if (equipmentId >= 0) {
+ Int_t ddlIndex;
+ return AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
+ }
+ else
+ return -1;
+}
+
+Int_t AliRawReader::GetDDLID() const
+{
+ // Get the DDL ID (within one sub-detector)
+ // The list of detector IDs
+ // can be found in AliDAQ.h
+ Int_t equipmentId;
+ if (fEquipmentIdsIn && fEquipmentIdsIn)
+ equipmentId = GetMappedEquipmentId();
+ else
+ equipmentId = GetEquipmentId();
+
+ if (equipmentId >= 0) {
+ Int_t ddlIndex;
+ AliDAQ::DetectorIDFromDdlID(equipmentId,ddlIndex);
+ return ddlIndex;
+ }
+ else
+ return -1;
+}
+
+void AliRawReader::Select(const char *detectorName, Int_t minDDLID, Int_t maxDDLID)
+{
+// read only data of the detector with the given name and in the given
+// range of DDLs (minDDLID <= DDLID <= maxDDLID).
+// no selection is applied if a value < 0 is used.
+ Int_t detectorID = AliDAQ::DetectorID(detectorName);
+ if(detectorID >= 0)
+ Select(detectorID,minDDLID,maxDDLID);
+}
void AliRawReader::Select(Int_t detectorID, Int_t minDDLID, Int_t maxDDLID)
{
// range of DDLs (minDDLID <= DDLID <= maxDDLID).
// no selection is applied if a value < 0 is used.
- fSelectDetectorID = detectorID;
- fSelectMinDDLID = minDDLID;
- fSelectMaxDDLID = maxDDLID;
+ fSelectEquipmentType = -1;
+
+ if (minDDLID < 0)
+ fSelectMinEquipmentId = AliDAQ::DdlIDOffset(detectorID);
+ else
+ fSelectMinEquipmentId = AliDAQ::DdlID(detectorID,minDDLID);
+
+ if (maxDDLID < 0)
+ fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,AliDAQ::NumberOfDdls(detectorID)-1);
+ else
+ fSelectMaxEquipmentId = AliDAQ::DdlID(detectorID,maxDDLID);
}
void AliRawReader::SelectEquipment(Int_t equipmentType,
fSelectMaxEquipmentId = maxEquipmentId;
}
+void AliRawReader::SelectEvents(Int_t type)
+{
+// read only events with the given type.
+// no selection is applied if a value < 0 is used.
+
+ fSelectEventType = type;
+}
+
Bool_t AliRawReader::IsSelected() const
{
// apply the selection (if any)
- if (fSelectDetectorID >= 0) {
- if (!fMiniHeader) return kFALSE;
- if (fMiniHeader->fDetectorID != fSelectDetectorID) return kFALSE;
- if ((fSelectMinDDLID >= 0) && (fMiniHeader->fDDLID < fSelectMinDDLID))
- return kFALSE;
- if ((fSelectMaxDDLID >= 0) && (fMiniHeader->fDDLID > fSelectMaxDDLID))
- return kFALSE;
- }
+ if (fSkipInvalid && !IsValid()) return kFALSE;
- if (fSelectEquipmentType >= 0) {
+ if (fSelectEquipmentType >= 0)
if (GetEquipmentType() != fSelectEquipmentType) return kFALSE;
- if ((fSelectMinEquipmentId >= 0) &&
- (GetEquipmentId() < fSelectMinEquipmentId))
- return kFALSE;
- if ((fSelectMaxEquipmentId >= 0) &&
- (GetEquipmentId() > fSelectMaxEquipmentId))
- return kFALSE;
- }
+
+ Int_t equipmentId;
+ if (fEquipmentIdsIn && fEquipmentIdsIn)
+ equipmentId = GetMappedEquipmentId();
+ else
+ equipmentId = GetEquipmentId();
+
+ if ((fSelectMinEquipmentId >= 0) &&
+ (equipmentId < fSelectMinEquipmentId))
+ return kFALSE;
+ if ((fSelectMaxEquipmentId >= 0) &&
+ (equipmentId > fSelectMaxEquipmentId))
+ return kFALSE;
return kTRUE;
}
-
-Bool_t AliRawReader::CheckMiniHeader(AliMiniHeader* miniHeader) const
+Bool_t AliRawReader::IsEventSelected() const
{
-// check the magic number of the mini header
+// apply the event selection (if any)
- if (!miniHeader) miniHeader = fMiniHeader;
- if (!miniHeader) return kFALSE;
- UInt_t magicWord = miniHeader->fMagicWord[2]*65536 +
- miniHeader->fMagicWord[1]*256 + miniHeader->fMagicWord[0];
- if (magicWord != AliMiniHeader::kMagicWord) {
- return kFALSE;
+ if (fSelectEventType >= 0) {
+ if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
}
+
return kTRUE;
}
+
Bool_t AliRawReader::ReadNextInt(UInt_t& data)
{
// reads the next 4 bytes at the current position
}
printf("element size = %d\n", GetEquipmentElementSize());
- printf("mini header:\n"
- " size = %d detector = %d DDL = %d\n"
- " version = %d compression = %d\n",
- GetDataSize(), GetDetectorID(), GetDDLID(),
- GetVersion(), IsCompressed());
+ printf("data header:\n"
+ " size = %d version = %d valid = %d compression = %d\n",
+ GetDataSize(), GetVersion(), IsValid(), IsCompressed());
printf("\n");
if (limit == 0) continue;
} while (ReadHeader());
}
+
+void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
+ Int_t code,
+ const char *message)
+{
+ // Add a raw data error message to the list
+ // of raw-data decoding errors
+ if (fEventNumber < 0) {
+ AliError("No events have read so far! Impossible to add a raw data error log!");
+ return;
+ }
+ Int_t ddlId = GetDDLID();
+ if (ddlId < 0) {
+ AliError("No ddl raw data have been read so far! Impossible to add a raw data error log!");
+ return;
+ }
+
+ Int_t prevEventNumber = -1;
+ Int_t prevDdlId = -1;
+ Int_t prevErrorCode = -1;
+ AliRawDataErrorLog *prevLog = (AliRawDataErrorLog *)fErrorLogs.Last();
+ if (prevLog) {
+ prevEventNumber = prevLog->GetEventNumber();
+ prevDdlId = prevLog->GetDdlID();
+ prevErrorCode = prevLog->GetErrorCode();
+ }
+
+ if ((prevEventNumber != fEventNumber) ||
+ (prevDdlId != ddlId) ||
+ (prevErrorCode != code)) {
+ new (fErrorLogs[fErrorLogs.GetEntriesFast()])
+ AliRawDataErrorLog(fEventNumber,
+ ddlId,
+ level,
+ code,
+ message);
+ }
+ else
+ if (prevLog) prevLog->AddCount();
+
+}