]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawDB.cxx
Fix for 64-bit platforms
[u/mrichter/AliRoot.git] / RAW / AliRawDB.cxx
index 1bf1e618d5976b3e91c3ba8db8402351d4cbd20a..2be89658da47301555453045618b0192fd71d338 100644 (file)
 //////////////////////////////////////////////////////////////////////////
 
 #include <errno.h>
+#include <Riostream.h>
+
+#if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
+#include <TBufferFile.h>
+#else
+#include <TBuffer.h>
+#endif
 
 #include <TSystem.h>
 #include <TKey.h>
 
-#ifdef ALI_DATE
-#include "event.h"
-#endif
+#include <TObjString.h>
 
 #include "AliESD.h"
 #include "AliRawEvent.h"
-#include "AliRawEventHeader.h"
+#include "AliRawDataArray.h"
+#include "AliRawEventHeaderBase.h"
+#include "AliRawEquipment.h"
+#include "AliRawEquipmentHeader.h"
 #include "AliStats.h"
 
 #include "AliRawDB.h"
@@ -41,6 +49,7 @@
 
 ClassImp(AliRawDB)
 
+const char *AliRawDB::fgkAliRootTag = "$Name$";
 
 //______________________________________________________________________________
 AliRawDB::AliRawDB(AliRawEvent *event,
@@ -61,14 +70,10 @@ 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
+  for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++)
+    fDetRawData[iDet] = new AliRawDataArray(AliDAQ::NumberOfDdls(iDet));
+
+  fDetRawData[AliDAQ::kNDetectors] = new AliRawDataArray(100);
 
    if (fileName) {
       if (!Create(fileName))
@@ -76,21 +81,15 @@ AliRawDB::AliRawDB(AliRawEvent *event,
    }
 }
 
-//______________________________________________________________________________
-AliRawDB::AliRawDB(const AliRawDB& rawDB): TObject(rawDB)
-{
-// copy constructor
-
-  Fatal("AliRawDB", "copy constructor not implemented");
-}
 
 //______________________________________________________________________________
-AliRawDB& AliRawDB::operator = (const AliRawDB& /*rawDB*/)
-{
-// assignment operator
+AliRawDB::~AliRawDB() {
+  // Destructor
+
+  if(Close()==-1) Error("~AliRawDB", "cannot close output file!");
 
-  Fatal("operator =", "assignment operator not implemented");
-  return *this;
+  for (Int_t iDet = 0; iDet < (AliDAQ::kNDetectors + 1); iDet++)
+    delete fDetRawData[iDet];
 }
 
 //______________________________________________________________________________
@@ -203,7 +202,7 @@ again:
    retry++;
 
    fRawDB = TFile::Open(fname, GetOpenOption(),
-                       Form("ALICE MDC%d raw DB", kMDC), fCompress,
+                       Form("ALICE raw-data file (%s)", GetAliRootTag()), fCompress,
                        GetNetopt());
    if (!fRawDB) {
       if (retry < kMaxRetry) {
@@ -254,19 +253,30 @@ void AliRawDB::MakeTree()
 {
    // Create ROOT Tree object container.
 
-   fTree = new TTree("RAW", Form("ALICE MDC%d raw data tree", kMDC));
+   fTree = new TTree("RAW", Form("ALICE raw-data tree (%s)", GetAliRootTag()));
    fTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
 
+   fTree->BranchRef();
+
    Int_t bufsize = 256000;
    // splitting 29.6 MB/s, no splitting 35.3 MB/s on P4 2GHz 15k SCSI
    //Int_t split   = 1;
    Int_t split   = 0;
    fTree->Branch("rawevent", "AliRawEvent", &fEvent, bufsize, split);
 
+   // 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);
+   }
+   // Make special branch for unrecognized raw-data payloads
+   fTree->Branch("Common","AliRawDataArray",
+                  &fDetRawData[AliDAQ::kNDetectors],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 = new TTree("esdTree", Form("ALICE HLT ESD tree (%s)", GetAliRootTag()));
      fESDTree->SetAutoSave(2000000000);  // autosave when 2 Gbyte written
      split   = 0;
      fESDTree->Branch("ESD", "AliESD", &fESD, bufsize, split);
@@ -307,10 +317,6 @@ Int_t AliRawDB::Close()
        return -1;
    }
 
-   // Create semaphore to say this file is finished
-   Int_t tfd = ::creat(Form("%s.done", fRawDB->GetName()), 0644);
-   close(tfd);
-
    delete fRawDB;
    fRawDB = 0;
    if(!error)
@@ -324,6 +330,23 @@ 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();
+
+   // Move the raw-data payloads to the corresponding branches
+  for(Int_t iSubEvent = 0; iSubEvent < fEvent->GetNSubEvents(); iSubEvent++) {
+    AliRawEvent *subEvent = fEvent->GetSubEvent(iSubEvent);
+    for(Int_t iEquipment = 0; iEquipment < subEvent->GetNEquipments(); iEquipment++) {
+      AliRawEquipment *equipment = subEvent->GetEquipment(iEquipment);
+      UInt_t eqId = equipment->GetEquipmentHeader()->GetId();
+      Int_t ddlIndex;
+      Int_t iDet = AliDAQ::DetectorIDFromDdlID(eqId,ddlIndex);
+      if (iDet < 0 || iDet > AliDAQ::kNDetectors)
+       iDet = AliDAQ::kNDetectors;
+      equipment->SetRawDataRef(fDetRawData[iDet]);
+    }
+  }
+
    Double_t bytes = fRawDB->GetBytesWritten();
    Bool_t error = kFALSE;
    if (fTree->Fill() == -1)
@@ -350,11 +373,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();
-    TBuffer b(TBuffer::kWrite,10000);
-    TTree::Class()->WriteBuffer(b,fTree);
-    total += b.Length();
+    total += skey + fTree->GetZipBytes();
   }
 
   if(fESDTree)
@@ -365,11 +384,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();
-      TBuffer b(TBuffer::kWrite,10000);
-      TTree::Class()->WriteBuffer(b,fESDTree);
-      total += b.Length();
+      total += skey + fESDTree->GetZipBytes();
     }
 
   return total;
@@ -380,13 +395,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.GetP("Id")[0]);
    stats->SetFileSize(GetBytesWritten());
    stats->SetCompressionFactor(GetCompressionFactor());
    stats->SetEndTime();
@@ -416,3 +431,53 @@ Float_t AliRawDB::GetCompressionFactor() const
    else
       return fTree->GetTotBytes()/fTree->GetZipBytes();
 }
+
+//______________________________________________________________________________
+const char *AliRawDB::GetAliRootTag()
+{
+  // Return the aliroot tag (version)
+  // used to generate the raw data file.
+  // Stored in the raw-data file title.
+
+  TString version = fgkAliRootTag;
+  version.Remove(TString::kBoth,'$');
+  version.ReplaceAll("Name","AliRoot version");
+
+  return version.Data();
+}
+
+//______________________________________________________________________________
+Bool_t AliRawDB::WriteGuidFile(const char *guidFileFolder)
+{
+  // Write the guid file
+  // in the specified folder or
+  // in the folder where the raw data
+  // file is.
+
+   TString guidFileName;
+   if (guidFileFolder) {
+     guidFileName = guidFileFolder;
+
+     TString pathStr = fRawDB->GetName();
+     TObjArray *pathArr = pathStr.Tokenize('/');
+     guidFileName.Append("/");
+     guidFileName.Append(((TObjString *)pathArr->Last())->String());
+     pathArr->Delete();
+     delete pathArr;
+   }
+   else
+     guidFileName = fRawDB->GetName();
+
+   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;
+}