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