]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliDetector.cxx
Transition to NewIO
[u/mrichter/AliRoot.git] / STEER / AliDetector.cxx
index 3b64bd66948ce8f6ec219f41efd47a3f944212a4..b3897c432ebbe520b3f94635ad2230596484dcae 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.7  2000/10/02 21:28:14  fca
-Removal of useless dependecies via forward declarations
-
-Revision 1.6  2000/07/12 08:56:25  fca
-Coding convention correction and warning removal
-
-Revision 1.5  1999/09/29 09:24:29  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -44,36 +33,75 @@ Introduction of the Copyright and cvs Log
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
+#include <assert.h>
+
+#include <TBrowser.h>
+#include <TFile.h>
+#include <TFolder.h>
+#include <TROOT.h>
 #include <TTree.h>
-#include "TBrowser.h"
+#include <Riostream.h>
 
+#include "AliConfig.h"
 #include "AliDetector.h"
-#include "AliRun.h"
 #include "AliHit.h"
 #include "AliPoints.h"
+#include "AliLoader.h"
+#include "AliRun.h"
+
+
 // Static variables for the hit iterator routines
 static Int_t sMaxIterHit=0;
 static Int_t sCurIterHit=0;
 
+
 ClassImp(AliDetector)
  
-//_____________________________________________________________________________
-AliDetector::AliDetector()
+//_______________________________________________________________________
+AliDetector::AliDetector():
+  fTimeGate(200.e-9),
+  fIshunt(0),
+  fNhits(0),
+  fNdigits(0),
+  fBufferSize(1600),
+  fHits(0),
+  fDigits(0),
+  fPoints(0),
+  fLoader(0x0)
 {
   //
   // Default constructor for the AliDetector class
   //
-  fNhits      = 0;
-  fNdigits    = 0;
-  fPoints     = 0;
-  fHits       = 0;
-  fDigits     = 0;
-  fTimeGate   = 200.e-9;
-  fBufferSize = 16000;
 }
  
+//_______________________________________________________________________
+AliDetector::AliDetector(const AliDetector &det):
+  AliModule(det),
+  fTimeGate(200.e-9),
+  fIshunt(0),
+  fNhits(0),
+  fNdigits(0),
+  fBufferSize(1600),
+  fHits(0),
+  fDigits(0),
+  fPoints(0),
+  fLoader(0x0)
+{
+  det.Copy(*this);
+}
+
 //_____________________________________________________________________________
-AliDetector::AliDetector(const char* name,const char *title):AliModule(name,title)
+AliDetector::AliDetector(const char* name,const char *title):
+  AliModule(name,title),
+  fTimeGate(200.e-9),
+  fIshunt(0),
+  fNhits(0),
+  fNdigits(0),
+  fBufferSize(1600),
+  fHits(0),
+  fDigits(0),
+  fPoints(0),
+  fLoader(0x0)
 {
   //
   // Normal constructor invoked by all Detectors.
@@ -81,32 +109,94 @@ AliDetector::AliDetector(const char* name,const char *title):AliModule(name,titl
   // Add this Detector to the global list of Detectors in Run.
   //
 
-  fTimeGate   = 200.e-9;
   fActive     = kTRUE;
-  fNhits      = 0;
-  fHits       = 0;
-  fDigits     = 0;
-  fNdigits    = 0;
-  fPoints     = 0;
-  fBufferSize = 16000;
+  AliConfig::Instance()->Add(this);
+
 }
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 AliDetector::~AliDetector()
 {
   //
   // Destructor
   //
-  fNhits      = 0;
-  fNdigits    = 0;
-  //
+
   // Delete space point structure
-  if (fPoints) fPoints->Delete();
-  delete fPoints;
-  fPoints     = 0;
+  if (fPoints) {
+    fPoints->Delete();
+    delete fPoints;
+    fPoints     = 0;
+  }
+  // Delete digits structure
+  if (fDigits) {
+    fDigits->Delete();
+    delete fDigits;
+    fDigits     = 0;
+  }
+
+  if (fLoader)
+   {
+    fLoader->GetModulesFolder()->Remove(this);
+   }
+
 }
-//_____________________________________________________________________________
+
+//_______________________________________________________________________
+void AliDetector::Publish(const char *dir, void *address, const char *name)
+{
+//
+// Register pointer to detector objects. 
+// 
+//  TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
+  MayNotUse("Publish");
+}
+
+//_______________________________________________________________________
+TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, 
+                                       void* address, Int_t size,
+                                       const char *file)
+{ 
+    return(MakeBranchInTree(tree,name,0,address,size,99,file));
+}
+
+//_______________________________________________________________________
+TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, 
+                                       const char *classname, 
+                                       void* address,Int_t size, 
+                                       Int_t splitlevel, const char *file)
+{ 
+//
+// Makes branch in given tree and diverts them to a separate file
+// 
+//
+//
+// if (GetDebug()>1)
+ if(GetDebug()) Info("MakeBranch","Making Branch %s",name);
+ if (tree == 0x0) 
+  {
+   Error("MakeBranch","Making Branch %s Tree is NULL",name);
+   return 0x0;
+  }
+ TBranch *branch = tree->GetBranch(name);
+ if (branch) 
+  {  
+    if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",name);
+    return branch;
+  }
+    
+ if (classname) 
+  {
+    branch = tree->Branch(name,classname,address,size,splitlevel);
+  } 
+ else 
+  {
+    branch = tree->Branch(name,address,size);
+  }
+ if(GetDebug()) Info("MakeBranch","Branch %s returning branch %#x",name,branch);
+ return branch;
+}
+
+//_______________________________________________________________________
 void AliDetector::Browse(TBrowser *b)
 {
   //
@@ -125,16 +215,16 @@ void AliDetector::Browse(TBrowser *b)
   }
 }
 
