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