]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveEventManager.cxx
Fixes for inconsistent types in BinarySearch
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveEventManager.cxx
CommitLineData
d810d0de 1// $Id$
2// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
5a5a1232 3
d810d0de 4/**************************************************************************
5 * Copyright(c) 1998-2008, ALICE Experiment at CERN, all rights reserved. *
6 * See http://aliceinfo.cern.ch/Offline/AliRoot/License.html for *
51346b82 7 * full copyright notice. *
d810d0de 8 **************************************************************************/
9
10#include "AliEveEventManager.h"
84aff7a4 11#include <TEveUtil.h>
12#include <TEveManager.h>
5a5a1232 13
14#include <AliRunLoader.h>
93845f6c 15#include <AliRun.h>
af885e0f 16#include <AliESDEvent.h>
3aecaefc 17#include <AliESDfriend.h>
93845f6c 18#include <AliMagFMaps.h>
632d2b03 19#include <AliCDBManager.h>
20#include <AliHeader.h>
21#include <AliGeomManager.h>
5a5a1232 22
23#include <TFile.h>
24#include <TTree.h>
632d2b03 25#include <TError.h>
5a5a1232 26
27#include <TROOT.h>
28#include <TSystem.h>
d810d0de 29
5a5a1232 30
57ffa5fb 31//______________________________________________________________________________
d810d0de 32// AliEveEventManager
5a5a1232 33//
4852ff6f 34// Provide interface for loading and navigating standard AliRoot data
35// (AliRunLoader) and ESDs.
36//
37// Missing support for raw-data. For now this is handled individually
38// by each sub-detector.
51346b82 39//
5a5a1232 40
d810d0de 41ClassImp(AliEveEventManager)
5a5a1232 42
d810d0de 43AliEveEventManager* gEvent = 0;
5a5a1232 44
d810d0de 45Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE;
c76ea574 46Bool_t AliEveEventManager::fgAssertESD = kFALSE;
5a5a1232 47
d810d0de 48TString AliEveEventManager::fgCdbUri("local://$ALICE_ROOT");
632d2b03 49
d810d0de 50AliMagF* AliEveEventManager::fgMagField = 0;
93845f6c 51
52
d810d0de 53AliEveEventManager::AliEveEventManager() :
84aff7a4 54 TEveEventManager(),
265ecb21 55
c76ea574 56 fPath (), fEventId (0),
265ecb21 57 fRunLoader (0),
90fa773e 58 fESDFile (0), fESDTree (0), fESD (0),
32e219c2 59 fESDfriend (0), fESDfriendExists(kFALSE)
c76ea574 60{
61 // Default constructor.
62}
5a5a1232 63
d810d0de 64AliEveEventManager::AliEveEventManager(TString path, Int_t ev) :
65 TEveEventManager("AliEVE AliEveEventManager"),
265ecb21 66
c76ea574 67 fPath (path), fEventId(-1),
265ecb21 68 fRunLoader (0),
90fa773e 69 fESDFile (0), fESDTree (0), fESD (0),
32e219c2 70 fESDfriend (0), fESDfriendExists(kFALSE)
5a5a1232 71{
c76ea574 72 // Constructor with event-directory URL and event-id.
73
5a5a1232 74 Open();
90fa773e 75 if (ev >= 0) GotoEvent(ev);
5a5a1232 76}
77
57ffa5fb 78/******************************************************************************/
5a5a1232 79
d810d0de 80void AliEveEventManager::Open()
5a5a1232 81{
c76ea574 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.
87
d810d0de 88 static const TEveException eH("AliEveEventManager::Open ");
5a5a1232 89
90 gSystem->ExpandPathName(fPath);
84aff7a4 91 if (fPath[0] != '/')
5a5a1232 92 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
93
632d2b03 94 Int_t runNo = -1;
95
a1896a82 96 TString ga_path(Form("%s/galice.root", fPath.Data()));
84aff7a4 97 if (gSystem->AccessPathName(ga_path, kReadPermission) == kFALSE)
90fa773e 98 {
5a5a1232 99 fRunLoader = AliRunLoader::Open(ga_path);
a1896a82 100 if (fRunLoader)
5a5a1232 101 {
102 TString alice_path = fPath + "/";
103 fRunLoader->SetDirName(alice_path);
a1896a82 104
105 if (fRunLoader->LoadgAlice() != 0)
106 Warning(eH, "failed loading gAlice via run-loader.");
107
108 if (fRunLoader->LoadHeader() == 0)
109 {
110 runNo = fRunLoader->GetHeader()->GetRun();
111 }
112 else
113 {
114 Warning(eH, "failed loading run-loader's header.");
115 delete fRunLoader;
116 fRunLoader = 0;
117 }
118 }
119 else // run-loader open failed
120 {
121 Warning(eH, "failed opening ALICE run-loader from '%s'.", ga_path.Data());
5a5a1232 122 }
5a5a1232 123 }
a1896a82 124 else // galice not readable
125 {
126 Warning(eH, "can not read '%s'.", ga_path.Data());
127 }
128 if (fRunLoader == 0)
129 {
84aff7a4 130 if (fgAssertRunLoader)
a1896a82 131 throw(eH + "Bootstraping of run-loader failed. Its precence was requested.");
132 else
133 Warning(eH, "Bootstraping of run-loader failed.");
134 }
51346b82 135
5a5a1232 136
a1896a82 137 TString esd_path(Form("%s/AliESDs.root", fPath.Data()));
84aff7a4 138 if (gSystem->AccessPathName(esd_path, kReadPermission) == kFALSE)
90fa773e 139 {
a1896a82 140 fESDFile = new TFile(esd_path);
84aff7a4 141 if (fESDFile->IsZombie() == kFALSE)
90fa773e 142 {
af885e0f 143 fESD = new AliESDEvent();
a1896a82 144 fESDTree = (TTree*) fESDFile->Get("esdTree");
145 if (fESDTree != 0)
146 {
147 fESD->ReadFromTree(fESDTree);
148 runNo = fESD->GetESDRun()->GetRunNumber();
149
150 // Check if ESDfriends exists and attach the branch
151 TString p = Form("%s/AliESDfriends.root", fPath.Data());
84aff7a4 152 if (gSystem->AccessPathName(p, kReadPermission) == kFALSE)
a1896a82 153 {
154 fESDfriendExists = kTRUE;
155 fESDTree->SetBranchStatus ("ESDfriend*", 1);
156 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
157 }
158 }
159 else // esdtree == 0
160 {
161 delete fESDFile; fESDFile = 0;
162 Warning(eH, "failed getting the esdTree.");
753fdd1e 163 }
164 }
a1896a82 165 else // esd tfile is zombie
166 {
5a5a1232 167 delete fESDFile; fESDFile = 0;
a1896a82 168 Warning(eH, "failed opening ESD from '%s'.", esd_path.Data());
5a5a1232 169 }
a1896a82 170 }
171 else // esd not readable
172 {
173 Warning(eH, "can not read ESD file '%s'.", esd_path.Data());
174 }
175 if (fESDTree == 0)
176 {
c76ea574 177 if (fgAssertESD)
90fa773e 178 {
a1896a82 179 throw(eH + "ESD not initialized. Its precence was requested.");
51346b82 180 } else {
a1896a82 181 Warning(eH, "ESD not initialized.");
3aecaefc 182 }
5a5a1232 183 }
184
632d2b03 185 if (runNo < 0)
186 throw(eH + "invalid run number.");
187
188 {
189 AliCDBManager* cdb = AliCDBManager::Instance();
190 cdb->SetDefaultStorage(fgCdbUri);
191 if (cdb->IsDefaultStorageSet() == kFALSE)
192 throw(eH + "CDB initialization failed.");
193 cdb->SetRun(runNo);
194 }
195
73c1c0ec 196 SetName(Form("Event %d", fEventId));
5a5a1232 197 SetTitle(fPath);
198}
199
d810d0de 200void AliEveEventManager::GotoEvent(Int_t event)
1eaa5849 201{
73c1c0ec 202 // Load data for specified event.
203 // If event is out of range an exception is thrown and old state
204 // is preserved.
205 // After successful loading of event, the virtual function
206 // AfterNewEventLoaded() is called. This executes commands that
207 // were registered via TEveEventManager::AddNewEventCommand().
208
d810d0de 209 static const TEveException eH("AliEveEventManager::GotoEvent ");
1eaa5849 210
1eaa5849 211 Int_t maxEvent = 0;
84aff7a4 212 if (fRunLoader)
1eaa5849 213 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
84aff7a4 214 else if (fESDTree)
1eaa5849 215 maxEvent = fESDTree->GetEntries() - 1;
753fdd1e 216 else
217 throw(eH + "neither RunLoader nor ESD loaded.");
1eaa5849 218
84aff7a4 219 if (event < 0 || event > maxEvent)
1eaa5849 220 throw(eH + Form("event %d not present, available range [%d, %d].",
221 event, 0, maxEvent));
222
84aff7a4 223 TEveManager::TRedrawDisabler rd(gEve);
224 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 225
32e219c2 226 // !!! MT this is somewhat brutal; at least optionally, one could be
227 // a bit gentler, checking for objs owning their external refs and having
228 // additinal parents.
1eaa5849 229 DestroyElements();
230 fEventId = event;
73c1c0ec 231 SetName(Form("Event %d", fEventId));
1eaa5849 232 UpdateItems();
233
84aff7a4 234 if (fRunLoader) {
235 if (fRunLoader->GetEvent(fEventId) != 0)
1eaa5849 236 throw(eH + "failed getting required event.");
237 }
238
84aff7a4 239 if (fESDTree) {
240 if (fESDTree->GetEntry(fEventId) <= 0)
1eaa5849 241 throw(eH + "failed getting required event from ESD.");
242
2cea771a 243 if (fESDfriendExists)
1eaa5849 244 fESD->SetESDfriend(fESDfriend);
1eaa5849 245 }
90fa773e 246
247 AfterNewEventLoaded();
1eaa5849 248}
249
d810d0de 250void AliEveEventManager::Close()
5a5a1232 251{
73c1c0ec 252 // Close the event files.
253 // For the moment only ESD is closed. Needs to be investigated for
254 // AliRunLoader and Raw.
255
2cea771a 256 if (fESDTree) {
257 delete fESD; fESD = 0;
258 delete fESDfriend; fESDfriend = 0;
259
260 delete fESDTree; fESDTree = 0;
261 delete fESDFile; fESDFile = 0;
262 }
5a5a1232 263}
264
90fa773e 265
57ffa5fb 266/******************************************************************************/
c76ea574 267// Static convenience functions, mainly used from macros.
57ffa5fb 268/******************************************************************************/
5a5a1232 269
d810d0de 270AliRunLoader* AliEveEventManager::AssertRunLoader()
5a5a1232 271{
73c1c0ec 272 // Make sure AliRunLoader is initialized and return it.
273 // Throws exception in case run-loader is not available.
274 // Static utility for macros.
275
d810d0de 276 static const TEveException eH("AliEveEventManager::AssertRunLoader ");
5a5a1232 277
84aff7a4 278 if (gEvent == 0)
5a5a1232 279 throw(eH + "ALICE event not ready.");
84aff7a4 280 if (gEvent->fRunLoader == 0)
5a5a1232 281 throw(eH + "AliRunLoader not initialised.");
282 return gEvent->fRunLoader;
283}
284
d810d0de 285AliESDEvent* AliEveEventManager::AssertESD()
5a5a1232 286{
73c1c0ec 287 // Make sure AliESDEvent is initialized and return it.
288 // Throws exception in case ESD is not available.
289 // Static utility for macros.
290
d810d0de 291 static const TEveException eH("AliEveEventManager::AssertESD ");
5a5a1232 292
84aff7a4 293 if (gEvent == 0)
5a5a1232 294 throw(eH + "ALICE event not ready.");
84aff7a4 295 if (gEvent->fESD == 0)
5a5a1232 296 throw(eH + "AliESD not initialised.");
297 return gEvent->fESD;
298}
3aecaefc 299
d810d0de 300AliESDfriend* AliEveEventManager::AssertESDfriend()
3aecaefc 301{
73c1c0ec 302 // Make sure AliESDfriend is initialized and return it.
303 // Throws exception in case ESDfriend-loader is not available.
304 // Static utility for macros.
305
d810d0de 306 static const TEveException eH("AliEveEventManager::AssertESDfriend ");
3aecaefc 307
84aff7a4 308 if (gEvent == 0)
3aecaefc 309 throw(eH + "ALICE event not ready.");
84aff7a4 310 if (gEvent->fESDfriend == 0)
3aecaefc 311 throw(eH + "AliESDfriend not initialised.");
312 return gEvent->fESDfriend;
313}
93845f6c 314
d810d0de 315AliMagF* AliEveEventManager::AssertMagField()
93845f6c 316{
73c1c0ec 317 // Make sure AliMagF is initialized and return it.
318 // Throws exception in case magnetic field is not available.
319 // Static utility for macros.
320
93845f6c 321 if (fgMagField == 0)
322 {
323 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
324 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
325 else
326 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
327 }
328 return fgMagField;
329}
632d2b03 330
d810d0de 331TGeoManager* AliEveEventManager::AssertGeometry()
632d2b03 332{
73c1c0ec 333 // Make sure AliGeomManager is initialized and returns the
334 // corresponding TGeoManger.
335 // gGeoManager is not set, maybe it should be.
336 // Throws exception in case run-loader is not available.
337 // Static utility for macros.
338
339 // !!!! Should we set gGeoManager here?
340
d810d0de 341 static const TEveException eH("AliEveEventManager::AssertGeometry ");
632d2b03 342
343 if (AliGeomManager::GetGeometry() == 0)
344 {
af2e4ef5 345 gGeoManager = 0;
632d2b03 346 AliGeomManager::LoadGeometry();
347 if ( ! AliGeomManager::GetGeometry())
348 {
349 throw(eH + "can not load geometry.");
350 }
351 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
352 {
353 ::Warning(eH, "mismatch of alignable volumes. Proceeding.");
354 // throw(eH + "could not apply align objs.");
355 }
356 }
357
358 return AliGeomManager::GetGeometry();
359}