File indexing completed on 2025-01-18 10:10:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
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};
0118
0119 TMap *fVizDB{nullptr};
0120 Bool_t fVizDBReplace{kFALSE};
0121 Bool_t fVizDBUpdate{kFALSE};
0122
0123 TMap *fGeometries{nullptr};
0124 TMap *fGeometryAliases{nullptr};
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
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
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
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 void WindowConnect(unsigned connid);
0162 void WindowData(unsigned connid, const std::string &arg);
0163 void WindowDisconnect(unsigned connid);
0164
0165 void MIRExecThread();
0166 void ExecuteMIR(std::shared_ptr<MIR> mir);
0167
0168 void StreamSceneChangesToJson();
0169 void SendSceneChanges();
0170
0171 public:
0172 REveManager();
0173 virtual ~REveManager();
0174
0175 RExceptionHandler *GetExcHandler() const { return fExcHandler; }
0176
0177 REveSelection *GetSelection() const { return fSelection; }
0178 REveSelection *GetHighlight() const { return fHighlight; }
0179
0180 REveSceneList *GetScenes() const { return fScenes; }
0181 REveViewerList *GetViewers() const { return fViewers; }
0182
0183 REveScene *GetGlobalScene() const { return fGlobalScene; }
0184 REveScene *GetEventScene() const { return fEventScene; }
0185
0186 REveScene *GetWorld() const { return fWorld; }
0187
0188 REveViewer* GetDefaultViewer() const;
0189
0190 REveViewer *SpawnNewViewer(const char *name, const char *title = "");
0191 REveScene *SpawnNewScene (const char *name, const char *title = "");
0192
0193 void AllowMultipleRemoteConnections(bool loopBack = true, bool useAuthKey = true);
0194
0195 void BeginChange();
0196 void EndChange();
0197
0198 void SceneSubscriberProcessingChanges(unsigned cinnId);
0199 void SceneSubscriberWaitingResponse(unsigned cinnId);
0200
0201 bool ClientConnectionsFree() const;
0202
0203 void DisableRedraw() { printf("REveManager::DisableRedraw obsolete \n"); }
0204 void EnableRedraw() { printf("REveManager::EnableRedraw obsolete \n"); }
0205
0206 void Redraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE)
0207 {
0208 printf("REveManager::Redraw3D oboslete %d %d\n",resetCameras , dropLogicals);
0209 }
0210 void RegisterRedraw3D();
0211 void DoRedraw3D();
0212 void FullRedraw3D(Bool_t resetCameras = kFALSE, Bool_t dropLogicals = kFALSE);
0213
0214 void ClearAllSelections();
0215
0216 Bool_t GetKeepEmptyCont() const { return fKeepEmptyCont; }
0217 void SetKeepEmptyCont(Bool_t k) { fKeepEmptyCont = k; }
0218
0219 void AddElement(REveElement *element, REveElement *parent = nullptr);
0220 void AddGlobalElement(REveElement *element, REveElement *parent = nullptr);
0221
0222 void RemoveElement(REveElement* element, REveElement *parent);
0223
0224 REveElement *FindElementById (ElementId_t id) const;
0225 void AssignElementId (REveElement* element);
0226 void PreDeleteElement(REveElement* element);
0227 void BrowseElement(ElementId_t id);
0228
0229
0230 Bool_t InsertVizDBEntry(const TString& tag, REveElement* model,
0231 Bool_t replace, Bool_t update);
0232 Bool_t InsertVizDBEntry(const TString& tag, REveElement* model);
0233 REveElement *FindVizDBEntry (const TString& tag);
0234
0235 void LoadVizDB(const TString& filename, Bool_t replace, Bool_t update);
0236 void LoadVizDB(const TString& filename);
0237 void SaveVizDB(const TString& filename);
0238
0239 Bool_t GetVizDBReplace() const { return fVizDBReplace; }
0240 Bool_t GetVizDBUpdate () const { return fVizDBUpdate; }
0241 void SetVizDBReplace(Bool_t r) { fVizDBReplace = r; }
0242 void SetVizDBUpdate (Bool_t u) { fVizDBUpdate = u; }
0243
0244
0245
0246 TGeoManager *GetGeometry(const TString& filename);
0247 TGeoManager *GetGeometryByAlias(const TString& alias);
0248 TGeoManager *GetDefaultGeometry();
0249 void RegisterGeometryAlias(const TString& alias, const TString& filename);
0250
0251 void ClearROOTClassSaved();
0252
0253 void AddLocation(const std::string& name, const std::string& path);
0254 void SetDefaultHtmlPage(const std::string& path);
0255 void SetClientVersion(const std::string& version);
0256
0257 void ScheduleMIR(const std::string &cmd, ElementId_t i, const std::string& ctype, unsigned connid);
0258
0259 static REveManager* Create();
0260 static void Terminate();
0261 static void ExecuteInMainThread(std::function<void()> func);
0262 static void QuitRoot();
0263
0264 static void ErrorHandler(Int_t level, Bool_t abort, const char *location,
0265 const char *msg);
0266
0267
0268
0269
0270
0271 std::shared_ptr<ROOT::RWebWindow> GetWebWindow() const { return fWebWindow; }
0272
0273
0274 void Send(unsigned connid, const std::string &data);
0275 void SendBinary(unsigned connid, const void *data, std::size_t len);
0276
0277 void Show(const RWebDisplayArgs &args = "");
0278
0279 void DisconnectEveViewer(REveViewer*);
0280 void ConnectEveViewer(REveViewer*);
0281
0282 void GetServerStatus(REveServerStatus&);
0283 bool IsRCore() const { return fIsRCore; }
0284 };
0285
0286 R__EXTERN REveManager* gEve;
0287
0288 }}
0289
0290 #endif