]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/Alieve/EventAlieve.cxx
fixed typo in ESDListNames
[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>
af885e0f 9#include <AliESDEvent.h>
3aecaefc 10#include <AliESDfriend.h>
93845f6c 11#include <AliMagFMaps.h>
632d2b03 12#include <AliCDBManager.h>
13#include <AliHeader.h>
14#include <AliGeomManager.h>
5a5a1232 15
16#include <TFile.h>
17#include <TTree.h>
90fa773e 18#include <TObjString.h>
632d2b03 19#include <TError.h>
5a5a1232 20
21#include <TROOT.h>
22#include <TSystem.h>
90fa773e 23#include <TCint.h>
5a5a1232 24
25using namespace Reve;
26using namespace Alieve;
27
28//______________________________________________________________________
29// Event
30//
4852ff6f 31// Provide interface for loading and navigating standard AliRoot data
32// (AliRunLoader) and ESDs.
33//
34// Missing support for raw-data. For now this is handled individually
35// by each sub-detector.
36//
5a5a1232 37
38ClassImp(Event)
39
40Event* Alieve::gEvent = 0;
41
a1896a82 42Bool_t Alieve::Event::fgAssertRunLoader = kFALSE;
43Bool_t Alieve::Event::fgAssertESDTree = kFALSE;
5a5a1232 44
632d2b03 45TString Alieve::Event::fgCdbUri("local://$ALICE_ROOT");
46
93845f6c 47AliMagF* Alieve::Event::fgMagField = 0;
48
49
6f0b0040 50Event::Event() :
265ecb21 51 EventBase(),
52
53 fPath (), fEventId (0),
54 fRunLoader (0),
90fa773e 55 fESDFile (0), fESDTree (0), fESD (0),
2aa55da0 56 fESDfriend (0), fESDfriendExists(kFALSE),
57 fNewEventCommands()
265ecb21 58{}
5a5a1232 59
6f0b0040 60Event::Event(TString path, Int_t ev) :
61 EventBase("AliEVE Event"),
265ecb21 62
90fa773e 63 fPath (path), fEventId(-1),
265ecb21 64 fRunLoader (0),
90fa773e 65 fESDFile (0), fESDTree (0), fESD (0),
2aa55da0 66 fESDfriend (0), fESDfriendExists(kFALSE),
67 fNewEventCommands()
5a5a1232 68{
5a5a1232 69 Open();
90fa773e 70 if (ev >= 0) GotoEvent(ev);
5a5a1232 71}
72
73/**************************************************************************/
74
75void Event::Open()
76{
77 static const Exc_t eH("Event::Open ");
78
79 gSystem->ExpandPathName(fPath);
80 if(fPath[0] != '/')
81 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
82
632d2b03 83 Int_t runNo = -1;
84
a1896a82 85 TString ga_path(Form("%s/galice.root", fPath.Data()));
86 if(gSystem->AccessPathName(ga_path, kReadPermission) == kFALSE)
90fa773e 87 {
5a5a1232 88 fRunLoader = AliRunLoader::Open(ga_path);
a1896a82 89 if (fRunLoader)
5a5a1232 90 {
91 TString alice_path = fPath + "/";
92 fRunLoader->SetDirName(alice_path);
a1896a82 93
94 if (fRunLoader->LoadgAlice() != 0)
95 Warning(eH, "failed loading gAlice via run-loader.");
96
97 if (fRunLoader->LoadHeader() == 0)
98 {
99 runNo = fRunLoader->GetHeader()->GetRun();
100 }
101 else
102 {
103 Warning(eH, "failed loading run-loader's header.");
104 delete fRunLoader;
105 fRunLoader = 0;
106 }
107 }
108 else // run-loader open failed
109 {
110 Warning(eH, "failed opening ALICE run-loader from '%s'.", ga_path.Data());
5a5a1232 111 }
5a5a1232 112 }
a1896a82 113 else // galice not readable
114 {
115 Warning(eH, "can not read '%s'.", ga_path.Data());
116 }
117 if (fRunLoader == 0)
118 {
119 if(fgAssertRunLoader)
120 throw(eH + "Bootstraping of run-loader failed. Its precence was requested.");
121 else
122 Warning(eH, "Bootstraping of run-loader failed.");
123 }
124
5a5a1232 125
a1896a82 126 TString esd_path(Form("%s/AliESDs.root", fPath.Data()));
127 if(gSystem->AccessPathName(esd_path, kReadPermission) == kFALSE)
90fa773e 128 {
a1896a82 129 fESDFile = new TFile(esd_path);
130 if(fESDFile->IsZombie() == kFALSE)
90fa773e 131 {
af885e0f 132 fESD = new AliESDEvent();
a1896a82 133 fESDTree = (TTree*) fESDFile->Get("esdTree");
134 if (fESDTree != 0)
135 {
136 fESD->ReadFromTree(fESDTree);
137 runNo = fESD->GetESDRun()->GetRunNumber();
138
139 // Check if ESDfriends exists and attach the branch
140 TString p = Form("%s/AliESDfriends.root", fPath.Data());
141 if(gSystem->AccessPathName(p, kReadPermission) == kFALSE)
142 {
143 fESDfriendExists = kTRUE;
144 fESDTree->SetBranchStatus ("ESDfriend*", 1);
145 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
146 }
147 }
148 else // esdtree == 0
149 {
150 delete fESDFile; fESDFile = 0;
151 Warning(eH, "failed getting the esdTree.");
753fdd1e 152 }
153 }
a1896a82 154 else // esd tfile is zombie
155 {
5a5a1232 156 delete fESDFile; fESDFile = 0;
a1896a82 157 Warning(eH, "failed opening ESD from '%s'.", esd_path.Data());
5a5a1232 158 }
a1896a82 159 }
160 else // esd not readable
161 {
162 Warning(eH, "can not read ESD file '%s'.", esd_path.Data());
163 }
164 if (fESDTree == 0)
165 {
166 if (fgAssertESDTree)
90fa773e 167 {
a1896a82 168 throw(eH + "ESD not initialized. Its precence was requested.");
169 } else {
170 Warning(eH, "ESD not initialized.");
3aecaefc 171 }
5a5a1232 172 }
173
632d2b03 174 if (runNo < 0)
175 throw(eH + "invalid run number.");
176
177 {
178 AliCDBManager* cdb = AliCDBManager::Instance();
179 cdb->SetDefaultStorage(fgCdbUri);
180 if (cdb->IsDefaultStorageSet() == kFALSE)
181 throw(eH + "CDB initialization failed.");
182 cdb->SetRun(runNo);
183 }
184
1eaa5849 185 SetName(Form("Event %d", fEventId));
5a5a1232 186 SetTitle(fPath);
187}
188
1eaa5849 189void Event::GotoEvent(Int_t event)
190{
191 static const Exc_t eH("Event::GotoEvent ");
192
1eaa5849 193 Int_t maxEvent = 0;
753fdd1e 194 if(fRunLoader)
1eaa5849 195 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
753fdd1e 196 else if(fESDTree)
1eaa5849 197 maxEvent = fESDTree->GetEntries() - 1;
753fdd1e 198 else
199 throw(eH + "neither RunLoader nor ESD loaded.");
1eaa5849 200
201 if(event < 0 || event > maxEvent)
202 throw(eH + Form("event %d not present, available range [%d, %d].",
203 event, 0, maxEvent));
204
d9e0d6c5 205 RGTopFrame::RedrawDisabler rd(gReve);
541e09b4 206 gReve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 207
1eaa5849 208 DestroyElements();
209 fEventId = event;
210 SetName(Form("Event %d", fEventId));
211 UpdateItems();
212
753fdd1e 213 if(fRunLoader) {
1eaa5849 214 if(fRunLoader->GetEvent(fEventId) != 0)
215 throw(eH + "failed getting required event.");
216 }
217
753fdd1e 218 if(fESDTree) {
1eaa5849 219 if(fESDTree->GetEntry(fEventId) <= 0)
220 throw(eH + "failed getting required event from ESD.");
221
2cea771a 222 if (fESDfriendExists)
1eaa5849 223 fESD->SetESDfriend(fESDfriend);
1eaa5849 224 }
90fa773e 225
226 AfterNewEventLoaded();
1eaa5849 227}
228
5a5a1232 229void Event::Close()
230{
2cea771a 231 if (fESDTree) {
232 delete fESD; fESD = 0;
233 delete fESDfriend; fESDfriend = 0;
234
235 delete fESDTree; fESDTree = 0;
236 delete fESDFile; fESDFile = 0;
237 }
5a5a1232 238}
239
90fa773e 240/**************************************************************************/
241
242void Event::AfterNewEventLoaded()
243{
244 TIter next(&fNewEventCommands);
245 TObject* o;
246 while ((o = next())) {
247 TObjString* s = dynamic_cast<TObjString*>(o);
248 if (s)
249 gInterpreter->ProcessLine(s->String());
250 }
251}
252
253void Event::AddNewEventCommand(const Text_t* cmd)
254{
255 fNewEventCommands.Add(new TObjString(cmd));
256}
257
5a5a1232 258/**************************************************************************/
259/**************************************************************************/
260
261// Static convenience functions.
262
263AliRunLoader* Event::AssertRunLoader()
264{
265 static const Exc_t eH("Event::AssertRunLoader ");
266
267 if(gEvent == 0)
268 throw(eH + "ALICE event not ready.");
269 if(gEvent->fRunLoader == 0)
270 throw(eH + "AliRunLoader not initialised.");
271 return gEvent->fRunLoader;
272}
273
af885e0f 274AliESDEvent* Event::AssertESD()
5a5a1232 275{
276 static const Exc_t eH("Event::AssertESD ");
277
278 if(gEvent == 0)
279 throw(eH + "ALICE event not ready.");
280 if(gEvent->fESD == 0)
281 throw(eH + "AliESD not initialised.");
282 return gEvent->fESD;
283}
3aecaefc 284
285AliESDfriend* Event::AssertESDfriend()
286{
287 static const Exc_t eH("Event::AssertESDfriend ");
288
289 if(gEvent == 0)
290 throw(eH + "ALICE event not ready.");
291 if(gEvent->fESDfriend == 0)
292 throw(eH + "AliESDfriend not initialised.");
293 return gEvent->fESDfriend;
294}
93845f6c 295
296AliMagF* Event::AssertMagField()
297{
298 if (fgMagField == 0)
299 {
300 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
301 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
302 else
303 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
304 }
305 return fgMagField;
306}
632d2b03 307
308TGeoManager* Event::AssertGeometry()
309{
310 static const Exc_t eH("Event::AssertGeometry ");
311
312 if (AliGeomManager::GetGeometry() == 0)
313 {
af2e4ef5 314 gGeoManager = 0;
632d2b03 315 AliGeomManager::LoadGeometry();
316 if ( ! AliGeomManager::GetGeometry())
317 {
318 throw(eH + "can not load geometry.");
319 }
320 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
321 {
322 ::Warning(eH, "mismatch of alignable volumes. Proceeding.");
323 // throw(eH + "could not apply align objs.");
324 }
325 }
326
327 return AliGeomManager::GetGeometry();
328}