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