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