Getter to TGeoManager
[u/mrichter/AliRoot.git] / EVE / Alieve / EventAlieve.cxx
CommitLineData
5a5a1232 1// $Header$
2
3#include "EventAlieve.h"
4#include <Reve/Reve.h>
d9e0d6c5 5#include <Reve/RGTopFrame.h>
5a5a1232 6
7#include <AliRunLoader.h>
93845f6c 8#include <AliRun.h>
5a5a1232 9#include <AliESD.h>
3aecaefc 10#include <AliESDfriend.h>
93845f6c 11#include <AliMagFMaps.h>
5a5a1232 12
13#include <TFile.h>
14#include <TTree.h>
90fa773e 15#include <TObjString.h>
5a5a1232 16
17#include <TROOT.h>
18#include <TSystem.h>
90fa773e 19#include <TCint.h>
5a5a1232 20
21using namespace Reve;
22using namespace Alieve;
23
24//______________________________________________________________________
25// Event
26//
4852ff6f 27// Provide interface for loading and navigating standard AliRoot data
28// (AliRunLoader) and ESDs.
29//
30// Missing support for raw-data. For now this is handled individually
31// by each sub-detector.
32//
5a5a1232 33
34ClassImp(Event)
35
36Event* Alieve::gEvent = 0;
37
753fdd1e 38Bool_t Alieve::Event::fgUseRunLoader = kTRUE;
39Bool_t Alieve::Event::fgUseESDTree = kTRUE;
40Bool_t Alieve::Event::fgAvoidExcOnOpen = kTRUE;
5a5a1232 41
93845f6c 42AliMagF* Alieve::Event::fgMagField = 0;
43
44
753fdd1e 45void Event::Initialize(Bool_t use_runloader, Bool_t use_esd,
46 Bool_t avoid_exc_on_open)
5a5a1232 47{
48 static const Exc_t eH("Event::Initialize ");
49
753fdd1e 50 fgUseRunLoader = use_runloader;
51 fgUseESDTree = use_esd;
52 fgAvoidExcOnOpen = avoid_exc_on_open;
5a5a1232 53
54 /*
55 if(fgUseRunLoader == false && fgUseESDTree == false)
56 throw(eH + "should use at least one data source.");
57
58 if(fgUseRunLoader) {
59 AssertMacro("loadlibs.C");
60 }
61 else if(fgUseESDTree) {
62 gSystem->Load("libESD.so");
63 }
64 */
65}
66
67/**************************************************************************/
68
6f0b0040 69Event::Event() :
265ecb21 70 EventBase(),
71
72 fPath (), fEventId (0),
73 fRunLoader (0),
90fa773e 74 fESDFile (0), fESDTree (0), fESD (0),
2aa55da0 75 fESDfriend (0), fESDfriendExists(kFALSE),
76 fNewEventCommands()
265ecb21 77{}
5a5a1232 78
6f0b0040 79Event::Event(TString path, Int_t ev) :
80 EventBase("AliEVE Event"),
265ecb21 81
90fa773e 82 fPath (path), fEventId(-1),
265ecb21 83 fRunLoader (0),
90fa773e 84 fESDFile (0), fESDTree (0), fESD (0),
2aa55da0 85 fESDfriend (0), fESDfriendExists(kFALSE),
86 fNewEventCommands()
5a5a1232 87{
5a5a1232 88 Open();
90fa773e 89 if (ev >= 0) GotoEvent(ev);
5a5a1232 90}
91
92/**************************************************************************/
93
94void Event::Open()
95{
96 static const Exc_t eH("Event::Open ");
97
98 gSystem->ExpandPathName(fPath);
99 if(fPath[0] != '/')
100 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
101
90fa773e 102 if(fgUseRunLoader)
103 {
5a5a1232 104 TString ga_path(Form("%s/galice.root", fPath.Data()));
90fa773e 105 if(gSystem->AccessPathName(ga_path, kReadPermission))
106 {
753fdd1e 107 if (fgAvoidExcOnOpen) {
108 Warning(eH, "RunLoader not initialized.");
109 goto end_run_loader;
110 } else {
111 throw(eH + "can not read '" + ga_path + "'.");
112 }
113 }
5a5a1232 114 fRunLoader = AliRunLoader::Open(ga_path);
115 if(!fRunLoader)
116 throw(eH + "failed opening ALICE run loader from '" + ga_path + "'.");
117 {
118 TString alice_path = fPath + "/";
119 fRunLoader->SetDirName(alice_path);
120 }
1eaa5849 121 if(fRunLoader->LoadgAlice() != 0)
5a5a1232 122 throw(eH + "failed loading gAlice.");
cf94c7c2 123 if(fRunLoader->LoadHeader() != 0)
124 throw(eH + "failed loading header.");
5a5a1232 125 }
753fdd1e 126end_run_loader:
5a5a1232 127
90fa773e 128 if(fgUseESDTree)
129 {
5a5a1232 130 TString p(Form("%s/AliESDs.root", fPath.Data()));
90fa773e 131 if(gSystem->AccessPathName(p, kReadPermission))
132 {
753fdd1e 133 if (fgAvoidExcOnOpen) {
134 Warning(eH, "ESD not initialized.");
135 goto end_esd_loader;
136 } else {
137 throw(eH + "can not read '" + p + "'.");
138 }
139 }
5a5a1232 140 fESDFile = new TFile(p);
141 if(fESDFile->IsZombie()) {
142 delete fESDFile; fESDFile = 0;
143 throw(eH + "failed opening ALICE ESD from '" + p + "'.");
144 }
145
43ce2ae3 146 fESD = new AliESD();
5a5a1232 147 fESDTree = (TTree*) fESDFile->Get("esdTree");
148 if(fESDTree == 0)
149 throw(eH + "failed getting the esdTree.");
43ce2ae3 150 fESD->ReadFromTree(fESDTree);
3aecaefc 151
938142f5 152 // Check if ESDfriends exists and attach the branch
3aecaefc 153 p = Form("%s/AliESDfriends.root", fPath.Data());
90fa773e 154 if(gSystem->AccessPathName(p, kReadPermission) == kFALSE)
155 {
2cea771a 156 fESDfriendExists = kTRUE;
157 fESDTree->SetBranchStatus ("ESDfriend*", 1);
158 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
3aecaefc 159 }
5a5a1232 160 }
161
90fa773e 162end_esd_loader:
1eaa5849 163 SetName(Form("Event %d", fEventId));
5a5a1232 164 SetTitle(fPath);
165}
166
1eaa5849 167void Event::GotoEvent(Int_t event)
168{
169 static const Exc_t eH("Event::GotoEvent ");
170
1eaa5849 171 Int_t maxEvent = 0;
753fdd1e 172 if(fRunLoader)
1eaa5849 173 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
753fdd1e 174 else if(fESDTree)
1eaa5849 175 maxEvent = fESDTree->GetEntries() - 1;
753fdd1e 176 else
177 throw(eH + "neither RunLoader nor ESD loaded.");
1eaa5849 178
179 if(event < 0 || event > maxEvent)
180 throw(eH + Form("event %d not present, available range [%d, %d].",
181 event, 0, maxEvent));
182
d9e0d6c5 183 RGTopFrame::RedrawDisabler rd(gReve);
541e09b4 184 gReve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 185
1eaa5849 186 DestroyElements();
187 fEventId = event;
188 SetName(Form("Event %d", fEventId));
189 UpdateItems();
190
753fdd1e 191 if(fRunLoader) {
1eaa5849 192 if(fRunLoader->GetEvent(fEventId) != 0)
193 throw(eH + "failed getting required event.");
194 }
195
753fdd1e 196 if(fESDTree) {
1eaa5849 197 if(fESDTree->GetEntry(fEventId) <= 0)
198 throw(eH + "failed getting required event from ESD.");
199
2cea771a 200 if (fESDfriendExists)
1eaa5849 201 fESD->SetESDfriend(fESDfriend);
1eaa5849 202 }
90fa773e 203
204 AfterNewEventLoaded();
1eaa5849 205}
206
5a5a1232 207void Event::Close()
208{
2cea771a 209 if (fESDTree) {
210 delete fESD; fESD = 0;
211 delete fESDfriend; fESDfriend = 0;
212
213 delete fESDTree; fESDTree = 0;
214 delete fESDFile; fESDFile = 0;
215 }
5a5a1232 216}
217
90fa773e 218/**************************************************************************/
219
220void Event::AfterNewEventLoaded()
221{
222 TIter next(&fNewEventCommands);
223 TObject* o;
224 while ((o = next())) {
225 TObjString* s = dynamic_cast<TObjString*>(o);
226 if (s)
227 gInterpreter->ProcessLine(s->String());
228 }
229}
230
231void Event::AddNewEventCommand(const Text_t* cmd)
232{
233 fNewEventCommands.Add(new TObjString(cmd));
234}
235
5a5a1232 236/**************************************************************************/
237/**************************************************************************/
238
239// Static convenience functions.
240
241AliRunLoader* Event::AssertRunLoader()
242{
243 static const Exc_t eH("Event::AssertRunLoader ");
244
245 if(gEvent == 0)
246 throw(eH + "ALICE event not ready.");
247 if(gEvent->fRunLoader == 0)
248 throw(eH + "AliRunLoader not initialised.");
249 return gEvent->fRunLoader;
250}
251
252AliESD* Event::AssertESD()
253{
254 static const Exc_t eH("Event::AssertESD ");
255
256 if(gEvent == 0)
257 throw(eH + "ALICE event not ready.");
258 if(gEvent->fESD == 0)
259 throw(eH + "AliESD not initialised.");
260 return gEvent->fESD;
261}
3aecaefc 262
263AliESDfriend* Event::AssertESDfriend()
264{
265 static const Exc_t eH("Event::AssertESDfriend ");
266
267 if(gEvent == 0)
268 throw(eH + "ALICE event not ready.");
269 if(gEvent->fESDfriend == 0)
270 throw(eH + "AliESDfriend not initialised.");
271 return gEvent->fESDfriend;
272}
93845f6c 273
274AliMagF* Event::AssertMagField()
275{
276 if (fgMagField == 0)
277 {
278 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
279 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
280 else
281 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
282 }
283 return fgMagField;
284}