]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
effc++ corrections
[u/mrichter/AliRoot.git] / STEER / AliESDInputHandler.cxx
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
23 #include <TTree.h>
24 #include <TString.h>
25 #include <TObjString.h>
26 #include <TProcessID.h>
27
28 #include "AliESDInputHandler.h"
29 #include "AliESDEvent.h"
30 #include "AliESD.h"
31 #include "AliLog.h"
32
33 ClassImp(AliESDInputHandler)
34
35 //______________________________________________________________________________
36 AliESDInputHandler::AliESDInputHandler() :
37   AliInputEventHandler(),
38   fEvent(0x0),
39   fBranches(""),
40   fBranchesOn(""),
41   fNObjCount(0)
42 {
43   // default constructor
44 }
45
46 //______________________________________________________________________________
47 AliESDInputHandler::~AliESDInputHandler() 
48 {
49   // destructor
50   //  delete fEvent;
51 }
52
53 //______________________________________________________________________________
54 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
55   AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn(""),fNObjCount(0)
56 {
57 }
58
59 Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* /*opt*/)
60 {
61     // Initialisation necessary for each new tree 
62     fTree = tree;
63     
64     if (!fTree) return kFALSE;
65     // Get pointer to ESD event
66     SwitchOffBranches();
67     SwitchOnBranches();
68     
69     if (fEvent) {
70       delete fEvent;
71       fEvent = 0;
72     }
73     fEvent = new AliESDEvent();
74
75     fEvent->ReadFromTree(fTree);
76     return kTRUE;
77 }
78
79 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
80 {
81     // Copy from old to new format if necessary
82   AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
83   if (old) {
84         ((AliESDEvent*)fEvent)->CopyFromOldESD();
85         old->Reset();
86   }
87   fNObjCount = TProcessID::GetObjectCount();
88
89   return kTRUE;
90 }
91
92 Bool_t  AliESDInputHandler::FinishEvent(){
93   if(fEvent)fEvent->Reset();
94   TProcessID::SetObjectCount(fNObjCount);
95   return kTRUE;
96
97
98 void AliESDInputHandler::SwitchOffBranches() const {
99   //
100   // Switch of branches on user request
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
112 void AliESDInputHandler::SwitchOnBranches() const {
113   //
114   // Switch of branches on user request
115   TObjArray * tokens = fBranchesOn.Tokenize(" ");
116   Int_t ntok = tokens->GetEntries();
117
118   for (Int_t i = 0; i < ntok; i++)  {
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()));
124   }
125 }