]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliESDInputHandler.cxx
Geometry checked and corrected with sampling option.
[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 {
42   // default constructor
43 }
44
45 //______________________________________________________________________________
46 AliESDInputHandler::~AliESDInputHandler() 
47 {
48   // destructor
49   //  delete fEvent;
50 }
51
52 //______________________________________________________________________________
53 AliESDInputHandler::AliESDInputHandler(const char* name, const char* title):
54   AliInputEventHandler(name, title), fEvent(0x0), fBranches(""), fBranchesOn("")
55 {
56     // Constructor
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   return kTRUE;
88 }
89
90 Bool_t  AliESDInputHandler::FinishEvent()
91 {
92     // Finish the event 
93     if(fEvent)fEvent->Reset();
94     return kTRUE;
95
96
97 void AliESDInputHandler::SwitchOffBranches() const {
98   //
99   // Switch of branches on user request
100     TObjArray * tokens = fBranches.Tokenize(" ");
101     Int_t ntok = tokens->GetEntries();
102     for (Int_t i = 0; i < ntok; i++)  {
103         TString str = ((TObjString*) tokens->At(i))->GetString();
104         if (str.Length() == 0)
105             continue;
106         fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 0);
107         AliInfo(Form("Branch %s switched off \n", str.Data()));
108     }
109 }
110
111 void AliESDInputHandler::SwitchOnBranches() const {
112   //
113   // Switch of branches on user request
114   TObjArray * tokens = fBranchesOn.Tokenize(" ");
115   Int_t ntok = tokens->GetEntries();
116
117   for (Int_t i = 0; i < ntok; i++)  {
118       TString str = ((TObjString*) tokens->At(i))->GetString();
119       if (str.Length() == 0)
120           continue;
121       fTree->SetBranchStatus(Form("%s%s%s","*", str.Data(), "*"), 1);
122       AliInfo(Form("Branch %s switched on \n", str.Data()));
123   }
124 }