Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveManager.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <ROOT/REveManager.hxx>
13
14#include <ROOT/REveCamera.hxx>
15#include <ROOT/REveUtil.hxx>
17#include <ROOT/REveViewer.hxx>
18#include <ROOT/REveScene.hxx>
20#include <ROOT/REveClient.hxx>
21#include <ROOT/RWebWindow.hxx>
22#include <ROOT/RLogger.hxx>
23#include <ROOT/REveSystem.hxx>
26#include <ROOT/REveText.hxx>
27
28#include "TGeoManager.h"
29#include "TGeoMatrix.h"
30#include "TObjString.h"
31#include "TROOT.h"
32#include "TSystem.h"
33#include "TFile.h"
34#include "TMap.h"
35#include "TExMap.h"
36#include "TEnv.h"
37#include "TError.h"
38#include "TColor.h"
39#include "TPRegexp.h"
40#include "TClass.h"
41#include "TMethod.h"
42#include "TMethodCall.h"
43#include "THttpServer.h"
44#include "TTimer.h"
45#include "TApplication.h"
46
47#include "REveAssetDir.hxx"
48
49#include <exception>
50#include <fstream>
51#include <memory>
52#include <sstream>
53#include <iostream>
54#include <regex>
55#include <system_error>
56#include <thread>
57
58#if defined(R__LINUX) || defined(R__MACOSX)
59#include <pthread.h>
60#endif
61
62#include <nlohmann/json.hpp>
63
64using namespace ROOT::Experimental;
65namespace REX = ROOT::Experimental;
66
67REveManager *REX::gEve = nullptr;
68
70{
71 std::vector<REveScene*> addedWatch;
72 std::vector<REveScene*> removedWatch;
73
74 void reset() {
75 addedWatch.clear();
76 removedWatch.clear();
77 }
78};
79
80thread_local std::vector<ROOT::RLogEntry> gEveLogEntries;
82
83namespace {
84
85/// Stack size of the calling thread in bytes, or 0 if it cannot be determined.
86size_t CurrentThreadStackSize()
87{
88#if defined(R__LINUX)
89 size_t size = 0;
90 pthread_attr_t attr;
91 if (pthread_getattr_np(pthread_self(), &attr) == 0) {
92 pthread_attr_getstacksize(&attr, &size);
93 pthread_attr_destroy(&attr);
94 }
95 return size;
96#elif defined(R__MACOSX)
97 return pthread_get_stacksize_np(pthread_self());
98#else
99 return 0;
100#endif
101}
102
103} // namespace
104
105/** \class REveManager
106\ingroup REve
107\ingroup webwidgets
108
109\brief Central application manager for web-based REve.
110
111Manages elements, GUI, GL scenes and GL viewers.
112
113Following parameters can be specified in .rootrc file
114
115WebEve.DisableShow: 1 # do not start new web browser when REveManager::Show is called
116WebEve.HTimeout: 200 # timeout in ms for elements highlight
117WebEve.TableRowHeight: 33 # size of each row in pixels in the Table view, can be used to make design more compact
118*/
119
120////////////////////////////////////////////////////////////////////////////////
121
122REveManager::REveManager()
123 : // (Bool_t map_window, Option_t* opt) :
124 fExcHandler(nullptr), fVizDB(nullptr), fVizDBReplace(kTRUE), fVizDBUpdate(kTRUE), fGeometries(nullptr),
125 fGeometryAliases(nullptr),
126 fKeepEmptyCont(kFALSE)
127{
128 // Constructor.
129
130 static const REveException eh("REveManager::REveManager ");
131
132 if (REX::gEve)
133 throw eh + "There can be only one REve!";
134
135 REX::gEve = this;
136
138 fServerStatus.fTStart = std::time(nullptr);
139
141
142 fGeometries = new TMap;
146 fVizDB = new TMap;
148
149 fElementIdMap[0] = nullptr; // do not increase count for null element.
150
151 fWorld = new REveScene("EveWorld", "Top-level Eve Scene");
154
155 fSelectionList = new REveElement("Selection List");
156 fSelectionList->SetChildClass(TClass::GetClass<REveSelection>());
159 fSelection = new REveSelection("Global Selection", "", kRed, kViolet);
160 fSelection->SetIsMaster(true);
163 fHighlight = new REveSelection("Global Highlight", "", kGreen, kCyan);
164 fHighlight->SetIsMaster(true);
168
169 fViewers = new REveViewerList("Viewers");
172
173 fScenes = new REveSceneList("Scenes");
176
177 // --------------------------------
178 // Create camera list
179 // --------------------------------
180 fCameras = new REveElement("Cameras", "Camera list");
183
184 fGlobalScene = new REveScene("Geometry scene");
187
188 fEventScene = new REveScene("Event scene");
191
192 {
193 REveViewer *v = SpawnNewViewer("Default Viewer");
194 v->AddScene(fGlobalScene);
195 v->AddScene(fEventScene);
196 }
197
198 // !!! AMT increase threshold to enable color pick on client
200
201 // allow multiple connections
203
205 fWebWindow->UseServerThreads();
206 fWebWindow->SetDefaultPage("file:rootui5sys/eve7/index.html");
207
208 // Serve the SDF font and image directories, which can be set before the manager exists.
209 REX::Internal::REveAssetDir::RegisterAll();
210
211 Int_t htimeout = gEnv->GetValue("WebEve.HTimeout", 250);
212 Int_t table_row_height = gEnv->GetValue("WebEve.TableRowHeight", 0);
213 fWebWindow->SetUserArgs(Form("{ HTimeout: %d, TableRowHeight: %d }", htimeout, table_row_height));
214
215 // this is call-back, invoked when message received via websocket
216 fWebWindow->SetCallBacks([this](unsigned connid) { WindowConnect(connid); },
217 [this](unsigned connid, const std::string &arg) { WindowData(connid, arg); },
218 [this](unsigned connid) { WindowDisconnect(connid); });
219 fWebWindow->SetGeometry(900, 700); // configure predefined window geometry
220 fWebWindow->SetConnLimit(100); // maximal number of connections
221 fWebWindow->SetMaxQueueLength(1000); // number of allowed entries in the window queue
222
223 // The hover tooltip of GL viewers is drawn with this SDF font. Asserting it
224 // also serves the sdf-fonts/ location, which otherwise only happens when an
225 // REveText or viewer axes are created.
226 {
227 std::string fn = "LiberationSerif-Regular";
228 REveText::AssertSdfFont(fn, std::string(TROOT::GetDataDir().Data()) + "/fonts/" + fn + ".ttf");
229 }
230
231 fMIRExecThread = std::thread{[this] { MIRExecThread(); }};
232
233 // activate interpreter error report
234 gInterpreter->ReportDiagnosticsToErrorHandler();
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Destructor.
240
242{
243 fMIRExecThread.join();
244
245 // QQQQ How do we stop THttpServer / fWebWindow?
246
251 // Not needed - no more top-items: fScenes->Destroy();
252 fScenes = nullptr;
253
256 // Not needed - no more top-items: fViewers->Destroy();
257 fViewers = nullptr;
258
259 // fWindowManager->DestroyWindows();
260 // fWindowManager->DecDenyDestroy();
261 // fWindowManager->Destroy();
262 // fWindowManager = 0;
263
266
267 delete fGeometryAliases;
268 delete fGeometries;
269 delete fVizDB;
270 delete fExcHandler;
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Create a new GL viewer.
275
276REveViewer *REveManager::SpawnNewViewer(const char *name, const char *title)
277{
278 REveViewer *v = new REveViewer(name, title);
280 return v;
281}
282
283////////////////////////////////////////////////////////////////////////////////
284/// Create a new scene.
285
286REveScene *REveManager::SpawnNewScene(const char *name, const char *title)
287{
288 REveScene *s = new REveScene(name, title);
290 return s;
291}
292
294{
295 printf("REveManager::RegisterRedraw3D() obsolete\n");
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Perform 3D redraw of scenes and viewers whose contents has
300/// changed.
301
303{
304 printf("REveManager::DoRedraw3D() obsolete\n");
305}
306
307////////////////////////////////////////////////////////////////////////////////
308/// Perform 3D redraw of all scenes and viewers.
309
310void REveManager::FullRedraw3D(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
311{
312 printf("REveManager::FullRedraw3D() obsolete\n");
313}
314
315////////////////////////////////////////////////////////////////////////////////
316/// Clear all selection objects. Can make things easier for EVE when going to
317/// the next event. Still, destruction os selected object should still work
318/// correctly as long as it is executed within a change cycle.
319
321{
322 for (auto el : fSelectionList->fChildren) {
323 dynamic_cast<REveSelection *>(el)->ClearSelection();
324 }
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Add an element. If parent is not specified it is added into
329/// current event (which is created if does not exist).
330
332{
333 if (parent == nullptr) {
334 // XXXX
335 }
336
337 parent->AddElement(element);
338}
339
340////////////////////////////////////////////////////////////////////////////////
341/// Add a global element, i.e. one that does not change on each
342/// event, like geometry or projection manager.
343/// If parent is not specified it is added to a global scene.
344
346{
347 if (!parent)
348 parent = fGlobalScene;
349
350 parent->AddElement(element);
351}
352
353////////////////////////////////////////////////////////////////////////////////
354/// Remove element from parent.
355
357{
358 parent->RemoveElement(element);
359}
360
361////////////////////////////////////////////////////////////////////////////////
362/// Lookup ElementId in element map and return corresponding REveElement*.
363/// Returns nullptr if the id is not found
364
366{
367 auto it = fElementIdMap.find(id);
368 return (it != fElementIdMap.end()) ? it->second : nullptr;
369}
370
371////////////////////////////////////////////////////////////////////////////////
372/// Assign a unique ElementId to given element.
373
375{
376 static const REveException eh("REveManager::AssignElementId ");
377
379 throw eh + "ElementId map is full.";
380
381next_free_id:
382 while (fElementIdMap.find(++fLastElementId) != fElementIdMap.end())
383 ;
384 if (fLastElementId == 0)
385 goto next_free_id;
386 // MT - alternatively, we could spawn a thread to find next thousand or so ids and
387 // put them in a vector of ranges. Or collect them when they are freed.
388 // Don't think this won't happen ... online event display can run for months
389 // and easily produce 100000 objects per minute -- about a month to use up all id space!
390
391 element->fElementId = fLastElementId;
392 fElementIdMap.insert(std::make_pair(fLastElementId, element));
394}
395
396////////////////////////////////////////////////////////////////////////////////
397/// Activate EVE browser (summary view) for specified element id
398
400{
401 nlohmann::json msg = {};
402 msg["content"] = "BrowseElement";
403 msg["id"] = id;
404
405 fWebWindow->Send(0, msg.dump());
406}
407
408////////////////////////////////////////////////////////////////////////////////
409/// Ask every connected client to grab its GL viewers and POST each image to an
410/// image collector. Each client posts the views it shows, all tagged with the
411/// same `event_id`.
412///
413/// The body is `application/octet-stream`, width*height*4 bytes of RGBA8 with
414/// straight alpha and no background, so it composites onto any backdrop.
415/// Headers X-Width, X-Height, X-Event-ID and X-View-Type describe it; X-Flip-Y
416/// is 1 when the rows are in WebGL bottom-up order. RenderCore's
417/// util/image-gator.js is a reference receiver. The default collector is on
418/// loopback; a remote one needs TLS and authentication.
419///
420/// \param event_id tag recorded with the image, e.g. run/lumi/event
421/// \param url collector endpoint; empty takes rootrc `WebEve.ImageGatorUrl`,
422/// which defaults to http://localhost:3000/capture
423/// \param scale multiplier on the viewer viewport; 1 is what the operator sees
424/// \param viewers restrict to these viewer names; empty means all of them
425
426void REveManager::GrabImages(std::string_view event_id, std::string_view url, int scale,
427 const std::vector<std::string> &viewers)
428{
429 std::string dest(url);
430 if (dest.empty())
431 dest = gEnv->GetValue("WebEve.ImageGatorUrl", "http://localhost:3000/capture");
432
433 nlohmann::json msg = {};
434 // clang-format off
435 msg["content"] = "GrabImage";
436 msg["event_id"] = std::string(event_id);
437 msg["url"] = dest;
438 msg["scale"] = scale;
439 msg["viewers"] = viewers;
440 // clang-format on
441
442 fWebWindow->Send(0, msg.dump());
443}
444
445////////////////////////////////////////////////////////////////////////////////
446/// Called from REveElement prior to its destruction so the
447/// framework components (like object editor) can unreference it.
448
450{
451 if (el->fImpliedSelected > 0) {
452 for (auto slc : fSelectionList->fChildren) {
453 REveSelection *sel = dynamic_cast<REveSelection *>(slc);
454 sel->RemoveImpliedSelectedReferencesTo(el);
455 }
456
457 if (el->fImpliedSelected != 0)
458 Error("REveManager::PreDeleteElement", "ImpliedSelected not zero (%d) after cleanup of selections.",
459 el->fImpliedSelected);
460 }
461 // Primary selection deregistration is handled through Niece removal from Aunts.
462
463 if (el->fElementId != 0) {
464 auto it = fElementIdMap.find(el->fElementId);
465 if (it != fElementIdMap.end()) {
466 if (it->second == el) {
467 fElementIdMap.erase(it);
469 } else
470 Error("PreDeleteElement", "element ptr in ElementIdMap does not match the argument element.");
471 } else
472 Error("PreDeleteElement", "element id %u was not registered in ElementIdMap.", el->fElementId);
473 } else
474 Error("PreDeleteElement", "element with 0 ElementId passed in.");
475}
476
477////////////////////////////////////////////////////////////////////////////////
478/// Insert a new visualization-parameter database entry. Returns
479/// true if the element is inserted successfully.
480/// If entry with the same key already exists the behaviour depends on the
481/// 'replace' flag:
482/// - true - The old model is deleted and new one is inserted (default).
483/// Clients of the old model are transferred to the new one and
484/// if 'update' flag is true (default), the new model's parameters
485/// are assigned to all clients.
486/// - false - The old model is kept, false is returned.
487///
488/// If insert is successful, the ownership of the model-element is
489/// transferred to the manager.
490
492{
493 TPair *pair = (TPair *)fVizDB->FindObject(tag);
494 if (pair) {
495 if (replace) {
496 model->IncDenyDestroy();
497 model->SetRnrChildren(kFALSE);
498
499 REveElement *old_model = dynamic_cast<REveElement *>(pair->Value());
500 if (old_model) {
501 while (old_model->HasChildren()) {
502 REveElement *el = old_model->FirstChild();
503 el->SetVizModel(model);
504 if (update) {
505 el->CopyVizParams(model);
507 }
508 }
509 old_model->DecDenyDestroy();
510 }
511 pair->SetValue(dynamic_cast<TObject *>(model));
512 return kTRUE;
513 } else {
514 return kFALSE;
515 }
516 } else {
517 model->IncDenyDestroy();
518 model->SetRnrChildren(kFALSE);
519 fVizDB->Add(new TObjString(tag), dynamic_cast<TObject *>(model));
520 return kTRUE;
521 }
522}
523
524////////////////////////////////////////////////////////////////////////////////
525/// Insert a new visualization-parameter database entry with the default
526/// parameters for replace and update, as specified by members
527/// fVizDBReplace(default=kTRUE) and fVizDBUpdate(default=kTRUE).
528/// See docs of the above function.
529
534
535////////////////////////////////////////////////////////////////////////////////
536/// Find a visualization-parameter database entry corresponding to tag.
537/// If the entry is not found 0 is returned.
538
540{
541 return dynamic_cast<REveElement *>(fVizDB->GetValue(tag));
542}
543
544////////////////////////////////////////////////////////////////////////////////
545/// Load visualization-parameter database from file filename. The
546/// replace, update arguments replace the values of fVizDBReplace
547/// and fVizDBUpdate members for the duration of the macro
548/// execution.
549
551{
552 Bool_t ex_replace = fVizDBReplace;
553 Bool_t ex_update = fVizDBUpdate;
554 fVizDBReplace = replace;
556
558
559 fVizDBReplace = ex_replace;
560 fVizDBUpdate = ex_update;
561}
562
563////////////////////////////////////////////////////////////////////////////////
564/// Load visualization-parameter database from file filename.
565/// State of data-members fVizDBReplace and fVizDBUpdate determine
566/// how the registered entries are handled.
567
573
574////////////////////////////////////////////////////////////////////////////////
575/// Save visualization-parameter database to file filename.
576
578{
579 TPMERegexp re("(.+)\\.\\w+");
580 if (re.Match(filename) != 2) {
581 Error("SaveVizDB", "filename does not match required format '(.+)\\.\\w+'.");
582 return;
583 }
584
585 TString exp_filename(filename);
586 gSystem->ExpandPathName(exp_filename);
587
588 std::ofstream out(exp_filename, std::ios::out | std::ios::trunc);
589 out << "void " << re[1] << "()\n";
590 out << "{\n";
591 out << " REveManager::Create();\n";
592
594
595 Int_t var_id = 0;
596 TString var_name;
597 TIter next(fVizDB);
598 TObjString *key;
599 while ((key = (TObjString *)next())) {
600 REveElement *mdl = dynamic_cast<REveElement *>(fVizDB->GetValue(key));
601 if (mdl) {
602 var_name.Form("x%03d", var_id++);
603 mdl->SaveVizParams(out, key->String(), var_name);
604 } else {
605 Warning("SaveVizDB", "Saving failed for key '%s'.", key->String().Data());
606 }
607 }
608
609 out << "}\n";
610 out.close();
611}
612
613////////////////////////////////////////////////////////////////////////////////
614/// Get geometry with given filename.
615/// This is cached internally so the second time this function is
616/// called with the same argument the same geo-manager is returned.
617/// gGeoManager is set to the return value.
618
620{
621 static const REveException eh("REveManager::GetGeometry ");
622
623 TString exp_filename = filename;
624 gSystem->ExpandPathName(exp_filename);
625 printf("REveManager::GetGeometry loading: '%s' -> '%s'.\n", filename.Data(), exp_filename.Data());
626
628 if (gGeoManager) {
630 } else {
631 Bool_t locked = TGeoManager::IsLocked();
632 if (locked) {
633 Warning("REveManager::GetGeometry", "TGeoManager is locked ... unlocking it.");
635 }
636 if (TGeoManager::Import(filename) == nullptr) {
637 throw eh + "TGeoManager::Import() failed for '" + exp_filename + "'.";
638 }
639 if (locked) {
641 }
642
644
645 // Import colors exported by Gled, if they exist.
646 {
647 TFile f(exp_filename, "READ");
648 TObjArray *collist = (TObjArray *)f.Get("ColorList");
649 f.Close();
650 if (collist) {
652 TGeoVolume *vol;
653 while ((vol = (TGeoVolume *)next()) != nullptr) {
654 Int_t oldID = vol->GetLineColor();
655 TColor *col = (TColor *)collist->At(oldID);
656 Float_t r, g, b;
657 col->GetRGB(r, g, b);
658 Int_t newID = TColor::GetColor(r, g, b);
659 vol->SetLineColor(newID);
660 }
661 }
662 }
663
665 }
666 return gGeoManager;
667}
668
669////////////////////////////////////////////////////////////////////////////////
670/// Get geometry with given alias.
671/// The alias must be registered via RegisterGeometryAlias().
672
674{
675 static const REveException eh("REveManager::GetGeometry ");
676
677 TObjString *full_name = (TObjString *)fGeometryAliases->GetValue(alias);
678 if (!full_name)
679 throw eh + "geometry alias '" + alias + "' not registered.";
680 return GetGeometry(full_name->String());
681}
682
683////////////////////////////////////////////////////////////////////////////////
684/// Get the default geometry.
685/// It should be registered via RegisterGeometryName("Default", `<URL>`).
686
691
692////////////////////////////////////////////////////////////////////////////////
693/// Get the default viewer.
694///
695
697{
698 return dynamic_cast<REveViewer*>(fViewers->FirstChild());
699}
700
701////////////////////////////////////////////////////////////////////////////////
702/// Utility function to allow remote RWebWindow connections.
703/// Disable loopback when use remote client.
704/// Authentification key has to be disabled in the case of multiple connections.
705/// The default arguments prevent remote connections for the security reasons.
706//
707void REveManager::AllowMultipleRemoteConnections(bool loopBack, bool requireAuthKey)
708{
710 fWebWindow->SetRequireAuthKey(requireAuthKey);
711}
712
713////////////////////////////////////////////////////////////////////////////////
714/// Register 'name' as an alias for geometry file 'filename'.
715/// The old aliases are silently overwritten.
716/// After that the geometry can be retrieved also by calling:
717/// REX::gEve->GetGeometryByName(name);
718
723
724////////////////////////////////////////////////////////////////////////////////
725/// Work-around uber ugly hack used in SavePrimitive and co.
726
728{
729 gROOT->ResetClassSaved();
730}
731
732////////////////////////////////////////////////////////////////////////////////
733/// Register new directory to THttpServer
734// For example: AddLocation("mydir/", "/test/EveWebApp/ui5");
735//
736void REveManager::AddLocation(const std::string &locationName, const std::string &path)
737{
738 fWebWindow->GetServer()->AddLocation(locationName.c_str(), path.c_str());
739}
740
741////////////////////////////////////////////////////////////////////////////////
742/// Set content of default window HTML page
743// Got example: SetDefaultHtmlPage("file:currentdir/test.html")
744//
745void REveManager::SetDefaultHtmlPage(const std::string &path)
746{
747 fWebWindow->SetDefaultPage(path);
748}
749
750////////////////////////////////////////////////////////////////////////////////
751/// Set client version, used as prefix in scripts URL
752/// When changed, web browser will reload all related JS files while full URL will be different
753/// Default is empty value - no extra string in URL
754/// Version should be string like "1.2" or "ver1.subv2" and not contain any special symbols
755void REveManager::SetClientVersion(const std::string &version)
756{
757 fWebWindow->SetClientVersion(version);
758}
759
760////////////////////////////////////////////////////////////////////////////////
761/// If global REveManager* REX::gEve is not set initialize it.
762/// Returns REX::gEve.
763
765{
766 static const REveException eh("REveManager::Create ");
767
768 if (!REX::gEve) {
769 // XXXX Initialize some server stuff ???
770
771 REX::gEve = new REveManager();
772 }
773 return REX::gEve;
774}
775
776////////////////////////////////////////////////////////////////////////////////
777/// Properly terminate global REveManager.
778
780{
781 if (!REX::gEve)
782 return;
783
784 delete REX::gEve;
785 REX::gEve = nullptr;
786}
787
788void REveManager::ExecuteInMainThread(std::function<void()> func)
789{
790 class XThreadTimer : public TTimer {
791 std::function<void()> foo_;
792 public:
793 XThreadTimer(std::function<void()> f) : foo_(f)
794 {
795 SetTime(0);
797 gSystem->AddTimer(this);
798 }
799 Bool_t Notify() override
800 {
801 foo_();
802 gSystem->RemoveTimer(this);
803 delete this;
804 return kTRUE;
805 }
806 };
807
808 new XThreadTimer(func);
809}
810
812{
814 // QQQQ Should call Terminate() but it needs to:
815 // - properly stop MIRExecThread;
816 // - shutdown civet/THttp/RWebWindow
818 });
819}
820
821////////////////////////////////////////////////////////////////////////////////
822/// Process new connection from web window.
823///
824/// This is called in a web-server thread, which can have a small stack (the
825/// builtin civetweb uses 100 KB unless configured otherwise). Streaming the
826/// scenes can need much more: the first IsA() of an element class makes cling
827/// load declarations, which recurses deeply. If the current thread's stack is
828/// small, the streaming runs in a thread with the default stack size instead,
829/// and this thread waits for it.
830
831void REveManager::WindowConnect(unsigned connid)
832{
833 static constexpr size_t kMinStackSize = 1024 * 1024;
834
835 size_t stack_size = CurrentThreadStackSize();
836 if (stack_size == 0 || stack_size >= kMinStackSize) {
837 StreamToNewConnection(connid);
838 return;
839 }
840
841 // An exception is passed back to this thread, where it would have appeared before.
842 std::exception_ptr exc;
843 std::thread thrd;
844 try {
845 thrd = std::thread([this, connid, &exc] {
846#if defined(R__LINUX)
847 pthread_setname_np(pthread_self(), "eve_connect");
848#endif
849 try {
850 StreamToNewConnection(connid);
851 } catch (...) {
852 exc = std::current_exception();
853 }
854 });
855 } catch (const std::system_error &e) {
856 ::Warning("REveManager::WindowConnect",
857 "could not start streaming thread (%s), streaming in the web-server thread with stack size %zu",
858 e.what(), stack_size);
859 StreamToNewConnection(connid);
860 return;
861 }
862 thrd.join();
863 if (exc)
864 std::rethrow_exception(exc);
865}
866
867////////////////////////////////////////////////////////////////////////////////
868/// Register new connection and stream the world and the mandatory scenes to it.
869
871{
872 std::unique_lock<std::mutex> lock(fServerState.fMutex);
873
875 {
876 fServerState.fCV.wait(lock);
877 }
878
879 fConnList.emplace_back(connid);
880 printf("connection established %u\n", connid);
881
882 // QQQQ do we want mir-time here as well? maybe set it at the end of function?
883 // Note, this is all under lock, so nobody will get state out in between.
884 fServerStatus.fTLastMir = fServerStatus.fTLastConnect = std::time(nullptr);
886
887 // This prepares core and render data buffers.
888 printf("\nEVEMNG ............. streaming the world scene.\n");
889
890 fWorld->AddSubscriber(std::make_unique<REveClient>(connid, fWebWindow));
892
893 printf(" sending json, len = %d\n", (int)fWorld->fOutputJson.size());
895 Send(connid, fWorld->fOutputJson);
896 printf(" for now assume world-scene has no render data, binary-size=%d\n", fWorld->fTotalBinarySize);
897 assert(fWorld->fTotalBinarySize == 0);
898 // Sent to this connection only; the next SendSceneChanges() must not send
899 // it to everyone again.
901
902 for (auto &c : fScenes->RefChildren()) {
903 REveScene *scene = dynamic_cast<REveScene *>(c);
904 if (!scene->GetMandatory())
905 continue;
906
907 scene->AddSubscriber(std::make_unique<REveClient>(connid, fWebWindow));
908 printf("\nEVEMNG ............. streaming scene %s [%s]\n", scene->GetCTitle(), scene->GetCName());
909
910 // This prepares core and render data buffers.
911 scene->StreamElements();
912
913 printf(" sending json, len = %d\n", (int)scene->fOutputJson.size());
915 Send(connid, scene->fOutputJson);
916
917 if (scene->fTotalBinarySize > 0) {
918 printf(" sending binary, len = %d\n", scene->fTotalBinarySize);
919 SendBinary(connid, &scene->fOutputBinary[0], scene->fTotalBinarySize);
920 } else {
921 printf(" NOT sending binary, len = %d\n", scene->fTotalBinarySize);
922 }
923 scene->ClearOutput();
924 }
925
926 fServerState.fCV.notify_all();
927}
928
929////////////////////////////////////////////////////////////////////////////////
930/// Process disconnect of web window
931
932void REveManager::WindowDisconnect(unsigned connid)
933{
934 std::unique_lock<std::mutex> lock(fServerState.fMutex);
935 auto conn = fConnList.end();
936 for (auto i = fConnList.begin(); i != fConnList.end(); ++i) {
937 if (i->fId == connid) {
938 conn = i;
939 break;
940 }
941 }
942 // this should not happen, just check
943 if (conn == fConnList.end()) {
944 printf("error, connection not found!");
945 } else {
946 printf("connection closed %u\n", connid);
947 fConnList.erase(conn);
948 for (auto &c : fScenes->RefChildren()) {
949 REveScene *scene = dynamic_cast<REveScene *>(c);
950 scene->RemoveSubscriber(connid);
951 }
952 fWorld->RemoveSubscriber(connid);
953 }
954
955 // User case: someone can close browser tab as clients are updateding
956 // note if scene changes are in progess the new serverstate will be changes after finish those
958 {
959 if (fPendingSceneChanges && !fConnList.empty()) {
960 // The closed connection was the last one busy: send the changes held
961 // back for it, as its acknowledgement would have.
962 fPendingSceneChanges = false;
965 } else {
966 // No one left to send to; the stamps stay for the next EndChange().
967 fPendingSceneChanges = false;
969 }
970 fServerState.fCV.notify_all();
971 }
972
973 fServerStatus.fTLastDisconnect = std::time(nullptr);
975
976 fServerState.fCV.notify_all();
977}
978
979////////////////////////////////////////////////////////////////////////////////
980/// Process data from web window
981
982void REveManager::WindowData(unsigned connid, const std::string &arg)
983{
984 static const REveException eh("REveManager::WindowData ");
985
986 // find connection object
987 bool found = false;
988 for (auto &conn : fConnList) {
989 if (conn.fId == connid) {
990 found = true;
991 break;
992 }
993 }
994
995 // this should not happen, just check
996 if (!found) {
997 R__LOG_ERROR(REveLog()) << "Internal error - no connection with id " << connid << " found";
998 return;
999 }
1000
1001
1002 if (arg.compare("__REveDoneChanges") == 0)
1003 {
1004 // client status data
1005 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1006
1007 for (auto &conn : fConnList) {
1008 if (conn.fId == connid) {
1009 conn.fState = Conn::Free;
1010 break;
1011 }
1012 }
1013
1016 // Changes stamped while the previous ones were in flight. Sending
1017 // them leaves the clients busy again.
1018 fPendingSceneChanges = false;
1021 } else {
1023 }
1024 fServerState.fCV.notify_all();
1025 }
1026
1027 return;
1028 }
1030 {
1031 if (fHttpPublic)
1032 {
1033 R__LOG_INFO(REveLog()) << "REveManager::WindowData, file dialog is not allowed in restriced public mode";
1034 }
1035 else
1036 {
1038 }
1039 return;
1040 }
1041 else if (arg.compare(0, 11, "SETCHANNEL:") == 0) {
1042 std::string s = arg.substr(11);
1043 auto p = s.find(",");
1044 int eveid = std::stoi(s.substr(0, p));
1045 int chid = std::stoi(s.substr(p+1));
1046
1047 REveElement* n = FindElementById(eveid);
1048 auto nn = dynamic_cast<REveGeoTopNodeData*>(n);
1049 if (nn) nn->SetChannel(connid, chid);
1050
1051 return;
1052 }
1053
1054 nlohmann::json cj = nlohmann::json::parse(arg);
1055 if (gDebug > 0)
1056 ::Info("REveManager::WindowData", "MIR test %s\n", cj.dump().c_str());
1057
1058 std::string cmd = cj["mir"];
1059 int id = cj["fElementId"];
1060 std::string ctype = cj["class"];
1061
1062 ScheduleMIR(cmd, id, ctype, connid);
1063}
1064
1065//
1066//____________________________________________________________________
1067void REveManager::ScheduleMIR(const std::string &cmd, ElementId_t id, const std::string& ctype, unsigned connid)
1068{
1069 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1070 fServerStatus.fTLastMir = std::time(nullptr);
1071 fMIRqueue.push(std::make_shared<MIR>(cmd, id, ctype, connid));
1072
1073 if (fMIRqueue.size() > 5)
1074 std::cout << "Warning, REveManager::ScheduleMIR(). queue size " << fMIRqueue.size() << std::endl;
1075
1077 fServerState.fCV.notify_all();
1078}
1079
1080//
1081//____________________________________________________________________
1082void REveManager::ExecuteMIR(std::shared_ptr<MIR> mir)
1083{
1084 static const REveException eh(""); // Empty -- all errors go to R__LOG
1085
1086 //if (gDebug > 0)
1087 ::Info("REveManager::ExecuteCommand", "MIR cmd %s", mir->fCmd.c_str());
1088
1089 std::string tag = mir->fCtype + "::<to-be-determined>";
1090
1091 try {
1092 REveElement *el = FindElementById(mir->fId);
1093 if ( ! el) throw eh + "Element with id " + mir->fId + " not found";
1094
1095 static const std::regex cmd_re("^(\\w[\\w\\d]*)\\(\\s*(.*)\\s*\\)\\s*;?\\s*$", std::regex::optimize);
1096 std::smatch m;
1097 std::regex_search(mir->fCmd, m, cmd_re);
1098 if (m.size() != 3)
1099 throw eh + "Command string parse error: '" + mir->fCmd + "'.";
1100
1101 static const TClass *elem_cls = TClass::GetClass<REX::REveElement>();
1102
1103 TClass *call_cls = TClass::GetClass(mir->fCtype.c_str());
1104 if ( ! call_cls)
1105 throw eh + "Class '" + mir->fCtype + "' not found.";
1106
1107 void *el_casted = call_cls->DynamicCast(elem_cls, el, false);
1108 if ( ! el_casted)
1109 throw eh + "Dynamic cast from REveElement to '" + mir->fCtype + "' failed.";
1110
1111 tag = mir->fCtype + "::" + m.str(1);
1112
1113 std::shared_ptr<TMethodCall> mc;
1114 auto mmi = fMethCallMap.find(tag);
1115 if (mmi != fMethCallMap.end())
1116 {
1117 mc = mmi->second;
1118 }
1119 else
1120 {
1121 const TMethod *meth = call_cls->GetMethodAllAny(m.str(1).c_str());
1122 if ( ! meth)
1123 throw eh + "Can not find TMethod matching '" + m.str(1) + "'.";
1124 mc = std::make_shared<TMethodCall>(meth);
1125 fMethCallMap.insert(std::make_pair(tag, mc));
1126 }
1127
1129
1131 mc->Execute(el_casted, m.str(2).c_str());
1132
1134 R__LOG_ERROR(REveLog()) << eh << "error executing " << tag << ":" << REveElement::stlMirErrorString << " (code " << REveElement::stlMirError << ").";
1135 }
1137
1138 // Alternative implementation through Cling. "Leaks" 200 kB per call.
1139 // This might be needed for function calls that involve data-types TMethodCall
1140 // can not handle.
1141 // std::stringstream cmd;
1142 // cmd << "((" << mir->fCtype << "*)" << std::hex << std::showbase << (size_t)el << ")->" << mir->fCmd << ";";
1143 // std::cout << cmd.str() << std::endl;
1144 // gROOT->ProcessLine(cmd.str().c_str());
1145 } catch (std::exception &e) {
1146 R__LOG_ERROR(REveLog()) << "caught exception executing " << tag << ": " << e.what();
1147 } catch (...) {
1148 R__LOG_ERROR(REveLog()) << "caught unknown execption.";
1149 }
1150}
1151
1152// Write scene change into scenes's internal json member
1154{
1156
1157 for (auto &el : fScenes->RefChildren())
1158 {
1159 REveScene* s = dynamic_cast<REveScene*>(el);
1161 }
1162}
1163
1164////////////////////////////////////////////////////////////////////////////////
1165/// Send transformation-only changes on the motion channel: the same websocket,
1166/// outside the BeginChanges/EndChanges cycle, with no acknowledgement. The
1167/// message is sent directly, so it goes only when every connection can take a
1168/// direct send. Otherwise the elements stay stamped and go out with the
1169/// regular changes, which carry the same matrix and motion. The motion's t0 is
1170/// stamped by REveTrans::SetMotion(), so the delay does not shift the
1171/// trajectory.
1172
1174{
1175 if (fConnList.empty())
1176 return;
1177
1178 for (auto &conn : fConnList)
1179 if (!fWebWindow->CanSend(conn.fId, true))
1180 return;
1181
1182 nlohmann::json arr = nlohmann::json::array();
1183
1185 for (auto &el : fScenes->RefChildren()) {
1186 auto s = dynamic_cast<REveScene *>(el);
1187 if (s)
1188 s->StreamMotionChanges(arr);
1189 }
1190
1191 if (arr.empty())
1192 return;
1193
1194 nlohmann::json msg = {};
1195 // clang-format off
1196 msg["content"] = "Motion";
1197 msg["els"] = arr;
1198 // clang-format on
1199
1200 std::string data = msg.dump();
1202
1203 for (auto &conn : fConnList) {
1205 fWebWindow->Send(conn.fId, data);
1206 }
1207}
1208
1209////////////////////////////////////////////////////////////////////////////////
1210// Send json and binary data to scene's connections
1212{
1213 // send begin message
1214 nlohmann::json jobj = {};
1215 jobj["content"] = "BeginChanges";
1216 SendToAllConnections(jobj.dump());
1217
1218 // send the change json
1220
1221 for (auto &el : fScenes->RefChildren())
1222 {
1223 REveScene* s = dynamic_cast<REveScene*>(el);
1225 }
1226
1227 // send end changes message and log messages
1228 jobj["content"] = "EndChanges";
1229
1230 if (!gEveLogEntries.empty()) {
1231 constexpr static int numLevels = static_cast<int>(ELogLevel::kDebug) + 1;
1232 constexpr static std::array<const char *, numLevels> sTag{
1233 {"{unset-error-level please report}", "FATAL", "Error", "Warning", "Info", "Debug"}};
1234
1235 jobj["log"] = nlohmann::json::array();
1236 std::stringstream strm;
1237 for (auto entry : gEveLogEntries) {
1238 strm.str("");
1239 nlohmann::json item = {};
1240 item["lvl"] = entry.fLevel;
1241 int cappedLevel = std::min(static_cast<int>(entry.fLevel), numLevels - 1);
1242 strm << "Server " << sTag[cappedLevel] << ":";
1243
1244 if (!entry.fLocation.fFuncName.empty())
1245 strm << " " << entry.fLocation.fFuncName;
1246 strm << " " << entry.fMessage;
1247 item["msg"] = strm.str();
1248 jobj["log"].push_back(item);
1249 }
1250 gEveLogEntries.clear();
1251 }
1252 SendToAllConnections(jobj.dump());
1253}
1254
1255//
1256//____________________________________________________________________
1258{
1259#if defined(R__LINUX)
1260 pthread_setname_np(pthread_self(), "mir_exec");
1261#endif
1262 while (true)
1263 {
1264 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1265 underlock:
1267 {
1268 fServerState.fCV.wait(lock);
1269 goto underlock;
1270 }
1271 else
1272 {
1273 // set server state and update the queue under lock
1274 //
1276 std::shared_ptr<MIR> mir = fMIRqueue.front();
1277
1278 // reset local thread related data
1279 gMIRData.reset();
1280 fMIRqueue.pop();
1281
1282 lock.unlock();
1283
1284 // Ideally, as in gled, MIR execution would be steered by scenes themselves.
1285 // But this requires alpha/beta/gamma MIR elements and scene dependenices,
1286 // so dependent scenes can be locked, too.
1287 // On top of that, one could also implements authorization framework, as in gled.
1288
1291
1292 ExecuteMIR(mir);
1293
1296
1298
1299 // send changes (need to access client connection list) and set the state under lock
1300 //
1301 lock.lock();
1302
1303 // disconnect requested scene from clients
1304 for (auto &scene : gMIRData.removedWatch)
1305 scene->RemoveSubscriber(mir->fConnId);
1306
1307
1308 // connect and stream scenes to new clients
1309 for (auto &scene : gMIRData.addedWatch) {
1310 scene->AddSubscriber(std::make_unique<REveClient>(mir->fConnId, fWebWindow));
1311 scene->StreamElements();
1312 Send(mir->fConnId, scene->fOutputJson);
1313 if (scene->fTotalBinarySize > 0)
1314 SendBinary(mir->fConnId, &scene->fOutputBinary[0], scene->fTotalBinarySize);
1315 // Streamed to this connection only; SendSceneChanges() below must
1316 // not send it to every subscriber.
1317 scene->ClearOutput();
1318 }
1319
1321
1323 fServerState.fCV.notify_all();
1324 }
1325 }
1326}
1327
1328//____________________________________________________________________
1330{
1331 for (auto &c : view->RefChildren()) {
1332 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
1333 std::cout << "Disconnect scee " << sinfo->GetScene()->GetName();
1334 gMIRData.removedWatch.push_back(sinfo->GetScene());
1335 }
1336}
1337//____________________________________________________________________
1339{
1340 view->StampObjProps();
1341 for (auto &c : view->RefChildren()) {
1342 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
1343 std::cout << "Connect scene " << sinfo->GetScene()->GetName();
1344 gMIRData.addedWatch.push_back(sinfo->GetScene());
1345 }
1346}
1347
1348//____________________________________________________________________
1350{
1351 for (auto &conn : fConnList) {
1352 fWebWindow->Send(conn.fId, data);
1353 }
1354}
1355
1356void REveManager::Send(unsigned connid, const std::string &data)
1357{
1358 fWebWindow->Send(connid, data);
1359}
1360
1361void REveManager::SendBinary(unsigned connid, const void *data, std::size_t len)
1362{
1363 fWebWindow->SendBinary(connid, data, len);
1364}
1365
1366////////////////////////////////////////////////////////////////////////////////
1367/// Is there anything stamped and not yet streamed?
1368
1370{
1371 if (fWorld->IsChanged())
1372 return true;
1373
1374 for (auto &el : fScenes->RefChildren()) {
1375 auto s = dynamic_cast<REveScene *>(el);
1376 if (s && s->IsChanged())
1377 return true;
1378 }
1379 return false;
1380}
1381
1382////////////////////////////////////////////////////////////////////////////////
1383
1385{
1386 for (auto &conn : fConnList) {
1387 if (conn.fState != Conn::Free)
1388 return false;
1389 }
1390
1391 return true;
1392}
1393
1394// called from REveScene::SendChangesToSubscribers
1396{
1397 for (auto &conn : fConnList) {
1398 if (conn.fId == cinnId)
1399 {
1400 conn.fState = Conn::WaitingResponse;
1401 break;
1402 }
1403 }
1404}
1405
1406//////////////////////////////////////////////////////////////////
1407/// Show eve manager in specified browser.
1408
1409/// If rootrc variable WebEve.DisableShow is set, HTTP server will be
1410/// started and access URL printed on stdout.
1411
1413{
1414 if (gEnv->GetValue("WebEve.DisableShow", 0) != 0) {
1415 std::string url = fWebWindow->GetUrl(true);
1416 printf("EVE URL %s\n", url.c_str());
1417 } else {
1418 fWebWindow->Show(args);
1419 }
1420}
1421
1422
1423//____________________________________________________________________
1425{
1426 // set server state and tag scenes to begin accepting changees
1427 {
1428 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1430 fServerState.fCV.wait(lock);
1431 }
1433 }
1436}
1437
1438//____________________________________________________________________
1439/// Stop accepting changes and stream them. If the clients have not yet
1440/// acknowledged the previous changes, keep the stamps and let the last
1441/// acknowledgement in WindowData() flush them. Stamps coalesce per element.
1442/// Motion changes are sent in either case when the connections can take a
1443/// direct send, see SendMotionChanges(). Changes made by a MIR are not held
1444/// back.
1445
1447{
1448 // tag scene to disable accepting chages, write the change json
1451
1452 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1453
1454 // Motion is outside the change cycle, so it is sent even when changes
1455 // are held. What cannot be sent now stays stamped and goes with them.
1457
1458 if (!fConnList.empty() && !ClientConnectionsFree()) {
1459 // Previous changes not yet acknowledged. Leave everything stamped.
1460 if (AnySceneChanged())
1461 fPendingSceneChanges = true;
1462
1464 fServerState.fCV.notify_all();
1465 return;
1466 }
1467
1470 fPendingSceneChanges = false;
1471
1473 fServerState.fCV.notify_all();
1474}
1475
1476//____________________________________________________________________
1478{
1479 std::unique_lock<std::mutex> lock(fServerState.fMutex);
1481#if defined(_MSC_VER)
1482 std::timespec_get(&fServerStatus.fTReport, TIME_UTC);
1483#else
1484 fServerStatus.fTReport = std::time_t(nullptr);
1485#endif
1486 st = fServerStatus;
1487}
1488
1489/** \class REveManager::ChangeGuard
1490\ingroup REve
1491RAII guard for locking Eve manager (ctor) and processing changes (dtor).
1492*/
1493
1494//////////////////////////////////////////////////////////////////////
1495//
1496// Helper struct to guard update mechanism
1497//
1502
1507
1508// gInterpreter error handlder
1509void REveManager::ErrorHandler(Int_t level, Bool_t abort, const char * location, const char *msg)
1510{
1511 if (level >= kError)
1512 {
1514 entry.fMessage = msg;
1515 gEveLogEntries.emplace_back(entry);
1516 }
1517 ::DefaultErrorHandler(level, abort, location, msg);
1518}
1519
1520/** \class REveManager::RExceptionHandler
1521\ingroup REve
1522Exception handler for Eve exceptions.
1523*/
1524
1525////////////////////////////////////////////////////////////////////////////////
1526/// Handle exceptions deriving from REveException.
1527
1529{
1530 REveException *ex = dynamic_cast<REveException *>(&exc);
1531 if (ex) {
1532 Info("Handle", "Exception %s", ex->what());
1533 // REX::gEve->SetStatusLine(ex->Data());
1534 gSystem->Beep();
1535 return kSEHandled;
1536 }
1537 return kSEProceed;
1538}
1539
1540
1541////////////////////////////////////////////////////////////////////////////////
1542/// Utility to stream loggs to client.
1543/// Return false to supress further emission
1544
1546{
1547 gEveLogEntries.emplace_back(entry);
1548 return false;
1549}
1550
1551
1552////////////////////////////////////////////////////////////////////////////////
1553/// Restrict functionality for this server when open to public
1554
1556{
1557 R__LOG_INFO(REveLog()) << "Set public mode to " << x <<".";
1558 fHttpPublic = x;
1559}
thread_local std::vector< ROOT::RLogEntry > gEveLogEntries
thread_local MIR_TL_Data_t gMIRData
#define R__LOG_ERROR(...)
Definition RLogger.hxx:356
#define R__LOG_INFO(...)
Definition RLogger.hxx:358
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define e(i)
Definition RSha256.hxx:103
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
constexpr Bool_t kFALSE
Definition RtypesCore.h:109
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kViolet
Definition Rtypes.h:67
R__EXTERN TApplication * gApplication
R__EXTERN TEnv * gEnv
Definition TEnv.h:126
void DefaultErrorHandler(Int_t level, Bool_t abort_bool, const char *location, const char *msg)
The default error handler function.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:241
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:208
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:252
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
Definition TError.cxx:92
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
char name[80]
Definition TGX11.cxx:142
R__EXTERN TGeoManager * gGeoManager
R__EXTERN TGeoIdentity * gGeoIdentity
Definition TGeoMatrix.h:538
R__EXTERN TVirtualMutex * gInterpreterMutex
#define R__LOCKGUARD_CLING(mutex)
#define gInterpreter
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:792
#define gROOT
Definition TROOT.h:417
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
R__EXTERN TVirtualMutex * gSystemMutex
Definition TSystem.h:254
R__EXTERN TSystem * gSystem
Definition TSystem.h:582
#define R__LOCKGUARD2(mutex)
void DecDenyDestroy()
Decreases the deny-destroy count of the element.
const std::string & GetName() const
void SaveVizParams(std::ostream &out, const TString &tag, const TString &var)
Save visualization parameters for this element with given tag.
const char * GetCTitle() const
const char * GetCName() const
virtual void AddElement(REveElement *el)
Add el to the list of children.
static thread_local int stlMirError
virtual void DestroyElements()
Destroy all children of this element.
REveElement * FirstChild() const
Returns the first child element or 0 if the list is empty.
static void SetMirContext(REveElement *el)
void IncDenyDestroy()
Increases the deny-destroy count of the element.
static thread_local std::string stlMirErrorString
virtual void CopyVizParams(const REveElement *el)
Copy visualization parameters from element el.
void SetVizModel(REveElement *model)
Set visualization-parameter model element.
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
virtual void PropagateVizParamsToProjecteds()
Propagate visualization parameters to dependent elements.
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
void SetChannel(unsigned connid, int chid)
bool Emit(const RLogEntry &entry) override
Utility to stream loggs to client.
EStatus Handle(std::exception &exc) override
Handle exceptions deriving from REveException.
void DisconnectEveViewer(REveViewer *)
void ScheduleMIR(const std::string &cmd, ElementId_t i, const std::string &ctype, unsigned connid)
void ClearROOTClassSaved()
Work-around uber ugly hack used in SavePrimitive and co.
void StreamToNewConnection(unsigned connid)
Register new connection and stream the world and the mandatory scenes to it.
void SendToAllConnections(const std::string &data)
std::shared_ptr< ROOT::RWebWindow > fWebWindow
void RegisterGeometryAlias(const TString &alias, const TString &filename)
Register 'name' as an alias for geometry file 'filename'.
void PreDeleteElement(REveElement *element)
Called from REveElement prior to its destruction so the framework components (like object editor) can...
void ExecuteMIR(std::shared_ptr< MIR > mir)
REveSceneList * GetScenes() const
void ClearAllSelections()
Clear all selection objects.
RExceptionHandler * fExcHandler
!< exception handler
void AssignElementId(REveElement *element)
Assign a unique ElementId to given element.
TGeoManager * GetDefaultGeometry()
Get the default geometry.
static void ExecuteInMainThread(std::function< void()> func)
void GrabImages(std::string_view event_id, std::string_view url="", int scale=1, const std::vector< std::string > &viewers={})
Ask every connected client to grab its GL viewers and POST each image to an image collector.
void GetServerStatus(REveServerStatus &)
void SetDefaultHtmlPage(const std::string &path)
Set content of default window HTML page.
void AddLocation(const std::string &name, const std::string &path)
Register new directory to THttpServer.
void Send(unsigned connid, const std::string &data)
static void Terminate()
Properly terminate global REveManager.
REveElement * FindElementById(ElementId_t id) const
Lookup ElementId in element map and return corresponding REveElement*.
void SaveVizDB(const TString &filename)
Save visualization-parameter database to file filename.
void EndChange()
Stop accepting changes and stream them.
TGeoManager * GetGeometryByAlias(const TString &alias)
Get geometry with given alias.
bool AnySceneChanged() const
Is there anything stamped and not yet streamed?
std::unordered_map< ElementId_t, REveElement * > fElementIdMap
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
std::unordered_map< std::string, std::shared_ptr< TMethodCall > > fMethCallMap
void WindowConnect(unsigned connid)
Process new connection from web window.
void AllowMultipleRemoteConnections(bool loopBack=true, bool useAuthKey=true)
Utility function to allow remote RWebWindow connections.
void SendMotionChanges()
Send transformation-only changes on the motion channel: the same websocket, outside the BeginChanges/...
REveElement * FindVizDBEntry(const TString &tag)
Find a visualization-parameter database entry corresponding to tag.
TGeoManager * GetGeometry(const TString &filename)
Get geometry with given filename.
void ConnectEveViewer(REveViewer *)
static void ErrorHandler(Int_t level, Bool_t abort, const char *location, const char *msg)
bool fPendingSceneChanges
Changes are stamped but not yet streamed, because the clients had not acknowledged the previous scene...
std::queue< std::shared_ptr< MIR > > fMIRqueue
void LoadVizDB(const TString &filename, Bool_t replace, Bool_t update)
Load visualization-parameter database from file filename.
void DoRedraw3D()
Perform 3D redraw of scenes and viewers whose contents has changed.
void SendBinary(unsigned connid, const void *data, std::size_t len)
void AddElement(REveElement *element, REveElement *parent=nullptr)
Add an element.
void SetClientVersion(const std::string &version)
Set client version, used as prefix in scripts URL When changed, web browser will reload all related J...
void AddGlobalElement(REveElement *element, REveElement *parent=nullptr)
Add a global element, i.e.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
void SceneSubscriberWaitingResponse(unsigned cinnId)
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
void SetHttpPublic(bool)
Restrict functionality for this server when open to public.
void RemoveElement(REveElement *element, REveElement *parent)
Remove element from parent.
virtual ~REveManager()
Destructor.
void WindowDisconnect(unsigned connid)
Process disconnect of web window.
void FullRedraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Perform 3D redraw of all scenes and viewers.
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
Bool_t InsertVizDBEntry(const TString &tag, REveElement *model, Bool_t replace, Bool_t update)
Insert a new visualization-parameter database entry.
REveViewer * GetDefaultViewer() const
Get the default viewer.
void BrowseElement(ElementId_t id)
Activate EVE browser (summary view) for specified element id.
void WindowData(unsigned connid, const std::string &arg)
Process data from web window.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
REveSceneInfo Scene in a viewer.
void BeginAcceptingChanges()
Loop-wrapers over Scene children, element type checked on insertion.
void DestroyScenes()
Destroy all scenes and their contents.
void AddSubscriber(std::unique_ptr< REveClient > &&sub)
Definition REveScene.cxx:73
void ClearOutput()
Drop the output of the last StreamElements() or StreamRepresentationChanges() once it has been sent,...
std::vector< char > fOutputBinary
!
Definition REveScene.hxx:76
void StreamRepresentationChanges()
Prepare data for sending element changes.
void StreamMotionChanges(nlohmann::json &arr)
Move every element whose only pending change is kCBTrans from the change list into arr,...
void RemoveSubscriber(unsigned int)
Definition REveScene.cxx:84
REveSelection Container for selected and highlighted elements.
static bool AssertSdfFont(const std::string &font_name, const std::string &ttf_font)
Check if font exists, otherwise try to create it.
Definition REveText.cxx:249
static void Macro(const char *mac)
Execute macro 'mac'. Do not reload the macro.
Definition REveUtil.cxx:144
static void AppendServerTime(std::string &msg)
Append "server_time" to the JSON message msg, a non-empty object or array: as its last key,...
Definition REveUtil.cxx:63
static void StampServerTime(std::string &msg)
Set the "server_time" that AppendServerTime() put at the end of msg to now.
Definition REveUtil.cxx:76
REveViewerList List of Viewers providing common operations on REveViewer collections.
void AddElement(REveElement *el) override
Call base-class implementation.
REveViewer Reve representation of TGLViewer.
A diagnostic that can be emitted by the RLogManager.
Definition RLogger.hxx:174
std::string fMessage
Definition RLogger.hxx:177
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static bool EmbedFileDialog(const std::shared_ptr< RWebWindow > &window, unsigned connid, const std::string &args)
Create dialog instance to use as embedded dialog inside provided widget Loads libROOTBrowserv7 and tr...
static bool IsFileDialogMessage(const std::string &msg)
Check if this could be the message send by client to start new file dialog If returns true,...
static void SetSingleConnMode(bool on=true)
Enable or disable single connection mode (default on) If enabled, one connection only with any web wi...
static void SetLoopbackMode(bool on=true)
Set loopback mode for THttpServer used for web widgets By default is on.
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual Color_t GetLineColor() const
Return the line color.
Definition TAttLine.h:36
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
void * DynamicCast(const TClass *base, void *obj, Bool_t up=kTRUE)
Cast obj of this class type up to baseclass cl if up is true.
Definition TClass.cxx:5032
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4501
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2999
The color creation and management class.
Definition TColor.h:23
virtual void GetRGB(Float_t &r, Float_t &g, Float_t &b) const
Definition TColor.h:59
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition TColor.cxx:1941
static void SetColorThreshold(Float_t t)
This method specifies the color threshold used by GetColor to retrieve a color.
Definition TColor.cxx:2007
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:511
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
An identity transformation.
Definition TGeoMatrix.h:407
The manager class for any TGeo geometry.
Definition TGeoManager.h:46
static void UnlockGeometry()
Unlock current geometry.
TObjArray * GetListOfVolumes() const
TObjArray * GetListOfMatrices() const
static Bool_t IsLocked()
Check lock state.
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
static void LockGeometry()
Lock current geometry so that no other geometry can be imported.
TGeoVolume * GetTopVolume() const
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:45
void VisibleDaughters(Bool_t vis=kTRUE)
set visibility for daughters
void SetLineColor(Color_t lcolor) override
Set the line color.
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition TMap.h:40
void Add(TObject *obj) override
This function may not be used (but we need to provide it since it is a pure virtual in TCollection).
Definition TMap.cxx:53
virtual void SetOwnerKeyValue(Bool_t ownkeys=kTRUE, Bool_t ownvals=kTRUE)
Set ownership for keys and values.
Definition TMap.cxx:351
TObject * FindObject(const char *keyname) const override
Check if a (key,value) pair exists with keyname as name of the key.
Definition TMap.cxx:214
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition TMap.cxx:235
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
An array of TObjects.
Definition TObjArray.h:31
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
Collectable string class.
Definition TObjString.h:28
TString & String()
Definition TObjString.h:48
Mother of all ROOT objects.
Definition TObject.h:42
Wrapper for PCRE library (Perl Compatible Regular Expressions).
Definition TPRegexp.h:97
Class used by TMap to store (key,value) pairs.
Definition TMap.h:103
void SetValue(TObject *val)
Definition TMap.h:123
TObject * Value() const
Definition TMap.h:122
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Definition TROOT.cxx:3407
Basic string class.
Definition TString.h:137
const char * Data() const
Definition TString.h:385
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2438
void Beep(Int_t freq=-1, Int_t duration=-1, Bool_t setDefault=kFALSE)
Beep for duration milliseconds with a tone of frequency freq.
Definition TSystem.cxx:328
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
Definition TSystem.cxx:1297
virtual int GetPid()
Get process id.
Definition TSystem.cxx:722
virtual void AddTimer(TTimer *t)
Add timer to list of system timers.
Definition TSystem.cxx:475
virtual int GetProcInfo(ProcInfo_t *info) const
Returns cpu and memory used by this process into the ProcInfo_t structure.
Definition TSystem.cxx:2517
virtual TTimer * RemoveTimer(TTimer *t)
Remove timer from list of system timers.
Definition TSystem.cxx:485
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Double_t ex[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
ROOT::RLogChannel & REveLog()
Log channel for Eve diagnostics.
Definition REveTypes.cxx:52
R__EXTERN REveManager * gEve
@ kDebug
Debug information; only useful for developers; can have added verbosity up to 255-kDebug.
@ kError
An error.
std::vector< REveScene * > removedWatch
std::vector< REveScene * > addedWatch
TMarker m
Definition textangle.C:8