]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReader.cxx
New AliRawReader factory method. It uses plugin handler in order to load the raw...
[u/mrichter/AliRoot.git] / RAW / AliRawReader.cxx
index cb626f33526ba1a67f318207ee1b2c9746c64ee3..91195ceea9a8b435b80c6c947bc5a0c9c140671f 100644 (file)
 ///
 ///////////////////////////////////////////////////////////////////////////////
 
+#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 "AliDAQ.h"
 #include "AliLog.h"
 
@@ -157,6 +164,58 @@ AliRawReader::~AliRawReader()
   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;
+  }
+
+  AliRawReader *rawReader = NULL;
+  if (!strURI.BeginsWith("mem://")) {
+    AliInfoClass(Form("Creating raw-reader in order to read raw-data file: %s",strURI.Data()));
+    if (strURI.EndsWith("/")) {
+      rawReader = new AliRawReaderFile(strURI);
+    } else if (strURI.EndsWith(".root")) {
+      rawReader = new AliRawReaderRoot(strURI);
+    } else {
+      rawReader = new AliRawReaderDate(strURI);
+    }
+  }
+  else {
+    strURI.ReplaceAll("mem://","");
+    AliInfoClass(Form("Creating raw-reader in order to read events in shared memory (option=%s)",strURI.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,strURI.Data());
+    }
+    else {
+      return NULL;
+    }
+  }
+
+  return rawReader;
+}
+
 Int_t AliRawReader::GetMappedEquipmentId() const
 {
   if (!fEquipmentIdsIn || !fEquipmentIdsOut) {