]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliReaderESDTree.cxx
ReaderESDtree, MUON analysis, reading MUON data froESD in ReaderESD (Christian FINCK)
[u/mrichter/AliRoot.git] / ANALYSIS / AliReaderESDTree.cxx
CommitLineData
beb1c41d 1#include "AliReaderESDTree.h"
2//_______________________________________________________________________
3/////////////////////////////////////////////////////////////////////////
4//
5// class AliReaderESDTree
6//
7// Reader for MUON ESD Tree (only for rec)
8//
9// finck@subatech.in2p3.fr
10//
11/////////////////////////////////////////////////////////////////////////
12
13#include <TString.h>
14#include <TTree.h>
15#include <TFile.h>
16
17
18#include <AliRun.h>
19#include <AliRunLoader.h>
20
21#include <AliESD.h>
22#include "AliAOD.h"
23
24ClassImp(AliReaderESDTree)
25
26AliReaderESDTree::AliReaderESDTree(const Char_t* esdfilename, const Char_t* galfilename):
27 AliReaderESD(esdfilename,galfilename),
28 fTree(0x0)
29{
30//ctor
31}
32
33/********************************************************************/
34AliReaderESDTree::~AliReaderESDTree()
35{
36//dtor
37 delete fTree;
38}
39
40/**********************************************************/
41Int_t AliReaderESDTree::ReadNext()
42{
43//reads next event from fFile
44//fRunLoader is for reading Kine
45
46 if (AliVAODParticle::GetDebug())
47 Info("ReadNext","Entered");
48
49 if (fEventSim == 0x0) fEventSim = new AliAOD();
50 if (fEventRec == 0x0) fEventRec = new AliAOD();
51
52 fEventSim->Reset();
53 fEventRec->Reset();
54
55 do //do{}while; is OK even if 0 dirs specified. In that case we try to read from "./"
56 {
57 if (fFile == 0x0)
58 {
59 fFile = OpenFile(fCurrentDir);//rl is opened here
60 if (fFile == 0x0)
61 {
62 Error("ReadNext","Cannot get fFile for dir no. %d",fCurrentDir);
63 fCurrentDir++;
64 continue;
65 }
66 fCurrentEvent = 0;
67 }
68
69 static AliESD* esd = 0x0;
70 fTree->SetBranchAddress("ESD", &esd);
71 Int_t status = fTree->GetEvent(fCurrentEvent);
72
73 if (!status)
74 {
75 if (AliVAODParticle::GetDebug() > 2 )
76 {
77 Info("ReadNext","Can not find event# %d in Tree", fCurrentEvent);
78 }
79 fCurrentDir++;
80 delete fFile;//we have to assume there is no more ESD objects in the fFile
81 fFile = 0x0;
82 delete fRunLoader;
83 fRunLoader = 0x0;
84 continue;
85 }
86
87 ReadESD(esd);
88
89 fCurrentEvent++;
90 fNEventsRead++;
91 return 0;//success -> read one event
92 }while(fCurrentDir < GetNumberOfDirs());//end of loop over directories specified in fDirs Obj Array
93
94 return 1; //no more directories to read
95}
96
97/**********************************************************/
98TFile* AliReaderESDTree::OpenFile(Int_t n)
99{
100//opens fFile with kine tree
101
102 const TString& dirname = GetDirName(n);
103 if (dirname == "")
104 {
105 Error("OpenFiles","Can not get directory name");
106 return 0x0;
107 }
108 TString filename = dirname +"/"+ fESDFileName;
109 TFile *ret = TFile::Open(filename.Data());
110
111 if (ret == 0x0)
112 {
113 Error("OpenFiles","Can't open fFile %s",filename.Data());
114 return 0x0;
115 }
116 if (!ret->IsOpen())
117 {
118 Error("OpenFiles","Can't open fFile %s",filename.Data());
119 return 0x0;
120 }
121
122 TString esdname = "esdTree";
123 fTree = dynamic_cast<TTree*> (ret->Get(esdname));
124
125 if (!fTree)
126 {
127 Error("OpenFiles","Can't open ESD Tree %s",esdname.Data());
128 return 0x0;
129
130 }
131
132 if (fReadSim )
133 {
134 fRunLoader = AliRunLoader::Open(dirname +"/"+ fGAlFileName);
135 if (fRunLoader == 0x0)
136 {
137 Error("OpenFiles","Can't get RunLoader for directory %s",dirname.Data());
138 delete ret;
139 return 0x0;
140 }
141
142 fRunLoader->LoadHeader();
143 if (fRunLoader->LoadKinematics())
144 {
145 Error("Next","Error occured while loading kinematics.");
146 delete fRunLoader;
147 delete ret;
148 return 0x0;
149 }
150 }
151
152 return ret;
153}