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"
11 #include <TEveManager.h>
13 #include <AliRunLoader.h>
15 #include <AliESDEvent.h>
16 #include <AliESDfriend.h>
17 #include <AliRawReaderRoot.h>
18 #include <AliRawReaderFile.h>
19 #include <AliRawReaderDate.h>
20 #include <AliMagFMaps.h>
21 #include <AliCDBManager.h>
22 #include <AliHeader.h>
23 #include <AliGeomManager.h>
29 //==============================================================================
30 //==============================================================================
32 //==============================================================================
34 //______________________________________________________________________________
36 // Provide interface for loading and navigating standard AliRoot data
37 // (AliRunLoader) and ESDs.
39 // Missing support for raw-data. For now this is handled individually
40 // by each sub-detector.
42 // Also provides interface to magnetic-field and geometry. Mostly
43 // intended as wrappers over standard AliRoot functionality for
44 // convenient use from visualizateion macros.
46 ClassImp(AliEveEventManager)
48 AliEveEventManager* gAliEveEvent = 0;
50 Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE;
51 Bool_t AliEveEventManager::fgAssertESD = kFALSE;
52 Bool_t AliEveEventManager::fgAssertRaw = kFALSE;
54 TString AliEveEventManager::fgESDFileName("AliESDs.root");
55 TString AliEveEventManager::fgRawFileName("raw.root");
56 TString AliEveEventManager::fgCdbUri("local://$ALICE_ROOT");
58 AliMagF* AliEveEventManager::fgMagField = 0;
61 AliEveEventManager::AliEveEventManager() :
64 fPath ( ), fEventId (-1),
66 fESDFile (0), fESDTree (0), fESD (0),
67 fESDfriend (0), fESDfriendExists(kFALSE),
70 // Default constructor.
73 AliEveEventManager::AliEveEventManager(TString path, Int_t ev) :
74 TEveEventManager("AliEVE AliEveEventManager"),
76 fPath (path), fEventId(-1),
78 fESDFile (0), fESDTree (0), fESD (0),
79 fESDfriend (0), fESDfriendExists(kFALSE),
82 // Constructor with event-directory URL and event-id.
85 if (ev >= 0) GotoEvent(ev);
88 AliEveEventManager::~AliEveEventManager()
92 // Somewhat unclear what to do here.
93 // In principle should close all data sources and deregister from
97 /******************************************************************************/
99 void AliEveEventManager::SetESDFileName(const Text_t* esd)
101 // Set file-name for opening ESD, default "AliESDs.root".
103 if (esd) fgESDFileName = esd;
106 void AliEveEventManager::SetRawFileName(const Text_t* raw)
108 // Set file-name for opening of raw-data, default "raw.root"
109 if (raw) fgRawFileName = raw;
112 void AliEveEventManager::SetCdbUri(const Text_t* cdb)
114 // Set path to CDB, default "local://$ALICE_ROOT".
116 if (cdb) fgCdbUri = cdb;
119 void AliEveEventManager::SetAssertElements(Bool_t assertRunloader,
123 // Set global flags that detrmine which parts of the event-data must
124 // be present when the event is opened.
126 fgAssertRunLoader = assertRunloader;
127 fgAssertESD = assertEsd;
128 fgAssertRaw = assertRaw;
131 /******************************************************************************/
133 void AliEveEventManager::Open()
135 // Open event-data from URL specified in fPath.
136 // Attempts to create AliRunLoader() and to open ESD with ESDfriends.
137 // Warning is reported if run-loader or ESD is not found.
138 // Global data-members fgAssertRunLoader and fgAssertESD can be set
139 // to throw exceptions instead.
141 static const TEveException kEH("AliEveEventManager::Open ");
143 gSystem->ExpandPathName(fPath);
145 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
149 TString gaPath(Form("%s/galice.root", fPath.Data()));
150 // If i use open directly, we get fatal.
151 // Is this (AccessPathName check) ok for xrootd / alien?
152 if (gSystem->AccessPathName(gaPath, kReadPermission) == kFALSE)
154 fRunLoader = AliRunLoader::Open(gaPath);
157 TString alicePath = fPath + "/";
158 fRunLoader->SetDirName(alicePath);
160 if (fRunLoader->LoadgAlice() != 0)
161 Warning(kEH, "failed loading gAlice via run-loader.");
163 if (fRunLoader->LoadHeader() == 0)
165 runNo = fRunLoader->GetHeader()->GetRun();
169 Warning(kEH, "failed loading run-loader's header.");
174 else // run-loader open failed
176 Warning(kEH, "failed opening ALICE run-loader from '%s'.", gaPath.Data());
179 else // galice not readable
181 Warning(kEH, "can not read '%s'.", gaPath.Data());
185 if (fgAssertRunLoader)
186 throw (kEH + "Bootstraping of run-loader failed. Its precence was requested.");
188 Warning(kEH, "Bootstraping of run-loader failed.");
192 TString esdPath(Form("%s/%s", fPath.Data(), fgESDFileName.Data()));
193 if ((fESDFile = TFile::Open(esdPath)))
195 fESD = new AliESDEvent();
196 fESDTree = (TTree*) fESDFile->Get("esdTree");
199 fESD->ReadFromTree(fESDTree);
200 runNo = fESD->GetESDRun()->GetRunNumber();
202 // Check if ESDfriends exists and attach the branch
203 TString p = Form("%s/AliESDfriends.root", fPath.Data());
204 if (gSystem->AccessPathName(p, kReadPermission) == kFALSE)
206 fESDfriendExists = kTRUE;
207 fESDTree->SetBranchStatus ("ESDfriend*", 1);
208 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
213 delete fESDFile; fESDFile = 0;
214 Warning(kEH, "failed getting the esdTree.");
217 else // esd not readable
219 Warning(kEH, "can not read ESD file '%s'.", esdPath.Data());
225 throw (kEH + "ESD not initialized. Its precence was requested.");
227 Warning(kEH, "ESD not initialized.");
231 TString rawPath(Form("%s/%s", fPath.Data(), fgRawFileName.Data()));
232 // If i use open directly, raw-reader reports an error but i have
233 // no way to detect it.
234 // Is this (AccessPathName check) ok for xrootd / alien?
235 if (gSystem->AccessPathName(rawPath, kReadPermission) == kFALSE)
237 if (fgRawFileName.EndsWith("/"))
239 fRawReader = new AliRawReaderFile(rawPath);
241 else if (fgRawFileName.EndsWith(".root"))
243 fRawReader = new AliRawReaderRoot(rawPath);
245 else if (!fgRawFileName.IsNull())
247 fRawReader = new AliRawReaderDate(rawPath);
255 throw (kEH + "raw-data not initialized. Its precence was requested.");
257 Warning(kEH, "raw-data not initialized.");
265 fRawReader->NextEvent();
266 runNo = fRawReader->GetRunNumber();
267 printf("Determining run-no from raw ... run=%d\n", runNo);
268 fRawReader->RewindEvents();
270 throw (kEH + "unknown run number.");
275 AliCDBManager* cdb = AliCDBManager::Instance();
276 cdb->SetDefaultStorage(fgCdbUri);
277 if (cdb->IsDefaultStorageSet() == kFALSE)
278 throw (kEH + "CDB initialization failed.");
282 SetName(Form("Event %d", fEventId));
286 void AliEveEventManager::GotoEvent(Int_t event)
288 // Load data for specified event.
289 // If event is out of range an exception is thrown and old state
291 // After successful loading of event, the virtual function
292 // AfterNewEventLoaded() is called. This executes commands that
293 // were registered via TEveEventManager::AddNewEventCommand().
295 static const TEveException kEH("AliEveEventManager::GotoEvent ");
298 Error(kEH, "event must be non-negative.");
304 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
305 } else if (fESDTree) {
306 maxEvent = fESDTree->GetEntries() - 1;
307 } else if (fRawReader) {
309 Info(kEH, "number of events unknown for raw-data, setting max-event id to 10M.");
311 throw (kEH + "neither RunLoader, ESD nor Raw loaded.");
313 if (event < 0 || event > maxEvent)
314 throw (kEH + Form("event %d not present, available range [%d, %d].",
315 event, 0, maxEvent));
317 TEveManager::TRedrawDisabler rd(gEve);
318 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
320 // !!! MT this is somewhat brutal; at least optionally, one could be
321 // a bit gentler, checking for objs owning their external refs and having
322 // additinal parents.
326 if (fRunLoader->GetEvent(event) != 0)
327 throw (kEH + "failed getting required event.");
331 if (fESDTree->GetEntry(event) <= 0)
332 throw (kEH + "failed getting required event from ESD.");
334 if (fESDfriendExists)
335 fESD->SetESDfriend(fESDfriend);
340 Int_t rawEv = fEventId;
343 fRawReader->RewindEvents();
347 while (rawEv < event)
349 if ( ! fRawReader->NextEvent())
351 fRawReader->RewindEvents();
353 throw (kEH + Form("Error going to next raw-event from event %d.", rawEv));
358 printf ("Loaded raw-event %d.\n", rawEv);
362 SetName(Form("Event %d", fEventId));
365 AfterNewEventLoaded();
368 void AliEveEventManager::Close()
370 // Close the event files.
371 // For the moment only ESD is closed. Needs to be investigated for
372 // AliRunLoader and Raw.
375 delete fESD; fESD = 0;
376 delete fESDfriend; fESDfriend = 0;
378 delete fESDTree; fESDTree = 0;
379 delete fESDFile; fESDFile = 0;
384 /******************************************************************************/
385 // Static convenience functions, mainly used from macros.
386 /******************************************************************************/
388 AliRunLoader* AliEveEventManager::AssertRunLoader()
390 // Make sure AliRunLoader is initialized and return it.
391 // Throws exception in case run-loader is not available.
392 // Static utility for macros.
394 static const TEveException kEH("AliEveEventManager::AssertRunLoader ");
396 if (gAliEveEvent == 0)
397 throw (kEH + "ALICE event not ready.");
398 if (gAliEveEvent->fRunLoader == 0)
399 throw (kEH + "AliRunLoader not initialised.");
400 return gAliEveEvent->fRunLoader;
403 AliESDEvent* AliEveEventManager::AssertESD()
405 // Make sure AliESDEvent is initialized and return it.
406 // Throws exception in case ESD is not available.
407 // Static utility for macros.
409 static const TEveException kEH("AliEveEventManager::AssertESD ");
411 if (gAliEveEvent == 0)
412 throw (kEH + "ALICE event not ready.");
413 if (gAliEveEvent->fESD == 0)
414 throw (kEH + "AliESD not initialised.");
415 return gAliEveEvent->fESD;
418 AliESDfriend* AliEveEventManager::AssertESDfriend()
420 // Make sure AliESDfriend is initialized and return it.
421 // Throws exception in case ESDfriend-loader is not available.
422 // Static utility for macros.
424 static const TEveException kEH("AliEveEventManager::AssertESDfriend ");
426 if (gAliEveEvent == 0)
427 throw (kEH + "ALICE event not ready.");
428 if (gAliEveEvent->fESDfriend == 0)
429 throw (kEH + "AliESDfriend not initialised.");
430 return gAliEveEvent->fESDfriend;
433 AliRawReader* AliEveEventManager::AssertRawReader()
435 // Make sure raw-reader is initialized and return it.
437 static const TEveException kEH("AliEveEventManager::AssertRawReader ");
439 if (gAliEveEvent == 0)
440 throw (kEH + "ALICE event not ready.");
441 if (gAliEveEvent->fRawReader == 0)
442 throw (kEH + "RawReader not ready.");
444 return gAliEveEvent->fRawReader;
447 AliMagF* AliEveEventManager::AssertMagField()
449 // Make sure AliMagF is initialized and return it.
450 // Throws exception in case magnetic field is not available.
451 // Static utility for macros.
455 if (gAliEveEvent && gAliEveEvent->fRunLoader && gAliEveEvent->fRunLoader->GetAliRun())
456 fgMagField = gAliEveEvent->fRunLoader->GetAliRun()->Field();
458 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
463 TGeoManager* AliEveEventManager::AssertGeometry()
465 // Make sure AliGeomManager is initialized and returns the
466 // corresponding TGeoManger.
467 // gGeoManager is set to the return value.
468 // Throws exception if geometry can not be loaded or if it is not
469 // available and the TGeoManager is locked.
470 // Static utility for macros.
472 static const TEveException kEH("AliEveEventManager::AssertGeometry ");
474 if (AliGeomManager::GetGeometry() == 0)
476 if (TGeoManager::IsLocked())
477 throw (kEH + "geometry is not loaded but TGeoManager is locked.");
480 AliGeomManager::LoadGeometry();
481 if ( ! AliGeomManager::GetGeometry())
483 throw (kEH + "can not load geometry.");
485 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
487 ::Warning(kEH, "mismatch of alignable volumes. Proceeding.");
488 // throw (kEH + "could not apply align objs.");
491 // @@NEWROOT@@ Temporary fix.
492 // In AliEve several simplified geometries can be loaded at a later stage.
493 // Locking/unlocking is now handled properly in
494 // TEveManager::GetGeometry() but we're waiting for next root
495 // version due on 14.5.2008.
496 TGeoManager::UnlockGeometry();
499 gGeoManager = AliGeomManager::GetGeometry();