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