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