-//_____________________________________________________________________________
-void AliDetector::Copy(AliDetector &det) const
+//_______________________________________________________________________
+void AliDetector::Copy(AliDetector &) const
 {
   //
   // Copy *this onto det -- not implemented
   //
-  Fatal("Copy","Not implemented~\n");
+  Fatal("Copy","Not implemented\n");
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::FinishRun()
 {
   //
@@ -142,7 +232,7 @@ void AliDetector::FinishRun()
   //
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 AliHit* AliDetector::FirstHit(Int_t track)
 {
   //
@@ -153,17 +243,17 @@ AliHit* AliDetector::FirstHit(Int_t track)
   // track is returned
   // 
   if(track>=0) {
-    gAlice->ResetHits();
-    gAlice->TreeH()->GetEvent(track);
+    gAlice->ResetHits(); //stupid = if N detector this method is called N times
+    TreeH()->GetEvent(track); //skowron
   }
   //
   sMaxIterHit=fHits->GetEntriesFast();
   sCurIterHit=0;
-  if(sMaxIterHit) return (AliHit*) fHits->UncheckedAt(0);
+  if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
   else            return 0;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 AliHit* AliDetector::NextHit()
 {
   //
@@ -171,7 +261,7 @@ AliHit* AliDetector::NextHit()
   //
   if(sMaxIterHit) {
     if(++sCurIterHit<sMaxIterHit) 
-      return (AliHit*) fHits->UncheckedAt(sCurIterHit);
+      return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
     else        
       return 0;
   } else {
@@ -180,16 +270,24 @@ AliHit* AliDetector::NextHit()
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::LoadPoints(Int_t)
 {
   //
   // Store x, y, z of all hits in memory
   //
-  if (fHits == 0) return;
+  if (fHits == 0) 
+   {
+    Error("LoadPoints","fHits == 0. Name is %s",GetName());
+    return;
+   }
   //
   Int_t nhits = fHits->GetEntriesFast();
-  if (nhits == 0) return;
+  if (nhits == 0) 
+   {
+//    Error("LoadPoints","nhits == 0. Name is %s",GetName());
+    return;
+   }
   Int_t tracks = gAlice->GetNtrack();
   if (fPoints == 0) fPoints = new TObjArray(tracks);
   AliHit *ahit;
@@ -210,21 +308,26 @@ void AliDetector::LoadPoints(Int_t)
   //
   // Loop over all the hits and store their position
   for (Int_t hit=0;hit<nhits;hit++) {
-    ahit = (AliHit*)fHits->UncheckedAt(hit);
+    ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
     trk=ahit->GetTrack();
-    if(ntrk[trk]==limi[trk]) {
+    assert(trk<=tracks);
+    if(ntrk[trk]==limi[trk])
+     {
       //
       // Initialise a new track
       fp=new Float_t[3*(limi[trk]+chunk)];
-      if(coor[trk]) {
-       memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
-       delete [] coor[trk];
-      }
+      if(coor[trk]) 
+       {
+          memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
+          delete [] coor[trk];
+       }
       limi[trk]+=chunk;
       coor[trk] = fp;
-    } else {
+     } 
+    else 
+     {
       fp = coor[trk];
-    }
+     }
     fp[3*ntrk[trk]  ] = ahit->X();
     fp[3*ntrk[trk]+1] = ahit->Y();
     fp[3*ntrk[trk]+2] = ahit->Z();
@@ -249,46 +352,43 @@ void AliDetector::LoadPoints(Int_t)
   delete [] limi;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::MakeBranch(Option_t *option)
 {
   //
-  // Create a new branch in the current Root Tree
-  // The branch of fHits is automatically split
-  //
-  char branchname[10];
-  sprintf(branchname,"%s",GetName());
-  //
-  // Get the pointer to the header
-  char *cH = strstr(option,"H");
+  // Create a new branch for this detector in its treeH
   //
-  if (fHits   && gAlice->TreeH() && cH) {
-    gAlice->TreeH()->Branch(branchname,&fHits, fBufferSize);
-    printf("* AliDetector::MakeBranch * Making Branch %s for hits\n",branchname);
-  }    
+
+  if(GetDebug()) Info("MakeBranch"," for %s",GetName());
+  const char *cH = strstr(option,"H");
+
+  if (fHits && TreeH() && cH) 
+   {
+     MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
+   }   
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::ResetDigits()
 {
   //
   // Reset number of digits and the digits array
   //
   fNdigits   = 0;
-  if (fDigits)   fDigits->Clear();
+  if (fDigits) fDigits->Clear();
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::ResetHits()
 {
   //
   // Reset number of hits and the hits array
   //
   fNhits   = 0;
-  if (fHits)   fHits->Clear();
+  if (fHits) fHits->Clear();
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::ResetPoints()
 {
   //
@@ -301,64 +401,85 @@ void AliDetector::ResetPoints()
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliDetector::SetTreeAddress()
 {
   //
   // Set branch address for the Hits and Digits Trees
   //
   TBranch *branch;
-  char branchname[20];
-  sprintf(branchname,"%s",GetName());
   //
   // Branch address for hit tree
-  TTree *treeH = gAlice->TreeH();
-  if (treeH && fHits) {
-    branch = treeH->GetBranch(branchname);
-    if (branch) branch->SetAddress(&fHits);
+  
+  TTree *tree = TreeH();
+  if (tree && fHits) {
+    branch = tree->GetBranch(GetName());
+    if (branch) 
+     {
+       if(GetDebug()) Info("SetTreeAddress","(%s) Setting for Hits",GetName());
+       branch->SetAddress(&fHits);
+     }
+    else
+     {
+       Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
+     }
   }
+  
   //
   // Branch address for digit tree
-  TTree *treeD = gAlice->TreeD();
+  TTree *treeD = fLoader->TreeD();
   if (treeD && fDigits) {
-    branch = treeD->GetBranch(branchname);
+    branch = treeD->GetBranch(GetName());
     if (branch) branch->SetAddress(&fDigits);
   }
+  
+  AliModule::SetTreeAddress();
 }
 
-//_____________________________________________________________________________
-void AliDetector::Streamer(TBuffer &R__b)
-{
-  //
-  // Stream an object of class Detector.
-  //
-  if (R__b.IsReading()) {
-    Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    AliModule::Streamer(R__b);
-    R__b >> fTimeGate;
-    R__b >> fIshunt;
-    //R__b >> fNhits;
-    //
-    // Stream the pointers but not the TClonesArrays
-    R__b >> fHits; // diff
-    R__b >> fDigits; // diff
-    
-  } else {
-    R__b.WriteVersion(AliDetector::IsA());
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    AliModule::Streamer(R__b);
-    R__b << fTimeGate;
-    R__b << fIshunt;
-    //R__b << fNhits;
-    //
-    // Stream the pointers but not the TClonesArrays
-    R__b << fHits; // diff
-    R__b << fDigits; // diff
-  }
+//_______________________________________________________________________
+void AliDetector::MakeTree(Option_t *option)
+ {
+ //makes a tree (container) for the data defined in option
+ //"H" - hits
+ //"D" - digits
+ //"S" - summable digits
+ //"R" - recontructed points and tracks
+    AliLoader* loader = GetLoader();
+    if (loader == 0x0)
+     {
+       Error("MakeTree","Can not get loader for %s",GetName());
+       return;
+     }
+    loader->MakeTree(option); //delegate this job to getter
+ }
+
+//_______________________________________________________________________
+AliLoader* AliDetector::MakeLoader(const char* topfoldername)
+{ 
+//builds standard getter (AliLoader type)
+//if detector wants to use castomized getter, it must overload this method
+
+ cout<<"AliDetector::MakeLoader: Creating standard getter for detector "<<GetName()
+     <<". top folder is "<<topfoldername<<endl;
+     
+ fLoader = new AliLoader(GetName(),topfoldername);
+ return fLoader;
 }
+
+//_______________________________________________________________________
+TTree* AliDetector::TreeH()
+{
+//Get the hits container from the folder
+  if (GetLoader() == 0x0) 
+    {
+    //sunstitude this with make getter when we can obtain the event folder name 
+     Error("TreeH","Can not get the getter");
+     return 0x0;
+    }
  
+  TTree* tree = (TTree*)GetLoader()->TreeH();
+  return tree;
+}
+