]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliMDC.cxx
Possibility to specify event selection criteria within the raw-data input URI. The...
[u/mrichter/AliRoot.git] / RAW / AliMDC.cxx
index 5b5844d0615c3470a6980355e87282a81b1972c4..724c235e63a394c891f70bda83c29e1e2cfd23a8 100644 (file)
@@ -1,4 +1,4 @@
-// @(#)alimdc:$Name$:$Id$
+// @(#)alimdc:$Name:  $:$Id$
 // Author: Fons Rademakers  26/11/99
 // Updated: Dario Favretto  15/04/2003
 
 #include <TSystem.h>
 #include <TROOT.h>
 #include <TStopwatch.h>
+#include <TPluginManager.h>
 
 #include <sys/uio.h>
 #ifdef USE_EB
 #include "libDateEb.h"
 #endif
 
+#include "AliMDC.h"
+
 #include <AliLog.h>
-#include <AliESD.h>
+#include <AliESDEvent.h>
 
 #include "AliRawEvent.h"
 #include "AliRawEventHeaderBase.h"
 #include "AliRawRootdDB.h"
 #include "AliRawNullDB.h"
 #include "AliTagDB.h"
+#include "AliRawEventTag.h"
 #include "AliFilter.h"
 
-#include "AliMDC.h"
+
 
 ClassImp(AliMDC)
 
@@ -82,20 +86,25 @@ const char* const AliMDC::fgkFilterName[kNFilters] = {"AliHoughFilter"};
 
 //______________________________________________________________________________
 AliMDC::AliMDC(Int_t compress, Bool_t deleteFiles, EFilterMode filterMode, 
-              Double_t maxSizeTagDB, const char* fileNameTagDB) :
+              Double_t maxSizeTagDB, const char* fileNameTagDB,
+              const char *guidFileFolder,
+              Int_t basketsize) :
   fEvent(new AliRawEvent),
   fESD(NULL),
   fStats(NULL),
   fRawDB(NULL),
   fTagDB(NULL),
+  fEventTag(new AliRawEventTag),
   fCompress(compress),
+  fBasketSize(basketsize),
   fDeleteFiles(deleteFiles),
   fFilterMode(filterMode),
   fFilters(),
   fStop(kFALSE),
   fIsTagDBCreated(kFALSE),
   fMaxSizeTagDB(maxSizeTagDB),
-  fFileNameTagDB(fileNameTagDB)
+  fFileNameTagDB(fileNameTagDB),
+  fGuidFileFolder(guidFileFolder)
 {
   // Create MDC processor object.
   // compress is the file compression mode.
@@ -109,24 +118,34 @@ AliMDC::AliMDC(Int_t compress, Bool_t deleteFiles, EFilterMode filterMode,
   // tag DB and then fileNameTagDB is the directory name for the tag DB.
   // Otherwise fileNameTagDB is the file name of the tag DB. If it is NULL
   // no tag DB will be created.
+  // Optional 'guidFileFolder' specifies the folder in which *.guid files
+  // will be stored. In case this option is not given, the *.guid files
+  // will be written to the same folder as the raw-data files.
+
+  // Set the maximum tree size to 19GB
+  // in order to allow big raw data files
+  TTree::SetMaxTreeSize(20000000000LL);
  
+  // This line is needed in case of a stand-alone application w/o
+  // $ROOTSYS/etc/system.rootrc file
+  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
+                                       "*",
+                                       "TStreamerInfo",
+                                       "RIO",
+                                       "TStreamerInfo()");
 
   if (fFilterMode != kFilterOff) {
-    fESD = new AliESD;
+    fESD = new AliESDEvent();
   }
 
-// Tag DB is now created at the point where the header version is
-// already known
-//   if (fileNameTagDB) {
-//     if (maxSizeTagDB > 0) {
-//       fTagDB = new AliTagDB(fEvent->GetHeader(), NULL);
-//       fTagDB->SetMaxSize(maxSizeTagDB);
-//       fTagDB->SetFS(fileNameTagDB);
-//       fTagDB->Create();
-//     } else {
-//       fTagDB = new AliTagDB(fEvent->GetHeader(), fileNameTagDB);
-//     }
-//   }
+  // Create the guid files folder if it does not exist
+  if (!fGuidFileFolder.IsNull()) {
+    gSystem->ResetErrno();
+    gSystem->MakeDirectory(fGuidFileFolder.Data());
+    if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
+      SysError("AliMDC", "mkdir %s", fGuidFileFolder.Data());
+    }
+  }
 
   // install SIGUSR1 handler to allow clean interrupts
   gSystem->AddSignalHandler(new AliMDCInterruptHandler(this));
