Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
server.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webgui
3/// This tutorial demonstrates how three.js model for geometry can be created.
4/// In server.cxx one uses RGeomDescription class from geometry viewer, which produces
5/// JSON data with all necessary information. Then RWebWindow is started and this information provided.
6/// In client.html one uses **build** function to create Object3D with geometry
7/// Then such object placed in three.js scene and rendered. Also simple animation is implemented
8///
9/// \macro_code
10///
11/// \author Sergey Linev
12
13#include <ROOT/RGeomData.hxx>
14
15#include <ROOT/RWebWindow.hxx>
16
17
18std::shared_ptr<ROOT::RWebWindow> window;
19
20std::string json;
21
22TString base64;
23
24
25void ProcessData(unsigned connid, const std::string &arg)
26{
27 if (arg == "get") {
28 // send arbitrary text message
29 window->Send(connid, base64.Data());
30 } else if (arg == "halt") {
31 // terminate ROOT
32 window->TerminateROOT();
33 }
34}
35
36void server()
37{
38
40
41 TGeoManager::Import("https://root.cern/files/cms.root");
42
43 gGeoManager->DefaultColors();
44 gGeoManager->SetVisLevel(4);
45 gGeoManager->GetVolume("TRAK")->InvisibleAll();
46 gGeoManager->GetVolume("HVP2")->SetTransparency(20);
47 gGeoManager->GetVolume("HVEQ")->SetTransparency(20);
48 gGeoManager->GetVolume("YE4")->SetTransparency(10);
49 gGeoManager->GetVolume("YE3")->SetTransparency(20);
50 gGeoManager->GetVolume("RB2")->SetTransparency(99);
51 gGeoManager->GetVolume("RB3")->SetTransparency(99);
52 gGeoManager->GetVolume("COCF")->SetTransparency(99);
53 gGeoManager->GetVolume("HEC1")->SetLineColor(7);
54 gGeoManager->GetVolume("EAP1")->SetLineColor(7);
55 gGeoManager->GetVolume("EAP2")->SetLineColor(7);
56 gGeoManager->GetVolume("EAP3")->SetLineColor(7);
57 gGeoManager->GetVolume("EAP4")->SetLineColor(7);
58 gGeoManager->GetVolume("HTC1")->SetLineColor(2);
59
61
62 data.Build(gGeoManager, "CMSE");
63
64 json = data.ProduceJson();
65
66 base64 = TBase64::Encode(json.c_str());
67
68 // create window
69 window = ROOT::RWebWindow::Create();
70
71 // configure default html page
72 // either HTML code can be specified or just name of file after 'file:' prefix
73 window->SetDefaultPage("file:client.html");
74
75 // this is call-back, invoked when message received from client
76 window->SetDataCallBack(ProcessData);
77
78 window->SetGeometry(800, 600); // configure predefined geometry
79
80 window->Show();
81}
nlohmann::json json
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
R__EXTERN TGeoManager * gGeoManager
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4647
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376