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