]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawDB.cxx
Updated error definitions.
[u/mrichter/AliRoot.git] / RAW / AliRawDB.cxx
index eef17957274e5980079d3f3571383c2d848b0e92..22515f0efde6d9705b317b9d967b7dbd4982736d 100644 (file)
@@ -1,4 +1,4 @@
-// @(#)alimdc:$Name$:$Id$
+// @(#)alimdc:$Name:  $:$Id$
 // Author: Fons Rademakers  26/11/99
 
 /**************************************************************************
@@ -36,7 +36,7 @@
 
 #include <TObjString.h>
 
-#include "AliESD.h"
+#include "AliESDEvent.h"
 #include "AliRawEvent.h"
 #include "AliRawDataArray.h"
 #include "AliRawEventHeaderBase.h"
 
 ClassImp(AliRawDB)
 
-const char *AliRawDB::fgkAliRootTag = "$Name$";
+const char *AliRawDB::fgkAliRootTag = "$Rev$";
+
+// Split TPC into 9 branches in order to avoid problems with big memory
+// consumption in case of TPC events w/o zero-suppression
+Int_t AliRawDB::fgkDetBranches[AliDAQ::kNDetectors+1] = {1,1,1,18,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
 
 //______________________________________________________________________________
 AliRawDB::AliRawDB(AliRawEvent *event,
-                  AliESD *esd, 
+                  AliESDEvent *esd, 
                   Int_t compress,
                    const char* fileName) :
   fRawDB(NULL),
@@ -66,15 +70,20 @@ AliRawDB::AliRawDB(AliRawEvent *event,
   fFS1(""),
   fFS2(""),
   fDeleteFiles(kFALSE),
-  fStop(kFALSE),
-  fGuidFileFolder(NULL)
+  fStop(kFALSE)
 {
    // Create a new raw DB
 
-  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++)
-    fDetRawData[iDet] = new AliRawDataArray(AliDAQ::NumberOfDdls(iDet));
+  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
+    fDetRawData[iDet] = new AliRawDataArray*[fgkDetBranches[iDet]];
+    Int_t nDDLsPerBranch = AliDAQ::NumberOfDdls(iDet)/fgkDetBranches[iDet];
+    for (Int_t iBranch = 0; iBranch < fgkDetBranches[iDet]; iBranch++)
+      fDetRawData[iDet][iBranch] = new AliRawDataArray(nDDLsPerBranch);
+  }
 
-  fDetRawData[AliDAQ::kNDetectors] = new AliRawDataArray(100);
+  fDetRawData[AliDAQ::kNDetectors] = new AliRawDataArray*[fgkDetBranches[AliDAQ::kNDetectors]];
+  for (Int_t iBranch = 0; iBranch < fgkDetBranches[AliDAQ::kNDetectors]; iBranch++)
+    fDetRawData[AliDAQ::kNDetectors][iBranch] = new AliRawDataArray(100);
 
    if (fileName) {
       if (!Create(fileName))
@@ -89,8 +98,11 @@ AliRawDB::~AliRawDB() {
 
   if(Close()==-1) Error("~AliRawDB", "cannot close output file!");
 
-  for (Int_t iDet = 0; iDet < (AliDAQ::kNDetectors + 1); iDet++)
-    delete fDetRawData[iDet];
+  for (Int_t iDet = 0; iDet < (AliDAQ::kNDetectors + 1); iDet++) {
+    for (Int_t iBranch = 0; iBranch < fgkDetBranches[iDet]; iBranch++)
+      delete fDetRawData[iDet][iBranch];
+    delete [] fDetRawData[iDet];
+  }
 }
 
 //______________________________________________________________________________
@@ -255,7 +267,7 @@ void AliRawDB::MakeTree()
    // Create ROOT Tree object container.
 
    fTree = new TTree("RAW", Form("ALICE raw-data tree (%s)", GetAliRootTag()));
-   fTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
+   fTree->SetAutoSave(21000000000LL);  // autosave when 21 Gbyte written
 
    fTree->BranchRef();
 
@@ -267,26 +279,28 @@ void AliRawDB::MakeTree()
 
    // Make brach for each sub-detector
    for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
-     fTree->Branch(AliDAQ::DetectorName(iDet),"AliRawDataArray",
-                  &fDetRawData[iDet],bufsize,split);
+     for (Int_t iBranch = 0; iBranch < fgkDetBranches[iDet]; iBranch++)
+       fTree->Branch(Form("%s%d",AliDAQ::DetectorName(iDet),iBranch),"AliRawDataArray",
+                    &fDetRawData[iDet][iBranch],bufsize,split);
    }
    // Make special branch for unrecognized raw-data payloads
-   fTree->Branch("Common","AliRawDataArray",
-                  &fDetRawData[AliDAQ::kNDetectors],bufsize,split);
+   for (Int_t iBranch = 0; iBranch < fgkDetBranches[AliDAQ::kNDetectors]; iBranch++)
+     fTree->Branch(Form("Common%d",iBranch),"AliRawDataArray",
+                  &fDetRawData[AliDAQ::kNDetectors][iBranch],bufsize,split);
 
    // Create tree which will contain the HLT ESD information
 
    if (fESD) {
      fESDTree = new TTree("esdTree", Form("ALICE HLT ESD tree (%s)", GetAliRootTag()));
-     fESDTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
+     fESDTree->SetAutoSave(21000000000LL);  // autosave when 21 Gbyte written
      split   = 0;
-     fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split);
+     fESDTree->Branch("ESD", "AliESDEvent", &fESD, bufsize, split);
    }
 
 }
 
 //______________________________________________________________________________
-Int_t AliRawDB::Close()
+Long64_t AliRawDB::Close()
 {
    // Close raw DB.
    if (!fRawDB) return 0;
@@ -306,7 +320,7 @@ Int_t AliRawDB::Close()
    // Close DB, this also deletes the fTree
    fRawDB->Close();
 
-   Int_t filesize = fRawDB->GetEND();
+   Long64_t filesize = fRawDB->GetEND();
 
    if (fDeleteFiles) {
       gSystem->Unlink(fRawDB->GetName());
@@ -318,10 +332,6 @@ Int_t AliRawDB::Close()
        return -1;
    }
 
-   // Write a text file with file GUID
-   // in the specified folder
-   WriteGuidFile();
-
    delete fRawDB;
    fRawDB = 0;
    if(!error)
@@ -336,7 +346,8 @@ Int_t AliRawDB::Fill()
    // Fill the trees and return the number of written bytes
 
   for (Int_t iDet = 0; iDet < (AliDAQ::kNDetectors + 1); iDet++)
-    fDetRawData[iDet]->ClearData();
+    for (Int_t iBranch = 0; iBranch < fgkDetBranches[iDet]; iBranch++)
+      fDetRawData[iDet][iBranch]->ClearData();
 
    // Move the raw-data payloads to the corresponding branches
   for(Int_t iSubEvent = 0; iSubEvent < fEvent->GetNSubEvents(); iSubEvent++) {
@@ -346,9 +357,15 @@ Int_t AliRawDB::Fill()
       UInt_t eqId = equipment->GetEquipmentHeader()->GetId();
       Int_t ddlIndex;
       Int_t iDet = AliDAQ::DetectorIDFromDdlID(eqId,ddlIndex);
-      if (iDet < 0 || iDet > AliDAQ::kNDetectors)
+      Int_t iBranch;
+      if (iDet < 0 || iDet > AliDAQ::kNDetectors) {
        iDet = AliDAQ::kNDetectors;
-      equipment->SetRawDataRef(fDetRawData[iDet]);
+       iBranch = 0; // can we split somehow the unrecognized data??? For the moment - no
+      }
+      else {
+       iBranch = (ddlIndex * fgkDetBranches[iDet])/AliDAQ::NumberOfDdls(iDet);
+      }
+      equipment->SetRawDataRef(fDetRawData[iDet][iBranch]);
     }
   }
 
@@ -366,10 +383,10 @@ Int_t AliRawDB::Fill()
 }
 
 //______________________________________________________________________________
-Int_t AliRawDB::GetTotalSize()
+Long64_t AliRawDB::GetTotalSize()
 {
    // Return the total size of the trees
-  Int_t total = 0;
+  Long64_t total = 0;
 
   {
     Int_t skey = 0;
@@ -378,15 +395,7 @@ Int_t AliRawDB::GetTotalSize()
       TKey *key = dir->GetKey(fTree->GetName());
       if (key) skey = key->GetKeylen();
     }
-    total += skey;
-    if (fTree->GetZipBytes() > 0) total += fTree->GetTotBytes();
-#if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
-    TBufferFile b(TBuffer::kWrite,10000);
-#else
-    TBuffer b(TBuffer::kWrite,10000);
-#endif
-    TTree::Class()->WriteBuffer(b,fTree);
-    total += b.Length();
+    total += (Long64_t)skey + fTree->GetZipBytes();
   }
 
   if(fESDTree)
@@ -397,15 +406,7 @@ Int_t AliRawDB::GetTotalSize()
        TKey *key = dir->GetKey(fESDTree->GetName());
        if (key) skey = key->GetKeylen();
       }
-      total += skey;
-      if (fESDTree->GetZipBytes() > 0) total += fESDTree->GetTotBytes();
-#if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
-      TBufferFile b(TBuffer::kWrite,10000);
-#else
-      TBuffer b(TBuffer::kWrite,10000);
-#endif
-      TTree::Class()->WriteBuffer(b,fESDTree);
-      total += b.Length();
+      total += (Long64_t)skey + fESDTree->GetZipBytes();
     }
 
   return total;
@@ -462,20 +463,22 @@ const char *AliRawDB::GetAliRootTag()
 
   TString version = fgkAliRootTag;
   version.Remove(TString::kBoth,'$');
-  version.ReplaceAll("Name","AliRoot version");
+  version.ReplaceAll("Rev","AliRoot version");
 
   return version.Data();
 }
 
 //______________________________________________________________________________
-void AliRawDB::WriteGuidFile()
+Bool_t AliRawDB::WriteGuidFile(TString &guidFileFolder)
 {
   // Write the guid file
-  // in the specified folder
+  // in the specified folder or
+  // in the folder where the raw data
+  // file is.
 
    TString guidFileName;
-   if (fGuidFileFolder) {
-     guidFileName = fGuidFileFolder;
+   if (!guidFileFolder.IsNull()) {
+     guidFileName = guidFileFolder;
 
      TString pathStr = fRawDB->GetName();
      TObjArray *pathArr = pathStr.Tokenize('/');
@@ -490,7 +493,13 @@ void AliRawDB::WriteGuidFile()
    guidFileName += ".guid";
 
    ofstream fguid(guidFileName.Data());
+   if (!fguid.is_open()) {
+     Error("WriteGuidFile", "failure to open guid file %s", guidFileName.Data());
+     return kFALSE;
+   }
    TString guid = fRawDB->GetUUID().AsString();
    fguid << "guid: \t" << guid.Data();
    fguid.close();
+
+   return kTRUE;
 }