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