Fix tracklet writing
authorcblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 7 Jul 2009 15:13:26 +0000 (15:13 +0000)
committercblume <cblume@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 7 Jul 2009 15:13:26 +0000 (15:13 +0000)
TRD/AliTRDReconstructor.cxx
TRD/AliTRDrawData.cxx
TRD/AliTRDrawData.h

index d54a2fa..4f62790 100644 (file)
@@ -188,6 +188,7 @@ void AliTRDReconstructor::ConvertDigits(AliRawReader *rawReader
   AliTRDrawData rawData;
   rawReader->Reset();
   rawReader->Select("TRD");
+  rawData.OpenOutput();
   AliTRDdigitsManager *manager = rawData.Raw2Digits(rawReader);
   manager->MakeBranch(digitsTree);
   manager->WriteDigits();
index 442fc68..a4b5de1 100644 (file)
@@ -51,9 +51,12 @@ Int_t AliTRDrawData::fgDataSuppressionLevel = 1;
 //_____________________________________________________________________________
 AliTRDrawData::AliTRDrawData()
   :TObject()
+  ,fRunLoader(NULL)
   ,fGeo(NULL)
   ,fFee(NULL)
   ,fNumberOfDDLs(0)
+  ,fTrackletTree(NULL)
+  ,fTrackletContainer(NULL)
   ,fSMindexPos(0)
   ,fStackindexPos(0)
   ,fEventCounter(0)
@@ -70,9 +73,12 @@ AliTRDrawData::AliTRDrawData()
 //_____________________________________________________________________________
 AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
   :TObject(r)
+  ,fRunLoader(NULL)
   ,fGeo(NULL)
   ,fFee(NULL)
   ,fNumberOfDDLs(0)
+  ,fTrackletTree(NULL)
+  ,fTrackletContainer(NULL)
   ,fSMindexPos(0)
   ,fStackindexPos(0)
   ,fEventCounter(0)
@@ -93,6 +99,11 @@ AliTRDrawData::~AliTRDrawData()
   // Destructor
   //
 
+  if (fTrackletContainer){
+    delete fTrackletContainer;
+    fTrackletContainer = NULL;
+  }
+
 }
 
 //_____________________________________________________________________________
@@ -955,6 +966,15 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
   AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
   digitsManager->CreateArrays();
 
+  if (!fTrackletContainer) {
+  //if (!fTrackletContainer && ( fReconstructor->IsWritingTracklets() || fReconstructor->IsProcessingTracklets() )) {
+    // maximum tracklets for one HC
+    const Int_t kTrackletChmb=256;
+    fTrackletContainer = new UInt_t *[2];
+    fTrackletContainer[0] = new UInt_t[kTrackletChmb];
+    fTrackletContainer[1] = new UInt_t[kTrackletChmb];
+  }
+
   AliTRDrawStreamBase *pinput = AliTRDrawStreamBase::GetRawStream(rawReader);
   AliTRDrawStreamBase &input = *pinput;
   input.SetRawVersion( fFee->GetRAWversion() ); //<= ADDED by MinJung
@@ -966,7 +986,12 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
 
   while (det >= 0)
     {
-      det = input.NextChamber(digitsManager);
+      //det = input.NextChamber(digitsManager);
+      det = input.NextChamber(digitsManager,fTrackletContainer);
+
+    //if (!fReconstructor->IsWritingTracklets()) continue;
+    if (*(fTrackletContainer[0]) > 0 || *(fTrackletContainer[1]) > 0) WriteTracklets(det);
+
       if (det >= 0)
        {
          // get...
@@ -982,6 +1007,13 @@ AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
        }
     }
 
+  if (fTrackletContainer){
+    delete [] fTrackletContainer[0];
+    delete [] fTrackletContainer[1];
+    delete [] fTrackletContainer;
+    fTrackletContainer = NULL;
+  }
+
   delete pinput;
   pinput = NULL;
 
@@ -1194,4 +1226,92 @@ AliTRDdigitsManager *AliTRDrawData::Raw2DigitsOLD(AliRawReader *rawReader)
 
 }
 
