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