]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveEventManager.cxx
Remove default OCDB location and exit with fatal error if OCDB URI is
[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"
008ac94c 11#include "AliEveEventSelector.h"
f6afd0e1 12#include "AliEveMacroExecutor.h"
84aff7a4 13#include <TEveManager.h>
b9579f03 14#include <TEveViewer.h>
5a5a1232 15
16#include <AliRunLoader.h>
93845f6c 17#include <AliRun.h>
b3b7b8d3 18#include <AliESDRun.h>
af885e0f 19#include <AliESDEvent.h>
3aecaefc 20#include <AliESDfriend.h>
b3b7b8d3 21#include <AliAODEvent.h>
22
ec835ab5 23#include <AliDAQ.h>
24#include <AliRawEventHeaderBase.h>
c2c4b7a2 25#include <AliRawReaderRoot.h>
26#include <AliRawReaderFile.h>
27#include <AliRawReaderDate.h>
f7a1cc68 28#include <AliMagF.h>
632d2b03 29#include <AliCDBManager.h>
d3ed470c 30#include <AliCDBStorage.h>
8661a211 31#include <AliGRPObject.h>
632d2b03 32#include <AliHeader.h>
33#include <AliGeomManager.h>
55216596 34#include <AliGRPManager.h>
14a4b686 35#include <AliSysInfo.h>
5a5a1232 36
37#include <TFile.h>
38#include <TTree.h>
fbc350a3 39#include <TGeoManager.h>
8661a211 40#include <TGeoGlobalMagField.h>
5a5a1232 41#include <TSystem.h>
12365217 42#include <TTimeStamp.h>
8661a211 43#include <TPRegexp.h>
44#include <TError.h>
d810d0de 45
a15e6d7d 46//==============================================================================
47//==============================================================================
48// AliEveEventManager
49//==============================================================================
5a5a1232 50
57ffa5fb 51//______________________________________________________________________________
5a5a1232 52//
4d62585e 53// Provides interface for loading and navigating standard AliRoot data
b3b7b8d3 54// (AliRunLoader), ESD, AOD and RAW.
55//
56// ESDfriend is attached automatically, if the file is found.
57//
58// AODfriends are not attached automatically as there are several
59// possible files involved. To have a specific AODfriend attached, call
60// static method
61// AliEveEventManager::AddAODfriend("AliAOD.VertexingHF.root");
62// before initializing the event-manager.
51346b82 63//
a15e6d7d 64// Also provides interface to magnetic-field and geometry. Mostly
65// intended as wrappers over standard AliRoot functionality for
66// convenient use from visualizateion macros.
4d62585e 67//
68// There can be a single main event-manger, it is stored in private
69// data member fgMaster and can be accessed via static member function
70// GetMaster().
71//
72// For event overlaying and embedding one can instantiate additional
73// event-managers via static method AddDependentManager(const TString& path).
74// This interface is under development.
5a5a1232 75
d810d0de 76ClassImp(AliEveEventManager)
5a5a1232 77
d810d0de 78Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE;
c76ea574 79Bool_t AliEveEventManager::fgAssertESD = kFALSE;
b3b7b8d3 80Bool_t AliEveEventManager::fgAssertAOD = kFALSE;
c2c4b7a2 81Bool_t AliEveEventManager::fgAssertRaw = kFALSE;
5a5a1232 82
c2c4b7a2 83TString AliEveEventManager::fgESDFileName("AliESDs.root");
b3b7b8d3 84TString AliEveEventManager::fgAODFileName("AliAOD.root");
c2c4b7a2 85TString AliEveEventManager::fgRawFileName("raw.root");
c63f2997 86TString AliEveEventManager::fgCdbUri;
632d2b03 87
b3b7b8d3 88TList* AliEveEventManager::fgAODfriends = 0;
89
55216596 90Bool_t AliEveEventManager::fgGRPLoaded = kFALSE;
8661a211 91AliMagF* AliEveEventManager::fgMagField = 0;
92Bool_t AliEveEventManager::fgUniformField = kFALSE;
93
4d62585e 94AliEveEventManager* AliEveEventManager::fgMaster = 0;
95AliEveEventManager* AliEveEventManager::fgCurrent = 0;
96
488869c1 97void AliEveEventManager::InitInternals()
98{
99 // Initialize internal members.
100
4d62585e 101 static const TEveException kEH("AliEveEventManager::InitInternals ");
102
103 if (fgCurrent != 0)
104 {
105 throw(kEH + "Dependent event-managers should be created via static method AddDependentManager().");
106 }
107
108 if (fgMaster == 0)
109 {
110 fgMaster = this;
111 }
112
113 fgCurrent = this;
114
488869c1 115 fAutoLoadTimer = new TTimer;
116 fAutoLoadTimer->Connect("Timeout()", "AliEveEventManager", this, "AutoLoadNextEvent()");
117
118 fExecutor = new AliEveMacroExecutor;
08b0f222 119
120 fTransients = new TEveElementList("Transients", "Transient per-event elements.");
121 fTransients->IncDenyDestroy();
8661a211 122 gEve->AddToListTree(fTransients, kFALSE);
123
124 fTransientLists = new TEveElementList("Transient Lists", "Containers of transient elements.");
125 fTransientLists->IncDenyDestroy();
126 gEve->AddToListTree(fTransientLists, kFALSE);
008ac94c 127
128 fPEventSelector = new AliEveEventSelector(this);
488869c1 129}
93845f6c 130
ba5d58f2 131AliEveEventManager::AliEveEventManager(const TString& name) :
132 TEveEventManager(name),
265ecb21 133
c2c4b7a2 134 fPath ( ), fEventId (-1),
265ecb21 135 fRunLoader (0),
90fa773e 136 fESDFile (0), fESDTree (0), fESD (0),
c2c4b7a2 137 fESDfriend (0), fESDfriendExists(kFALSE),
b3b7b8d3 138 fAODFile (0), fAODTree (0), fAOD (0),
319f3084 139 fRawReader (0),
80547f2d 140 fAutoLoad (kFALSE), fAutoLoadTime (5.), fAutoLoadTimer(0),
141 fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE),
8661a211 142 fExecutor (0), fTransients(0), fTransientLists(0),
008ac94c 143 fPEventSelector(0),
4d62585e 144 fSubManagers (0),
488869c1 145 fAutoLoadTimerRunning(kFALSE)
c76ea574 146{
147 // Default constructor.
488869c1 148
149 InitInternals();
c76ea574 150}
5a5a1232 151
ba5d58f2 152AliEveEventManager::AliEveEventManager(const TString& name, const TString& path, Int_t ev) :
153 TEveEventManager(name, path),
265ecb21 154
c76ea574 155 fPath (path), fEventId(-1),
265ecb21 156 fRunLoader (0),
90fa773e 157 fESDFile (0), fESDTree (0), fESD (0),
c2c4b7a2 158 fESDfriend (0), fESDfriendExists(kFALSE),
b3b7b8d3 159 fAODFile (0), fAODTree (0), fAOD (0),
319f3084 160 fRawReader (0),
488869c1 161 fAutoLoad (kFALSE), fAutoLoadTime (5), fAutoLoadTimer(0),
80547f2d 162 fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE),
8661a211 163 fExecutor (0), fTransients(0), fTransientLists(0),
008ac94c 164 fPEventSelector(0),
4d62585e 165 fSubManagers (0),
488869c1 166 fAutoLoadTimerRunning(kFALSE)
5a5a1232 167{
c76ea574 168 // Constructor with event-directory URL and event-id.
169
488869c1 170 InitInternals();
171
5a5a1232 172 Open();
488869c1 173 if (ev >= 0)
174 {
175 GotoEvent(ev);
176 }
5a5a1232 177}
178
a15e6d7d 179AliEveEventManager::~AliEveEventManager()
180{
181 // Destructor.
182
ba5d58f2 183 delete fSubManagers;
184
80547f2d 185 if (fIsOpen)
186 {
187 Close();
188 }
08b0f222 189
190 fTransients->DecDenyDestroy();
191 fTransients->Destroy();
8661a211 192
193 fTransientLists->DecDenyDestroy();
194 fTransientLists->Destroy();
a15e6d7d 195}
196
57ffa5fb 197/******************************************************************************/
5a5a1232 198
4d62585e 199void AliEveEventManager::SetESDFileName(const TString& esd)
c2c4b7a2 200{
201 // Set file-name for opening ESD, default "AliESDs.root".
202
4d62585e 203 if ( ! esd.IsNull()) fgESDFileName = esd;
c2c4b7a2 204}
205
b3b7b8d3 206void AliEveEventManager::SetAODFileName(const TString& aod)
207{
208 // Set file-name for opening AOD, default "AliAOD.root".
209
210 if ( ! aod.IsNull()) fgAODFileName = aod;
211}
212
213void AliEveEventManager::AddAODfriend(const TString& friendFileName)
214{
215 // Add new AOD friend file-name to be attached when opening AOD.
216 // This should include '.root', as in 'AliAOD.VertexingHF.root'.
217
218 if (fgAODfriends == 0)
219 {
220 fgAODfriends = new TList;
221 fgAODfriends->SetOwner(kTRUE);
222 }
f8d5a389 223 if (fgAODfriends->FindObject(friendFileName) == 0)
224 {
225 fgAODfriends->Add(new TObjString(friendFileName));
226 }
b3b7b8d3 227}
228
4d62585e 229void AliEveEventManager::SetRawFileName(const TString& raw)
c2c4b7a2 230{
231 // Set file-name for opening of raw-data, default "raw.root"
4d62585e 232 if ( ! raw.IsNull()) fgRawFileName = raw;
c2c4b7a2 233}
234
4d62585e 235void AliEveEventManager::SetCdbUri(const TString& cdb)
c2c4b7a2 236{
c63f2997 237 // Set path to CDB, there is no default.
c2c4b7a2 238
4d62585e 239 if ( ! cdb.IsNull()) fgCdbUri = cdb;
c2c4b7a2 240}
241
b3b7b8d3 242void AliEveEventManager::SetAssertElements(Bool_t assertRunloader, Bool_t assertEsd,
243 Bool_t assertAod, Bool_t assertRaw)
c2c4b7a2 244{
245 // Set global flags that detrmine which parts of the event-data must
246 // be present when the event is opened.
247
248 fgAssertRunLoader = assertRunloader;
249 fgAssertESD = assertEsd;
b3b7b8d3 250 fgAssertAOD = assertAod;
c2c4b7a2 251 fgAssertRaw = assertRaw;
252}
253
254/******************************************************************************/
255
d810d0de 256void AliEveEventManager::Open()
5a5a1232 257{
c76ea574 258 // Open event-data from URL specified in fPath.
259 // Attempts to create AliRunLoader() and to open ESD with ESDfriends.
260 // Warning is reported if run-loader or ESD is not found.
261 // Global data-members fgAssertRunLoader and fgAssertESD can be set
262 // to throw exceptions instead.
263
a15e6d7d 264 static const TEveException kEH("AliEveEventManager::Open ");
5a5a1232 265
80547f2d 266 if (fExternalCtrl)
267 {
268 throw (kEH + "Event-loop is under external control.");
269 }
270 if (fIsOpen)
271 {
272 throw (kEH + "Event-files already opened.");
273 }
274
5a5a1232 275 gSystem->ExpandPathName(fPath);
ba5d58f2 276 // The following magick is required for ESDfriends to be loaded properly
5a58dc18 277 // from non-current directory.
278 if (fPath.IsNull() || fPath == ".")
279 {
280 fPath = gSystem->WorkingDirectory();
281 }
282 else if ( ! fPath.BeginsWith("file:/"))
283 {
284 TUrl url(fPath, kTRUE);
285 TString protocol(url.GetProtocol());
286 if (protocol == "file" && fPath[0] != '/')
287 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
288 }
5a5a1232 289
632d2b03 290 Int_t runNo = -1;
291
db748c38 292 // Open ESD and ESDfriends
293
294 TString esdPath(Form("%s/%s", fPath.Data(), fgESDFileName.Data()));
295 if ((fESDFile = TFile::Open(esdPath)))
296 {
297 fESD = new AliESDEvent();
298 fESDTree = (TTree*) fESDFile->Get("esdTree");
299 if (fESDTree != 0)
300 {
73267f50 301 // Check if ESDfriends exists and attach the branch.
302 // We use TFile::Open() instead of gSystem->AccessPathName
303 // as it seems to work better when attachine alieve to a
304 // running reconstruction process with auto-save on.
305 // There was also a problem with TTree::Refresh() - it didn't
306 // save the friend branch on a separate file, fixed in 5.22.2 -
307 // so we might want to try the old way again soon.
db748c38 308 TString p(Form("%s/AliESDfriends.root", fPath.Data()));
fa46c586 309 TFile *esdFriendFile = TFile::Open(p);
73267f50 310 if (esdFriendFile)
311 {
fa46c586 312 if (!esdFriendFile->IsZombie())
73267f50 313 {
314 esdFriendFile->Close();
315 fESDfriendExists = kTRUE;
316 fESDTree->SetBranchStatus ("ESDfriend*", 1);
317 }
318 delete esdFriendFile;
db748c38 319 }
fa46c586 320
321 fESD->ReadFromTree(fESDTree);
73267f50 322 if (fESDfriendExists)
323 {
324 fESDfriend = (AliESDfriend*) fESD->FindListObject("AliESDfriend");
325 Info(kEH, "found and attached ESD friend.");
326 }
327 else
328 {
329 Warning(kEH, "ESDfriend not found.");
330 }
331
fa46c586 332 if (fESDTree->GetEntry(0) <= 0)
73267f50 333 {
334 delete fESDFile; fESDFile = 0;
335 delete fESD; fESD = 0;
336 Warning(kEH, "failed getting the first entry from esdTree.");
337 }
fa46c586 338 else
73267f50 339 {
340 if (runNo < 0)
341 runNo = fESD->GetESDRun()->GetRunNumber();
342 }
db748c38 343 }
344 else // esdtree == 0
345 {
346 delete fESDFile; fESDFile = 0;
fa46c586 347 delete fESD; fESD = 0;
db748c38 348 Warning(kEH, "failed getting the esdTree.");
349 }
350 }
351 else // esd not readable
352 {
353 Warning(kEH, "can not read ESD file '%s'.", esdPath.Data());
354 }
355 if (fESDTree == 0)
356 {
357 if (fgAssertESD)
358 {
359 throw (kEH + "ESD not initialized. Its precence was requested.");
360 } else {
361 Warning(kEH, "ESD not initialized.");
362 }
363 }
364
b3b7b8d3 365 // Open AOD and registered friends
366
367 TString aodPath(Form("%s/%s", fPath.Data(), fgAODFileName.Data()));
368 if ((fAODFile = TFile::Open(aodPath)))
369 {
370 fAOD = new AliAODEvent();
371 fAODTree = (TTree*) fAODFile->Get("aodTree");
372 if (fAODTree != 0)
373 {
374 // Check if AODfriends exist and attach them.
375 TIter friends(fgAODfriends);
376 TObjString *name;
377 while ((name = (TObjString*) friends()) != 0)
378 {
379 TString p(Form("%s/%s", fPath.Data(), name->GetName()));
380 if (gSystem->AccessPathName(p, kReadPermission) == kFALSE)
381 {
382 fAODTree->AddFriend("aodTree", name->GetName());
383 }
384 }
385
386 fAOD->ReadFromTree(fAODTree);
387
388 if (fAODTree->GetEntry(0) <= 0)
389 {
390 delete fAODFile; fAODFile = 0;
391 delete fAOD; fAOD = 0;
392 Warning(kEH, "failed getting the first entry from addTree.");
393 }
394 else
395 {
396 if (runNo < 0)
397 runNo = fAOD->GetRunNumber();
398 }
399 }
400 else // aodtree == 0
401 {
402 delete fAODFile; fAODFile = 0;
403 delete fAOD; fAOD = 0;
404 Warning(kEH, "failed getting the aodTree.");
405 }
406 }
407 else // aod not readable
408 {
409 Warning(kEH, "can not read AOD file '%s'.", aodPath.Data());
410 }
411 if (fAODTree == 0)
412 {
413 if (fgAssertAOD)
414 {
415 throw (kEH + "AOD not initialized. Its precence was requested.");
416 } else {
417 Warning(kEH, "AOD not initialized.");
418 }
419 }
420
db748c38 421 // Open RunLoader from galice.root
422
a15e6d7d 423 TString gaPath(Form("%s/galice.root", fPath.Data()));
c2c4b7a2 424 // If i use open directly, we get fatal.
db748c38 425 // Is AccessPathName check ok for xrootd / alien? Yes, not for http.
a15e6d7d 426 if (gSystem->AccessPathName(gaPath, kReadPermission) == kFALSE)
90fa773e 427 {
ba5d58f2 428 fRunLoader = AliRunLoader::Open(gaPath, GetName());
a1896a82 429 if (fRunLoader)
5a5a1232 430 {
a15e6d7d 431 TString alicePath = fPath + "/";
432 fRunLoader->SetDirName(alicePath);
a1896a82 433
434 if (fRunLoader->LoadgAlice() != 0)
c2c4b7a2 435 Warning(kEH, "failed loading gAlice via run-loader.");
a1896a82 436
437 if (fRunLoader->LoadHeader() == 0)
438 {
db748c38 439 if (runNo < 0)
440 runNo = fRunLoader->GetHeader()->GetRun();
a1896a82 441 }
442 else
443 {
c2c4b7a2 444 Warning(kEH, "failed loading run-loader's header.");
445 delete fRunLoader;
446 fRunLoader = 0;
a1896a82 447 }
448 }
449 else // run-loader open failed
450 {
a15e6d7d 451 Warning(kEH, "failed opening ALICE run-loader from '%s'.", gaPath.Data());
5a5a1232 452 }
5a5a1232 453 }
a1896a82 454 else // galice not readable
455 {
a15e6d7d 456 Warning(kEH, "can not read '%s'.", gaPath.Data());
a1896a82 457 }
458 if (fRunLoader == 0)
459 {
84aff7a4 460 if (fgAssertRunLoader)
c2c4b7a2 461 throw (kEH + "Bootstraping of run-loader failed. Its precence was requested.");
a1896a82 462 else
a15e6d7d 463 Warning(kEH, "Bootstraping of run-loader failed.");
a1896a82 464 }
51346b82 465
db748c38 466 // Open raw-data file
5a5a1232 467
c2c4b7a2 468 TString rawPath(Form("%s/%s", fPath.Data(), fgRawFileName.Data()));
ecb84424 469 // If i use open directly, raw-reader reports an error but i have
470 // no way to detect it.
471 // Is this (AccessPathName check) ok for xrootd / alien? Yes, not for http.
f337c1d6 472 AliLog::EType_t oldLogLevel = (AliLog::EType_t) AliLog::GetGlobalLogLevel();
473 if (fgAssertRaw == kFALSE)
474 {
475 AliLog::SetGlobalLogLevel(AliLog::kFatal);
476 }
ecb84424 477 if (gSystem->AccessPathName(rawPath, kReadPermission) == kFALSE)
2827badf 478 {
479 fRawReader = AliRawReader::Create(rawPath);
480 }
481 else
482 {
483 fRawReader = AliRawReader::Create(fgRawFileName);
484 }
f337c1d6 485 if (fgAssertRaw == kFALSE)
486 {
487 AliLog::SetGlobalLogLevel(oldLogLevel);
488 }
489
c2c4b7a2 490 if (fRawReader == 0)
491 {
492 if (fgAssertRaw)
493 {
494 throw (kEH + "raw-data not initialized. Its precence was requested.");
495 } else {
496 Warning(kEH, "raw-data not initialized.");
497 }
498 }
499
632d2b03 500 if (runNo < 0)
c2c4b7a2 501 {
502 if (fRawReader)
503 {
504 fRawReader->NextEvent();
505 runNo = fRawReader->GetRunNumber();
ca49b003 506 Info(kEH, "Determining run-no from raw ... run=%d.", runNo);
c2c4b7a2 507 fRawReader->RewindEvents();
508 } else {
509 throw (kEH + "unknown run number.");
510 }
511 }
632d2b03 512
b3b7b8d3 513 // Initialize OCDB ... only in master event-manager
514
ba5d58f2 515 if (this == fgMaster)
632d2b03 516 {
517 AliCDBManager* cdb = AliCDBManager::Instance();
d3ed470c 518 if (cdb->IsDefaultStorageSet() == kTRUE)
519 {
520 Warning(kEH, "CDB already set - using the old storage:\n '%s'",
521 cdb->GetDefaultStorage()->GetURI().Data());
522 }
523 else
524 {
c63f2997 525 if (fgCdbUri.IsNull())
526 {
527 gEnv->SetValue("Root.Stacktrace", "no");
528 Fatal("Open()", "OCDB path was not specified.");
529 }
530
531 // Handle some special cases for MC (should be in OCDBManager).
532 if (fgCdbUri == "mcideal://")
533 cdb->SetDefaultStorage("MC", "Ideal");
534 else if (fgCdbUri == "mcresidual://")
535 cdb->SetDefaultStorage("MC", "Residual");
536 else if (fgCdbUri == "mcfull://")
537 cdb->SetDefaultStorage("MC", "Full");
538 else if (fgCdbUri == "local://") {
539 fgCdbUri = "local://$ALICE_ROOT/OCDB";
540 cdb->SetDefaultStorage(fgCdbUri);
541 } else
542 cdb->SetDefaultStorage(fgCdbUri);
d3ed470c 543 if (cdb->IsDefaultStorageSet() == kFALSE)
c63f2997 544 throw kEH + "CDB initialization failed.";
d3ed470c 545 }
047cb6f4 546
c63f2997 547 if (fgCdbUri.BeginsWith("local://"))
047cb6f4 548 {
549 TString grp = "GRP/GRP/Data";
550 TString grppath = fPath + "/" + grp;
551 if (gSystem->AccessPathName(grppath, kReadPermission) == kFALSE)
552 {
553 if (cdb->GetSpecificStorage(grp))
554 {
555 Warning(kEH, "Local GRP exists, but the specific storage is already set.");
556 }
557 else
558 {
559 Info(kEH, "Setting CDB specific-storage for GRP from event directory.");
560 TString lpath("local://");
561 lpath += fPath;
562 cdb->SetSpecificStorage(grp, lpath);
563 }
564 }
565 }
632d2b03 566 cdb->SetRun(runNo);
567 }
568
80547f2d 569 fIsOpen = kTRUE;
5a5a1232 570}
571
482d0751 572void AliEveEventManager::SetEvent(AliRunLoader *runLoader, AliRawReader *rawReader, AliESDEvent *esd, AliESDfriend *esdf)
319f3084 573{
b3b7b8d3 574 // Set an event from an external source.
575 // The method is used in the online visualisation.
576 // AOD is not supported.
80547f2d 577
578 static const TEveException kEH("AliEveEventManager::SetEvent ");
579
580 if (fIsOpen)
581 {
582 Warning(kEH, "Event-files were open. Closing and switching to external control.");
583 Close();
584 }
585
319f3084 586 fRunLoader = runLoader;
587 fRawReader = rawReader;
80547f2d 588 fESD = esd;
482d0751 589 fESDfriend = esdf;
b3b7b8d3 590 fAOD = 0;
80547f2d 591
592 fEventId++;
593 fHasEvent = kTRUE;
594 fExternalCtrl = kTRUE;
595
319f3084 596 SetTitle("Online event in memory");
80547f2d 597 SetName ("Online Event");
319f3084 598 ElementChanged();
ba5d58f2 599
319f3084 600 AfterNewEventLoaded();
47aab29b 601
ecb84424 602 if (fAutoLoad) StartAutoLoadTimer();
319f3084 603}
604
f76c9e9b 605Int_t AliEveEventManager::GetMaxEventId(Bool_t /*refreshESD*/) const
516389a2 606{
607 // Returns maximum available event id.
80547f2d 608 // If under external control or event is not opened -1 is returned.
516389a2 609 // If raw-data is the only data-source this can not be known
610 // and 10,000,000 is returned.
611 // If neither data-source is initialised an exception is thrown.
612 // If refresh_esd is true and ESD is the primary event-data source
613 // its header is re-read from disk.
614
615 static const TEveException kEH("AliEveEventManager::GetMaxEventId ");
616
80547f2d 617 if (fExternalCtrl || fIsOpen == kFALSE)
618 {
619 return -1;
620 }
621
f76c9e9b 622 if (fESDTree)
516389a2 623 {
f76c9e9b 624 // Refresh crashes with root-5.21.1-alice.
625 // Fixed by Philippe 5.8.2008 r25053, can be reactivated
626 // when we move to a newer root.
627 // if (refreshESD)
628 // fESDTree->Refresh();
629 return fESDTree->GetEntries() - 1;
516389a2 630 }
b3b7b8d3 631 else if (fAODTree)
632 {
633 return fAODTree->GetEntries() - 1;
634 }
f76c9e9b 635 else if (fRunLoader)
516389a2 636 {
f76c9e9b 637 return fRunLoader->GetNumberOfEvents() - 1;
516389a2 638 }
639 else if (fRawReader)
640 {
ae1a1b11 641 Int_t n = fRawReader->GetNumberOfEvents() - 1;
642 return n > -1 ? n : 10000000;
516389a2 643 }
644 else
645 {
b3b7b8d3 646 throw (kEH + "neither ESD, AOD, RunLoader nor Raw loaded.");
516389a2 647 }
648}
649
d810d0de 650void AliEveEventManager::GotoEvent(Int_t event)
1eaa5849 651{
73c1c0ec 652 // Load data for specified event.
653 // If event is out of range an exception is thrown and old state
654 // is preserved.
655 // After successful loading of event, the virtual function
656 // AfterNewEventLoaded() is called. This executes commands that
657 // were registered via TEveEventManager::AddNewEventCommand().
516389a2 658 //
659 // If event is negative, it is subtracted from the number of
660 // available events, thus passing -1 will load the last event.
661 // This is not supported when raw-data is the only data-source
662 // as the number of events is not known.
73c1c0ec 663
a15e6d7d 664 static const TEveException kEH("AliEveEventManager::GotoEvent ");
1eaa5849 665
488869c1 666 if (fAutoLoadTimerRunning)
667 {
668 throw (kEH + "Event auto-load timer is running.");
669 }
80547f2d 670 if (fExternalCtrl)
671 {
672 throw (kEH + "Event-loop is under external control.");
673 }
488869c1 674 else if (!fIsOpen)
80547f2d 675 {
676 throw (kEH + "Event-files not opened.");
677 }
678
679 fHasEvent = kFALSE;
680
1eaa5849 681 Int_t maxEvent = 0;
db748c38 682 if (fESDTree)
516389a2 683 {
ca49b003 684 // Refresh crashes with root-5.21.1-alice.
685 // Fixed by Philippe 5.8.2008 r25053, can be reactivated
686 // when we move to a newer root.
687 // fESDTree->Refresh();
1eaa5849 688 maxEvent = fESDTree->GetEntries() - 1;
516389a2 689 if (event < 0)
690 event = fESDTree->GetEntries() + event;
691 }
b3b7b8d3 692 else if (fAODTree)
693 {
694 maxEvent = fAODTree->GetEntries() - 1;
695 if (event < 0)
696 event = fAODTree->GetEntries() + event;
697 }
db748c38 698 else if (fRunLoader)
699 {
700 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
701 if (event < 0)
702 event = fRunLoader->GetNumberOfEvents() + event;
703 }
516389a2 704 else if (fRawReader)
705 {
ae1a1b11 706 maxEvent = fRawReader->GetNumberOfEvents() - 1;
707 if (maxEvent < 0)
708 {
709 maxEvent = 10000000;
710 if (event < 0) {
711 Error(kEH, "current raw-data source does not support direct event access.");
712 return;
713 }
714 Info(kEH, "number of events unknown for current raw-data source, setting max-event id to 10M.");
715 }
716 else
717 {
718 if (event < 0)
719 event = fRawReader->GetNumberOfEvents() + event;
516389a2 720 }
516389a2 721 }
722 else
723 {
c2c4b7a2 724 throw (kEH + "neither RunLoader, ESD nor Raw loaded.");
725 }
84aff7a4 726 if (event < 0 || event > maxEvent)
516389a2 727 {
c2c4b7a2 728 throw (kEH + Form("event %d not present, available range [%d, %d].",
729 event, 0, maxEvent));
516389a2 730 }
1eaa5849 731
14a4b686 732 TString sysInfoHeader;
733 sysInfoHeader.Form("AliEveEventManager::GotoEvent(%d) - ", event);
734 AliSysInfo::AddStamp(sysInfoHeader + "Start");
735
84aff7a4 736 TEveManager::TRedrawDisabler rd(gEve);
737 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 738
32e219c2 739 // !!! MT this is somewhat brutal; at least optionally, one could be
740 // a bit gentler, checking for objs owning their external refs and having
741 // additinal parents.
b9579f03 742 gEve->GetViewers()->DeleteAnnotations();
08b0f222 743 fTransients->DestroyElements();
8661a211 744 for (TEveElement::List_i i = fTransientLists->BeginChildren();
745 i != fTransientLists->EndChildren(); ++i)
746 {
747 (*i)->DestroyElements();
748 }
1eaa5849 749 DestroyElements();
1eaa5849 750
14a4b686 751 AliSysInfo::AddStamp(sysInfoHeader + "PostDestroy");
752
84aff7a4 753 if (fESDTree) {
c2c4b7a2 754 if (fESDTree->GetEntry(event) <= 0)
755 throw (kEH + "failed getting required event from ESD.");
1eaa5849 756
2cea771a 757 if (fESDfriendExists)
1eaa5849 758 fESD->SetESDfriend(fESDfriend);
1eaa5849 759 }
90fa773e 760
b3b7b8d3 761 if (fAODTree) {
762 if (fAODTree->GetEntry(event) <= 0)
763 throw (kEH + "failed getting required event from AOD.");
764 }
765
db748c38 766 if (fRunLoader) {
767 if (fRunLoader->GetEvent(event) != 0)
768 throw (kEH + "failed getting required event.");
769 }
770
c2c4b7a2 771 if (fRawReader)
772 {
ca49b003 773 // AliRawReader::GotoEvent(Int_t) works for AliRawReaderRoot/Chain.
774 if (fRawReader->GotoEvent(event) == kFALSE)
c2c4b7a2 775 {
ca49b003 776 // Use fallback method - iteration with NextEvent().
777 Int_t rawEv = fEventId;
778 if (event < rawEv)
c2c4b7a2 779 {
780 fRawReader->RewindEvents();
ca49b003 781 rawEv = -1;
c2c4b7a2 782 }
c2c4b7a2 783
ca49b003 784 while (rawEv < event)
785 {
786 if ( ! fRawReader->NextEvent())
787 {
788 fRawReader->RewindEvents();
789 fEventId = -1;
790 throw (kEH + Form("Error going to next raw-event from event %d.", rawEv));
791 }
792 ++rawEv;
793 }
794 Warning(kEH, "Loaded raw-event %d with fallback method.\n", rawEv);
795 }
c2c4b7a2 796 }
797
80547f2d 798 fHasEvent = kTRUE;
799 fEventId = event;
ba5d58f2 800 if (this == fgMaster)
801 {
802 SetName(Form("Event %d", fEventId));
803 ElementChanged();
804 }
c2c4b7a2 805
14a4b686 806 AliSysInfo::AddStamp(sysInfoHeader + "PostLoadEvent");
807
90fa773e 808 AfterNewEventLoaded();
14a4b686 809
810 AliSysInfo::AddStamp(sysInfoHeader + "PostUserActions");
1eaa5849 811}
812
516389a2 813void AliEveEventManager::NextEvent()
814{
80547f2d 815 // Loads next event.
816 // Does magick needed for online display when under external event control.
ecb84424 817
488869c1 818 static const TEveException kEH("AliEveEventManager::NextEvent ");
819
820 if (fAutoLoadTimerRunning)
ae1a1b11 821 {
488869c1 822 throw (kEH + "Event auto-load timer is running.");
823 }
516389a2 824
488869c1 825 if (fExternalCtrl)
826 {
827 // !!! This should really go somewhere else. It is done in GotoEvent(),
828 // so here we should do it in SetEvent().
516389a2 829 DestroyElements();
830
831 gSystem->ExitLoop();
ae1a1b11 832 }
833 else
834 {
008ac94c 835 Int_t nextevent=0;
836 if (fPEventSelector->FindNext(nextevent))
ecb84424 837 {
008ac94c 838 GotoEvent(nextevent);
ecb84424 839 }
516389a2 840 }
841}
842
843void AliEveEventManager::PrevEvent()
844{
80547f2d 845 // Loads previous event.
846
847 static const TEveException kEH("AliEveEventManager::PrevEvent ");
848
488869c1 849 if (fAutoLoadTimerRunning)
80547f2d 850 {
488869c1 851 throw (kEH + "Event auto-load timer is running.");
516389a2 852 }
488869c1 853 if (fExternalCtrl)
80547f2d 854 {
488869c1 855 throw (kEH + "Event-loop is under external control.");
80547f2d 856 }
008ac94c 857 Int_t nextevent=0;
858 if (fPEventSelector->FindPrev(nextevent))
ecb84424 859 {
008ac94c 860 GotoEvent(nextevent);
ecb84424 861 }
516389a2 862}
863
d810d0de 864void AliEveEventManager::Close()
5a5a1232 865{
ca49b003 866 // Close the event data-files and delete ESD, ESDfriend, run-loader
867 // and raw-reader.
73c1c0ec 868
80547f2d 869 static const TEveException kEH("AliEveEventManager::Close ");
870
871 if (!fIsOpen)
872 {
873 throw (kEH + "Event-files not opened.");
874 }
875
488869c1 876 if (fAutoLoadTimerRunning)
877 StopAutoLoadTimer();
878
2cea771a 879 if (fESDTree) {
880 delete fESD; fESD = 0;
881 delete fESDfriend; fESDfriend = 0;
73267f50 882 fESDfriendExists = kFALSE;
2cea771a 883
ca49b003 884 delete fESDTree; fESDTree = 0;
885 delete fESDFile; fESDFile = 0;
886 }
887
b3b7b8d3 888 if (fAODTree) {
889 delete fAOD; fAOD = 0;
890
891 delete fAODTree; fAODTree = 0;
892 delete fAODFile; fAODFile = 0;
893 }
894
ca49b003 895 if (fRunLoader) {
896 delete fRunLoader; fRunLoader = 0;
897 }
898
899 if (fRawReader) {
900 delete fRawReader; fRawReader = 0;
2cea771a 901 }
80547f2d 902
903 fEventId = -1;
904 fIsOpen = kFALSE;
905 fHasEvent = kFALSE;
5a5a1232 906}
907
90fa773e 908
80547f2d 909//------------------------------------------------------------------------------
c76ea574 910// Static convenience functions, mainly used from macros.
80547f2d 911//------------------------------------------------------------------------------
5a5a1232 912
f6afd0e1 913Bool_t AliEveEventManager::HasRunLoader()
914{
915 // Check if AliRunLoader is initialized.
916
4d62585e 917 return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fRunLoader;
f6afd0e1 918}
919
920Bool_t AliEveEventManager::HasESD()
921{
922 // Check if AliESDEvent is initialized.
923
4d62585e 924 return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fESD;
f6afd0e1 925}
926
927Bool_t AliEveEventManager::HasESDfriend()
928{
929 // Check if AliESDfriend is initialized.
930
4d62585e 931 return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fESDfriend;
f6afd0e1 932}
933
b3b7b8d3 934Bool_t AliEveEventManager::HasAOD()
935{
936 // Check if AliESDEvent is initialized.
937
938 return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fAOD;
939}
940
f6afd0e1 941Bool_t AliEveEventManager::HasRawReader()
942{
943 // Check if raw-reader is initialized.
944
4d62585e 945 return fgCurrent && fgCurrent->fHasEvent && fgCurrent->fRawReader;
f6afd0e1 946}
947
d810d0de 948AliRunLoader* AliEveEventManager::AssertRunLoader()
5a5a1232 949{
73c1c0ec 950 // Make sure AliRunLoader is initialized and return it.
951 // Throws exception in case run-loader is not available.
952 // Static utility for macros.
953
a15e6d7d 954 static const TEveException kEH("AliEveEventManager::AssertRunLoader ");
5a5a1232 955
4d62585e 956 if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE)
c2c4b7a2 957 throw (kEH + "ALICE event not ready.");
4d62585e 958 if (fgCurrent->fRunLoader == 0)
c2c4b7a2 959 throw (kEH + "AliRunLoader not initialised.");
4d62585e 960 return fgCurrent->fRunLoader;
5a5a1232 961}
962
d810d0de 963AliESDEvent* AliEveEventManager::AssertESD()
5a5a1232 964{
73c1c0ec 965 // Make sure AliESDEvent is initialized and return it.
966 // Throws exception in case ESD is not available.
967 // Static utility for macros.
968
a15e6d7d 969 static const TEveException kEH("AliEveEventManager::AssertESD ");
5a5a1232 970
4d62585e 971 if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE)
c2c4b7a2 972 throw (kEH + "ALICE event not ready.");
4d62585e 973 if (fgCurrent->fESD == 0)
c2c4b7a2 974 throw (kEH + "AliESD not initialised.");
4d62585e 975 return fgCurrent->fESD;
5a5a1232 976}
3aecaefc 977
d810d0de 978AliESDfriend* AliEveEventManager::AssertESDfriend()
3aecaefc 979{
73c1c0ec 980 // Make sure AliESDfriend is initialized and return it.
981 // Throws exception in case ESDfriend-loader is not available.
982 // Static utility for macros.
983
a15e6d7d 984 static const TEveException kEH("AliEveEventManager::AssertESDfriend ");
3aecaefc 985
4d62585e 986 if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE)
c2c4b7a2 987 throw (kEH + "ALICE event not ready.");
4d62585e 988 if (fgCurrent->fESDfriend == 0)
c2c4b7a2 989 throw (kEH + "AliESDfriend not initialised.");
4d62585e 990 return fgCurrent->fESDfriend;
3aecaefc 991}
93845f6c 992
b3b7b8d3 993AliAODEvent* AliEveEventManager::AssertAOD()
994{
995 // Make sure AliAODEvent is initialized and return it.
996 // Throws exception in case AOD is not available.
997 // Static utility for macros.
998
999 static const TEveException kEH("AliEveEventManager::AssertAOD ");
1000
1001 if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE)
1002 throw (kEH + "ALICE event not ready.");
1003 if (fgCurrent->fAOD == 0)
1004 throw (kEH + "AliAOD not initialised.");
1005 return fgCurrent->fAOD;
1006}
1007
c2c4b7a2 1008AliRawReader* AliEveEventManager::AssertRawReader()
1009{
1010 // Make sure raw-reader is initialized and return it.
1011
1012 static const TEveException kEH("AliEveEventManager::AssertRawReader ");
1013
4d62585e 1014 if (fgCurrent == 0 || fgCurrent->fHasEvent == kFALSE)
c2c4b7a2 1015 throw (kEH + "ALICE event not ready.");
4d62585e 1016 if (fgCurrent->fRawReader == 0)
c2c4b7a2 1017 throw (kEH + "RawReader not ready.");
1018
4d62585e 1019 return fgCurrent->fRawReader;
c2c4b7a2 1020}
1021
8661a211 1022//==============================================================================
1023
1024AliMagF* AliEveEventManager::AssertMagField()
1025{
1026 // Make sure AliMagF is initialized and returns it.
1027 // Throws exception in case magnetic field is not available.
1028 // Static utility for macros.
1029
1030 static const TEveException kEH("AliEveEventManager::AssertMagField ");
1031
1032 if (fgMagField)
1033 return fgMagField;
1034
911af103 1035 if (TGeoGlobalMagField::Instance()->GetField())
1036 {
1037 fgMagField = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
1038 if (fgMagField == 0)
1039 throw kEH + "Global field set, but it is not AliMagF.";
1040 return fgMagField;
1041 }
1042
55216596 1043 if (!fgGRPLoaded)
8661a211 1044 {
1045 InitGRP();
1046 }
1047
047cb6f4 1048 if (TGeoGlobalMagField::Instance()->GetField())
8661a211 1049 {
1050 fgMagField = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField());
1051 if (fgMagField == 0)
1052 throw kEH + "Global field set, but it is not AliMagF.";
1053 }
1054 else
1055 {
1056 throw kEH + "Could not initialize magnetic field.";
1057 }
1058
1059 return fgMagField;
1060}
632d2b03 1061
d810d0de 1062TGeoManager* AliEveEventManager::AssertGeometry()
632d2b03 1063{
73c1c0ec 1064 // Make sure AliGeomManager is initialized and returns the
1065 // corresponding TGeoManger.
647814a2 1066 // gGeoManager is set to the return value.
1067 // Throws exception if geometry can not be loaded or if it is not
1068 // available and the TGeoManager is locked.
73c1c0ec 1069 // Static utility for macros.
1070
a15e6d7d 1071 static const TEveException kEH("AliEveEventManager::AssertGeometry ");
632d2b03 1072
1073 if (AliGeomManager::GetGeometry() == 0)
1074 {
647814a2 1075 if (TGeoManager::IsLocked())
1076 throw (kEH + "geometry is not loaded but TGeoManager is locked.");
1077
af2e4ef5 1078 gGeoManager = 0;
632d2b03 1079 AliGeomManager::LoadGeometry();
1080 if ( ! AliGeomManager::GetGeometry())
1081 {
c2c4b7a2 1082 throw (kEH + "can not load geometry.");
632d2b03 1083 }
1084 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
1085 {
a15e6d7d 1086 ::Warning(kEH, "mismatch of alignable volumes. Proceeding.");
c2c4b7a2 1087 // throw (kEH + "could not apply align objs.");
632d2b03 1088 }
81515106 1089 AliGeomManager::GetGeometry()->DefaultColors();
632d2b03 1090 }
1091
647814a2 1092 gGeoManager = AliGeomManager::GetGeometry();
1093 return gGeoManager;
632d2b03 1094}
319f3084 1095
4d62585e 1096//------------------------------------------------------------------------------
1097
ba5d58f2 1098AliEveEventManager* AliEveEventManager::AddDependentManager(const TString& name, const TString& path)
4d62585e 1099{
1100 // Create and attach a dependent event-manager.
ba5d58f2 1101 // It is not added into eve list tree.
4d62585e 1102
1103 static const TEveException kEH("AliEveEventManager::AddDependentManager ");
1104
4d62585e 1105 if (fgMaster == 0)
1106 throw(kEH + "Master event-manager must be instantiated first.");
1107
1108 if (fgMaster->fSubManagers == 0)
ba5d58f2 1109 {
4d62585e 1110 fgMaster->fSubManagers = new TList;
ba5d58f2 1111 fgMaster->fSubManagers->SetOwner(kTRUE);
1112 }
4d62585e 1113
ba5d58f2 1114 AliEveEventManager* new_mgr = 0;
1115 fgCurrent = 0;
1116 try
1117 {
1118 new_mgr = new AliEveEventManager(name, path, fgMaster->fEventId);
1119 fgMaster->fSubManagers->Add(new_mgr);
1120 }
1121 catch (TEveException& exc)
1122 {
1123 ::Error(kEH, "Creation of new event-manager failed: '%s'.", exc.Data());
1124 }
1125 fgCurrent = fgMaster;
1126
1127 return new_mgr;
1128}
1129
1130AliEveEventManager* AliEveEventManager::GetDependentManager(const TString& name)
1131{
1132 // Get a dependant manager by name.
1133 // This will not change the current manager, use helper class
1134 // AliEveEventManager::CurrentChanger for that.
1135
1136 static const TEveException kEH("AliEveEventManager::GetDependentManager ");
1137
1138 if (fgMaster == 0)
1139 throw(kEH + "Master event-manager must be instantiated first.");
1140
1141 if (fgMaster->fSubManagers == 0)
1142 return 0;
1143
1144 return dynamic_cast<AliEveEventManager*>(fgMaster->fSubManagers->FindObject(name));
4d62585e 1145}
1146
1147AliEveEventManager* AliEveEventManager::GetMaster()
1148{
1149 // Get master event-manager.
1150
1151 return fgMaster;
1152}
1153
1154AliEveEventManager* AliEveEventManager::GetCurrent()
1155{
1156 // Get current event-manager.
1157
1158 return fgCurrent;
1159}
80547f2d 1160
08b0f222 1161void AliEveEventManager::RegisterTransient(TEveElement* element)
1162{
1163 GetCurrent()->fTransients->AddElement(element);
1164}
1165
8661a211 1166void AliEveEventManager::RegisterTransientList(TEveElement* element)
1167{
1168 GetCurrent()->fTransientLists->AddElement(element);
1169}
1170
80547f2d 1171//------------------------------------------------------------------------------
488869c1 1172// Autoloading of events
80547f2d 1173//------------------------------------------------------------------------------
1174
488869c1 1175void AliEveEventManager::SetAutoLoadTime(Float_t time)
1176{
1177 // Set the auto-load time in seconds
1178
1179 fAutoLoadTime = time;
1180}
1181
319f3084 1182void AliEveEventManager::SetAutoLoad(Bool_t autoLoad)
1183{
1184 // Set the automatic event loading mode
80547f2d 1185
488869c1 1186 static const TEveException kEH("AliEveEventManager::SetAutoLoad ");
1187
1188 if (fAutoLoad == autoLoad)
1189 {
1190 Warning(kEH, "Setting autoload to the same value as before - %s. Ignoring.", fAutoLoad ? "true" : "false");
1191 return;
1192 }
1193
319f3084 1194 fAutoLoad = autoLoad;
488869c1 1195 if (fAutoLoad)
1196 {
1197 StartAutoLoadTimer();
1198 }
1199 else
1200 {
1201 StopAutoLoadTimer();
1202 }
319f3084 1203}
1204
969d3431 1205void AliEveEventManager::SetTrigSel(Int_t trig)
1206{
1207 static const TEveException kEH("AliEveEventManager::SetTrigSel ");
1208
1209 if (!fRawReader)
1210 {
1211 Warning(kEH, "No Raw-reader exists. Ignoring the call.");
1212 return;
1213 }
1214 else
1215 {
1216 ULong64_t trigMask = 0;
1217 if (trig >= 0) trigMask = (1ull << trig);
1218 Info(kEH,"Trigger selection: 0x%llx",trigMask);
1219 fRawReader->SelectEvents(-1,trigMask,NULL);
1220 }
1221}
1222
488869c1 1223void AliEveEventManager::StartAutoLoadTimer()
319f3084 1224{
488869c1 1225 // Start the auto-load timer.
80547f2d 1226
488869c1 1227 fAutoLoadTimer->SetTime((Long_t)(1000*fAutoLoadTime));
1228 fAutoLoadTimer->Reset();
1229 fAutoLoadTimer->TurnOn();
1230 fAutoLoadTimerRunning = kTRUE;
319f3084 1231}
1232
488869c1 1233void AliEveEventManager::StopAutoLoadTimer()
319f3084 1234{
488869c1 1235 // Stop the auto-load timer.
80547f2d 1236
488869c1 1237 fAutoLoadTimerRunning = kFALSE;
1238 fAutoLoadTimer->TurnOff();
1239}
1240
1241void AliEveEventManager::AutoLoadNextEvent()
1242{
1243 // Called from auto-load timer, so it has to be public.
1244 // Do NOT call it directly.
1245
1246 static const TEveException kEH("AliEveEventManager::AutoLoadNextEvent ");
1247
1248 if ( ! fAutoLoadTimerRunning || ! fAutoLoadTimer->HasTimedOut())
f76c9e9b 1249 {
488869c1 1250 Warning(kEH, "Called unexpectedly - ignoring the call. Should ONLY be called from an internal timer.");
1251 return;
319f3084 1252 }
488869c1 1253
1254 StopAutoLoadTimer();
1255 NextEvent();
47aab29b 1256 if (fAutoLoad && !fExternalCtrl)
488869c1 1257 StartAutoLoadTimer();
319f3084 1258}
1259
80547f2d 1260//------------------------------------------------------------------------------
1261// Post event-loading functions
1262//------------------------------------------------------------------------------
1263
f6afd0e1 1264void AliEveEventManager::AfterNewEventLoaded()
1265{
1266 // Execute registered macros and commands.
1267 // At the end emit NewEventLoaded signal.
1268 //
1269 // Virtual from TEveEventManager.
1270
ba5d58f2 1271 static const TEveException kEH("AliEveEventManager::AfterNewEventLoaded ");
1272
f6afd0e1 1273 if (fExecutor)
1274 fExecutor->ExecMacros();
1275
1276 TEveEventManager::AfterNewEventLoaded();
1277
1278 NewEventLoaded();
ba5d58f2 1279
1280 if (this == fgMaster && fSubManagers != 0)
1281 {
1282 TIter next(fSubManagers);
1283 while ((fgCurrent = dynamic_cast<AliEveEventManager*>(next())) != 0)
1284 {
68ca2fe7 1285 gEve->SetCurrentEvent(fgCurrent);
ba5d58f2 1286 try
1287 {
1288 fgCurrent->GotoEvent(fEventId);
1289 }
1290 catch (TEveException& exc)
1291 {
1292 // !!! Should somehow tag / disable / remove it?
1293 Error(kEH, "Getting event %d for sub-event-manager '%s' failed: '%s'.",
1294 fEventId, fgCurrent->GetName(), exc.Data());
1295 }
1296 }
1297 fgCurrent = fgMaster;
68ca2fe7 1298 gEve->SetCurrentEvent(fgMaster);
ba5d58f2 1299 }
f6afd0e1 1300}
1301
f76c9e9b 1302void AliEveEventManager::NewEventLoaded()
1303{
1304 // Emit NewEventLoaded signal.
1305
1306 Emit("NewEventLoaded()");
1307}
1308
80547f2d 1309
1310//------------------------------------------------------------------------------
1311// Event info dumpers
1312//------------------------------------------------------------------------------
12365217 1313
1314TString AliEveEventManager::GetEventInfoHorizontal() const
1315{
1316 // Dumps the event-header contents in vertical formatting.
1317
1318 TString rawInfo, esdInfo;
1319
1320 if (!fRawReader)
1321 {
1322 rawInfo = "No raw-data event info is available!\n";
1323 }
1324 else
1325 {
1326 const UInt_t* attr = fRawReader->GetAttributes();
1327 TTimeStamp ts(fRawReader->GetTimestamp());
1328 rawInfo.Form("RAW event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n"
1329 "Trigger: %llx\nDetectors: %x (%s)\nAttributes:%x-%x-%x Timestamp: %s\n",
1330 fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()),
1331 fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(),
1332 fRawReader->GetClassMask(),
1333 *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()),
1334 attr[0],attr[1],attr[2], ts.AsString("s"));
1335 }
1336
1337 if (!fESD)
1338 {
1339 esdInfo = "No ESD event info is available!";
1340 }
1341 else
1342 {
1343 TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses();
1344 TString firedtrclasses = fESD->GetFiredTriggerClasses();
1345 TTimeStamp ts(fESD->GetTimeStamp());
1346 esdInfo.Form("ESD event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n"
ecb84424 1347 "Active trigger classes: %s\nTrigger: %llx (%s)\nEvent# in file: %d Timestamp: %s, MagField: %.2e",
12365217 1348 fESD->GetRunNumber(),
1349 fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()),
1350 fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(),
1351 acttrclasses.Data(),
1352 fESD->GetTriggerMask(),firedtrclasses.Data(),
ecb84424 1353 fESD->GetEventNumberInFile(), ts.AsString("s"), fESD->GetMagneticField());
12365217 1354 }
1355
1356 return rawInfo + esdInfo;
1357}
1358
1359TString AliEveEventManager::GetEventInfoVertical() const
319f3084 1360{
12365217 1361 // Dumps the event-header contents in vertical formatting.
319f3084 1362
12365217 1363 TString rawInfo, esdInfo;
319f3084 1364
12365217 1365 if (!fRawReader)
1366 {
1367 rawInfo = "No raw-data event info is available!\n";
ec835ab5 1368 }
12365217 1369 else
1370 {
ec835ab5 1371 const UInt_t* attr = fRawReader->GetAttributes();
12365217 1372 rawInfo.Form("Raw-data event info:\nRun#: %d\nEvent type: %d (%s)\nPeriod: %x\nOrbit: %x BC: %x\nTrigger: %llx\nDetectors: %x (%s)\nAttributes:%x-%x-%x\nTimestamp: %x\n",
1373 fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()),
1374 fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(),
1375 fRawReader->GetClassMask(),
1376 *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()),
1377 attr[0],attr[1],attr[2],
1378 fRawReader->GetTimestamp());
1379 }
1380
1381 if (!fESD)
1382 {
1383 esdInfo = "No ESD event info is available!\n";
1384 }
1385 else
1386 {
1387 TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses();
ec835ab5 1388 TString firedtrclasses = fESD->GetFiredTriggerClasses();
12365217 1389 esdInfo.Form("ESD event info:\nRun#: %d\nActive trigger classes: %s\nEvent type: %d (%s)\nPeriod: %x\nOrbit: %x BC: %x\nTrigger: %llx (%s)\nEvent# in file:%d\nTimestamp: %x\n",
1390 fESD->GetRunNumber(),
1391 acttrclasses.Data(),
1392 fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()),
1393 fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(),
1394 fESD->GetTriggerMask(),firedtrclasses.Data(),
1395 fESD->GetEventNumberInFile(),
1396 fESD->GetTimeStamp());
ec835ab5 1397 }
319f3084 1398
12365217 1399 return rawInfo + "\n" + esdInfo;
319f3084 1400}
8661a211 1401
1402
1403//==============================================================================
1404// Reading of GRP and MagneticField.
1405// This is a reap-off from reconstruction ... should really be a common
1406// code to do this somewhere in STEER.
1407//==============================================================================
1408
1409Bool_t AliEveEventManager::InitGRP()
1410{
1411 //------------------------------------
1412 // Initialization of the GRP entry
1413 //------------------------------------
1414
1415 static const TEveException kEH("AliEveEventManager::InitGRP ");
1416
55216596 1417 AliGRPManager grpMgr;
1418 if (!grpMgr.ReadGRPEntry()) {
8661a211 1419 return kFALSE;
1420 }
55216596 1421 fgGRPLoaded = kTRUE;
1422 if (!grpMgr.SetMagField()) {
1423 throw kEH + "Setting of field failed!";
8661a211 1424 }
1425
8661a211 1426 //*** Get the diamond profiles from OCDB
1427 // Eventually useful.
1428
1429 /*
1430 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1431 if (entry) {
1432 fDiamondProfileSPD = dynamic_cast<AliESDVertex*> (entry->GetObject());
1433 } else {
1434 ::Error(kEH, "No SPD diamond profile found in OCDB!");
1435 }
1436
1437 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1438 if (entry) {
1439 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
1440 } else {
1441 ::Error(kEH, "No diamond profile found in OCDB!");
1442 }
1443
1444 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexTPC");
1445 if (entry) {
1446 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
1447 } else {
1448 ::Error(kEH, "No TPC diamond profile found in OCDB!");
1449 }
1450 */
1451
1452 return kTRUE;
1453}