]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawDB.cxx
Adding new calibration flavours for trigger
[u/mrichter/AliRoot.git] / RAW / AliRawDB.cxx
index 5259a34447903bf96d9b31238461d9c82a60d587..a2d8ab03237079848e52bd3fc602bd47f444227e 100644 (file)
 #include <errno.h>
 
 #include <TSystem.h>
-
-#ifdef ALI_DATE
-#include "event.h"
-#endif
+#include <TKey.h>
 
 #include "AliESD.h"
 #include "AliRawEvent.h"
-#include "AliRawEventHeader.h"
+#include "AliRawEventHeaderBase.h"
 #include "AliStats.h"
 
 #include "AliRawDB.h"
@@ -60,15 +57,6 @@ AliRawDB::AliRawDB(AliRawEvent *event,
 {
    // Create a new raw DB
 
-   // Consistency check with DATE header file
-#ifdef ALI_DATE
-   if (fEvent->GetHeader()->HeaderSize() != EVENT_HEAD_BASE_SIZE) {
-      Error("AliRawDB", "inconsistency between DATE and AliRawEvent headers");
-      MakeZombie();
-      return;
-   }
-#endif
-
    if (fileName) {
       if (!Create(fileName))
          MakeZombie();
@@ -184,7 +172,7 @@ Bool_t AliRawDB::Create(const char* fileName)
 {
    // Create a new raw DB.
 
-   const Int_t kMaxRetry = 200;
+   const Int_t kMaxRetry = 1;
    const Int_t kMaxSleep = 1;      // seconds
    const Int_t kMaxSleepLong = 10; // seconds
    Int_t retry = 0;
@@ -202,8 +190,8 @@ again:
    retry++;
 
    fRawDB = TFile::Open(fname, GetOpenOption(),
-                        Form("ALICE MDC%d raw DB", kMDC), fCompress,
-                        GetNetopt());
+                       Form("ALICE MDC%d raw DB", kMDC), fCompress,
+                       GetNetopt());
    if (!fRawDB) {
       if (retry < kMaxRetry) {
          Warning("Create", "failure to open file, sleeping %d %s before retrying...",
@@ -267,33 +255,43 @@ void AliRawDB::MakeTree()
    if (fESD) {
      fESDTree = new TTree("esdTree", Form("ALICE MDC%d HLT ESD tree", kMDC));
      fESDTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
-     split   = 99;
+     split   = 0;
      fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split);
    }
 
 }
 
 //______________________________________________________________________________
-void AliRawDB::Close()
+Int_t AliRawDB::Close()
 {
    // Close raw DB.
+   if (!fRawDB) return 0;
 
-   if (!fRawDB) return;
+   if (!fRawDB->IsOpen()) return 0;
 
    fRawDB->cd();
 
    // Write the tree.
-   fTree->Write();
-   if (fESDTree) fESDTree->Write();
+   Bool_t error = kFALSE;
+   if (fTree->Write() == 0)
+     error = kTRUE;
+   if (fESDTree)
+     if (fESDTree->Write() == 0)
+       error = kTRUE;
 
    // Close DB, this also deletes the fTree
    fRawDB->Close();
 
+   Int_t filesize = fRawDB->GetEND();
+
    if (fDeleteFiles) {
       gSystem->Unlink(fRawDB->GetName());
       delete fRawDB;
       fRawDB = 0;
-      return;
+      if(!error)
+       return filesize;
+      else
+       return -1;
    }
 
    // Create semaphore to say this file is finished
@@ -302,6 +300,10 @@ void AliRawDB::Close()
 
    delete fRawDB;
    fRawDB = 0;
+   if(!error)
+     return filesize;
+   else
+     return -1;
 }
 
 //______________________________________________________________________________
@@ -310,9 +312,54 @@ 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);
+   Bool_t error = kFALSE;
+   if (fTree->Fill() == -1)
+     error = kTRUE;
+   if (fESDTree) 
+     if (fESDTree->Fill() == -1)
+       error = kTRUE;
+   if(!error)
+     return Int_t(fRawDB->GetBytesWritten() - bytes);
+   else
+     return -1;
+}
+
+//______________________________________________________________________________
+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;
 }
 
 //______________________________________________________________________________
@@ -320,13 +367,13 @@ void AliRawDB::WriteStats(AliStats* stats)
 {
    // Write stats to raw DB, local run DB and global MySQL DB.
 
-   AliRawEventHeader &header = *GetEvent()->GetHeader();
+   AliRawEventHeaderBase &header = *GetEvent()->GetHeader();
 
    // Write stats into RawDB
    TDirectory *ds = gDirectory;
    GetDB()->cd();
    stats->SetEvents(GetEvents());
-   stats->SetLastId(header.GetRunNumber(), header.GetEventInRun());
+   stats->SetLastId(header.Get("RunNb"), header.GetP("Id")[0]);
    stats->SetFileSize(GetBytesWritten());
    stats->SetCompressionFactor(GetCompressionFactor());
    stats->SetEndTime();