+//_____________________________________________________________________________
+Bool_t AliTRDrawData::WriteTracklets(Int_t det)
+{
+  //
+  // Write the raw data tracklets into seperate file
+  //
+
+  UInt_t **leaves = new UInt_t *[2];
+  for (Int_t i=0; i<2 ;i++){
+    leaves[i] = new UInt_t[258];
+    leaves[i][0] = det; // det
+    leaves[i][1] = i;   // side
+    memcpy(leaves[i]+2, fTrackletContainer[i], sizeof(UInt_t) * 256);
+  }
+
+  if (!fTrackletTree){
+    AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
+    dl->MakeTree();
+    fTrackletTree = dl->Tree();
+  }
+
+  TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
+  if (!trkbranch) {
+    trkbranch = fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
+  }
+
+  for (Int_t i=0; i<2; i++){
+    if (leaves[i][2]>0) {
+      trkbranch->SetAddress(leaves[i]);
+      fTrackletTree->Fill();
+    }
+  }
+
+  AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
+  dl->WriteData("OVERWRITE");
+  //dl->Unload();
+  delete [] leaves;
+
+  return kTRUE;
+
+}
+
+//_____________________________________________________________________________
+Bool_t AliTRDrawData::OpenOutput()
+{
+  //
+  // Connect the output tree
+  //
+
+  // tracklet writing
+  if (1){
+  //if (fReconstructor->IsWritingTracklets()){
+    TString evfoldname = AliConfig::GetDefaultEventFolderName();
+    fRunLoader         = AliRunLoader::GetRunLoader(evfoldname);
+
+    if (!fRunLoader) {
+      fRunLoader = AliRunLoader::Open("galice.root");
+    }
+    if (!fRunLoader) {
+      AliError(Form("Can not open session for file galice.root."));
+      return kFALSE;
+    }
+
+    UInt_t **leaves = new UInt_t *[2];
+    AliDataLoader *dl = fRunLoader->GetLoader("TRDLoader")->GetDataLoader("tracklets");
+    if (!dl) {
+      AliError("Could not get the tracklets data loader!");
+      dl = new AliDataLoader("TRD.Tracklets.root","tracklets", "tracklets");
+      fRunLoader->GetLoader("TRDLoader")->AddDataLoader(dl);
+    }
+    else {
+      fTrackletTree = dl->Tree();
+      if (!fTrackletTree)
+        {
+        dl->MakeTree();
+        fTrackletTree = dl->Tree();
+        }
+      TBranch *trkbranch = fTrackletTree->GetBranch("trkbranch");
+      if (!trkbranch)
+        fTrackletTree->Branch("trkbranch",leaves[0],"det/i:side/i:tracklets[256]/i");
+    }
+  }
+  return kTRUE;
+
+}
+
+
+
 
index 01bd9ac..ed83da9 100644 (file)
@@ -15,6 +15,8 @@
 
 class TTree;
 
+class AliRunLoader;
+
 class AliRawReader;
 
 class AliTRDdigitsManager;
@@ -38,6 +40,8 @@ class AliTRDrawData : public TObject {
   virtual AliTRDdigitsManager *Raw2DigitsOLD(AliRawReader *rawReader);
   static void SetRawFormatVersion(Int_t iver){ fgRawFormatVersion=iver; };
   static void SetSuppressionLevel(Int_t ilevel){ fgDataSuppressionLevel=ilevel; };
+  Bool_t WriteTracklets(Int_t det);
+  Bool_t OpenOutput();
 
   enum FORMATTYPE
     {
@@ -60,9 +64,12 @@ class AliTRDrawData : public TObject {
           Int_t        AddStackIndexWords(UInt_t *buf, Int_t nStack, Int_t nMax);   // add stack index words and stack header when there is no data for the stack 
           Bool_t       ShiftWords(UInt_t *buf, Int_t nStart, Int_t nWords, Int_t nMax); // shifts n words
   
+  AliRunLoader        *fRunLoader;      //! Run Loader
   AliTRDgeometry      *fGeo;            //! Geometry
   AliTRDfeeParam      *fFee;            //! Fee Parameters
   Int_t                fNumberOfDDLs;   //  Number of DDLs
+  TTree               *fTrackletTree;        //! Tree for tracklets
+  UInt_t              **fTrackletContainer;  //! tracklet container
 
   ClassDef(AliTRDrawData,5)             //  TRD raw data class