]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDclusterizer.cxx
Transition to NewIO
[u/mrichter/AliRoot.git] / TRD / AliTRDclusterizer.cxx
index f13669d953faaa9ded0499fa81d456986fc897a3..e3f018a285996f40f9c596061226c8f868e525e7 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.3  2000/06/08 18:32:58  cblume
-Make code compliant to coding conventions
-
-Revision 1.2  2000/05/08 16:17:27  cblume
-Merge TRD-develop
-
-Revision 1.1.4.1  2000/05/08 15:08:03  cblume
-Remove the class AliTRDcluster
-
-Revision 1.1  2000/02/28 18:57:58  cblume
-Add new TRD classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -35,10 +21,20 @@ Add new TRD classes
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <TROOT.h>
+#include <TTree.h>
+#include <TFile.h>
+
 #include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
 
 #include "AliTRD.h"
 #include "AliTRDclusterizer.h"
+#include "AliTRDcluster.h"
+#include "AliTRDrecPoint.h"
+#include "AliTRDgeometry.h"
+#include "AliTRDparameter.h"
 
 ClassImp(AliTRDclusterizer)
 
@@ -49,8 +45,11 @@ AliTRDclusterizer::AliTRDclusterizer():TNamed()
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
+  fClusterTree = NULL;
+  fTRD         = 0;
+  fEvent       = 0;
+  fVerbose     = 0;
+  fPar         = 0;
 
 }
 
@@ -62,10 +61,10 @@ AliTRDclusterizer::AliTRDclusterizer(const Text_t* name, const Text_t* title)
   // AliTRDclusterizer default constructor
   //
 
-  fInputFile = NULL;
-  fEvent     = 0;
-
-  Init();
+  fClusterTree = NULL;
+  fEvent       = 0;
+  fVerbose     = 0;
+  fPar         = 0;
 
 }
 
@@ -87,11 +86,6 @@ AliTRDclusterizer::~AliTRDclusterizer()
   // AliTRDclusterizer destructor
   //
 
-  if (fInputFile) {
-    fInputFile->Close();
-    delete fInputFile;
-  }
-
 }
 
 //_____________________________________________________________________________
@@ -113,60 +107,82 @@ void AliTRDclusterizer::Copy(TObject &c)
   // Copy function
   //
 
-  ((AliTRDclusterizer &) c).fInputFile = NULL;
-  ((AliTRDclusterizer &) c).fEvent     = 0;  
+  ((AliTRDclusterizer &) c).fClusterTree = NULL;
+  ((AliTRDclusterizer &) c).fEvent       = 0;  
+  ((AliTRDclusterizer &) c).fVerbose     = fVerbose;  
+  ((AliTRDclusterizer &) c).fPar         = 0;
+
+}
 
+//_____________________________________________________________________________
+Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
+{
+  //
+  // Opens the AliROOT file. Output and input are in the same file
+  //
+  fRunLoader = AliRunLoader::Open(name);
+  if (!fRunLoader)
+   {
+     Error("Open","Can not open session for file %s.",name);
+     return kFALSE;
+   }
+
+  OpenInput(nEvent);
+  OpenOutput();
+  return kTRUE;
 }
 
+
 //_____________________________________________________________________________
