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