Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/ROOT/REveManager.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/eve7:$Id$
0002 // Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT7_REveManager
0013 #define ROOT7_REveManager
0014 
0015 #include <ROOT/REveElement.hxx>
0016 #include <ROOT/REveSystem.hxx>
0017 #include <ROOT/RLogger.hxx>
0018 
0019 #include <ROOT/RWebDisplayArgs.hxx>
0020 
0021 #include "TSysEvtHandler.h"
0022 
0023 #include <thread>
0024 #include <mutex>
0025 #include <condition_variable>
0026 #include <memory>
0027 #include <queue>
0028 #include <unordered_map>
0029 
0030 class TMap;
0031 class TExMap;
0032 class TGeoManager;
0033 class TMethodCall;
0034 
0035 namespace ROOT {
0036 namespace Experimental {
0037 
0038 class REveSelection;
0039 class REveViewer;
0040 class REveViewerList;
0041 class REveScene;
0042 class REveSceneList;
0043 
0044 class RWebWindow;
0045 
0046 class REveManager
0047 {
0048    REveManager(const REveManager&) = delete;
0049    REveManager& operator=(const REveManager&) = delete;
0050 
0051 public:
0052    class RExceptionHandler : public TStdExceptionHandler {
0053    public:
0054       RExceptionHandler() : TStdExceptionHandler() { Add(); }
0055       ~RExceptionHandler() override                 { Remove(); }
0056 
0057       EStatus Handle(std::exception& exc) override;
0058    };
0059 
0060    class ChangeGuard {
0061       public:
0062       ChangeGuard();
0063       ~ChangeGuard();
0064    };
0065 
0066    struct Conn
0067    {
0068       enum EConnState {Free, WaitingResponse };
0069       unsigned fId{0};
0070       EConnState   fState{Free};
0071 
0072       Conn() = default;
0073       Conn(unsigned int cId) : fId(cId) {}
0074    };
0075 
0076    class ServerState
0077    {
0078    public:
0079       enum EServerState {Waiting, UpdatingScenes, UpdatingClients};
0080 
0081       std::mutex fMutex{};
0082       std::condition_variable fCV{};
0083 
0084       EServerState fVal{Waiting};
0085    };
0086 
0087    class MIR
0088    {
0089       public:
0090        MIR(const std::string& cmd, ElementId_t id, const std::string& ctype, unsigned connid)
0091        :fCmd(cmd), fId(id), fCtype(ctype), fConnId(connid){}
0092 
0093        std::string fCmd;
0094        ElementId_t fId;
0095        std::string fCtype;
0096        unsigned    fConnId;
0097    };
0098 
0099    struct Logger {
0100       class Handler : public RLogHandler {
0101         public:
0102          bool Emit(const RLogEntry &entry) override;
0103       };
0104 
0105       Handler *fHandler;
0106       Logger()
0107       {
0108          auto uptr = std::make_unique<Handler>();
0109          fHandler = uptr.get();
0110          RLogManager::Get().PushFront(std::move(uptr));
0111       }
0112 
0113       ~Logger() { RLogManager::Get().Remove(fHandler); }
0114    };
0115 
0116 protected:
0117    RExceptionHandler        *fExcHandler{nullptr};   //!< exception handler
0118 
0119    TMap                     *fVizDB{nullptr};
0120    Bool_t                    fVizDBReplace{kFALSE};
0121    Bool_t                    fVizDBUpdate{kFALSE};
0122 
0123    TMap                     *fGeometries{nullptr};      //  TODO: use std::map<std::string, std::unique_ptr<TGeoManager>>
0124    TMap                     *fGeometryAliases{nullptr}; //  TODO: use std::map<std::string, std::string>
0125 
0126    REveScene                *fWorld{nullptr};
0127 
0128    REveViewerList           *fViewers{nullptr};
0129    REveSceneList            *fScenes{nullptr};
0130 
0131    REveScene                *fGlobalScene{nullptr};
0132    REveScene                *fEventScene{nullptr};
0133    Bool_t                    fResetCameras{kFALSE};
0134    Bool_t                    fDropLogicals{kFALSE};
0135    Bool_t                    fKeepEmptyCont{kFALSE};
0136 
0137    // ElementId management
0138    std::unordered_map<ElementId_t, REveElement*> fElementIdMap;
0139    ElementId_t                                   fLastElementId{0};
0140    ElementId_t                                   fNumElementIds{0};
0141    ElementId_t                                   fMaxElementIds{std::numeric_limits<ElementId_t>::max()};
0142 
0143    // Selection / highlight elements
0144    REveElement              *fSelectionList{nullptr};
0145    REveSelection            *fSelection{nullptr};
0146    REveSelection            *fHighlight{nullptr};
0147 
0148    std::shared_ptr<ROOT::RWebWindow>       fWebWindow;
0149    std::vector<Conn>                       fConnList;
0150    std::queue<std::shared_ptr<MIR> >       fMIRqueue;
0151 
0152    // MIR execution
0153    std::thread       fMIRExecThread;
0154    ServerState       fServerState;
0155    std::unordered_map<std::string, std::shared_ptr<TMethodCall> > fMethCallMap;
0156 
0157    Logger            fLogger;
0158    REveServerStatus  fServerStatus;
0159    bool              fIsRCore{false};
0160 
0161    // restricted functionality for public use
0162    bool              fHttpPublic{false};
0163 
0164    void WindowConnect(unsigned connid);
0165    void WindowData(unsigned connid, const std::string &arg);
0166    void WindowDisconnect(unsigned connid);
0167 
0168    void MIRExecThread();
0169    void ExecuteMIR(std::shared_ptr<MIR> mir);
0170 
0171    void StreamSceneChangesToJson();
0172    void SendSceneChanges();
0173 
0174 public:
0175    REveManager(); // (Bool_t map_window=kTRUE, Option_t* opt="FI");
0176    virtual ~REveManager();
0177 
0178    RExceptionHandler *GetExcHandler() const { return fExcHandler; }
0179 
0180    REveSelection *GetSelection() const { return fSelection; }
0181    REveSelection *GetHighlight() const { return fHighlight; }
0182 
0183    REveSceneList  *GetScenes()  const { return fScenes;  }
0184    REveViewerList *GetViewers() const { return fViewers; }
0185 
0186    REveScene *GetGlobalScene() const { return fGlobalScene; }
0187    REveScene *GetEventScene()  const { return fEventScene;  }
0188 
0189    REveScene *GetWorld() const { return fWorld; }
0190 
0191    REveViewer* GetDefaultViewer() const;
0192 
0193    REveViewer *SpawnNewViewer(const char *name, const char *title = "");
0194    REveScene  *SpawnNewScene (const char *name, const char *title = "");
0195 
0196    void AllowMultipleRemoteConnections(bool loopBack = true, bool useAuthKey = true);
0197 
0198    void BeginChange();
0199    void EndChange();
0200 
0201    void SceneSubscriberProcessingChanges(unsigned cinnId);
0202    void SceneSubscriberWaitingResponse(unsigned cinnId);
0203 
0204    bool ClientConnectionsFree() const;
0205 
0206    void DisableRedraw() { printf("REveManager::DisableRedraw obsolete \n"); }
0207    void EnableRedraw()  { printf("REveManager::EnableRedraw obsolete \n");  }
0208 
0209    void Redraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE)
0210    {
0211      printf("REveManager::Redraw3D oboslete %d %d\n",resetCameras , dropLogicals);
0212    }
0213    void RegisterRedraw3D();
0214    void DoRedraw3D();
0215    void FullRedraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE);
0216 
0217    void ClearAllSelections();
0218 
0219    Bool_t GetKeepEmptyCont() const   { return fKeepEmptyCont; }
0220    void   SetKeepEmptyCont(Bool_t k) { fKeepEmptyCont = k; }
0221 
0222    void AddElement(REveElement *element, REveElement *parent = nullptr);
0223    void AddGlobalElement(REveElement *element, REveElement *parent = nullptr);
0224 
0225    void RemoveElement(REveElement* element, REveElement *parent);
0226 
0227    REveElement *FindElementById (ElementId_t id) const;
0228    void         AssignElementId (REveElement* element);
0229    void         PreDeleteElement(REveElement* element);
0230    void         BrowseElement(ElementId_t id);
0231 
0232    // VizDB - Visualization-parameter data-base.
0233    Bool_t       InsertVizDBEntry(const TString& tag, REveElement* model,
0234                                  Bool_t replace, Bool_t update);
0235    Bool_t       InsertVizDBEntry(const TString& tag, REveElement* model);
0236    REveElement *FindVizDBEntry  (const TString& tag);
0237 
0238    void         LoadVizDB(const TString& filename, Bool_t replace, Bool_t update);
0239    void         LoadVizDB(const TString& filename);
0240    void         SaveVizDB(const TString& filename);
0241 
0242    Bool_t GetVizDBReplace()   const { return fVizDBReplace; }
0243    Bool_t GetVizDBUpdate ()   const { return fVizDBUpdate;  }
0244    void   SetVizDBReplace(Bool_t r) { fVizDBReplace = r; }
0245    void   SetVizDBUpdate (Bool_t u) { fVizDBUpdate  = u; }
0246 
0247 
0248    // Geometry management.
0249    TGeoManager *GetGeometry(const TString& filename);
0250    TGeoManager *GetGeometryByAlias(const TString& alias);
0251    TGeoManager *GetDefaultGeometry();
0252    void         RegisterGeometryAlias(const TString& alias, const TString& filename);
0253 
0254    void ClearROOTClassSaved();
0255 
0256    void AddLocation(const std::string& name, const std::string& path);
0257    void SetDefaultHtmlPage(const std::string& path);
0258    void SetClientVersion(const std::string& version);
0259 
0260    void ScheduleMIR(const std::string &cmd, ElementId_t i, const std::string& ctype, unsigned connid);
0261 
0262    static REveManager* Create();
0263    static void         Terminate();
0264    static void         ExecuteInMainThread(std::function<void()> func);
0265    static void         QuitRoot();
0266 
0267    static void    ErrorHandler(Int_t level, Bool_t abort, const char *location,
0268                                const char *msg);
0269 
0270 
0271    // Access to internals, needed for low-level control in advanced
0272    // applications.
0273 
0274    std::shared_ptr<ROOT::RWebWindow> GetWebWindow() const { return fWebWindow; }
0275 
0276    // void Send(void* buff, unsigned connid);
0277    void Send(unsigned connid, const std::string &data);
0278    void SendBinary(unsigned connid, const void *data, std::size_t len);
0279 
0280    void Show(const RWebDisplayArgs &args = "");
0281 
0282    void DisconnectEveViewer(REveViewer*);
0283    void ConnectEveViewer(REveViewer*);
0284 
0285    void GetServerStatus(REveServerStatus&);
0286    bool IsRCore() const { return fIsRCore; }
0287 
0288    bool GetHttpPublic() { return fHttpPublic;}
0289    void SetHttpPublic(bool);
0290 };
0291 
0292 R__EXTERN REveManager* gEve;
0293 
0294 }}
0295 
0296 #endif