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