#include <TClass.h>
#include <TPluginManager.h>
#include <TROOT.h>
+#include <TInterpreter.h>
+#include <TSystem.h>
+#include <TPRegexp.h>
+#include <THashList.h>
#include <Riostream.h>
#include "AliRawReader.h"
#include "AliDAQ.h"
#include "AliLog.h"
+using std::ifstream;
ClassImp(AliRawReader)
fSkipInvalid(kFALSE),
fSelectEventType(-1),
fSelectTriggerMask(0),
+ fSelectTriggerExpr(),
fErrorCode(0),
fEventNumber(-1),
fErrorLogs("AliRawDataErrorLog",100),
- fHeaderSwapped(NULL)
+ fHeaderSwapped(NULL),
+ fIsValid(kTRUE),
+ fIsTriggerClassLoaded(kFALSE)
{
// default constructor: initialize data members
// Allocate the swapped header in case of Mac
fSkipInvalid(rawReader.fSkipInvalid),
fSelectEventType(rawReader.fSelectEventType),
fSelectTriggerMask(rawReader.fSelectTriggerMask),
+ fSelectTriggerExpr(rawReader.fSelectTriggerExpr),
fErrorCode(0),
fEventNumber(-1),
fErrorLogs("AliRawDataErrorLog",100),
- fHeaderSwapped(NULL)
+ fHeaderSwapped(NULL),
+ fIsValid(rawReader.fIsValid),
+ fIsTriggerClassLoaded(rawReader.fIsTriggerClassLoaded)
{
// copy constructor
// Allocate the swapped header in case of Mac
AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
{
// assignment operator
+ if(&rawReader == this) return *this;
fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
fSkipInvalid = rawReader.fSkipInvalid;
fSelectEventType = rawReader.fSelectEventType;
fSelectTriggerMask = rawReader.fSelectTriggerMask;
+ fSelectTriggerExpr = rawReader.fSelectTriggerExpr;
fErrorCode = rawReader.fErrorCode;
fEventNumber = rawReader.fEventNumber;
fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
+ fIsValid = rawReader.fIsValid;
+ fIsTriggerClassLoaded = rawReader.fIsTriggerClassLoaded;
+
return *this;
}
TString &fileURI = ((TObjString*)fields->At(0))->String();
AliRawReader *rawReader = NULL;
- if (fileURI.BeginsWith("mem://")) {
- fileURI.ReplaceAll("mem://","");
+ if (fileURI.BeginsWith("mem://") || fileURI.BeginsWith("^")) {
+ 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();
return NULL;
}
}
+ else if (fileURI.BeginsWith("amore://")) {
+ // A special raw-data URL used in case
+ // the raw-data reading is steered from
+ // ouside, i.e. from AMORE
+ fileURI.ReplaceAll("amore://","");
+ AliInfoClass("Creating raw-reader in order to read events sent by AMORE");
+ rawReader = new AliRawReaderDate((void *)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 if (fileURI.BeginsWith("raw://run")) {
+ fileURI.ReplaceAll("raw://run","");
+ if (fileURI.IsDigit()) {
+ rawReader = new AliRawReaderChain(fileURI.Atoi());
+ }
+ else {
+ AliErrorClass(Form("Invalid syntax: %s",fileURI.Data()));
+ delete fields;
+ return NULL;
+ }
+ }
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);
+ TString filename(gSystem->ExpandPathName(fileURI.Data()));
+ if (filename.EndsWith("/")) {
+ rawReader = new AliRawReaderFile(filename);
+ } else if (filename.EndsWith(".root")) {
+ rawReader = new AliRawReaderRoot(filename);
} else {
- rawReader = new AliRawReaderDate(fileURI);
+ rawReader = new AliRawReaderDate(filename);
}
}
+ if (!rawReader->IsRawReaderValid()) {
+ AliErrorClass(Form("Raw-reader is invalid - check the input URI (%s)",fileURI.Data()));
+ delete rawReader;
+ delete fields;
+ return NULL;
+ }
+
// Now apply event selection criteria (if specified)
if (fields->GetEntries() > 1) {
Int_t eventType = -1;
ULong64_t triggerMask = 0;
+ TString triggerExpr;
for(Int_t i = 1; i < fields->GetEntries(); i++) {
if (!fields->At(i)) continue;
TString &option = ((TObjString*)fields->At(i))->String();
}
if (option.BeginsWith("Trigger=",TString::kIgnoreCase)) {
option.ReplaceAll("Trigger=","");
- triggerMask = option.Atoll();
+ if (option.IsDigit()) {
+ triggerMask = option.Atoll();
+ }
+ else {
+ triggerExpr = option.Data();
+ }
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);
+ AliInfoClass(Form("Event selection criteria specified: eventype=%d trigger mask=%llx trigger expression=%s",
+ eventType,triggerMask,triggerExpr.Data()));
+ rawReader->SelectEvents(eventType,triggerMask,triggerExpr.Data());
}
- fields->Delete();
delete fields;
return rawReader;
fSelectMaxEquipmentId = maxEquipmentId;
}
-void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask)
+void AliRawReader::SelectEvents(Int_t type, ULong64_t triggerMask,
+ const char *triggerExpr)
{
// read only events with the given type and optionally
// trigger mask.
-// no selection is applied if a value < 0 is used.
+// no selection is applied if value = 0 is used.
+// Trigger selection can be done via string (triggerExpr)
+// which defines the trigger logic to be used. It works only
+// after LoadTriggerClass() method is called for all involved
+// trigger classes.
fSelectEventType = type;
fSelectTriggerMask = triggerMask;
+ if (triggerExpr) fSelectTriggerExpr = triggerExpr;
+}
+
+void AliRawReader::LoadTriggerClass(const char* name, Int_t index)
+{
+ // Loads the list of trigger classes defined.
+ // Used in conjunction with IsEventSelected in the
+ // case when the trigger selection is given by
+ // fSelectedTriggerExpr
+
+ if (fSelectTriggerExpr.IsNull()) return;
+
+ fIsTriggerClassLoaded = kTRUE;
+
+ if (index >= 0)
+ fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index));
+ else
+ fSelectTriggerExpr.ReplaceAll(name,"0");
+}
+
+void AliRawReader::LoadTriggerAlias(const THashList *lst)
+{
+ // Loads the list of trigger aliases defined.
+ // Replaces the alias by the OR of the triggers included in it.
+ // The subsiquent call to LoadTriggerClass is needed
+ // to obtain the final expression in
+ // fSelectedTriggerExpr
+
+ if (fSelectTriggerExpr.IsNull()) return;
+
+ // Make a THashList alias -> trigger classes
+
+ THashList alias2trig;
+ TIter iter(lst);
+ TNamed *nmd = 0;
+
+ // Loop on triggers
+
+ while((nmd = dynamic_cast<TNamed*>(iter.Next()))){
+
+ TString aliasList(nmd->GetTitle());
+ TObjArray* arrAliases = aliasList.Tokenize(',');
+ Int_t nAliases = arrAliases->GetEntries();
+
+ // Loop on aliases for the current trigger
+ for(Int_t i=0; i<nAliases; i++){
+
+ TObjString *alias = (TObjString*) arrAliases->At(i);
+
+ // Find the current alias in the hash list. If it is not there, add TNamed entry
+ TNamed * inlist = (TNamed*)alias2trig.FindObject((alias->GetString()).Data());
+ if (!inlist) {
+ inlist = new TNamed((alias->GetString()).Data(),nmd->GetName());
+ alias2trig.Add(inlist);
+ }
+ else {
+ TString tt(inlist->GetTitle());
+ tt += " || ";
+ tt += nmd->GetName();
+ inlist->SetTitle(tt.Data());
+ }
+ }
+
+ delete arrAliases;
+ }
+ alias2trig.Sort(kSortDescending);
+
+ // Replace all the aliases by the OR of triggers
+ TIter iter1(&alias2trig);
+ while((nmd = dynamic_cast<TNamed*>(iter1.Next()))){
+ fSelectTriggerExpr.ReplaceAll(nmd->GetName(),nmd->GetTitle());
+ }
}
Bool_t AliRawReader::IsSelected() const
if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) return kFALSE;
}
+ if ( fIsTriggerClassLoaded && !fSelectTriggerExpr.IsNull()) {
+ TString expr(fSelectTriggerExpr);
+ ULong64_t mask = GetClassMask();
+ for(Int_t itrigger = 0; itrigger < 50; itrigger++) {
+ if (mask & ((ULong64_t)1 << itrigger)) {
+ expr.ReplaceAll(Form("[%d]",itrigger),"1");
+ }
+ else {
+ expr.ReplaceAll(Form("[%d]",itrigger),"0");
+ }
+ }
+ // Possibility to introduce downscaling
+ TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g");
+ Int_t error;
+ Bool_t result = gROOT->ProcessLineFast(expr.Data(),&error);
+ if ( error == TInterpreter::kNoError)
+ return result;
+ else
+ return kFALSE;
+ }
+
return kTRUE;
}
Bool_t AliRawReader::GotoEvent(Int_t event)
{
- Error("GotoEvent","Method not implemented! Nothing done");
- return kFALSE;
+ // Random access to certain
+ // event index. Could be very slow
+ // for some non-root raw-readers.
+ // So it should be reimplemented there.
+ if (event < fEventNumber) RewindEvents();
+
+ while (fEventNumber < event) {
+ if (!NextEvent()) return kFALSE;
+ }
+
+ return kTRUE;
}
Int_t AliRawReader::CheckData() const
line[pos+offset] = '.';
}
char hex[3];
- sprintf(hex, "%2.2x", byte);
+ snprintf(hex, 3, "%2.2x", byte);
line[max+max/4+3+2*pos+offset] = hex[0];
line[max+max/4+4+2*pos+offset] = hex[1];
pos++;
if (prevLog) prevLog->AddCount();
}
+
+Bool_t AliRawReader::GotoEventWithID(Int_t event,
+ UInt_t period,
+ UInt_t orbitID,
+ UShort_t bcID)
+{
+ // Go to certain event number by
+ // checking the event ID.
+ // Useful in case event-selection
+ // is applied and the 'event' is
+ // relative
+ if (!GotoEvent(event)) return kFALSE;
+
+ while (GetBCID() != period ||
+ GetOrbitID() != orbitID ||
+ GetPeriod() != bcID) {
+ if (!NextEvent()) return kFALSE;
+ }
+
+ return kTRUE;
+}
+