@@ -160,6 +179,7 @@ AliMDC::~AliMDC()
   delete fStats;
   delete fESD;
   delete fEvent;
+  delete fEventTag;
 }
  
 //______________________________________________________________________________
@@ -170,28 +190,39 @@ Int_t AliMDC::Open(EWriteMode mode, const char* fileName,
 // open a new raw DB file
 
   if (mode == kRFIO)
-    fRawDB = new AliRawRFIODB(fEvent, fESD, fCompress, fileName);
+    fRawDB = new AliRawRFIODB(fEvent, fESD, fCompress, fileName, fBasketSize);
   else if (mode == kROOTD)
-    fRawDB = new AliRawRootdDB(fEvent, fESD, fCompress, fileName);
+    fRawDB = new AliRawRootdDB(fEvent, fESD, fCompress, fileName, fBasketSize);
   else if (mode == kCASTOR)
-    fRawDB = new AliRawCastorDB(fEvent, fESD, fCompress, fileName);
+    fRawDB = new AliRawCastorDB(fEvent, fESD, fCompress, fileName, fBasketSize);
   else if (mode == kDEVNULL)
-    fRawDB = new AliRawNullDB(fEvent, fESD, fCompress, fileName);
+    fRawDB = new AliRawNullDB(fEvent, fESD, fCompress, fileName, fBasketSize);
   else
-    fRawDB = new AliRawDB(fEvent, fESD, fCompress, fileName);
+    fRawDB = new AliRawDB(fEvent, fESD, fCompress, fileName, fBasketSize);
   fRawDB->SetDeleteFiles(fDeleteFiles);
 
+  if (fRawDB->IsZombie()) {
+    delete fRawDB;
+    fRawDB = NULL;
+    return -1;
+  }
+
   if (fileName == NULL) {
     fRawDB->SetMaxSize(maxFileSize);
     fRawDB->SetFS(fs1, fs2);
-    fRawDB->Create();
+    if (!fRawDB->Create()) {
+      delete fRawDB;
+      fRawDB = NULL;
+      return -1;
+    }
   }
 
-  if (fRawDB->IsZombie()) {
+  if (!fRawDB->WriteGuidFile(fGuidFileFolder)) {
     delete fRawDB;
     fRawDB = NULL;
-    return -1;
+    return -2;
   }
+
   Info("Open", "Filling raw DB %s\n", fRawDB->GetDBName());
 
   // Create AliStats object
@@ -209,11 +240,12 @@ Int_t AliMDC::ProcessEvent(void* event, Bool_t isIovecArray)
 // or, if isIovecArray is kTRUE, a pointer to an array of iovecs with one
 // iovec per subevent (used by the event builder).
 // The return value is the number of written bytes or an error code
-  const UInt_t kFileSizeErrorLevel   = 1900000000;
+  const Long64_t kFileSizeErrorLevel   = 19000000000LL;
 
-  UInt_t currentFileSize = GetTotalSize();
+  Long64_t currentFileSize = GetTotalSize();
+  AliDebug(1,Form("current file size is %lld bytes",currentFileSize));
   if(currentFileSize > kFileSizeErrorLevel) {
-    Error("ProcessEvent", "file size (%u) exceeds the limit "
+    Error("ProcessEvent", "file size (%lu) exceeds the limit "
          , currentFileSize);
     return kErrFileSize;
   }
@@ -353,23 +385,29 @@ Int_t AliMDC::ProcessEvent(void* event, Bool_t isIovecArray)
   // Store raw event in tree
   Int_t nBytes = fRawDB->Fill();
 
+  // Fill the event tag object
+  fEventTag->SetHeader(fEvent->GetHeader());
+  fEventTag->SetGUID(fRawDB->GetDB()->GetUUID().AsString());
+  fEventTag->SetEventNumber(fRawDB->GetEvents()-1);
+
   // Create Tag DB here only after the raw data header
   // version was already identified
   if (!fIsTagDBCreated) {
-    if (fFileNameTagDB) {
+    if (!fFileNameTagDB.IsNull()) {
       if (fMaxSizeTagDB > 0) {
-       fTagDB = new AliTagDB(fEvent->GetHeader(), NULL);
+       fTagDB = new AliTagDB(fEventTag, NULL);
        fTagDB->SetMaxSize(fMaxSizeTagDB);
-       fTagDB->SetFS(fFileNameTagDB);
-       fTagDB->Create();
+       fTagDB->SetFS(fFileNameTagDB.Data());
+       if (!fTagDB->Create()) return kErrTagFile;
       } else {
-       fTagDB = new AliTagDB(fEvent->GetHeader(), fFileNameTagDB);
+       fTagDB = new AliTagDB(fEventTag, fFileNameTagDB.Data());
+       if (fTagDB->IsZombie()) return kErrTagFile;
       }
     }
     fIsTagDBCreated = kTRUE;
   }
 
-  // Store header in tree
+  // Store event tag in tree
   if (fTagDB) fTagDB->Fill();
 
   // Make top event object ready for next event data
@@ -384,7 +422,7 @@ Int_t AliMDC::ProcessEvent(void* event, Bool_t isIovecArray)
 }
 
 //______________________________________________________________________________
-Int_t AliMDC::GetTotalSize()
+Long64_t AliMDC::GetTotalSize()
 {
 // return the total current raw DB file size
 
@@ -394,14 +432,14 @@ Int_t AliMDC::GetTotalSize()
 }
 
 //______________________________________________________________________________
-Int_t AliMDC::Close()
+Long64_t AliMDC::Close()
 {
 // close the current raw DB file
 
   if (!fRawDB) return -1;
 
   fRawDB->WriteStats(fStats);
-  Int_t filesize = fRawDB->Close();
+  Long64_t filesize = fRawDB->Close();
   delete fRawDB;
   fRawDB = NULL;
   delete fStats;
@@ -409,6 +447,17 @@ Int_t AliMDC::Close()
   return filesize;
 }
 
+//______________________________________________________________________________
+Long64_t AliMDC::AutoSave()
+{
+  // Auto-save the raw-data
+  // and esd (if any) trees
+
+  if (!fRawDB) return -1;
+
+  return fRawDB->AutoSave();
+}
+
 //______________________________________________________________________________
 Int_t AliMDC::Run(const char* inputFile, Bool_t loop,
                  EWriteMode mode, Double_t maxFileSize, 
@@ -537,7 +586,7 @@ Int_t AliMDC::Run(const char* inputFile, Bool_t loop,
        eventSize = 2 * hdr->GetEventSize();
        event = new char[eventSize];
       }
-      memcpy(event, hdr->HeaderBaseBegin(), hdr->HeaderBaseSize());
+      memcpy(event, header.HeaderBaseBegin(), header.HeaderBaseSize());
       memcpy(event+hdr->HeaderBaseSize(), hdr->HeaderBegin(), hdr->HeaderSize());
       if (hdr->GetExtendedDataSize() != 0)
        memcpy(event+hdr->HeaderBaseSize()+hdr->HeaderSize(),