#ifndef AliEveEventManager_H
#define AliEveEventManager_H
#include <TEveEventManager.h>
#include <TQObject.h>
#include <TObjArray.h>
#include <TThread.h>
#include <AliEventInfo.h>
#include <AliESDEvent.h>
#include "AliStorageTypes.h"
class AliEveMacroExecutor;
class AliEveEventSelector;
class AliRunLoader;
class AliESDEvent;
class AliESDfriend;
class AliAODEvent;
class AliRawReader;
class AliGRPObject;
class AliRecoParam;
class AliMagF;
class TEveElement;
class TFile;
class TTree;
class TGeoManager;
class TString;
class TMap;
class AliEveEventManager : public TEveEventManager, public TQObject
{
public:
AliEveEventManager(const TString& name="Event", Int_t ev=0);
virtual ~AliEveEventManager();
enum EVisibleESDTrees{ kOfflineTree, kHLTTree };
static void SetESDFileName(const TString& esd, EVisibleESDTrees shown=kOfflineTree);
static void SetESDfriendFileName(const TString& esdf);
static void SetAODFileName(const TString& aod);
static void AddAODfriend (const TString& friendFileName);
static void SetRawFileName(const TString& raw);
static void SetCdbUri (const TString& cdb);
static void SetGAliceFileName(const TString& galice);
static void SetFilesPath(const TString& path);
static void SetAssertElements(Bool_t assertRunloader, Bool_t assertEsd,
Bool_t assertAod, Bool_t assertRaw);
static void SearchRawForCentralReconstruction();
virtual void Open();
virtual Int_t GetMaxEventId(Bool_t refreshESD=kFALSE) const;
virtual void GotoEvent(Int_t event);
virtual void NextEvent();
virtual void PrevEvent();
void MarkCurrentEvent();
virtual void Close();
void SetEvent(AliRunLoader *runLoader, AliRawReader *rawReader, AliESDEvent *esd, AliESDfriend *esdf);
void Timeout();
Int_t GetEventId() const { return fEventId; }
AliRunLoader* GetRunLoader() const { return fRunLoader; }
TFile* GetESDFile() const { return fESDFile; }
TTree* GetESDTree() const { return fESDTree; }
TTree* GetHLTESDTree() const { return fHLTESDTree; }
AliESDEvent* GetESD() const { return fESD; }
AliESDfriend* GetESDfriend() const { return fESDfriend; }
Bool_t GetESDfriendExists() const { return fESDfriendExists; }
TFile* GetAODFile() const { return fAODFile; }
TTree* GetAODTree() const { return fAODTree; }
AliAODEvent* GetAOD() const { return fAOD; }
AliEveEventSelector* GetEventSelector() const { return fPEventSelector; }
TString GetEventInfoHorizontal() const;
TString GetEventInfoVertical() const;
const AliEventInfo* GetEventInfo();
static Int_t CurrentEventId();
static Bool_t HasRunLoader();
static Bool_t HasESD();
static Bool_t HasESDfriend();
static Bool_t HasAOD();
static Bool_t HasRawReader();
static AliRunLoader* AssertRunLoader();
static AliESDEvent* AssertESD();
static AliESDfriend* AssertESDfriend();
static AliAODEvent* AssertAOD();
static AliRawReader* AssertRawReader();
static AliMagF* AssertMagField();
static TGeoManager* AssertGeometry();
static AliRecoParam* AssertRecoParams();
static AliEveEventManager* AddDependentManager(const TString& name, const TString& path);
static AliEveEventManager* GetDependentManager(const TString& name);
static AliEveEventManager* GetMaster();
static AliEveEventManager* GetCurrent();
static void RegisterTransient (TEveElement* element);
static void RegisterTransientList(TEveElement* element);
Double_t GetAutoLoadTime() const { return fAutoLoadTime; }
Bool_t GetAutoLoad() const { return fAutoLoad; }
Bool_t GetLoopMarked() const { return fLoopMarked; }
void SetAutoLoadTime(Float_t time);
void SetAutoLoad(Bool_t autoLoad);
void SetLoopMarked(Bool_t loopMarked);
void SetTrigSel(Int_t trig);
void AutoLoadNextEvent();
Bool_t AreEventFilesOpened() const { return fIsOpen; }
Bool_t IsEventAvailable() const { return fHasEvent; }
Bool_t IsUnderExternalControl() const { return fExternalCtrl; }
Bool_t IsOnlineMode() const { return fOnlineMode; }
Bool_t InsertGlobal(const TString& tag, TEveElement* model);
Bool_t InsertGlobal(const TString& tag, TEveElement* model,
Bool_t replace, Bool_t update);
TEveElement* FindGlobal(const TString& tag);
virtual void AfterNewEventLoaded();
void NewEventDataLoaded();
void NewEventLoaded();
void NoEventLoaded();
void StorageManagerOk();
void StorageManagerDown();
AliEveMacroExecutor* GetExecutor() const { return fExecutor; }
void InitOCDB(int runNo=-1);
void PrepareForNewEvent(AliESDEvent *event);
Int_t NewEventAvailable();
protected:
Int_t fEventId;
AliRunLoader* fRunLoader;
TFile *fESDFile;
TTree *fESDTree;
TTree *fHLTESDTree;
AliESDEvent *fESD;
AliESDfriend *fESDfriend;
Bool_t fESDfriendExists;
TFile *fAODFile;
TTree *fAODTree;
AliAODEvent *fAOD;
AliRawReader *fRawReader;
AliEventInfo fEventInfo;
Bool_t fAutoLoad;
Bool_t fLoopMarked;
Float_t fAutoLoadTime;
TTimer *fAutoLoadTimer;
Bool_t fIsOpen;
Bool_t fHasEvent;
Bool_t fExternalCtrl;
TMap* fGlobal;
Bool_t fGlobalReplace;
Bool_t fGlobalUpdate;
AliEveMacroExecutor *fExecutor;
TEveElementList *fTransients;
TEveElementList *fTransientLists;
AliEveEventSelector* fPEventSelector;
TList *fSubManagers;
static TString fgGAliceFileName;
static TString fgESDFileName;
static EVisibleESDTrees fgESDvisibleTrees;
static TString fgESDfriendsFileName;
static TString fgAODFileName;
static TString fgRawFileName;
static TString fgCdbUri;
static Bool_t fgAssertRunLoader;
static Bool_t fgAssertESD;
static Bool_t fgAssertAOD;
static Bool_t fgAssertRaw;
static TList *fgAODfriends;
static Bool_t fgRawFromStandardLoc;
static Bool_t fgGRPLoaded;
static AliMagF *fgMagField;
static AliRecoParam* fgRecoParam;
static Bool_t fgUniformField;
private:
void InitInternals();
void StartAutoLoadTimer();
void StopAutoLoadTimer();
Bool_t fAutoLoadTimerRunning;
static Bool_t InitGRP();
static Bool_t InitRecoParam();
TTree* readESDTree(const char* treeName, int &run);
static AliEveEventManager* fgMaster;
static AliEveEventManager* fgCurrent;
static void* DispatchEventListener(void *arg){static_cast<AliEveEventManager*>(arg)->GetNextEvent();return nullptr;}
static void* DispatchStorageManagerWatcher(void *arg){static_cast<AliEveEventManager*>(arg)->CheckStorageStatus();return nullptr;}
void GetNextEvent();
void CheckStorageStatus();
TThread *fEventListenerThread;
TThread *fStorageManagerWatcherThread;
TMutex *fMutex;
AliESDEvent *fCurrentEvent[2];
TTree *fCurrentTree[2];
int fEventInUse;
int fWritingToEventIndex;
bool fIsNewEventAvaliable;
storageSockets fgSubSock;
Bool_t fOnlineMode;
Bool_t fStorageDown;
Bool_t fFinished;
AliEveEventManager(const AliEveEventManager&);
AliEveEventManager& operator=(const AliEveEventManager&);
ClassDef(AliEveEventManager, 0);
};
#endif