-void AliTRDclusterizer::Init()
+Bool_t AliTRDclusterizer::OpenOutput()
 {
   //
-  // Initializes the cluster finder
+  // Open the output file
   //
 
+  TObjArray *ioArray = 0;
+
+  AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+  loader->MakeTree("R");
+  fClusterTree = loader->TreeR();
+  fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+
+
+  return kTRUE;
+
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
+Bool_t AliTRDclusterizer::OpenInput(Int_t nEvent)
 {
   //
   // Opens a ROOT-file with TRD-hits and reads in the digits-tree
   //
 
   // Connect the AliRoot file containing Geometry, Kine, and Hits
-  fInputFile = (TFile*) gROOT->GetListOfFiles()->FindObject(name);
-  if (!fInputFile) {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("Open the ALIROOT-file %s.\n",name);
-    fInputFile = new TFile(name,"UPDATE");
-  }
-  else {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("%s is already open.\n",name);
+  fRunLoader->LoadgAlice();
+  gAlice = fRunLoader->GetAliRun();
+
+  if (!(gAlice)) {
+    fRunLoader->LoadgAlice();
+    gAlice = fRunLoader->GetAliRun();
+      if (!(gAlice)) {
+        printf("AliTRDclusterizer::OpenInput -- ");
+        printf("Could not find AliRun object.\n");
+        return kFALSE;
+      }
   }
 
-  // Get AliRun object from file or create it if not on file
-  //if (!gAlice) {
-    gAlice = (AliRun*) fInputFile->Get("gAlice");
-    if (gAlice) {
-      printf("AliTRDclusterizer::Open -- ");
-      printf("AliRun object found on file.\n");
-    }
-    else {
-      printf("AliTRDclusterizer::Open -- ");
-      printf("Could not find AliRun object.\n");
-      return kFALSE;
-    }
-  //}
-
   fEvent = nEvent;
 
   // Import the Trees for the event nEvent in the file
-  Int_t nparticles = gAlice->GetEvent(fEvent);
-  if (nparticles <= 0) {
-    printf("AliTRDclusterizer::Open -- ");
-    printf("No entries in the trees for event %d.\n",fEvent);
+  fRunLoader->GetEvent(fEvent);
+  
+  // Get the TRD object
+  fTRD = (AliTRD*) gAlice->GetDetector("TRD"); 
+  if (!fTRD) {
+    printf("AliTRDclusterizer::OpenInput -- ");
+    printf("No TRD detector object found\n");
     return kFALSE;
   }
 
@@ -175,20 +191,75 @@ Bool_t AliTRDclusterizer::Open(const Char_t *name, Int_t nEvent)
 }
 
 //_____________________________________________________________________________
-Bool_t AliTRDclusterizer::WriteCluster()
+Bool_t AliTRDclusterizer::WriteClusters(Int_t det)
 {
   //
-  // Writes out the TRD-cluster
+  // Fills TRDcluster branch in the tree with the clusters 
+  // found in detector = det. For det=-1 writes the tree. 
   //
 
-  // Write the new tree into the input file (use overwrite option)
-  Char_t treeName[7];
-  sprintf(treeName,"TreeR%d",fEvent);
-  printf("AliTRDclusterizer::WriteCluster -- ");
-  printf("Write the cluster tree %s for event %d.\n"
-        ,treeName,fEvent);
-  gAlice->TreeR()->Write(treeName,2);
+  if ((det < -1) || (det >= AliTRDgeometry::Ndet())) {
+    printf("AliTRDclusterizer::WriteClusters -- ");
+    printf("Unexpected detector index %d.\n",det);
+    return kFALSE;
+  }
 
-  return kTRUE;
+  TBranch *branch = fClusterTree->GetBranch("TRDcluster");
+  if (!branch) {
+    TObjArray *ioArray = 0;
+    branch = fClusterTree->Branch("TRDcluster","TObjArray",&ioArray,32000,0);
+  }
+
+  if ((det >= 0) && (det < AliTRDgeometry::Ndet())) {
+
+    Int_t nRecPoints = fTRD->RecPoints()->GetEntriesFast();
+    TObjArray *detRecPoints = new TObjArray(400);
+
+    for (Int_t i = 0; i < nRecPoints; i++) {
+      AliTRDcluster *c = (AliTRDcluster *) fTRD->RecPoints()->UncheckedAt(i);
+      if (det == c->GetDetector()) {
+        detRecPoints->AddLast(c);
+      }
+      else {
+        printf("AliTRDclusterizer::WriteClusters --");
+        printf("Attempt to write a cluster with unexpected detector index\n");
+      }
+    }
+
+    branch->SetAddress(&detRecPoints);
+    fClusterTree->Fill();
 
+    return kTRUE;
+
+  }
+
+  if (det == -1) {
+
+    printf("AliTRDclusterizer::WriteClusters -- ");
+    printf("Writing the cluster tree %-18s for event %d.\n"
+         ,fClusterTree->GetName(),fEvent);
+
+    fClusterTree->Write();
+
+    AliTRDgeometry *geo = fTRD->GetGeometry();
+    geo->SetName("TRDgeometry");
+    geo->Write();
+    fPar->Write();     
+     
+    return kTRUE;  
+
+  }
+  
+  AliLoader* loader = fRunLoader->GetLoader("TRDLoader");
+  loader->WriteDigits("OVERWRITE");
+  
+  printf("AliTRDclusterizer::WriteClusters -- ");
+  printf("Unexpected detector index %d.\n",det);
+  return kFALSE;  
+  
 }
+
+
+