]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/AliSelector.cxx
debug is read from option string
[u/mrichter/AliRoot.git] / PWG0 / AliSelector.cxx
index ff1ddccb9da02088b04a5e7c8ad1ae1eb44ca9fb..12b5a5f75145144c519db891f372facc85281c9e 100644 (file)
@@ -1,3 +1,5 @@
+/* $Id$ */
+
 // The class definition in esdV0.h has been generated automatically
 // by the ROOT utility TTree::MakeSelector(). This class is derived
 // from the ROOT class TSelector. For more information on the TSelector
 //
 
 #include "AliSelector.h"
+
 #include <TStyle.h>
 #include <TSystem.h>
 #include <TCanvas.h>
 #include <TRegexp.h>
-
+#include <TTime.h>
 #include <TFriendElement.h>
+#include <TTree.h>
+#include <TChain.h>
+#include <TFile.h>
 
-#include <iostream>
-using namespace std;
+#include <AliLog.h>
+#include <AliESD.h>
 
 ClassImp(AliSelector)
 
-AliSelector::AliSelector(TTree *) :
+AliSelector::AliSelector() :
   TSelector(),
-  fChain(0),
+  fTree(0),
   fESD(0),
-  fHeader(0),
-  fKineFile(0),
-  fRunLoader(0)
+  fCountFiles(0),
+  fKineFile(0)
 {
   //
   // Constructor. Initialization of pointers
@@ -58,28 +63,43 @@ AliSelector::~AliSelector()
   // list is deleted by the TSelector dtor
 }
 
-void AliSelector::Begin(TTree *)
+void AliSelector::Begin(TTree*)
 {
   // The Begin() function is called at the start of the query.
   // When running with PROOF Begin() is only called on the client.
   // The tree argument is deprecated (on PROOF 0 is passed).
+
+  TString option = GetOption();
+
+  if (option.Contains("debug"))
+  {
+    AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
+    AliInfo(Form("Called with option %s.", option.Data()));
+  }
+
+  AliDebug(AliLog::kDebug, "============BEGIN===========");
 }
 
-void AliSelector::SlaveBegin(TTree * tree)
+void AliSelector::SlaveBegin(TTree* tree)
 {
   // The SlaveBegin() function is called after the Begin() function.
   // When running with PROOF SlaveBegin() is called on each slave server.
   // The tree argument is deprecated (on PROOF 0 is passed).
 
-  Init(tree);
+  TString option = GetOption();
 
-  printf("=======SLAVEBEGIN========\n");
-  gSystem->Exec("hostname");
-  gSystem->Exec("date");
-  TFile *f = fChain->GetCurrentFile();
-  printf("%s\n",f->GetName());
+  if (option.Contains("debug"))
+  {
+    AliLog::SetClassDebugLevel("AliSelector", AliLog::kDebug);
+    AliInfo(Form("Called with option %s.", option.Data()));
+  }
 
-  TString option = GetOption();
+  AliDebug(AliLog::kDebug, "=======SLAVEBEGIN========");
+  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+  AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
+
+  if (tree != 0)
+    Init(tree);
 }
 
 void AliSelector::Init(TTree *tree)
@@ -90,30 +110,20 @@ void AliSelector::Init(TTree *tree)
   // generated code, but the routine can be extended by the user if needed.
   // Init() will be called many times when running with PROOF.
 
-  printf("=========Init==========\n");
+  AliDebug(AliLog::kDebug, "=========Init==========");
 
-  // Set branch addresses
-  if (tree == 0)
-  {
-    printf("ERROR: tree argument is 0.\n");
-    return;
-  }
+  fTree = tree;
 
-  fChain = dynamic_cast<TChain*> (tree);
-  if (fChain == 0)
+  if (fTree == 0)
   {
-    printf("ERROR: tree argument could not be casted to TChain.\n");
+    AliDebug(AliLog::kError, "ERROR: tree argument is 0.");
     return;
   }
 
-  fChain->SetBranchAddress("ESD", &fESD);
+  // Set branch address
+  fTree->SetBranchAddress("ESD", &fESD);
   if (fESD != 0)
-    printf("INFO: Found ESD branch in chain.\n");
-
-  fChain->SetBranchAddress("Header", &fHeader);
-  if (fHeader != 0)
-    printf("INFO: Found event header branch in chain.\n");
-
+    AliDebug(AliLog::kInfo, "INFO: Found ESD branch in chain.");
 }
 
 Bool_t AliSelector::Notify()
@@ -125,15 +135,22 @@ Bool_t AliSelector::Notify()
   // to the generated code, but the routine can be extended by the
   // user if needed.
 
-  printf("=========NOTIFY==========\n");
-  gSystem->Exec("hostname");
-  gSystem->Exec("date");
-  TFile *f = fChain->GetCurrentFile();
-  TString fileName(f->GetName());
-  printf("%s\n",fileName.Data());
+  AliDebug(AliLog::kDebug, "=========NOTIFY==========");
+  AliDebug(AliLog::kDebug, Form("Hostname: %s", gSystem->HostName()));
+  AliDebug(AliLog::kDebug, Form("Time: %s", gSystem->Now().AsString()));
+
+  ++fCountFiles;
+  if (fTree)
+  {
+    TFile *f = fTree->GetCurrentFile();
+    AliDebug(AliLog::kInfo, Form("Processing %d. file %s", fCountFiles, f->GetName()));
+  }
+  else
+  {
+    AliDebug(AliLog::kError, "fTree not available");
+  }
 
   DeleteKinematicsFile();
-  DeleteRunLoader();
 
   return kTRUE;
 }
