2 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
4 /**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
7 * full copyright notice. *
8 **************************************************************************/
10 #include "AliEveEventManager.h"
12 #include <TEveManager.h>
14 #include <AliRunLoader.h>
16 #include <AliESDEvent.h>
17 #include <AliESDfriend.h>
18 #include <AliMagFMaps.h>
19 #include <AliCDBManager.h>
20 #include <AliHeader.h>
21 #include <AliGeomManager.h>
31 //______________________________________________________________________________
34 // Provide interface for loading and navigating standard AliRoot data
35 // (AliRunLoader) and ESDs.
37 // Missing support for raw-data. For now this is handled individually
38 // by each sub-detector.
41 ClassImp(AliEveEventManager)
43 AliEveEventManager* gEvent = 0;
45 Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE;
46 Bool_t AliEveEventManager::fgAssertESD = kFALSE;
48 TString AliEveEventManager::fgCdbUri("local://$ALICE_ROOT");
50 AliMagF* AliEveEventManager::fgMagField = 0;
53 AliEveEventManager::AliEveEventManager() :
56 fPath (), fEventId (0),
58 fESDFile (0), fESDTree (0), fESD (0),
59 fESDfriend (0), fESDfriendExists(kFALSE)
61 // Default constructor.
64 AliEveEventManager::AliEveEventManager(TString path, Int_t ev) :
65 TEveEventManager("AliEVE AliEveEventManager"),
67 fPath (path), fEventId(-1),
69 fESDFile (0), fESDTree (0), fESD (0),
70 fESDfriend (0), fESDfriendExists(kFALSE)
72 // Constructor with event-directory URL and event-id.
75 if (ev >= 0) GotoEvent(ev);
78 /******************************************************************************/
80 void AliEveEventManager::Open()
82 // Open event-data from URL specified in fPath.
83 // Attempts to create AliRunLoader() and to open ESD with ESDfriends.
84 // Warning is reported if run-loader or ESD is not found.
85 // Global data-members fgAssertRunLoader and fgAssertESD can be set
86 // to throw exceptions instead.
88 static const TEveException eH("AliEveEventManager::Open ");
90 gSystem->ExpandPathName(fPath);
92 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
96 TString ga_path(Form("%s/galice.root", fPath.Data()));
97 if (gSystem->AccessPathName(ga_path, kReadPermission) == kFALSE)
99 fRunLoader = AliRunLoader::Open(ga_path);
102 TString alice_path = fPath + "/";
103 fRunLoader->SetDirName(alice_path);
105 if (fRunLoader->LoadgAlice() != 0)
106 Warning(eH, "failed loading gAlice via run-loader.");
108 if (fRunLoader->LoadHeader() == 0)
110 runNo = fRunLoader->GetHeader()->GetRun();
114 Warning(eH, "failed loading run-loader's header.");
119 else // run-loader open failed
121 Warning(eH, "failed opening ALICE run-loader from '%s'.", ga_path.Data());
124 else // galice not readable
126 Warning(eH, "can not read '%s'.", ga_path.Data());
130 if (fgAssertRunLoader)
131 throw(eH + "Bootstraping of run-loader failed. Its precence was requested.");
133 Warning(eH, "Bootstraping of run-loader failed.");
137 TString esd_path(Form("%s/AliESDs.root", fPath.Data()));
138 if (gSystem->AccessPathName(esd_path, kReadPermission) == kFALSE)
140 fESDFile = new TFile(esd_path);
141 if (fESDFile->IsZombie() == kFALSE)
143 fESD = new AliESDEvent();
144 fESDTree = (TTree*) fESDFile->Get("esdTree");
147 fESD->ReadFromTree(fESDTree);
148 runNo = fESD->GetESDRun()->GetRunNumber();
150 // Check if ESDfriends exists and attach the branch
151 TString p = Form("%s/AliESDfriends.root", fPath.Data());
152 if (gSystem->AccessPathName(p, kReadPermission) == kFALSE)
154 fESDfriendExists = kTRUE;
155 fESDTree->SetBranchStatus ("ESDfriend*", 1);
156 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
161 delete fESDFile; fESDFile = 0;
162 Warning(eH, "failed getting the esdTree.");
165 else // esd tfile is zombie
167 delete fESDFile; fESDFile = 0;
168 Warning(eH, "failed opening ESD from '%s'.", esd_path.Data());
171 else // esd not readable
173 Warning(eH, "can not read ESD file '%s'.", esd_path.Data());
179 throw(eH + "ESD not initialized. Its precence was requested.");
181 Warning(eH, "ESD not initialized.");
186 throw(eH + "invalid run number.");
189 AliCDBManager* cdb = AliCDBManager::Instance();
190 cdb->SetDefaultStorage(fgCdbUri);
191 if (cdb->IsDefaultStorageSet() == kFALSE)
192 throw(eH + "CDB initialization failed.");
196 SetName(Form("AliEveEventManager %d", fEventId));
200 void AliEveEventManager::GotoEvent(Int_t event)
202 static const TEveException eH("AliEveEventManager::GotoEvent ");
206 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
208 maxEvent = fESDTree->GetEntries() - 1;
210 throw(eH + "neither RunLoader nor ESD loaded.");
212 if (event < 0 || event > maxEvent)
213 throw(eH + Form("event %d not present, available range [%d, %d].",
214 event, 0, maxEvent));
216 TEveManager::TRedrawDisabler rd(gEve);
217 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
219 // !!! MT this is somewhat brutal; at least optionally, one could be
220 // a bit gentler, checking for objs owning their external refs and having
221 // additinal parents.
224 SetName(Form("AliEveEventManager %d", fEventId));
228 if (fRunLoader->GetEvent(fEventId) != 0)
229 throw(eH + "failed getting required event.");
233 if (fESDTree->GetEntry(fEventId) <= 0)
234 throw(eH + "failed getting required event from ESD.");
236 if (fESDfriendExists)
237 fESD->SetESDfriend(fESDfriend);
240 AfterNewEventLoaded();
243 void AliEveEventManager::Close()
246 delete fESD; fESD = 0;
247 delete fESDfriend; fESDfriend = 0;
249 delete fESDTree; fESDTree = 0;
250 delete fESDFile; fESDFile = 0;
255 /******************************************************************************/
256 // Static convenience functions, mainly used from macros.
257 /******************************************************************************/
259 AliRunLoader* AliEveEventManager::AssertRunLoader()
261 static const TEveException eH("AliEveEventManager::AssertRunLoader ");
264 throw(eH + "ALICE event not ready.");
265 if (gEvent->fRunLoader == 0)
266 throw(eH + "AliRunLoader not initialised.");
267 return gEvent->fRunLoader;
270 AliESDEvent* AliEveEventManager::AssertESD()
272 static const TEveException eH("AliEveEventManager::AssertESD ");
275 throw(eH + "ALICE event not ready.");
276 if (gEvent->fESD == 0)
277 throw(eH + "AliESD not initialised.");
281 AliESDfriend* AliEveEventManager::AssertESDfriend()
283 static const TEveException eH("AliEveEventManager::AssertESDfriend ");
286 throw(eH + "ALICE event not ready.");
287 if (gEvent->fESDfriend == 0)
288 throw(eH + "AliESDfriend not initialised.");
289 return gEvent->fESDfriend;
292 AliMagF* AliEveEventManager::AssertMagField()
296 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
297 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
299 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
304 TGeoManager* AliEveEventManager::AssertGeometry()
306 static const TEveException eH("AliEveEventManager::AssertGeometry ");
308 if (AliGeomManager::GetGeometry() == 0)
311 AliGeomManager::LoadGeometry();
312 if ( ! AliGeomManager::GetGeometry())
314 throw(eH + "can not load geometry.");
316 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
318 ::Warning(eH, "mismatch of alignable volumes. Proceeding.");
319 // throw(eH + "could not apply align objs.");
323 return AliGeomManager::GetGeometry();