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