]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawDB.cxx
Put split level for the HLT ESD tree to zero.
[u/mrichter/AliRoot.git] / RAW / AliRawDB.cxx
index 508cd71aa59774457c76c7cf0d93ea2397d4a472..1810a69b595f8ad38477951d1b7c8248a38f9b17 100644 (file)
 #include <errno.h>
 
 #include <TSystem.h>
 #include <errno.h>
 
 #include <TSystem.h>
+#include <TKey.h>
 
 #ifdef ALI_DATE
 #include "event.h"
 #endif
 
 
 #ifdef ALI_DATE
 #include "event.h"
 #endif
 
+#include "AliESD.h"
 #include "AliRawEvent.h"
 #include "AliRawEventHeader.h"
 #include "AliRawEvent.h"
 #include "AliRawEventHeader.h"
-#include "AliMDC.h"
+#include "AliStats.h"
 
 #include "AliRawDB.h"
 
 
 #include "AliRawDB.h"
 
@@ -41,14 +43,23 @@ ClassImp(AliRawDB)
 
 
 //______________________________________________________________________________
 
 
 //______________________________________________________________________________
-AliRawDB::AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
-                   Bool_t create)
+AliRawDB::AliRawDB(AliRawEvent *event,
+                  AliESD *esd, 
+                  Int_t compress,
+                   const char* fileName) :
+  fRawDB(NULL),
+  fTree(NULL),
+  fEvent(event),
+  fESDTree(NULL),
+  fESD(esd),
+  fCompress(compress),
+  fMaxSize(-1),
+  fFS1(""),
+  fFS2(""),
+  fDeleteFiles(kFALSE),
+  fStop(kFALSE)
 {
 {
-   // Create a new raw DB containing at most maxsize bytes.
-
-   fEvent    = event;
-   fMaxSize  = maxsize;
-   fCompress = compress;
+   // Create a new raw DB
 
    // Consistency check with DATE header file
 #ifdef ALI_DATE
 
    // Consistency check with DATE header file
 #ifdef ALI_DATE
@@ -59,8 +70,8 @@ AliRawDB::AliRawDB(AliRawEvent *event, Double_t maxsize, Int_t compress,
    }
 #endif
 
    }
 #endif
 
-   if (create) {
-      if (!Create())
+   if (fileName) {
+      if (!Create(fileName))
          MakeZombie();
    }
 }
          MakeZombie();
    }
 }
@@ -115,7 +126,7 @@ const char *AliRawDB::GetFileName() const
    static TString fname;
    static Bool_t  fstoggle = kFALSE;
 
    static TString fname;
    static Bool_t  fstoggle = kFALSE;
 
-   TString fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0);
+   TString fs = fstoggle ? fFS2 : fFS1;
    TDatime dt;
 
    TString hostname = gSystem->HostName();
    TDatime dt;
 
    TString hostname = gSystem->HostName();
@@ -126,12 +137,11 @@ const char *AliRawDB::GetFileName() const
    if (!FSHasSpace(fs)) {
       while (1) {
          fstoggle = !fstoggle;
    if (!FSHasSpace(fs)) {
       while (1) {
          fstoggle = !fstoggle;
-         fs = fstoggle ? AliMDC::RawDBFS(1) : AliMDC::RawDBFS(0);
+         fs = fstoggle ? fFS2 : fFS1;
          if (FSHasSpace(fs)) break;
          Info("GetFileName", "sleeping 30 seconds before retrying...");
          gSystem->Sleep(30000);   // sleep for 30 seconds
          if (FSHasSpace(fs)) break;
          Info("GetFileName", "sleeping 30 seconds before retrying...");
          gSystem->Sleep(30000);   // sleep for 30 seconds
-         if (AliMDC::Instance() && AliMDC::Instance()->StopLoop())
-            return 0;
+         if (fStop) return 0;
       }
    }
 
       }
    }
 
@@ -147,7 +157,31 @@ const char *AliRawDB::GetFileName() const
 }
 
 //______________________________________________________________________________
 }
 
 //______________________________________________________________________________
