Skip to content
Snippets Groups Projects

Cleaned up dd_web_display

Merged Whitney Armstrong requested to merge whit/NPDet:master into master
1 file
+ 39
270
Compare changes
  • Side-by-side
  • Inline
#include "Math/Vector3D.h"
#include "Math/Vector4D.h"
#include "Math/VectorUtil.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TMath.h"
#include "TRandom3.h"
#include "TEveBrowser.h"
#include "TEveGeoNode.h"
#include "TEveGeoShape.h"
#include "TEveGeoShapeExtract.h"
#include "TEveManager.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TTree.h"
#include "TF1.h"
#include "TSystem.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH3F.h"
#include "TCanvas.h"
#include "TGeoManager.h"
#include "TGeoNode.h"
#include "TGeoVolume.h"
#include "TGraph.h"
#include "THttpServer.h"
#include <csignal>
#include <stdexcept>
#include <cstring>
#include <vector>
#include <map>
#include <memory>
#include <functional>
#include "TLegend.h"
#include "TMath.h"
#include "TMessage.h"
#include "TMonitor.h"
#include "TMultiGraph.h"
#include "TServerSocket.h"
#include "TSocket.h"
#include "TFile.h"
#include "TSystem.h"
#include <vector>
#include <tuple>
#include <algorithm>
#include <chrono>
#include <csignal>
#include <cstring>
#include <experimental/filesystem>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <stdexcept>
#include <string>
#include <thread>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#include <tuple>
#include <vector>
#include "DD4hep/DD4hepUnits.h"
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include "DDG4/Geant4Data.h"
#include "DDRec/CellIDPositionConverter.h"
#include "DDRec/SurfaceManager.h"
#include "DDRec/Surface.h"
#include "DD4hep/DD4hepUnits.h"
#include "TApplication.h"
#include "TMultiGraph.h"
#include "TGraph.h"
#include "TGeoManager.h"
#include "TGeoNode.h"
#include "TGeoVolume.h"
#include "TEveManager.h"
#include "TEveGeoNode.h"
#include "TEveGeoShapeExtract.h"
#include "TEveGeoShape.h"
#include "TEveBrowser.h"
#include "TSystem.h"
#include "ROOT/TFuture.hxx"
#include "Math/DisplacementVector3D.h"
#include <iostream>
#include <string>
#include <chrono>
#include "DDRec/SurfaceManager.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
namespace fs = std::experimental::filesystem;
volatile sig_atomic_t sig_caught = 0;
void handle_sig(int signum) {
@@ -116,11 +92,8 @@ struct settings {
string http_host = "127.0.0.1";
string in_out_file = "";
};
//______________________________________________________________________________
void run_http_server(const settings& s);
//void run_part_mode(const settings& s);
//______________________________________________________________________________
template<typename T>
void print_usage(T cli, const char* argv0 )
@@ -161,8 +134,8 @@ void print_man_page(T cli, const char* argv0 ){
//.merge_joinable_flags_with_common_prefix(true); //-abc instead of -a -b -c
auto mp = make_man_page(cli, argv0, fmt);
mp.prepend_section("DESCRIPTION", "Geometry tool for converting compact files to STEP (cad) files.");
mp.append_section("EXAMPLES", " $ npdet_to_teve list compact.xml");
mp.prepend_section("DESCRIPTION", "Web display for compact geometry.");
mp.append_section("EXAMPLES", " $ dd_web_display compact.xml");
std::cout << mp << "\n";
}
//______________________________________________________________________________
@@ -170,26 +143,6 @@ void print_man_page(T cli, const char* argv0 ){
settings cmdline_settings(int argc, char* argv[])
{
settings s;
auto partMode = "part mode:" % repeatable(
command("part").set(s.selected,mode::part) % "Select only the first level nodes by name",
repeatable(
required("-l","--level").set(s.level_set) & integer("level",s.part_level) % "Maximum level navigated to for part",
option("-c","--color") & integer("color",s.color),
option("-a","--alpha") & number("alpha",s.alpha),
value("name")([&](const std::string& p)
{
s.p_name = p;
if(!s.level_set) { s.part_level = -1; }
s.level_set = false;
std::cout << "s.color " << s.color << "\n";
std::cout << "s.alpha " << s.alpha << "\n";
s.part_name_levels[p] = s.part_level;
s.part_name_colors[p] = s.color;
s.part_name_alphas[p] = s.alpha;
}) % "Part/Node name (must be child of top node)"
)
);
auto lastOpt = " options:" % (
option("-h", "--help").set(s.selected, mode::help) % "show help",
option("-g","--global_level") & integer("level",s.geo_level),
@@ -199,7 +152,6 @@ settings cmdline_settings(int argc, char* argv[])
} ) % "input xml file"
);
auto server_cli =
((option("-p", "--port") & value("http_port", s.http_port)) %
"port to which the http serve attaches. Default: 8090 ",
@@ -208,11 +160,7 @@ settings cmdline_settings(int argc, char* argv[])
(option("-f", "--file") & value("io_file", s.in_out_file)) %
"File used to initialize and save plots. Default: top_folder.root");
std::string wrong;
auto cli = (
command("help").set(s.selected, mode::help) | (server_cli, lastOpt),
any_other(wrong)
);
auto cli = (command("help").set(s.selected, mode::help) | (server_cli, lastOpt));
assert( cli.flags_are_prefix_free() );
@@ -233,7 +181,6 @@ settings cmdline_settings(int argc, char* argv[])
}
//______________________________________________________________________________
int main (int argc, char *argv[]) {
settings s = cmdline_settings(argc,argv);
@@ -258,32 +205,14 @@ int main (int argc, char *argv[]) {
if( !has_suffix(s.outfile,".root") ) {
s.outfile += ".root";
}
//for(const auto& [part_name, part_level] : s.part_name_levels ) {
// std::cout << " SOME Part : " << part_name << ", level = " << part_level <<"\n";
//}
// ---------------------------------------------
// Run modes
//
//switch(s.selected) {
// case mode::list:
// run_list_mode(s);
// break;
// case mode::part:
// run_part_mode(s);
// break;
// default:
// break;
//}
run_http_server(s);
return 0;
}
//______________________________________________________________________________
void run_http_server(const settings& s)
{
void run_http_server(const settings& s) {
dd4hep::setPrintLevel(dd4hep::WARNING);
gErrorIgnoreLevel = kWarning;// kPrint, kInfo, kWarning,
@@ -295,7 +224,6 @@ void run_http_server(const settings& s)
dd4hep::Detector& detector = dd4hep::Detector::getInstance();
detector.fromCompact(s.infile);
auto serv = new THttpServer((std::string("http:") + s.http_host + ":" +
std::to_string(s.http_port) +
std::string("?top=geometry&thrds=1;rw;noglobal"))
@@ -310,7 +238,11 @@ void run_http_server(const settings& s)
//_server->SetDefaultPage("draw.htm");
serv->SetCors();
serv->Register("/",detector.manager().GetTopNode());
detector.manager().GetTopNode()->SetVisibility(kFALSE);
gGeoManager->SetVisLevel(5);
serv->Register("/",detector.manager().GetTopNode()->GetVolume());
serv->Register("/geoManager",gGeoManager);
// Loop until an interrupt (ctrl-c) is issued
while (1) {
@@ -323,168 +255,5 @@ void run_http_server(const settings& s)
}
signal(SIGINT, prev_handler);
//std::cout << gGeoManager->GetPath() << "\n";
//for(const auto& [p,l] : s.part_name_levels) {
// bool dir = gGeoManager->cd(p.c_str());
// if (!dir) {
// std::cerr << p << " not found!\n";
// continue;
// }
// TGeoNode *node = gGeoManager->GetCurrentNode();
// int level = gGeoManager->GetLevel();
// if( level > l ){
// std::cout << "\n" << p << " found at level " << level << " but above selected level of " << l << ")\n";
// continue;
// }
// std::cout << "\n";
// std::cout << "Subnodes for \"" << p << "\" (level = " << level << ")\n";
// if(node->GetNdaughters() == 0) {
// continue;
// }
// TObjArrayIter node_array_iter(node->GetVolume()->GetNodes());
// TGeoNode* a_node = nullptr;
// while( (a_node = dynamic_cast<TGeoNode*>(node_array_iter.Next())) ) {
// std::cout << p << "/" << a_node->GetName() << "\n";
// }
// //TGeoNode* currentNode = nullptr;
// //auto res = new TEveGeoNode(node);
// //TGeoIterator nextNode( node->GetVolume() );
// //nextNode.SetType(1);
// //while( (currentNode = nextNode()) ) {
// // auto nlevel = nextNode.GetLevel();
// // if( nlevel > l-level ) {
// // break;
// // }
// // //auto daughter = new TEveGeoNode( currentNode );
// // //res->AddElement(daughter);
// // currentNode->ls();
// //}
//}
}
//______________________________________________________________________________
//void run_part_mode(const settings& s)
//{
// int root_argc = 0;
// char *root_argv[1] = {"npdet_to_teve"};
// //argv[0] = "npdet_fields";
//
// gErrorIgnoreLevel = kWarning;// kPrint, kInfo, kWarning,
// TApplication app("tapp", &root_argc, root_argv);
//
// // Get the DD4hep instance
// dd4hep::setPrintLevel(dd4hep::WARNING);
// dd4hep::Detector& detector = dd4hep::Detector::getInstance();
// detector.fromCompact(s.infile);
//
// TEveManager::Create();//true,"");
//
// TEveGeoTopNode* eve_top_n = new TEveGeoTopNode(&(detector.manager()),detector.manager().GetTopNode());
// detector.manager().GetTopNode()->SetVisibility(kFALSE);
// eve_top_n->SetVisLevel(0);
// std::cout << "Path is " << gGeoManager->GetPath() << "\n";
//
// for(const auto& [p,l] : s.part_name_levels) {
// bool dir = gGeoManager->cd(p.c_str());
// if (!dir) {
// std::cerr << p << " not found!\n";
// return;
// }
// TGeoNode *node = gGeoManager->GetCurrentNode();
// if(!node){
// std::cerr << " bad node\n";
// return;
// }
// int ilevel = gGeoManager->GetLevel();
// if( ilevel > l ){
// std::cout << p << " found at level " << ilevel << " but above selected level of " << l << "\n";
// //return;
// }
//
// int istate = gGeoManager->GetCurrentNodeId();
// std::string ipath = gGeoManager->GetPath();
//
// auto pcolor = s.part_name_colors.find(p)->second;
// auto ptransparency = 100.0*(1.0 - s.part_name_alphas.find(p)->second);
//
// std::cout << " color " << pcolor << "\n";
// std::cout << " ptransparency " << ptransparency << "\n";
//
// node->GetVolume()->SetLineColor(pcolor);
// node->GetVolume()->SetFillColor(pcolor);
// node->GetVolume()->SetTransparency(ptransparency);
// node->GetVolume()->SetTransparency(ptransparency);
//
//
// TEveGeoNode* res = new TEveGeoNode(node);
// std::map<int,TEveGeoNode*> eve_nodes;
// eve_nodes[0] = res;
//
// TGeoIterator nextNode( node->GetVolume() );
// int path_index = 0;
// TGeoNode* currentNode = nullptr;
//
// while( (currentNode = nextNode()) ) {
// nextNode.SetType(0);
// // Not iterator level starts at 1
// auto nlevel = nextNode.GetLevel();
// if( nlevel > l ) {
// continue;
// }
// //if( path_index == nlevel) {
// // if(pcolor != s.part_name_colors.end() ){
// currentNode->GetVolume()->SetLineColor(pcolor);
// currentNode->GetVolume()->SetFillColor(pcolor);
// currentNode->GetVolume()->SetTransparency(ptransparency);
// currentNode->GetVolume()->SetTransparency(ptransparency);
// // }
// TEveGeoNode* daughter = new TEveGeoNode( currentNode );
// eve_nodes[nlevel] = daughter;
// eve_nodes[nlevel-1]->AddElement(daughter);
// //}
// //std::cout << nlevel << "\n";
// //std::cout << gGeoManager->PushPath() << "\n";
//
// //res->AddElement(daughter);
// currentNode->ls();
// }
// eve_top_n->AddElement(res);
// }
//
// eve_top_n->SaveExtract(s.outfile.c_str(), "extract", kTRUE);
//
// //--------------------------------------------
// // Now Quit ... it is harder than it should be.
// app.Run(kFALSE);
// TEveManager::Terminate();
// app.Terminate(0);
//
// //std::cout << "derp1 \n";
// //ROOT::EnableImplicitMT(2);
// ////TEveManager::Terminate();
// //auto wi0 = ROOT::Experimental::Async([&](){app.Run(kFALSE); return std::string("done1");});
// //auto wi1 = ROOT::Experimental::Async([&]() {
// // //using namespace std::chrono_literals;
// // std::cout << "Hello waiter" << std::endl;
// // gEve->GetBrowser()->CloseWindow();
// // gSystem->ProcessEvents() ;
// // std::chrono::seconds sec(2);
// // std::this_thread::sleep_for(sec);
// // std::cout << "Hello waiter" << std::endl;
// // app.Terminate(0);
// // std::cout << " " << wi0.get() << std::endl;
// // return std::string("done 2");
// //});
// ////app.Run(kTRUE);
// //std::cout << " " << wi1.get() << std::endl;
// ////app.Terminate(0);
// //// Pass kFALSE if you want application to terminate by itself.
// //// Then you just need "return 0;" below (to avoid compiler warnings).
// //// Optionally shutdown eve here (not really needed):
// //// TEveManager::Terminate();
// //std::cout << "derp \n";
//}
Loading