- Reset TProcessID count after each event
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
CommitLineData
d3dd3d14 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
17
18//-------------------------------------------------------------------------
19// Event handler for ESD input
20// Author: Andreas Morsch, CERN
21//-------------------------------------------------------------------------
22
933fd60f 23#include <TTree.h>
300d5701 24#include <TString.h>
25#include <TObjString.h>
80e1b60a 26#include <TProcessID.h>
d3dd3d14 27
28#include "AliESDInputHandler.h"
29#include "AliESDEvent.h"
30#include "AliESD.h"
300d5701 31#include "AliLog.h"
d3dd3d14 32
33ClassImp(AliESDInputHandler)
34
35//______________________________________________________________________________
6989bff3 36AliESDInputHandler::AliESDInputHandler() :
37 AliInputEventHandler(),
0cd61c1d 38 fEvent(0x0),
865d620a 39 fBranches(""),
80e1b60a 40 fBranchesOn(""),
41 fNObjCount(0)
d3dd3d14 42{
43 // default constructor
44}
45
46//______________________________________________________________________________
47AliESDInputHandler::~AliESDInputHandler()
48{
6989bff3 49 // destructor
50 // delete fEvent;
d3dd3d14 51}
52
53//______________________________________________________________________________
54AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
e5d3ba1a 55 AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""),fNObjCount(0)
d3dd3d14 56{
57}
58
300d5701 59Bool_t AliESDInputHandler::Init(TTree* tree, Option_t* /*opt*/)
d3dd3d14 60{
300d5701 61 // Initialisation necessary for each new tree
62 fTree = tree;
63
6073f8c9 64 if (!fTree) return kFALSE;
d3dd3d14 65 // Get pointer to ESD event
300d5701 66 SwitchOffBranches();
3858dd64 67 SwitchOnBranches();
300d5701 68
60996693 69 if (fEvent) {
70 delete fEvent;
71 fEvent = 0;
6989bff3 72 }
60996693 73 fEvent = new AliESDEvent();
74
75 fEvent->ReadFromTree(fTree);
d3dd3d14 76 return kTRUE;
77}
78
ed97dc98 79Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
d3dd3d14 80{
81 // Copy from old to new format if necessary
d7749dec 82 AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
83 if (old) {
d3dd3d14 84 ((AliESDEvent*)fEvent)->CopyFromOldESD();
85 old->Reset();
d7749dec 86 }
80e1b60a 87 fNObjCount = TProcessID::GetObjectCount();
88
d7749dec 89 return kTRUE;
d3dd3d14 90}
91
6989bff3 92Bool_t AliESDInputHandler::FinishEvent(){
d7749dec 93 if(fEvent)fEvent->Reset();
80e1b60a 94 TProcessID::SetObjectCount(fNObjCount);
6989bff3 95 return kTRUE;
96}
97
300d5701 98void AliESDInputHandler::SwitchOffBranches() const {
99 //
100 // Switch of branches on user request
3858dd64 101 TObjArray * tokens = fBranches.Tokenize(" ");
102 Int_t ntok = tokens->GetEntries();
103 for (Int_t i = 0; i < ntok; i++) {
104 TString str = ((TObjString*) tokens->At(i))->GetString();
105 if (str.Length() == 0)
106 continue;
107 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
108 AliInfo(Form("Branch %s switched off \n", str.Data()));
109 }
110}
111
112void AliESDInputHandler::SwitchOnBranches() const {
113 //
114 // Switch of branches on user request
115 TObjArray * tokens = fBranchesOn.Tokenize(" ");
300d5701 116 Int_t ntok = tokens->GetEntries();
3858dd64 117
300d5701 118 for (Int_t i = 0; i < ntok; i++) {
3858dd64 119 TString str = ((TObjString*) tokens->At(i))->GetString();
120 if (str.Length() == 0)
121 continue;
122 fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
123 AliInfo(Form("Branch %s switched on \n", str.Data()));
300d5701 124 }
125}