///
///////////////////////////////////////////////////////////////////////////////
+#include <Riostream.h>
#include "AliRawReader.h"
-
+#include "AliDAQ.h"
+#include "AliLog.h"
ClassImp(AliRawReader)
AliRawReader::AliRawReader() :
+ fEquipmentIdsIn(NULL),
+ fEquipmentIdsOut(NULL),
+ fRequireHeader(kTRUE),
fHeader(NULL),
fCount(0),
fSelectEquipmentType(-1),
fSelectMinEquipmentId(-1),
fSelectMaxEquipmentId(-1),
fSkipInvalid(kFALSE),
- fErrorCode(0)
+ 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),
+ fEquipmentIdsIn(rawReader.fEquipmentIdsIn),
+ fEquipmentIdsOut(rawReader.fEquipmentIdsOut),
+ fRequireHeader(rawReader.fRequireHeader),
fHeader(rawReader.fHeader),
fCount(rawReader.fCount),
fSelectEquipmentType(rawReader.fSelectEquipmentType),
fSelectMinEquipmentId(rawReader.fSelectMinEquipmentId),
fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
fSkipInvalid(rawReader.fSkipInvalid),
- fErrorCode(0)
+ 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;
fHeader = rawReader.fHeader;
fCount = rawReader.fCount;
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.
- fSelectEquipmentType = 0;
- if (minDDLID < 0) minDDLID = 0;
- fSelectMinEquipmentId = (detectorID << 8) + minDDLID;
- if (maxDDLID < 0) maxDDLID = 0xFF;
- fSelectMaxEquipmentId = (detectorID << 8) + 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 (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::IsEventSelected() const
+{
+// apply the event selection (if any)
+
+ if (fSelectEventType >= 0) {
+ if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
}
return kTRUE;
}
+UInt_t AliRawReader::SwapWord(UInt_t x) const
+{
+ // Swap the endianess of the integer value 'x'
+
+ return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) |
+ ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24));
+}
+
+UShort_t AliRawReader::SwapShort(UShort_t x) const
+{
+ // Swap the endianess of the short value 'x'
+
+ return (((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8)) ;
+}
Bool_t AliRawReader::ReadNextInt(UInt_t& data)
{
Error("ReadNextInt", "could not read data!");
return kFALSE;
}
+#ifndef R__BYTESWAP
+ data=SwapWord(data);
+#endif
return kTRUE;
}
Error("ReadNextShort", "could not read data!");
return kFALSE;
}
+#ifndef R__BYTESWAP
+ data=SwapShort(data);
+#endif
return kTRUE;
}
} 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 = GetEquipmentId();
+ 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();
+
+}