@@ -155,30 +172,21 @@ Bool_t AliSelector::Process(Long64_t entry)
   // WARNING when a selector is used with a TChain, you must use
   //  the pointer to the current TTree to call GetEntry(entry).
   //  The entry is always the local entry number in the current tree.
-  //  Assuming that fChain is the pointer to the TChain being processed,
-  //  use fChain->GetTree()->GetEntry(entry).
+  //  Assuming that fTree is the pointer to the TChain being processed,
+  //  use fTree->GetTree()->GetEntry(entry).
 
-  printf("=========PROCESS========== Entry %lld\n", entry);
+  AliDebug(AliLog::kDebug, Form("=========PROCESS========== Entry %lld", entry));
 
-  if (!fChain)
+  if (!fTree)
   {
-    printf("ERROR: fChain is 0.\n");
+    AliDebug(AliLog::kError, "ERROR: fTree is 0.");
     return kFALSE;
   }
 
-  fChain->GetTree()->GetEntry(entry);
+  fTree->GetTree()->GetEntry(entry);
 
   if (fESD)
-    printf("ESD: We have %d tracks.\n", fESD->GetNumberOfTracks());
-
-  if (fHeader)
-    printf("Header: We have %d primaries.\n", fHeader->GetNprimary());
-
-  TTree* kinematics = GetKinematics();
-  if (kinematics)
-    printf("Kinematics from folder: We have %lld particles.\n", kinematics->GetEntries());
-
-  printf("\n");
+    AliDebug(AliLog::kDebug, Form("ESD: We have %d tracks.", fESD->GetNumberOfTracks()));
 
   return kTRUE;
 }
@@ -189,8 +197,9 @@ void AliSelector::SlaveTerminate()
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.
 
+  AliDebug(AliLog::kDebug, "=======SLAVETERMINATE=======");
+
   DeleteKinematicsFile();
-  DeleteRunLoader();
 }
 
 void AliSelector::Terminate()
@@ -199,62 +208,31 @@ void AliSelector::Terminate()
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.
 
-  printf("=========TERMINATE==========\n");
+  AliDebug(AliLog::kDebug, "=========TERMINATE==========");
 }
 
 TTree* AliSelector::GetKinematics()
 {
-  // Returns kinematics tree corresponding to current ESD active in fChain
+  // Returns kinematics tree corresponding to current ESD active in fTree
   // Loads the kinematics from the kinematics file, the file is identified by replacing "AliESDs" to
   // "Kinematics" in the file path of the ESD file. This is a hack, to be changed!
 
   if (!fKineFile)
   {
-    if (!fChain->GetCurrentFile())
+    if (!fTree->GetCurrentFile())
       return 0;
 
-    TString fileName(fChain->GetCurrentFile()->GetName());
+    TString fileName(fTree->GetCurrentFile()->GetName());
     fileName.ReplaceAll("AliESDs", "Kinematics");
 
+    AliDebug(AliLog::kInfo, Form("Opening %s", fileName.Data()));
+
     fKineFile = TFile::Open(fileName);
     if (!fKineFile)
       return 0;
   }
 
-  return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fChain->GetTree()->GetReadEntry())));
-
-  /* this is if we want to get it from a TChain
-
-  define it in the header:
-
-    TChain*          fKineChain;
-
-  this creates the chain:
-
-    TChain* chainKine = new TChain("TreeK");
-    for (Int_t i=0; i<20; ++i)
-      chainKine->Add(Form("test/Kinematics.root/Event%d/TreeK", i));
-    for (Int_t i=0; i<20; ++i)
-      chainKine->Add(Form("test2/Kinematics.root/Event%d/TreeK", i));
-
-    <mainChain>->GetUserInfo()->Add(chainKine);
-
-  we retrieve it in init:
-
-    fKineChain = dynamic_cast<TChain*> (fChain->GetUserInfo()->FindObject("TreeK"));
-
-  and use it in process:
-
-    if (fKineChain)
-    {
-      Long64_t entryK = fKineChain->GetTreeOffset()[fChain->GetChainEntryNumber(entry)];
-      cout << "Entry in fKineChain: " << entryK << endl;
-      fKineChain->LoadTree(entryK);
-      TTree* kineTree = fKineChain->GetTree();
-
-      printf("Kinematics from tree friend: We have %lld particles.\n", kineTree->GetEntries());
-    }
-  */
+  return dynamic_cast<TTree*> (fKineFile->Get(Form("Event%d/TreeK", fTree->GetTree()->GetReadEntry())));
 }
 
 void AliSelector::DeleteKinematicsFile()
@@ -270,40 +248,3 @@ void AliSelector::DeleteKinematicsFile()
     fKineFile = 0;
   }
 }
-
-AliRun* AliSelector::GetAliRun()
-{
-  // Returns AliRun instance corresponding to current ESD active in fChain
-  // Loads galice.root, the file is identified by replacing "AliESDs" to
-  // "galice" in the file path of the ESD file. This is a hack, to be changed!
-
-  if (!fRunLoader)
-  {
-    if (!fChain->GetCurrentFile())
-      return 0;
-
-    TString fileName(fChain->GetCurrentFile()->GetName());
-    fileName.ReplaceAll("AliESDs", "galice");
-
-    fRunLoader = AliRunLoader::Open(fileName);
-    if (!fRunLoader)
-      return 0;
-
-    fRunLoader->LoadgAlice();
-  }
-
-  return fRunLoader->GetAliRun();
-}
-
-void AliSelector::DeleteRunLoader()
-{
-  //
-  // deletes the runloader
-  //
-  
-  if (fRunLoader)
-  {
-    fRunLoader->Delete();
-    fRunLoader = 0;
-  }
-}