-Bool_t AliRawDB::Create()
+void AliRawDB::SetFS(const char* fs1, const char* fs2)
+{
+// set the file system location
+
+  fFS1 = fs1;
+  if (fs1 && !fFS1.Contains(":")) {
+    gSystem->ResetErrno();
+    gSystem->MakeDirectory(fs1);
+    if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
+      SysError("SetFS", "mkdir %s", fs1);
+    }
+  }
+
+  fFS2 = fs2;
+  if (fs2) {
+    gSystem->ResetErrno();
+    gSystem->MakeDirectory(fs2);
+    if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
+      SysError("SetFS", "mkdir %s", fs2);
+    }
+  }
+}
+
+//______________________________________________________________________________
+Bool_t AliRawDB::Create(const char* fileName)
 {
    // Create a new raw DB.
 
 {
    // Create a new raw DB.
 
@@ -157,10 +191,10 @@ Bool_t AliRawDB::Create()
    Int_t retry = 0;
 
 again:
    Int_t retry = 0;
 
 again:
-   if (AliMDC::Instance() && AliMDC::Instance()->StopLoop())
-      return kFALSE;
+   if (fStop) return kFALSE;
 
 
-   const char *fname = GetFileName();
+   const char *fname = fileName;
+   if (!fname) fname = GetFileName();
    if (!fname) {
       Error("Create", "error getting raw DB file name");
       return kFALSE;
    if (!fname) {
       Error("Create", "error getting raw DB file name");
       return kFALSE;
@@ -169,7 +203,7 @@ again:
    retry++;
 
    fRawDB = TFile::Open(fname, GetOpenOption(),
    retry++;
 
    fRawDB = TFile::Open(fname, GetOpenOption(),
-                        Form("ALICE MDC%d raw DB", AliMDC::kMDC), fCompress,
+                        Form("ALICE MDC%d raw DB", kMDC), fCompress,
                         GetNetopt());
    if (!fRawDB) {
       if (retry < kMaxRetry) {
                         GetNetopt());
    if (!fRawDB) {
       if (retry < kMaxRetry) {
@@ -220,7 +254,7 @@ void AliRawDB::MakeTree()
 {
    // Create ROOT Tree object container.
 
 {
    // Create ROOT Tree object container.
 
-   fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", AliMDC::kMDC));
+   fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", kMDC));
    fTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
 
    Int_t bufsize = 256000;
    fTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
 
    Int_t bufsize = 256000;
@@ -228,6 +262,16 @@ void AliRawDB::MakeTree()
    //Int_t split   = 1;
    Int_t split   = 0;
    fTree->Branch("rawevent", "AliRawEvent", &fEvent, bufsize, split);
    //Int_t split   = 1;
    Int_t split   = 0;
    fTree->Branch("rawevent", "AliRawEvent", &fEvent, bufsize, split);
+
+   // Create tree which will contain the HLT ESD information
+
+   if (fESD) {
+     fESDTree = new TTree("esdTree", Form("ALICE MDC%d HLT ESD tree", kMDC));
+     fESDTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
+     split   = 0;
+     fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split);
+   }
+
 }
 
 //______________________________________________________________________________
 }
 
 //______________________________________________________________________________
@@ -241,11 +285,12 @@ void AliRawDB::Close()
 
    // Write the tree.
    fTree->Write();
 
    // Write the tree.
    fTree->Write();
+   if (fESDTree) fESDTree->Write();
 
    // Close DB, this also deletes the fTree
    fRawDB->Close();
 
 
    // Close DB, this also deletes the fTree
    fRawDB->Close();
 
-   if (AliMDC::DeleteFiles()) {
+   if (fDeleteFiles) {
       gSystem->Unlink(fRawDB->GetName());
       delete fRawDB;
       fRawDB = 0;
       gSystem->Unlink(fRawDB->GetName());
       delete fRawDB;
       fRawDB = 0;
@@ -261,14 +306,82 @@ void AliRawDB::Close()
 }
 
 //______________________________________________________________________________
 }
 
 //______________________________________________________________________________
-Bool_t AliRawDB::NextFile()
+Int_t AliRawDB::Fill()
+{
+   // Fill the trees and return the number of written bytes
+
+   Double_t bytes = fRawDB->GetBytesWritten();
+   fTree->Fill();
+   if (fESDTree) fESDTree->Fill();
+   return Int_t(fRawDB->GetBytesWritten() - bytes);
+}
+
+//______________________________________________________________________________
+Int_t AliRawDB::GetTotalSize()
+{
+   // Return the total size of the trees
+  Int_t total = 0;
+
+  {
+    Int_t skey = 0;
+    TDirectory *dir = fTree->GetDirectory();
+    if (dir) {
+      TKey *key = dir->GetKey(fTree->GetName());
+      if (key) skey = key->GetKeylen();
+    }
+    total += skey;
+    if (fTree->GetZipBytes() > 0) total += fTree->GetTotBytes();
+    TBuffer b(TBuffer::kWrite,10000);
+    TTree::Class()->WriteBuffer(b,fTree);
+    total += b.Length();
+  }
+
+  if(fESDTree)
+    {
+      Int_t skey = 0;
+      TDirectory *dir = fESDTree->GetDirectory();
+      if (dir) {
+       TKey *key = dir->GetKey(fESDTree->GetName());
+       if (key) skey = key->GetKeylen();
+      }
+      total += skey;
+      if (fESDTree->GetZipBytes() > 0) total += fESDTree->GetTotBytes();
+      TBuffer b(TBuffer::kWrite,10000);
+      TTree::Class()->WriteBuffer(b,fESDTree);
+      total += b.Length();
+    }
+
+  return total;
+}
+
+//______________________________________________________________________________
+void AliRawDB::WriteStats(AliStats* stats)
+{
+   // Write stats to raw DB, local run DB and global MySQL DB.
+
+   AliRawEventHeader &header = *GetEvent()->GetHeader();
+
+   // Write stats into RawDB
+   TDirectory *ds = gDirectory;
+   GetDB()->cd();
+   stats->SetEvents(GetEvents());
+   stats->SetLastId(header.GetRunNumber(), header.GetEventInRun());
+   stats->SetFileSize(GetBytesWritten());
+   stats->SetCompressionFactor(GetCompressionFactor());
+   stats->SetEndTime();
+   stats->Write("stats");
+   ds->cd();
+}
+
+//______________________________________________________________________________
+Bool_t AliRawDB::NextFile(const char* fileName)
 {
    // Close te current file and open a new one.
    // Returns kFALSE in case opening failed.
 
    Close();
 
 {
    // Close te current file and open a new one.
    // Returns kFALSE in case opening failed.
 
    Close();
 
-   if (!Create()) return kFALSE;
+   if (!Create(fileName)) return kFALSE;
    return kTRUE;
 }
 
    return kTRUE;
 }