]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveBase/AliEveEventManager.cxx
IsPhysicalPrimary(): Check status code > 1, this works for Pythia and Phojet
[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"
f6afd0e1 11#include "AliEveMacroExecutor.h"
84aff7a4 12#include <TEveManager.h>
5a5a1232 13
14#include <AliRunLoader.h>
93845f6c 15#include <AliRun.h>
af885e0f 16#include <AliESDEvent.h>
3aecaefc 17#include <AliESDfriend.h>
ec835ab5 18#include <AliDAQ.h>
19#include <AliRawEventHeaderBase.h>
c2c4b7a2 20#include <AliRawReaderRoot.h>
21#include <AliRawReaderFile.h>
22#include <AliRawReaderDate.h>
93845f6c 23#include <AliMagFMaps.h>
632d2b03 24#include <AliCDBManager.h>
25#include <AliHeader.h>
26#include <AliGeomManager.h>
5a5a1232 27
28#include <TFile.h>
29#include <TTree.h>
fbc350a3 30#include <TGeoManager.h>
5a5a1232 31#include <TSystem.h>
12365217 32#include <TTimeStamp.h>
d810d0de 33
a15e6d7d 34//==============================================================================
35//==============================================================================
36// AliEveEventManager
37//==============================================================================
5a5a1232 38
57ffa5fb 39//______________________________________________________________________________
5a5a1232 40//
4852ff6f 41// Provide interface for loading and navigating standard AliRoot data
42// (AliRunLoader) and ESDs.
43//
44// Missing support for raw-data. For now this is handled individually
45// by each sub-detector.
51346b82 46//
a15e6d7d 47// Also provides interface to magnetic-field and geometry. Mostly
48// intended as wrappers over standard AliRoot functionality for
49// convenient use from visualizateion macros.
5a5a1232 50
d810d0de 51ClassImp(AliEveEventManager)
5a5a1232 52
a15e6d7d 53AliEveEventManager* gAliEveEvent = 0;
5a5a1232 54
d810d0de 55Bool_t AliEveEventManager::fgAssertRunLoader = kFALSE;
c76ea574 56Bool_t AliEveEventManager::fgAssertESD = kFALSE;
c2c4b7a2 57Bool_t AliEveEventManager::fgAssertRaw = kFALSE;
5a5a1232 58
c2c4b7a2 59TString AliEveEventManager::fgESDFileName("AliESDs.root");
60TString AliEveEventManager::fgRawFileName("raw.root");
d810d0de 61TString AliEveEventManager::fgCdbUri("local://$ALICE_ROOT");
632d2b03 62
d810d0de 63AliMagF* AliEveEventManager::fgMagField = 0;
93845f6c 64
65
d810d0de 66AliEveEventManager::AliEveEventManager() :
84aff7a4 67 TEveEventManager(),
265ecb21 68
c2c4b7a2 69 fPath ( ), fEventId (-1),
265ecb21 70 fRunLoader (0),
90fa773e 71 fESDFile (0), fESDTree (0), fESD (0),
c2c4b7a2 72 fESDfriend (0), fESDfriendExists(kFALSE),
319f3084 73 fRawReader (0),
80547f2d 74 fAutoLoad (kFALSE), fAutoLoadTime (5.), fAutoLoadTimer(0),
75 fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE),
76 fExecutor (new AliEveMacroExecutor)
c76ea574 77{
78 // Default constructor.
79}
5a5a1232 80
d810d0de 81AliEveEventManager::AliEveEventManager(TString path, Int_t ev) :
82 TEveEventManager("AliEVE AliEveEventManager"),
265ecb21 83
c76ea574 84 fPath (path), fEventId(-1),
265ecb21 85 fRunLoader (0),
90fa773e 86 fESDFile (0), fESDTree (0), fESD (0),
c2c4b7a2 87 fESDfriend (0), fESDfriendExists(kFALSE),
319f3084 88 fRawReader (0),
80547f2d 89 fAutoLoad (kFALSE), fAutoLoadTime (5.), fAutoLoadTimer(0),
90 fIsOpen (kFALSE), fHasEvent (kFALSE), fExternalCtrl (kFALSE),
91 fExecutor (new AliEveMacroExecutor)
5a5a1232 92{
c76ea574 93 // Constructor with event-directory URL and event-id.
94
5a5a1232 95 Open();
90fa773e 96 if (ev >= 0) GotoEvent(ev);
5a5a1232 97}
98
a15e6d7d 99AliEveEventManager::~AliEveEventManager()
100{
101 // Destructor.
102
80547f2d 103 if (fIsOpen)
104 {
105 Close();
106 }
107
319f3084 108 if (fAutoLoadTimer) delete fAutoLoadTimer;
a15e6d7d 109 // Somewhat unclear what to do here.
110 // In principle should close all data sources and deregister from
111 // TEveManager.
112}
113
57ffa5fb 114/******************************************************************************/
5a5a1232 115
c2c4b7a2 116void AliEveEventManager::SetESDFileName(const Text_t* esd)
117{
118 // Set file-name for opening ESD, default "AliESDs.root".
119
120 if (esd) fgESDFileName = esd;
121}
122
123void AliEveEventManager::SetRawFileName(const Text_t* raw)
124{
125 // Set file-name for opening of raw-data, default "raw.root"
126 if (raw) fgRawFileName = raw;
127}
128
129void AliEveEventManager::SetCdbUri(const Text_t* cdb)
130{
131 // Set path to CDB, default "local://$ALICE_ROOT".
132
133 if (cdb) fgCdbUri = cdb;
134}
135
136void AliEveEventManager::SetAssertElements(Bool_t assertRunloader,
137 Bool_t assertEsd,
138 Bool_t assertRaw)
139{
140 // Set global flags that detrmine which parts of the event-data must
141 // be present when the event is opened.
142
143 fgAssertRunLoader = assertRunloader;
144 fgAssertESD = assertEsd;
145 fgAssertRaw = assertRaw;
146}
147
148/******************************************************************************/
149
d810d0de 150void AliEveEventManager::Open()
5a5a1232 151{
c76ea574 152 // Open event-data from URL specified in fPath.
153 // Attempts to create AliRunLoader() and to open ESD with ESDfriends.
154 // Warning is reported if run-loader or ESD is not found.
155 // Global data-members fgAssertRunLoader and fgAssertESD can be set
156 // to throw exceptions instead.
157
a15e6d7d 158 static const TEveException kEH("AliEveEventManager::Open ");
5a5a1232 159
80547f2d 160 if (fExternalCtrl)
161 {
162 throw (kEH + "Event-loop is under external control.");
163 }
164 if (fIsOpen)
165 {
166 throw (kEH + "Event-files already opened.");
167 }
168
5a5a1232 169 gSystem->ExpandPathName(fPath);
5a58dc18 170 // The following magick is required for ESDriends to be loaded properly
171 // from non-current directory.
172 if (fPath.IsNull() || fPath == ".")
173 {
174 fPath = gSystem->WorkingDirectory();
175 }
176 else if ( ! fPath.BeginsWith("file:/"))
177 {
178 TUrl url(fPath, kTRUE);
179 TString protocol(url.GetProtocol());
180 if (protocol == "file" && fPath[0] != '/')
181 fPath = Form("%s/%s", gSystem->WorkingDirectory(), fPath.Data());
182 }
5a5a1232 183
632d2b03 184 Int_t runNo = -1;
185
db748c38 186 // Open ESD and ESDfriends
187
188 TString esdPath(Form("%s/%s", fPath.Data(), fgESDFileName.Data()));
189 if ((fESDFile = TFile::Open(esdPath)))
190 {
191 fESD = new AliESDEvent();
192 fESDTree = (TTree*) fESDFile->Get("esdTree");
193 if (fESDTree != 0)
194 {
db748c38 195 // Check if ESDfriends exists and attach the branch
196 TString p(Form("%s/AliESDfriends.root", fPath.Data()));
fa46c586 197 TFile *esdFriendFile = TFile::Open(p);
198 if (esdFriendFile) {
199 if (!esdFriendFile->IsZombie())
200 {
201 esdFriendFile->Close();
202 delete esdFriendFile;
203 fESDfriendExists = kTRUE;
204 fESDTree->SetBranchStatus ("ESDfriend*", 1);
205 fESDTree->SetBranchAddress("ESDfriend.", &fESDfriend);
206 }
207 else
208 {
209 esdFriendFile->Close();
210 delete esdFriendFile;
211 }
db748c38 212 }
fa46c586 213
214 fESD->ReadFromTree(fESDTree);
215 if (!fESDfriendExists) fESDTree->SetBranchStatus ("ESDfriend*", 0);
216 if (fESDTree->GetEntry(0) <= 0)
217 {
218 delete fESDFile; fESDFile = 0;
219 delete fESD; fESD = 0;
220 Warning(kEH, "failed getting the first entry from esdTree.");
221 }
222 else
223 {
224 if (runNo < 0)
225 runNo = fESD->GetESDRun()->GetRunNumber();
226 }
db748c38 227 }
228 else // esdtree == 0
229 {
230 delete fESDFile; fESDFile = 0;
fa46c586 231 delete fESD; fESD = 0;
db748c38 232 Warning(kEH, "failed getting the esdTree.");
233 }
234 }
235 else // esd not readable
236 {
237 Warning(kEH, "can not read ESD file '%s'.", esdPath.Data());
238 }
239 if (fESDTree == 0)
240 {
241 if (fgAssertESD)
242 {
243 throw (kEH + "ESD not initialized. Its precence was requested.");
244 } else {
245 Warning(kEH, "ESD not initialized.");
246 }
247 }
248
249 // Open RunLoader from galice.root
250
a15e6d7d 251 TString gaPath(Form("%s/galice.root", fPath.Data()));
c2c4b7a2 252 // If i use open directly, we get fatal.
db748c38 253 // Is AccessPathName check ok for xrootd / alien? Yes, not for http.
a15e6d7d 254 if (gSystem->AccessPathName(gaPath, kReadPermission) == kFALSE)
90fa773e 255 {
a15e6d7d 256 fRunLoader = AliRunLoader::Open(gaPath);
a1896a82 257 if (fRunLoader)
5a5a1232 258 {
a15e6d7d 259 TString alicePath = fPath + "/";
260 fRunLoader->SetDirName(alicePath);
a1896a82 261
262 if (fRunLoader->LoadgAlice() != 0)
c2c4b7a2 263 Warning(kEH, "failed loading gAlice via run-loader.");
a1896a82 264
265 if (fRunLoader->LoadHeader() == 0)
266 {
db748c38 267 if (runNo < 0)
268 runNo = fRunLoader->GetHeader()->GetRun();
a1896a82 269 }
270 else
271 {
c2c4b7a2 272 Warning(kEH, "failed loading run-loader's header.");
273 delete fRunLoader;
274 fRunLoader = 0;
a1896a82 275 }
276 }
277 else // run-loader open failed
278 {
a15e6d7d 279 Warning(kEH, "failed opening ALICE run-loader from '%s'.", gaPath.Data());
5a5a1232 280 }
5a5a1232 281 }
a1896a82 282 else // galice not readable
283 {
a15e6d7d 284 Warning(kEH, "can not read '%s'.", gaPath.Data());
a1896a82 285 }
286 if (fRunLoader == 0)
287 {
84aff7a4 288 if (fgAssertRunLoader)
c2c4b7a2 289 throw (kEH + "Bootstraping of run-loader failed. Its precence was requested.");
a1896a82 290 else
a15e6d7d 291 Warning(kEH, "Bootstraping of run-loader failed.");
a1896a82 292 }
51346b82 293
db748c38 294 // Open raw-data file
5a5a1232 295
c2c4b7a2 296 TString rawPath(Form("%s/%s", fPath.Data(), fgRawFileName.Data()));
2827badf 297 // If i use open directly, raw-reader reports an error but i have
298 // no way to detect it.
299 // Is this (AccessPathName check) ok for xrootd / alien? Yes, not for http.
300 if (gSystem->AccessPathName(rawPath, kReadPermission) == kFALSE)
301 {
302 fRawReader = AliRawReader::Create(rawPath);
303 }
304 else
305 {
306 fRawReader = AliRawReader::Create(fgRawFileName);
307 }
c2c4b7a2 308 if (fRawReader == 0)
309 {
310 if (fgAssertRaw)
311 {
312 throw (kEH + "raw-data not initialized. Its precence was requested.");
313 } else {
314 Warning(kEH, "raw-data not initialized.");
315 }
316 }
317
632d2b03 318 if (runNo < 0)
c2c4b7a2 319 {
320 if (fRawReader)
321 {
322 fRawReader->NextEvent();
323 runNo = fRawReader->GetRunNumber();
ca49b003 324 Info(kEH, "Determining run-no from raw ... run=%d.", runNo);
c2c4b7a2 325 fRawReader->RewindEvents();
326 } else {
327 throw (kEH + "unknown run number.");
328 }
329 }
632d2b03 330
331 {
332 AliCDBManager* cdb = AliCDBManager::Instance();
333 cdb->SetDefaultStorage(fgCdbUri);
334 if (cdb->IsDefaultStorageSet() == kFALSE)
c2c4b7a2 335 throw (kEH + "CDB initialization failed.");
632d2b03 336 cdb->SetRun(runNo);
337 }
338
73c1c0ec 339 SetName(Form("Event %d", fEventId));
5a5a1232 340 SetTitle(fPath);
80547f2d 341 fIsOpen = kTRUE;
5a5a1232 342}
343
319f3084 344void AliEveEventManager::SetEvent(AliRunLoader *runLoader, AliRawReader *rawReader, AliESDEvent *esd)
345{
346 // Set an event from an external source
347 // The method is used in the online visualisation
80547f2d 348
349 static const TEveException kEH("AliEveEventManager::SetEvent ");
350
351 if (fIsOpen)
352 {
353 Warning(kEH, "Event-files were open. Closing and switching to external control.");
354 Close();
355 }
356
319f3084 357 fRunLoader = runLoader;
358 fRawReader = rawReader;
80547f2d 359 fESD = esd;
360
361 fEventId++;
362 fHasEvent = kTRUE;
363 fExternalCtrl = kTRUE;
364
319f3084 365 SetTitle("Online event in memory");
80547f2d 366 SetName ("Online Event");
319f3084 367
368 ElementChanged();
369 AfterNewEventLoaded();
370}
371
f76c9e9b 372Int_t AliEveEventManager::GetMaxEventId(Bool_t /*refreshESD*/) const
516389a2 373{
374 // Returns maximum available event id.
80547f2d 375 // If under external control or event is not opened -1 is returned.
516389a2 376 // If raw-data is the only data-source this can not be known
377 // and 10,000,000 is returned.
378 // If neither data-source is initialised an exception is thrown.
379 // If refresh_esd is true and ESD is the primary event-data source
380 // its header is re-read from disk.
381
382 static const TEveException kEH("AliEveEventManager::GetMaxEventId ");
383
80547f2d 384 if (fExternalCtrl || fIsOpen == kFALSE)
385 {
386 return -1;
387 }
388
f76c9e9b 389 if (fESDTree)
516389a2 390 {
f76c9e9b 391 // Refresh crashes with root-5.21.1-alice.
392 // Fixed by Philippe 5.8.2008 r25053, can be reactivated
393 // when we move to a newer root.
394 // if (refreshESD)
395 // fESDTree->Refresh();
396 return fESDTree->GetEntries() - 1;
516389a2 397 }
f76c9e9b 398 else if (fRunLoader)
516389a2 399 {
f76c9e9b 400 return fRunLoader->GetNumberOfEvents() - 1;
516389a2 401 }
402 else if (fRawReader)
403 {
ae1a1b11 404 Int_t n = fRawReader->GetNumberOfEvents() - 1;
405 return n > -1 ? n : 10000000;
516389a2 406 }
407 else
408 {
409 throw (kEH + "neither RunLoader, ESD nor Raw loaded.");
410 }
411}
412
d810d0de 413void AliEveEventManager::GotoEvent(Int_t event)
1eaa5849 414{
73c1c0ec 415 // Load data for specified event.
416 // If event is out of range an exception is thrown and old state
417 // is preserved.
418 // After successful loading of event, the virtual function
419 // AfterNewEventLoaded() is called. This executes commands that
420 // were registered via TEveEventManager::AddNewEventCommand().
516389a2 421 //
422 // If event is negative, it is subtracted from the number of
423 // available events, thus passing -1 will load the last event.
424 // This is not supported when raw-data is the only data-source
425 // as the number of events is not known.
73c1c0ec 426
a15e6d7d 427 static const TEveException kEH("AliEveEventManager::GotoEvent ");
1eaa5849 428
80547f2d 429 if (fExternalCtrl)
430 {
431 throw (kEH + "Event-loop is under external control.");
432 }
433 if (!fIsOpen)
434 {
435 throw (kEH + "Event-files not opened.");
436 }
437
438 fHasEvent = kFALSE;
439
1eaa5849 440 Int_t maxEvent = 0;
db748c38 441 if (fESDTree)
516389a2 442 {
ca49b003 443 // Refresh crashes with root-5.21.1-alice.
444 // Fixed by Philippe 5.8.2008 r25053, can be reactivated
445 // when we move to a newer root.
446 // fESDTree->Refresh();
1eaa5849 447 maxEvent = fESDTree->GetEntries() - 1;
516389a2 448 if (event < 0)
449 event = fESDTree->GetEntries() + event;
450 }
db748c38 451 else if (fRunLoader)
452 {
453 maxEvent = fRunLoader->GetNumberOfEvents() - 1;
454 if (event < 0)
455 event = fRunLoader->GetNumberOfEvents() + event;
456 }
516389a2 457 else if (fRawReader)
458 {
ae1a1b11 459 maxEvent = fRawReader->GetNumberOfEvents() - 1;
460 if (maxEvent < 0)
461 {
462 maxEvent = 10000000;
463 if (event < 0) {
464 Error(kEH, "current raw-data source does not support direct event access.");
465 return;
466 }
467 Info(kEH, "number of events unknown for current raw-data source, setting max-event id to 10M.");
468 }
469 else
470 {
471 if (event < 0)
472 event = fRawReader->GetNumberOfEvents() + event;
516389a2 473 }
516389a2 474 }
475 else
476 {
c2c4b7a2 477 throw (kEH + "neither RunLoader, ESD nor Raw loaded.");
478 }
84aff7a4 479 if (event < 0 || event > maxEvent)
516389a2 480 {
c2c4b7a2 481 throw (kEH + Form("event %d not present, available range [%d, %d].",
482 event, 0, maxEvent));
516389a2 483 }
1eaa5849 484
84aff7a4 485 TEveManager::TRedrawDisabler rd(gEve);
486 gEve->Redraw3D(kFALSE, kTRUE); // Enforce drop of all logicals.
d9e0d6c5 487
32e219c2 488 // !!! MT this is somewhat brutal; at least optionally, one could be
489 // a bit gentler, checking for objs owning their external refs and having
490 // additinal parents.
1eaa5849 491 DestroyElements();
1eaa5849 492
84aff7a4 493 if (fESDTree) {
c2c4b7a2 494 if (fESDTree->GetEntry(event) <= 0)
495 throw (kEH + "failed getting required event from ESD.");
1eaa5849 496
2cea771a 497 if (fESDfriendExists)
1eaa5849 498 fESD->SetESDfriend(fESDfriend);
1eaa5849 499 }
90fa773e 500
db748c38 501 if (fRunLoader) {
502 if (fRunLoader->GetEvent(event) != 0)
503 throw (kEH + "failed getting required event.");
504 }
505
c2c4b7a2 506 if (fRawReader)
507 {
ca49b003 508 // AliRawReader::GotoEvent(Int_t) works for AliRawReaderRoot/Chain.
509 if (fRawReader->GotoEvent(event) == kFALSE)
c2c4b7a2 510 {
ca49b003 511 // Use fallback method - iteration with NextEvent().
512 Int_t rawEv = fEventId;
513 if (event < rawEv)
c2c4b7a2 514 {
515 fRawReader->RewindEvents();
ca49b003 516 rawEv = -1;
c2c4b7a2 517 }
c2c4b7a2 518
ca49b003 519 while (rawEv < event)
520 {
521 if ( ! fRawReader->NextEvent())
522 {
523 fRawReader->RewindEvents();
524 fEventId = -1;
525 throw (kEH + Form("Error going to next raw-event from event %d.", rawEv));
526 }
527 ++rawEv;
528 }
529 Warning(kEH, "Loaded raw-event %d with fallback method.\n", rawEv);
530 }
c2c4b7a2 531 }
532
80547f2d 533 fHasEvent = kTRUE;
534 fEventId = event;
c2c4b7a2 535 SetName(Form("Event %d", fEventId));
319f3084 536 ElementChanged();
c2c4b7a2 537
90fa773e 538 AfterNewEventLoaded();
1eaa5849 539}
540
516389a2 541void AliEveEventManager::NextEvent()
542{
80547f2d 543 // Loads next event.
544 // Does magick needed for online display when under external event control.
516389a2 545
80547f2d 546 if (fExternalCtrl)
ae1a1b11 547 {
516389a2 548 if (fAutoLoadTimer) fAutoLoadTimer->Stop();
549
550 DestroyElements();
551
552 gSystem->ExitLoop();
ae1a1b11 553 }
554 else
555 {
516389a2 556 if (fEventId < GetMaxEventId(kTRUE))
557 GotoEvent(fEventId + 1);
558 else
559 GotoEvent(0);
560 StartStopAutoLoadTimer();
561 }
562}
563
564void AliEveEventManager::PrevEvent()
565{
80547f2d 566 // Loads previous event.
567
568 static const TEveException kEH("AliEveEventManager::PrevEvent ");
569
570 if (fExternalCtrl)
571 {
572 throw (kEH + "Event-loop is under external control.");
516389a2 573 }
80547f2d 574 if (!fIsOpen)
575 {
576 throw (kEH + "Event-files not opened.");
577 }
578
579 GotoEvent(fEventId - 1);
580 StartStopAutoLoadTimer();
516389a2 581}
582
d810d0de 583void AliEveEventManager::Close()
5a5a1232 584{
ca49b003 585 // Close the event data-files and delete ESD, ESDfriend, run-loader
586 // and raw-reader.
73c1c0ec 587
80547f2d 588 static const TEveException kEH("AliEveEventManager::Close ");
589
590 if (!fIsOpen)
591 {
592 throw (kEH + "Event-files not opened.");
593 }
594
2cea771a 595 if (fESDTree) {
596 delete fESD; fESD = 0;
597 delete fESDfriend; fESDfriend = 0;
598
ca49b003 599 delete fESDTree; fESDTree = 0;
600 delete fESDFile; fESDFile = 0;
601 }
602
603 if (fRunLoader) {
604 delete fRunLoader; fRunLoader = 0;
605 }
606
607 if (fRawReader) {
608 delete fRawReader; fRawReader = 0;
2cea771a 609 }
80547f2d 610
611 fEventId = -1;
612 fIsOpen = kFALSE;
613 fHasEvent = kFALSE;
5a5a1232 614}
615
90fa773e 616
80547f2d 617//------------------------------------------------------------------------------
c76ea574 618// Static convenience functions, mainly used from macros.
80547f2d 619//------------------------------------------------------------------------------
5a5a1232 620
f6afd0e1 621Bool_t AliEveEventManager::HasRunLoader()
622{
623 // Check if AliRunLoader is initialized.
624
80547f2d 625 return gAliEveEvent && gAliEveEvent->fHasEvent && gAliEveEvent->fRunLoader;
f6afd0e1 626}
627
628Bool_t AliEveEventManager::HasESD()
629{
630 // Check if AliESDEvent is initialized.
631
80547f2d 632 return gAliEveEvent && gAliEveEvent->fHasEvent && gAliEveEvent->fESD;
f6afd0e1 633}
634
635Bool_t AliEveEventManager::HasESDfriend()
636{
637 // Check if AliESDfriend is initialized.
638
80547f2d 639 return gAliEveEvent && gAliEveEvent->fHasEvent && gAliEveEvent->fESDfriend;
f6afd0e1 640}
641
642Bool_t AliEveEventManager::HasRawReader()
643{
644 // Check if raw-reader is initialized.
645
80547f2d 646 return gAliEveEvent && gAliEveEvent->fHasEvent && gAliEveEvent->fRawReader;
f6afd0e1 647}
648
d810d0de 649AliRunLoader* AliEveEventManager::AssertRunLoader()
5a5a1232 650{
73c1c0ec 651 // Make sure AliRunLoader is initialized and return it.
652 // Throws exception in case run-loader is not available.
653 // Static utility for macros.
654
a15e6d7d 655 static const TEveException kEH("AliEveEventManager::AssertRunLoader ");
5a5a1232 656
80547f2d 657 if (gAliEveEvent == 0 || gAliEveEvent->fHasEvent == kFALSE)
c2c4b7a2 658 throw (kEH + "ALICE event not ready.");
a15e6d7d 659 if (gAliEveEvent->fRunLoader == 0)
c2c4b7a2 660 throw (kEH + "AliRunLoader not initialised.");
a15e6d7d 661 return gAliEveEvent->fRunLoader;
5a5a1232 662}
663
d810d0de 664AliESDEvent* AliEveEventManager::AssertESD()
5a5a1232 665{
73c1c0ec 666 // Make sure AliESDEvent is initialized and return it.
667 // Throws exception in case ESD is not available.
668 // Static utility for macros.
669
a15e6d7d 670 static const TEveException kEH("AliEveEventManager::AssertESD ");
5a5a1232 671
80547f2d 672 if (gAliEveEvent == 0 || gAliEveEvent->fHasEvent == kFALSE)
c2c4b7a2 673 throw (kEH + "ALICE event not ready.");
a15e6d7d 674 if (gAliEveEvent->fESD == 0)
c2c4b7a2 675 throw (kEH + "AliESD not initialised.");
a15e6d7d 676 return gAliEveEvent->fESD;
5a5a1232 677}
3aecaefc 678
d810d0de 679AliESDfriend* AliEveEventManager::AssertESDfriend()
3aecaefc 680{
73c1c0ec 681 // Make sure AliESDfriend is initialized and return it.
682 // Throws exception in case ESDfriend-loader is not available.
683 // Static utility for macros.
684
a15e6d7d 685 static const TEveException kEH("AliEveEventManager::AssertESDfriend ");
3aecaefc 686
80547f2d 687 if (gAliEveEvent == 0 || gAliEveEvent->fHasEvent == kFALSE)
c2c4b7a2 688 throw (kEH + "ALICE event not ready.");
a15e6d7d 689 if (gAliEveEvent->fESDfriend == 0)
c2c4b7a2 690 throw (kEH + "AliESDfriend not initialised.");
a15e6d7d 691 return gAliEveEvent->fESDfriend;
3aecaefc 692}
93845f6c 693
c2c4b7a2 694AliRawReader* AliEveEventManager::AssertRawReader()
695{
696 // Make sure raw-reader is initialized and return it.
697
698 static const TEveException kEH("AliEveEventManager::AssertRawReader ");
699
80547f2d 700 if (gAliEveEvent == 0 || gAliEveEvent->fHasEvent == kFALSE)
c2c4b7a2 701 throw (kEH + "ALICE event not ready.");
702 if (gAliEveEvent->fRawReader == 0)
703 throw (kEH + "RawReader not ready.");
704
705 return gAliEveEvent->fRawReader;
706}
707
d810d0de 708AliMagF* AliEveEventManager::AssertMagField()
93845f6c 709{
80547f2d 710 // Make sure AliMagF is initialized and returns it.
711 // Run-loader must be initialized to get the correct magnetic field!
73c1c0ec 712 // Throws exception in case magnetic field is not available.
713 // Static utility for macros.
714
80547f2d 715 // !!!! This should be fixed ... get field also in some other way,
716 // not only via run-loader.
717
93845f6c 718 if (fgMagField == 0)
719 {
a15e6d7d 720 if (gAliEveEvent && gAliEveEvent->fRunLoader && gAliEveEvent->fRunLoader->GetAliRun())
721 fgMagField = gAliEveEvent->fRunLoader->GetAliRun()->Field();
93845f6c 722 else
723 fgMagField = new AliMagFMaps("Maps","Maps", 1, 1., 10., AliMagFMaps::k5kG);
724 }
725 return fgMagField;
726}
632d2b03 727
d810d0de 728TGeoManager* AliEveEventManager::AssertGeometry()
632d2b03 729{
73c1c0ec 730 // Make sure AliGeomManager is initialized and returns the
731 // corresponding TGeoManger.
647814a2 732 // gGeoManager is set to the return value.
733 // Throws exception if geometry can not be loaded or if it is not
734 // available and the TGeoManager is locked.
73c1c0ec 735 // Static utility for macros.
736
a15e6d7d 737 static const TEveException kEH("AliEveEventManager::AssertGeometry ");
632d2b03 738
739 if (AliGeomManager::GetGeometry() == 0)
740 {
647814a2 741 if (TGeoManager::IsLocked())
742 throw (kEH + "geometry is not loaded but TGeoManager is locked.");
743
af2e4ef5 744 gGeoManager = 0;
632d2b03 745 AliGeomManager::LoadGeometry();
746 if ( ! AliGeomManager::GetGeometry())
747 {
c2c4b7a2 748 throw (kEH + "can not load geometry.");
632d2b03 749 }
750 if ( ! AliGeomManager::ApplyAlignObjsFromCDB("ITS TPC TRD TOF PHOS HMPID EMCAL MUON FMD ZDC PMD T0 VZERO ACORDE"))
751 {
a15e6d7d 752 ::Warning(kEH, "mismatch of alignable volumes. Proceeding.");
c2c4b7a2 753 // throw (kEH + "could not apply align objs.");
632d2b03 754 }
81515106 755 AliGeomManager::GetGeometry()->DefaultColors();
632d2b03 756 }
757
647814a2 758 gGeoManager = AliGeomManager::GetGeometry();
759 return gGeoManager;
632d2b03 760}
319f3084 761
80547f2d 762
763//------------------------------------------------------------------------------
764// Autoloading
765//------------------------------------------------------------------------------
766
319f3084 767void AliEveEventManager::SetAutoLoad(Bool_t autoLoad)
768{
769 // Set the automatic event loading mode
80547f2d 770
319f3084 771 fAutoLoad = autoLoad;
772 StartStopAutoLoadTimer();
773}
774
775void AliEveEventManager::SetAutoLoadTime(Double_t time)
776{
777 // Set the auto-load time in seconds
80547f2d 778
319f3084 779 fAutoLoadTime = time;
780 StartStopAutoLoadTimer();
781}
782
783void AliEveEventManager::StartStopAutoLoadTimer()
784{
785 // Create if needed and start
786 // the automatic event loading timer
80547f2d 787
f76c9e9b 788 if (fAutoLoad)
789 {
790 if (!fAutoLoadTimer)
791 {
319f3084 792 fAutoLoadTimer = new TTimer;
80547f2d 793 fAutoLoadTimer->Connect("Timeout()", "AliEveEventManager", this, "NextEvent()");
319f3084 794 }
80547f2d 795 fAutoLoadTimer->Start((Long_t)fAutoLoadTime*1000, kTRUE);
319f3084 796 }
f76c9e9b 797 else
798 {
319f3084 799 if (fAutoLoadTimer) fAutoLoadTimer->Stop();
800 }
801}
802
80547f2d 803
804//------------------------------------------------------------------------------
805// Post event-loading functions
806//------------------------------------------------------------------------------
807
f6afd0e1 808void AliEveEventManager::AfterNewEventLoaded()
809{
810 // Execute registered macros and commands.
811 // At the end emit NewEventLoaded signal.
812 //
813 // Virtual from TEveEventManager.
814
815 if (fExecutor)
816 fExecutor->ExecMacros();
817
818 TEveEventManager::AfterNewEventLoaded();
819
820 NewEventLoaded();
821}
822
f76c9e9b 823void AliEveEventManager::NewEventLoaded()
824{
825 // Emit NewEventLoaded signal.
826
827 Emit("NewEventLoaded()");
828}
829
80547f2d 830
831//------------------------------------------------------------------------------
832// Event info dumpers
833//------------------------------------------------------------------------------
12365217 834
835TString AliEveEventManager::GetEventInfoHorizontal() const
836{
837 // Dumps the event-header contents in vertical formatting.
838
839 TString rawInfo, esdInfo;
840
841 if (!fRawReader)
842 {
843 rawInfo = "No raw-data event info is available!\n";
844 }
845 else
846 {
847 const UInt_t* attr = fRawReader->GetAttributes();
848 TTimeStamp ts(fRawReader->GetTimestamp());
849 rawInfo.Form("RAW event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n"
850 "Trigger: %llx\nDetectors: %x (%s)\nAttributes:%x-%x-%x Timestamp: %s\n",
851 fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()),
852 fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(),
853 fRawReader->GetClassMask(),
854 *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()),
855 attr[0],attr[1],attr[2], ts.AsString("s"));
856 }
857
858 if (!fESD)
859 {
860 esdInfo = "No ESD event info is available!";
861 }
862 else
863 {
864 TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses();
865 TString firedtrclasses = fESD->GetFiredTriggerClasses();
866 TTimeStamp ts(fESD->GetTimeStamp());
867 esdInfo.Form("ESD event info: Run#: %d Event type: %d (%s) Period: %x Orbit: %x BC: %x\n"
868 "Active trigger classes: %s\nTrigger: %llx (%s)\nEvent# in file: %d Timestamp: %s",
869 fESD->GetRunNumber(),
870 fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()),
871 fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(),
872 acttrclasses.Data(),
873 fESD->GetTriggerMask(),firedtrclasses.Data(),
874 fESD->GetEventNumberInFile(), ts.AsString("s"));
875 }
876
877 return rawInfo + esdInfo;
878}
879
880TString AliEveEventManager::GetEventInfoVertical() const
319f3084 881{
12365217 882 // Dumps the event-header contents in vertical formatting.
319f3084 883
12365217 884 TString rawInfo, esdInfo;
319f3084 885
12365217 886 if (!fRawReader)
887 {
888 rawInfo = "No raw-data event info is available!\n";
ec835ab5 889 }
12365217 890 else
891 {
ec835ab5 892 const UInt_t* attr = fRawReader->GetAttributes();
12365217 893 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",
894 fRawReader->GetRunNumber(),fRawReader->GetType(),AliRawEventHeaderBase::GetTypeName(fRawReader->GetType()),
895 fRawReader->GetPeriod(),fRawReader->GetOrbitID(),fRawReader->GetBCID(),
896 fRawReader->GetClassMask(),
897 *fRawReader->GetDetectorPattern(),AliDAQ::ListOfTriggeredDetectors(*fRawReader->GetDetectorPattern()),
898 attr[0],attr[1],attr[2],
899 fRawReader->GetTimestamp());
900 }
901
902 if (!fESD)
903 {
904 esdInfo = "No ESD event info is available!\n";
905 }
906 else
907 {
908 TString acttrclasses = fESD->GetESDRun()->GetActiveTriggerClasses();
ec835ab5 909 TString firedtrclasses = fESD->GetFiredTriggerClasses();
12365217 910 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",
911 fESD->GetRunNumber(),
912 acttrclasses.Data(),
913 fESD->GetEventType(),AliRawEventHeaderBase::GetTypeName(fESD->GetEventType()),
914 fESD->GetPeriodNumber(),fESD->GetOrbitNumber(),fESD->GetBunchCrossNumber(),
915 fESD->GetTriggerMask(),firedtrclasses.Data(),
916 fESD->GetEventNumberInFile(),
917 fESD->GetTimeStamp());
ec835ab5 918 }
319f3084 919
12365217 920 return rawInfo + "\n" + esdInfo;
319f3084 921}
922