///
///////////////////////////////////////////////////////////////////////////////
+#include <TClass.h>
+#include <TPluginManager.h>
+#include <TROOT.h>
+
#include <Riostream.h>
#include "AliRawReader.h"
+#include "AliRawReaderFile.h"
+#include "AliRawReaderDate.h"
+#include "AliRawReaderRoot.h"
+#include "AliRawReaderChain.h"
#include "AliDAQ.h"
#include "AliLog.h"
fSelectMaxEquipmentId(-1),
fSkipInvalid(kFALSE),
fSelectEventType(-1),
+ fSelectTriggerMask(0),
fErrorCode(0),
fEventNumber(-1),
- fErrorLogs("AliRawDataErrorLog",100)
+ 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)
fSelectMaxEquipmentId(rawReader.fSelectMaxEquipmentId),
fSkipInvalid(rawReader.fSkipInvalid),
fSelectEventType(rawReader.fSelectEventType),
+ fSelectTriggerMask(rawReader.fSelectTriggerMask),
fErrorCode(0),
fEventNumber(-1),
- fErrorLogs("AliRawDataErrorLog",100)
+ 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)
fSelectMaxEquipmentId = rawReader.fSelectMaxEquipmentId;
fSkipInvalid = rawReader.fSkipInvalid;
fSelectEventType = rawReader.fSelectEventType;
+ fSelectTriggerMask = rawReader.fSelectTriggerMask;
fErrorCode = rawReader.fErrorCode;
// initialized
if (fEquipmentIdsIn) delete fEquipmentIdsIn;
if (fEquipmentIdsOut) delete fEquipmentIdsOut;
+ fErrorLogs.Delete();
+ if (fHeaderSwapped) delete fHeaderSwapped;
+}
+
+AliRawReader* AliRawReader::Create(const char *uri)
+{
+ // RawReader's factory
+ // It instantiate corresponding raw-reader implementation class object
+ // depending on the URI provided
+ // Normal URIs point to files, while the URI starting with
+ // 'mem://:' or 'mem://<filename>' will create
+ // AliRawReaderDateOnline object which is supposed to be used
+ // in the online reconstruction
+
+ TString strURI = uri;
+
+ if (strURI.IsNull()) {
+ AliWarningClass("No raw-reader created");
+ return NULL;
+ }
+
+ TObjArray *fields = strURI.Tokenize("?");
+ TString &fileURI = ((TObjString*)fields->At(0))->String();
+
+ AliRawReader *rawReader = NULL;
+ if (fileURI.BeginsWith("mem://")) {
+ fileURI.ReplaceAll("mem://","");
+ AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",fileURI.Data()));
+
+ TPluginManager* pluginManager = gROOT->GetPluginManager();
+ TString rawReaderName = "AliRawReaderDateOnline";
+ TPluginHandler* pluginHandler = pluginManager->FindHandler("AliRawReader", "online");
+ // if not, add a plugin for it
+ if (!pluginHandler) {
+ pluginManager->AddHandler("AliRawReader", "online",
+ "AliRawReaderDateOnline", "RAWDatarecOnline", "AliRawReaderDateOnline(const char*)");
+ pluginHandler = pluginManager->FindHandler("AliRawReader", "online");
+ }
+ if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
+ rawReader = (AliRawReader*)pluginHandler->ExecPlugin(1,fileURI.Data());
+ }
+ else {
+ delete fields;
+ return NULL;
+ }
+ }
+ else if (fileURI.BeginsWith("collection://")) {
+ fileURI.ReplaceAll("collection://","");
+ AliInfoClass(Form("Creating raw-reader in order to read raw-data files collection defined in %s",fileURI.Data()));
+ rawReader = new AliRawReaderChain(fileURI);
+ }
+ else {
+ AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",fileURI.Data()));
+ if (fileURI.EndsWith("/")) {
+ rawReader = new AliRawReaderFile(fileURI);
+ } else if (fileURI.EndsWith(".root")) {
+ rawReader = new AliRawReaderRoot(fileURI);
+ } else {
+ rawReader = new AliRawReaderDate(fileURI);
+ }
+ }
+
+ // Now apply event selection criteria (if specified)
+ if (fields->GetEntries() > 1) {
+ Int_t eventType = -1;
+ ULong64_t triggerMask = 0;
+ for(Int_t i = 1; i < fields->GetEntries(); i++) {
+ if (!fields->At(i)) continue;
+ TString &option = ((TObjString*)fields->At(i))->String();
+ if (option.BeginsWith("EventType=",TString::kIgnoreCase)) {
+ option.ReplaceAll("EventType=","");
+ eventType = option.Atoi();
+ continue;
+ }
+ if (option.BeginsWith("Trigger=",TString::kIgnoreCase)) {
+ option.ReplaceAll("Trigger=","");
+ triggerMask = option.Atoll();
+ continue;
+ }
+ AliWarningClass(Form("Ignoring invalid event selection option: %s",option.Data()));
+ }
+ AliInfoClass(Form("Event selection criteria specified: eventype=%d trigger mask=%llx",
+ eventType,triggerMask));
+ rawReader->SelectEvents(eventType,triggerMask);
+ }
+
+ fields->Delete();
+ delete fields;
+
+ return rawReader;
}
Int_t AliRawReader::GetMappedEquipmentId() const
fSelectMaxEquipmentId = maxEquipmentId;
}
-void AliRawReader::SelectEvents(Int_t type)
+void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask)
{
-// read only events with the given type.
+// read only events with the given type and optionally
+// trigger mask.
// no selection is applied if a value < 0 is used.
fSelectEventType = type;
+ fSelectTriggerMask = triggerMask;
}
Bool_t AliRawReader::IsSelected() const
Bool_t AliRawReader::IsEventSelected() const
{
-// apply the event selection (if any)
+ // apply the event selection (if any)
+ // First check the event type
if (fSelectEventType >= 0) {
if (GetType() != (UInt_t) fSelectEventType) return kFALSE;
}
+ // Then check the trigger pattern and compared it
+ // to the required trigger mask
+ if (fSelectTriggerMask != 0) {
+ if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) 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;
}
return kTRUE;
}
+Bool_t AliRawReader::GotoEvent(Int_t event)
+{
+ Error("GotoEvent","Method not implemented! Nothing done");
+ return kFALSE;
+}
Int_t AliRawReader::CheckData() const
{
} while (ReadHeader());
}
-void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorType type,
+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();
+ 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;
}
- new (fErrorLogs[fErrorLogs.GetEntriesFast()])
- AliRawDataErrorLog(fEventNumber,
- ddlId,
- type,
- message);
+ 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();
+
}