]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
Fix a problem with old UserInfo written to the cloned TTree.
[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
27 #include "AliESDInputHandler.h"
28 #include "AliESDEvent.h"
29 #include "AliESD.h"
30 #include "AliLog.h"
31
32 ClassImp(AliESDInputHandler)
33
34 //______________________________________________________________________________
35 AliESDInputHandler::AliESDInputHandler() :
36   AliInputEventHandler(),
37   fEvent(0x0),
38   fBranches(""),
39   fBranchesOn("")
40 {
41   // default constructor
42 }
43
44 //______________________________________________________________________________
45 AliESDInputHandler::~AliESDInputHandler() 
46 {
47   // destructor
48   //  delete fEvent;
49 }
50
51 //______________________________________________________________________________
52 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
53     AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn("")
54 {
55 }
56
57 Bool_t AliESDInputHandler::Init(TTree* tree,  Option_t* /*opt*/)
58 {
59     // Initialisation necessary for each new tree 
60     fTree = tree;
61     
62     if (!fTree) return kFALSE;
63     // Get pointer to ESD event
64     SwitchOffBranches();
65     SwitchOnBranches();
66     
67     if (fEvent) {
68       delete fEvent;
69       fEvent = 0;
70     }
71     fEvent = new AliESDEvent();
72
73     fEvent->ReadFromTree(fTree);
74     return kTRUE;
75 }
76
77 Bool_t AliESDInputHandler::BeginEvent(Long64_t /*entry*/)
78 {
79     // Copy from old to new format if necessary
80   AliESD* old = ((AliESDEvent*) fEvent)->GetAliESDOld();
81   if (old) {
82         ((AliESDEvent*)fEvent)->CopyFromOldESD();
83         old->Reset();
84   }
85   return kTRUE;
86 }
87
88 Bool_t  AliESDInputHandler::FinishEvent(){
89   if(fEvent)fEvent->Reset();
90   return kTRUE;
91
92
93 void AliESDInputHandler::SwitchOffBranches() const {
94   //
95   // Switch of branches on user request
96     TObjArray * tokens = fBranches.Tokenize(" ");
97     Int_t ntok = tokens->GetEntries();
98     for (Int_t i = 0; i < ntok; i++)  {
99         TString str = ((TObjString*) tokens->At(i))->GetString();
100         if (str.Length() == 0)
101             continue;
102         fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
103         AliInfo(Form("Branch %s switched off \n", str.Data()));
104     }
105 }
106
107 void AliESDInputHandler::SwitchOnBranches() const {
108   //
109   // Switch of branches on user request
110   TObjArray * tokens = fBranchesOn.Tokenize(" ");
111   Int_t ntok = tokens->GetEntries();
112
113   for (Int_t i = 0; i < ntok; i++)  {
114       TString str = ((TObjString*) tokens->At(i))->GetString();
115       if (str.Length() == 0)
116           continue;
117       fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
118       AliInfo(Form("Branch %s switched on \n", str.Data()));
119   }
120 }