]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawDB.cxx
un comment the check for the need of ushort
[u/mrichter/AliRoot.git] / RAW / AliRawDB.cxx
index 00d2d204c952e3c42da6ea4f629091a417836edb..f9436e5cd3a24ba11ff93bf4e058c2eb0d8f569e 100644 (file)
 #include <TSystem.h>
 #include <TKey.h>
 
+#include <TObjString.h>
+
 #include "AliESD.h"
 #include "AliRawEvent.h"
+#include "AliRawDataArray.h"
 #include "AliRawEventHeaderBase.h"
+#include "AliRawEquipment.h"
+#include "AliRawEquipmentHeader.h"
 #include "AliStats.h"
 
 #include "AliRawDB.h"
@@ -61,16 +66,33 @@ AliRawDB::AliRawDB(AliRawEvent *event,
   fFS1(""),
   fFS2(""),
   fDeleteFiles(kFALSE),
-  fStop(kFALSE)
+  fStop(kFALSE),
+  fGuidFileFolder(NULL)
 {
    // Create a new raw DB
 
+  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))
          MakeZombie();
    }
 }
 
+
+//______________________________________________________________________________
+AliRawDB::~AliRawDB() {
+  // Destructor
+
+  if(Close()==-1) Error("~AliRawDB", "cannot close output file!");
+
+  for (Int_t iDet = 0; iDet < (AliDAQ::kNDetectors + 1); iDet++)
+    delete fDetRawData[iDet];
+}
+
 //______________________________________________________________________________
 Bool_t AliRawDB::FSHasSpace(const char *fs) const
 {
@@ -235,12 +257,23 @@ void AliRawDB::MakeTree()
    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) {
@@ -286,12 +319,8 @@ Int_t AliRawDB::Close()
    }
 
    // Write a text file with file GUID
-   TString guidFileName = fRawDB->GetName();
-   guidFileName += ".guid";
-   ofstream fguid(guidFileName.Data());
-   TString guid = fRawDB->GetUUID().AsString();
-   fguid << "guid: \t" << guid.Data();
-   fguid.close();
+   // in the specified folder
+   WriteGuidFile();
 
    delete fRawDB;
    fRawDB = 0;
@@ -306,6 +335,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)
@@ -332,15 +378,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 += skey + fTree->GetZipBytes();
   }
 
   if(fESDTree)
@@ -351,15 +389,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 += skey + fESDTree->GetZipBytes();
     }
 
   return total;
@@ -420,3 +450,31 @@ const char *AliRawDB::GetAliRootTag()
 
   return version.Data();
 }
+
+//______________________________________________________________________________
+void AliRawDB::WriteGuidFile()
+{
+  // Write the guid file
+  // in the specified folder
+
+   TString guidFileName;
+   if (fGuidFileFolder) {
+     guidFileName = fGuidFileFolder;
+
+     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());
+   TString guid = fRawDB->GetUUID().AsString();
+   fguid << "guid: \t" << guid.Data();
+   fguid.close();
+}