]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReader.cxx
bugfix
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
index 88a57cb5cd2de1ec09155e1d2bcf0de5641a8e31..1cdf94c39c607668d22f6688b91d6aaef2f494f4 100644 (file)
@@ -40,6 +40,7 @@
 #include <TPluginManager.h>
 #include <TROOT.h>
 #include <TInterpreter.h>
+#include <TSystem.h>
 
 #include <Riostream.h>
 #include "AliRawReader.h"
@@ -197,8 +198,8 @@ AliRawReader* AliRawReader::Create(const char *uri)
   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();
@@ -218,19 +219,39 @@ AliRawReader* AliRawReader::Create(const char *uri)
       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()));
+      fields->Delete();
+      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);
     }
   }
 
@@ -453,6 +474,8 @@ Bool_t AliRawReader::IsEventSelected() const
        expr.ReplaceAll(Form("[%d]",itrigger),"0");
       }
     }
+    // Possibility to introduce downscaling
+    expr.ReplaceAll("%",Form("&& !%d %%",GetEventIndex()));
     Int_t error;
     if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
        (error == TInterpreter::kNoError)) {
@@ -539,10 +562,19 @@ Bool_t AliRawReader::ReadNextChar(UChar_t& data)
   return kTRUE;
 }
 
-Bool_t  AliRawReader::GotoEvent(Int_t /*event*/)
+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
@@ -648,7 +680,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++;
@@ -699,3 +731,25 @@ void AliRawReader::AddErrorLog(AliRawDataErrorLog::ERawDataErrorLevel level,
     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;
+}
+