]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliTagDB.cxx
Fix
[u/mrichter/AliRoot.git] / RAW / AliTagDB.cxx
index 84f178cdfe6f44ec8c7f5471ed76fa143c236af1..797c13b5d25ac2bed0a71b0f3820adf7e4b33826 100644 (file)
@@ -1,4 +1,4 @@
-// @(#)alimdc:$Name$:$Id$
+// @(#) $Id$
 // Author: Fons Rademakers  26/11/99
 
 /**************************************************************************
 //                                                                      //
 //////////////////////////////////////////////////////////////////////////
 
+#include <errno.h>
+
 #include <TSystem.h>
+#include <TTimeStamp.h>
+#include <TBranch.h>
 
-#include "AliMDC.h"
+#include "AliESD.h"
 
+#include "AliRawDB.h"
+#include "AliRawEventTag.h"
 #include "AliTagDB.h"
+#include "AliRawEventHeaderBase.h"
 
 
 ClassImp(AliTagDB)
 
 
 //______________________________________________________________________________
-AliTagDB::AliTagDB(AliRawEventHeader *header, Double_t maxsize, Bool_t create)
+AliTagDB::AliTagDB(AliRawEventTag *eventTag, const char* fileName) :
+  fTagDB(NULL),
+  fTree(NULL),
+  fEventTag(eventTag),
+  fMaxSize(-1),
+  fFS(""),
+  fDeleteFiles(kFALSE)
 {
    // Create tag DB.
 
-   fHeader   = header;
-   fMaxSize  = maxsize;
-
-   if (create) {
-      if (!Create())
+   if (fileName) {
+      if (!Create(fileName))
          MakeZombie();
    }
 }
 
-//______________________________________________________________________________
-AliTagDB::AliTagDB(const AliTagDB& tagDB): TObject(tagDB)
-{
-// copy constructor
-
-  Fatal("AliTagDB", "copy constructor not implemented");
-}
-
-//______________________________________________________________________________
-AliTagDB& AliTagDB::operator = (const AliTagDB& /*tagDB*/)
+static void BranchResetBit(TBranch *b) 
 {
-// assignment operator
-
-  Fatal("operator =", "assignment operator not implemented");
-  return *this;
+  // Reset MapObject on this branch and all the sub-branches
+
+  b->ResetBit( kBranchObject | kBranchAny ); // Or in newer ROOT: b->ResetBit( kMapObject )
+  TIter next( b->GetListOfBranches() );
+  TBranch *sub = 0;
+  while ( (sub = (TBranch*)next() ) ) {
+    BranchResetBit( sub );
+  }
 }
 
 //______________________________________________________________________________
-Bool_t AliTagDB::Create()
+Bool_t AliTagDB::Create(const char* fileName)
 {
    // Create a new tag DB.
 
-   fTagDB = new TFile(GetFileName(), "RECREATE",
-                      Form("ALICE MDC%d tag DB", AliMDC::kMDC), 1);
+   const char *name = fileName;
+   if (!name) name = GetFileName();
+   fTagDB = new TFile(name, "RECREATE",
+                      Form("ALICE tag DB (%s)", AliRawDB::GetAliRootTag()), 1);
    if (fTagDB->IsZombie()) {
       Error("Create", "error opening tag DB");
       fTagDB = 0;
       return kFALSE;
    }
+   // Put wide read-write permissions
+   if(gSystem->Chmod(name,438)) {
+     Error("Create", "can't set permissions for tag DB file");
+     fTagDB = 0;
+     return kFALSE;
+   }
 
    // Create ROOT Tree object container
-   fTree = new TTree("TAG", Form("ALICE MDC%d header data tree", AliMDC::kMDC));
+   fTree = new TTree("T", Form("ALICE raw-data tag tree (%s)", AliRawDB::GetAliRootTag()));
    fTree->SetAutoSave(100000000);  // autosave when 100 Mbyte written
 
    Int_t bufsize = 32000;
    Int_t split   = 1;
-   fTree->Branch("header", "AliRawEventHeader", &fHeader, bufsize, split);
+   const char *tagname = fEventTag->GetName();
+   TBranch * b = fTree->Branch("TAG", tagname, &fEventTag, bufsize, split);
+   BranchResetBit(b);
 
    return kTRUE;
 }
@@ -102,7 +117,7 @@ void AliTagDB::Close()
    // Close DB, this also deletes the fTree
    fTagDB->Close();
 
-   if (AliMDC::DeleteFiles())
+   if (fDeleteFiles)
       gSystem->Unlink(fTagDB->GetName());
 
    delete fTagDB;
@@ -110,17 +125,32 @@ void AliTagDB::Close()
 }
 
 //______________________________________________________________________________
-Bool_t AliTagDB::NextFile()
+Bool_t AliTagDB::NextFile(const char* fileName)
 {
    // 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;
 }
 
+//______________________________________________________________________________
+void AliTagDB::SetFS(const char* fs)
+{
+// set the file system location
+
+  fFS = fs;
+  if (fs) {
+    gSystem->ResetErrno();
+    gSystem->MakeDirectory(fs);
+    if (gSystem->GetErrno() && gSystem->GetErrno() != EEXIST) {
+      SysError("SetFS", "mkdir %s", fs);
+    }
+  }
+}
+
 //______________________________________________________________________________
 Float_t AliTagDB::GetCompressionFactor() const
 {
@@ -138,23 +168,27 @@ const char *AliTagDB::GetFileName() const
    // Return filename based on hostname and date and time. This will make
    // each file unique. The tags will be stored in the /data1/tags directory.
 
-   static char fname[64];
-   const char *fs = AliMDC::TagDBFS();
+   static TString fname;
+   const char *fs = fFS;
 
    // check that fs exists (crude check fails if fs is a file)
    gSystem->MakeDirectory(fs);
 
-   char hostname[64];
-
-   strcpy(hostname, gSystem->HostName());
+   // Get the run number
+   Int_t runNumber = -1;
+   if (fEventTag) {
+     AliRawEventHeaderBase *header = fEventTag->GetHeader();
+     if (header) runNumber = header->Get("RunNb");
+   }
 
-   char *s;
-   if ((s = strchr(hostname, '.')))
-      *s = 0;
+   TString hostname;
+   hostname.Form("%s",gSystem->HostName());
+   if ( hostname.First('.') > 0 ) hostname.Resize(hostname.First('.'));
 
-   TDatime dt;
+   TTimeStamp ts;
 
-   sprintf(fname, "%s/%s_%d_%d.root", fs, hostname, dt.GetDate(), dt.GetTime());
+   fname.Form("%s/Run%d.%s_%d_%d_%d.RAW.tag.root", fs, runNumber, hostname.Data(),
+             ts.GetDate(), ts.GetTime(), ts.GetNanoSec());
 
-   return fname;
+   return fname.Data();
 }