]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReader.cxx
-correct order of classes
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
index 09b4f4a7068d65c6813756096046d374ad2b1f24..a6a6d1f555e8b3311723a9cd965da39ce77899a6 100644 (file)
@@ -41,6 +41,8 @@
 #include <TROOT.h>
 #include <TInterpreter.h>
 #include <TSystem.h>
+#include <TPRegexp.h>
+#include <THashList.h>
 
 #include <Riostream.h>
 #include "AliRawReader.h"
@@ -51,6 +53,7 @@
 #include "AliDAQ.h"
 #include "AliLog.h"
 
+using std::ifstream;
 ClassImp(AliRawReader)
 
 
@@ -71,7 +74,8 @@ AliRawReader::AliRawReader() :
   fEventNumber(-1),
   fErrorLogs("AliRawDataErrorLog",100),
   fHeaderSwapped(NULL),
-  fIsValid(kTRUE)
+  fIsValid(kTRUE),
+  fIsTriggerClassLoaded(kFALSE)
 {
 // default constructor: initialize data members
 // Allocate the swapped header in case of Mac
@@ -130,7 +134,8 @@ AliRawReader::AliRawReader(const AliRawReader& rawReader) :
   fEventNumber(-1),
   fErrorLogs("AliRawDataErrorLog",100),
   fHeaderSwapped(NULL),
-  fIsValid(rawReader.fIsValid)
+  fIsValid(rawReader.fIsValid),
+  fIsTriggerClassLoaded(rawReader.fIsTriggerClassLoaded)
 {
 // copy constructor
 // Allocate the swapped header in case of Mac
@@ -142,6 +147,7 @@ AliRawReader::AliRawReader(const AliRawReader& rawReader) :
 AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
 {
 // assignment operator
+  if(&rawReader == this) return *this;
   fEquipmentIdsIn = rawReader.fEquipmentIdsIn;
   fEquipmentIdsOut = rawReader.fEquipmentIdsOut;
 
@@ -162,6 +168,7 @@ AliRawReader& AliRawReader::operator = (const AliRawReader& rawReader)
   fErrorLogs = *((TClonesArray*)rawReader.fErrorLogs.Clone());
 
   fIsValid = rawReader.fIsValid;
+  fIsTriggerClassLoaded = rawReader.fIsTriggerClassLoaded;
 
   return *this;
 }
@@ -239,7 +246,7 @@ AliRawReader* AliRawReader::Create(const char *uri)
     }
     else {
       AliErrorClass(Form("Invalid syntax: %s",fileURI.Data()));
-      fields->Delete();
+      delete fields;
       return NULL;
     }
   }
@@ -258,7 +265,6 @@ AliRawReader* AliRawReader::Create(const char *uri)
   if (!rawReader->IsRawReaderValid()) {
     AliErrorClass(Form("Raw-reader is invalid - check the input URI (%s)",fileURI.Data()));
     delete rawReader;
-    fields->Delete();
     delete fields;
     return NULL;
   }
@@ -293,7 +299,6 @@ AliRawReader* AliRawReader::Create(const char *uri)
     rawReader->SelectEvents(eventType,triggerMask,triggerExpr.Data());
   }
 
-  fields->Delete();
   delete fields;
 
   return rawReader;
@@ -420,7 +425,66 @@ void AliRawReader::LoadTriggerClass(const char* name, Int_t index)
 
   if (fSelectTriggerExpr.IsNull()) return;
 
-  fSelectTriggerExpr.ReplaceAll(name,Form("[%d]",index));
+  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
@@ -463,11 +527,11 @@ Bool_t AliRawReader::IsEventSelected() const
     if ((GetClassMask() & fSelectTriggerMask) != fSelectTriggerMask) return kFALSE;
   }
 
-  if (!fSelectTriggerExpr.IsNull()) {
+  if (  fIsTriggerClassLoaded && !fSelectTriggerExpr.IsNull()) {
     TString expr(fSelectTriggerExpr);
     ULong64_t mask = GetClassMask();
     for(Int_t itrigger = 0; itrigger < 50; itrigger++) {
-      if (mask & (1 << itrigger)) {
+      if (mask & ((ULong64_t)1 << itrigger)) {
        expr.ReplaceAll(Form("[%d]",itrigger),"1");
       }
       else {
@@ -475,12 +539,13 @@ Bool_t AliRawReader::IsEventSelected() const
       }
     }
     // Possibility to introduce downscaling
-    expr.ReplaceAll("%",Form("&& !%d %%",GetEventIndex()));
+    TPRegexp("(%\\s*\\d+)").Substitute(expr,Form("&& !(%d$1)",GetEventIndex()),"g");
     Int_t error;
-    if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
-       (error == TInterpreter::kNoError)) {
+    Bool_t result = gROOT->ProcessLineFast(expr.Data(),&error);
+    if ( error == TInterpreter::kNoError)
+      return result;
+    else
       return kFALSE;
-    }
   }
 
   return kTRUE;
@@ -680,7 +745,7 @@ void AliRawReader::DumpData(Int_t limit)
        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++;