detect correctly the 64 bit version of libgfortran and libgfortranbegin.
[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
d810d0de 196 SetName(Form("AliEveEventManager %d", fEventId));
5a5a1232 197 SetTitle(fPath);
198}
199
d810d0de 200void AliEveEventManager::GotoEvent(Int_t event)
1eaa5849 201{
d810d0de 202 static const TEveException eH("AliEveEventManager::GotoEvent ");
1eaa5849 203
1eaa5849 204 Int_t maxEvent = 0;
84aff7a4 205 if (fRunLoader)
1eaa5849 206 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
84aff7a4 207 else if (fESDTree)
1eaa5849 208 maxEvent = fESDTree->GetEntries() - 1;
753fdd1e 209 else
210 throw(eH + "neither RunLoader nor ESD loaded.");
1eaa5849 211
84aff7a4 212 if (event < 0 || event > maxEvent)
1eaa5849 213 throw(eH + Form("event %d not present, available range [%d, %d].",
214 event, 0, maxEvent));
215
84aff7a4 216 TEveManager::TRedrawDisabler rd(gEve);
217 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 218
32e219c2 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.
1eaa5849 222 DestroyElements();
223 fEventId = event;
d810d0de 224 SetName(Form("AliEveEventManager %d", fEventId));
1eaa5849 225 UpdateItems();
226
84aff7a4 227 if (fRunLoader) {
228 if (fRunLoader->GetEvent(fEventId) != 0)
1eaa5849 229 throw(eH + "failed getting required event.");
230 }
231
84aff7a4 232 if (fESDTree) {
233 if (fESDTree->GetEntry(fEventId) <= 0)
1eaa5849 234 throw(eH + "failed getting required event from ESD.");
235
2cea771a 236 if (fESDfriendExists)
1eaa5849 237 fESD->SetESDfriend(fESDfriend);
1eaa5849 238 }
90fa773e 239
240 AfterNewEventLoaded();
1eaa5849 241}
242
d810d0de 243void AliEveEventManager::Close()
5a5a1232 244{
2cea771a 245 if (fESDTree) {
246 delete fESD; fESD = 0;
247 delete fESDfriend; fESDfriend = 0;
248
249 delete fESDTree; fESDTree = 0;
250 delete fESDFile; fESDFile = 0;
251 }
5a5a1232 252}
253
90fa773e 254
57ffa5fb 255/******************************************************************************/
c76ea574 256// Static convenience functions, mainly used from macros.
57ffa5fb 257/******************************************************************************/
5a5a1232 258
d810d0de 259AliRunLoader* AliEveEventManager::AssertRunLoader()
5a5a1232 260{
d810d0de 261 static const TEveException eH("AliEveEventManager::AssertRunLoader ");
5a5a1232 262
84aff7a4 263 if (gEvent == 0)
5a5a1232 264 throw(eH + "ALICE event not ready.");
84aff7a4 265 if (gEvent->fRunLoader == 0)
5a5a1232 266 throw(eH + "AliRunLoader not initialised.");
267 return gEvent->fRunLoader;
268}
269
d810d0de 270AliESDEvent* AliEveEventManager::AssertESD()
5a5a1232 271{
d810d0de 272 static const TEveException eH("AliEveEventManager::AssertESD ");
5a5a1232 273
84aff7a4 274 if (gEvent == 0)
5a5a1232 275 throw(eH + "ALICE event not ready.");
84aff7a4 276 if (gEvent->fESD == 0)
5a5a1232 277 throw(eH + "AliESD not initialised.");
278 return gEvent->fESD;
279}
3aecaefc 280
d810d0de 281AliESDfriend* AliEveEventManager::AssertESDfriend()
3aecaefc 282{
d810d0de 283 static const TEveException eH("AliEveEventManager::AssertESDfriend ");
3aecaefc 284
84aff7a4 285 if (gEvent == 0)
3aecaefc 286 throw(eH + "ALICE event not ready.");
84aff7a4 287 if (gEvent->fESDfriend == 0)
3aecaefc 288 throw(eH + "AliESDfriend not initialised.");
289 return gEvent->fESDfriend;
290}
93845f6c 291
d810d0de 292AliMagF* AliEveEventManager::AssertMagField()
93845f6c 293{
294 if (fgMagField == 0)
295 {
296 if (gEvent && gEvent->fRunLoader && gEvent->fRunLoader->GetAliRun())
297 fgMagField = gEvent->fRunLoader->GetAliRun()->Field();
298 else
299 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
300 }
301 return fgMagField;
302}
632d2b03 303
d810d0de 304TGeoManager* AliEveEventManager::AssertGeometry()
632d2b03 305{
d810d0de 306 static const TEveException eH("AliEveEventManager::AssertGeometry ");
632d2b03 307
308 if (AliGeomManager::GetGeometry() == 0)
309 {
af2e4ef5 310 gGeoManager = 0;
632d2b03 311 AliGeomManager::LoadGeometry();
312 if ( ! AliGeomManager::GetGeometry())
313 {
314 throw(eH + "can not load geometry.");
315 }
316 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
317 {
318 ::Warning(eH, "mismatch of alignable volumes. Proceeding.");
319 // throw(eH + "could not apply align objs.");
320 }
321 }
322
323 return AliGeomManager::GetGeometry();
324}