]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliESDInputHandler.cxx
Fix fixed-string length bug
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
index 9dd2d0aeff6a8dbcc3cf4c266f3b1315b9ab9b7c..e6e86712113532dc89cc2ea67fedb283c39b6e17 100644 (file)
 //-------------------------------------------------------------------------
 
 #include <TTree.h>
+#include <TString.h>
+#include <TObjString.h>
+#include <TProcessID.h>
 
 #include "AliESDInputHandler.h"
 #include "AliESDEvent.h"
 #include "AliESD.h"
+#include "AliLog.h"
 
 ClassImp(AliESDInputHandler)
 
 //______________________________________________________________________________
 AliESDInputHandler::AliESDInputHandler() :
   AliInputEventHandler(),
-  fEvent(0x0)
+  fEvent(0x0),
+  fBranches(""),
+  fBranchesOn("")
 {
   // default constructor
 }
@@ -45,34 +51,74 @@ AliESDInputHandler::~AliESDInputHandler()
 
 //______________________________________________________________________________
 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
-  AliInputEventHandler(name, title), fEvent(0x0)
+  AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn("")
 {
+    // Constructor
 }
 
-Bool_t AliESDInputHandler::InitIO(Option_t* /*opt*/)
+Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* /*opt*/)
 {
+    // Initialisation necessary for each new tree 
+    fTree = tree;
+    
     if (!fTree) return kFALSE;
     // Get pointer to ESD event
-    if(!fEvent){
-      fEvent = new AliESDEvent();
-      fEvent->ReadFromTree(fTree);
+    SwitchOffBranches();
+    SwitchOnBranches();
+    
+    if (fEvent) {
+      delete fEvent;
+      fEvent = 0;
     }
+    fEvent = new AliESDEvent();
+
+    fEvent->ReadFromTree(fTree);
     return kTRUE;
 }
 
 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
 {
     // Copy from old to new format if necessary
-    AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
-    if (old) {
+  AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
+  if (old) {
        ((AliESDEvent*)fEvent)->CopyFromOldESD();
        old->Reset();
-    }
-    return kTRUE;
+  }
+  return kTRUE;
 }
 
-Bool_t  AliESDInputHandler::FinishEvent(){
-  //  if(fEvent)fEvent->Reset();
-  return kTRUE;
+Bool_t  AliESDInputHandler::FinishEvent()
+{
+    // Finish the event 
+    if(fEvent)fEvent->Reset();
+    return kTRUE;
 } 
 
+void AliESDInputHandler::SwitchOffBranches() const {
+  //
+  // Switch of branches on user request
+    TObjArray * tokens = fBranches.Tokenize(" ");
+    Int_t ntok = tokens->GetEntries();
+    for (Int_t i = 0; i < ntok; i++)  {
+       TString str = ((TObjString*) tokens->At(i))->GetString();
+       if (str.Length() == 0)
+           continue;
+       fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
+       AliInfo(Form("Branch %s switched off \n", str.Data()));
+    }
+}
+
+void AliESDInputHandler::SwitchOnBranches() const {
+  //
+  // Switch of branches on user request
+  TObjArray * tokens = fBranchesOn.Tokenize(" ");
+  Int_t ntok = tokens->GetEntries();
+
+  for (Int_t i = 0; i < ntok; i++)  {
+      TString str = ((TObjString*) tokens->At(i))->GetString();
+      if (str.Length() == 0)
+         continue;
+      fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
+      AliInfo(Form("Branch %s switched on \n", str.Data()));
+  }
+}