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