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