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