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