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