From 1240b49f4be5c8d7e16895896f4a515c8759e574 Mon Sep 17 00:00:00 2001 From: Markus Frank <markus.frank@cern.ch> Date: Fri, 31 Jan 2014 19:58:03 +0000 Subject: [PATCH] Add simple TEve example program --- UtilityApps/CMakeLists.txt | 3 + UtilityApps/src/display.cpp | 60 +-------------- UtilityApps/src/plugin_runner.cpp | 3 +- UtilityApps/src/run_plugin.h | 120 +++++++++++++++++++++++------- UtilityApps/src/teve_display.cpp | 54 ++++++++++++++ 5 files changed, 152 insertions(+), 88 deletions(-) create mode 100644 UtilityApps/src/teve_display.cpp diff --git a/UtilityApps/CMakeLists.txt b/UtilityApps/CMakeLists.txt index 27e135b9c..184f91868 100644 --- a/UtilityApps/CMakeLists.txt +++ b/UtilityApps/CMakeLists.txt @@ -13,6 +13,9 @@ target_link_libraries(geoConverter DD4hepCore) #----------------------------------------------------------------------------------- add_executable(geoPluginRun src/plugin_runner.cpp) target_link_libraries(geoPluginRun DD4hepCore) +#----------------------------------------------------------------------------------- +add_executable(teveDisplay src/teve_display.cpp) +target_link_libraries(teveDisplay DD4hepCore ${ROOT_EVE_LIBRARIES}) #--- install target------------------------------------- diff --git a/UtilityApps/src/display.cpp b/UtilityApps/src/display.cpp index abb2c9cf7..e5f15dab4 100644 --- a/UtilityApps/src/display.cpp +++ b/UtilityApps/src/display.cpp @@ -9,66 +9,8 @@ // //==================================================================== #include "run_plugin.h" -#include "TRint.h" - -//______________________________________________________________________________ -namespace { - void usage() { - cout << "displayGeo -opt [-opt] \n" - " -compact <file> Specify the compact geometry file \n" - " [REQUIRED] At least one compact geo file is required!\n" - " -load_only [OPTIONAL] Dry-run to only load geometry without \n" - " starting the dispay. \n" - " -destroy [OPTIONAL] Force destruction of the LCDD instance \n" - " before exiting the application \n" - " -volmgr [OPTIONAL] Load and populate phys.volume manager to \n" - " check the volume ids for duplicates etc. \n" - << endl; - exit(EINVAL); - } -} //______________________________________________________________________________ int main(int argc,char** argv) { - bool volmgr = false; - bool dry_run = false, destroy = false; - vector<char*> geo_files; - for(int i=1; i<argc;++i) { - if ( argv[i][0]=='-' ) { - if ( strncmp(argv[i],"-compact",2)==0 ) - geo_files.push_back(argv[++i]); - else if ( strncmp(argv[i],"-load_only",2)==0 ) - dry_run = true; - else if ( strncmp(argv[i],"-destroy",2)==0 ) - destroy = true; - else if ( strncmp(argv[i],"-volmgr",2)==0 ) - volmgr = true; - else - usage(); - } - else { // This is the default - geo_files.push_back(argv[i]); - } - } - if ( geo_files.empty() ) - usage(); - - LCDD& lcdd = dd4hep_instance(); - // Load all compact files - run_plugin(lcdd,"DD4hepCompactLoader",int(geo_files.size()),&geo_files[0]); - // Create volume manager and populate it required - if ( volmgr ) run_plugin(lcdd,"DD4hepVolumeManager",0,0); - - // Create an interactive ROOT application - if ( !dry_run ) { - pair<int, char**> args(0,0); - TRint app("DD4hepGeometryDisplay", &args.first, args.second); - run_plugin(lcdd,"DD4hepGeometryDisplay",args.first,args.second); - app.Run(); - } - else { - cout << "The geometry was loaded. Application now exiting." << endl; - } - if ( destroy ) delete &lcdd; - return 0; + return main_default("DD4hepGeometryDisplay",argc,argv); } diff --git a/UtilityApps/src/plugin_runner.cpp b/UtilityApps/src/plugin_runner.cpp index 6fc2963a8..da6ac2436 100644 --- a/UtilityApps/src/plugin_runner.cpp +++ b/UtilityApps/src/plugin_runner.cpp @@ -28,11 +28,12 @@ namespace { //______________________________________________________________________________ int main(int argc,char** argv) { string plugin; + char plugin_runner[64] = "plugin_runner"; bool volmgr = false; bool destroy = false; vector<char*> geo_files; vector<char*> arg; - arg.push_back("plugin_runner"); + arg.push_back(plugin_runner); for(int i=1; i<argc;++i) { if ( argv[i][0]=='-' ) { if ( strncmp(argv[i],"-input",2)==0 ) diff --git a/UtilityApps/src/run_plugin.h b/UtilityApps/src/run_plugin.h index ae64760c7..7a6a2fd50 100644 --- a/UtilityApps/src/run_plugin.h +++ b/UtilityApps/src/run_plugin.h @@ -22,41 +22,105 @@ using namespace std; using namespace DD4hep::Geometry; -LCDD& dd4hep_instance(const char* name="") { +//______________________________________________________________________________ +#include "TRint.h" +//______________________________________________________________________________ +namespace { + + LCDD& dd4hep_instance(const char* name="") { #if 0 #include "Reflex/PluginService.h" - try { - union { void* p; LCDD* l; } v; - v.p = ROOT::Reflex::PluginService::Create<void*>("LCDD_constructor",name); - if ( v.p ) { - return *v.l; + try { + union { void* p; LCDD* l; } v; + v.p = ROOT::Reflex::PluginService::Create<void*>("LCDD_constructor",name); + if ( v.p ) { + return *v.l; + } + throw runtime_error("Failed to locate plugin to create LCDD instance"); + } + catch(const exception& e) { + cout << "Exception:" << e.what() << endl; + throw runtime_error("Exception:\""+string(e.what())); + } + catch(...) { + cout << "UNKNOWN Exception while creating LCDD instance." << endl; } - throw runtime_error("Failed to locate plugin to create LCDD instance"); + throw runtime_error("UNKNOWN Exception while creating LCDD instance."); +#endif + return LCDD::getInstance(); } - catch(const exception& e) { - cout << "Exception:" << e.what() << endl; - throw runtime_error("Exception:\""+string(e.what())); + + int run_plugin(LCDD& lcdd, const char* name, int argc, char** argv) { + try { + lcdd.apply(name,argc,argv); + return 0; + } + catch(const exception& e) { + cout << e.what() << endl; + } + catch(...) { + cout << "UNKNOWN Exception" << endl; + } + ::exit(EINVAL); + return EINVAL; } - catch(...) { - cout << "UNKNOWN Exception while creating LCDD instance." << endl; + + void usage_default(const char* name) { + cout << " " << name << " -opt [-opt] \n" + " -compact <file> Specify the compact geometry file \n" + " [REQUIRED] At least one compact geo file is required!\n" + " -load_only [OPTIONAL] Dry-run to only load geometry without \n" + " starting the dispay. \n" + " -destroy [OPTIONAL] Force destruction of the LCDD instance \n" + " before exiting the application \n" + " -volmgr [OPTIONAL] Load and populate phys.volume manager to \n" + " check the volume ids for duplicates etc. \n" + << endl; + exit(EINVAL); } - throw runtime_error("UNKNOWN Exception while creating LCDD instance."); -#endif - return LCDD::getInstance(); -} -int run_plugin(LCDD& lcdd, const char* name, int argc, char** argv) { - try { - lcdd.apply(name,argc,argv); + //______________________________________________________________________________ + int main_default(const char* name, int argc,char** argv) { + bool volmgr = false; + bool dry_run = false, destroy = false; + vector<char*> geo_files; + for(int i=1; i<argc;++i) { + if ( argv[i][0]=='-' ) { + if ( strncmp(argv[i],"-compact",2)==0 ) + geo_files.push_back(argv[++i]); + else if ( strncmp(argv[i],"-load_only",2)==0 ) + dry_run = true; + else if ( strncmp(argv[i],"-destroy",2)==0 ) + destroy = true; + else if ( strncmp(argv[i],"-volmgr",2)==0 ) + volmgr = true; + else + usage_default(name); + } + else { // This is the default + geo_files.push_back(argv[i]); + } + } + if ( geo_files.empty() ) + usage_default(name); + + LCDD& lcdd = dd4hep_instance(); + // Load all compact files + run_plugin(lcdd,"DD4hepCompactLoader",int(geo_files.size()),&geo_files[0]); + // Create volume manager and populate it required + if ( volmgr ) run_plugin(lcdd,"DD4hepVolumeManager",0,0); + + // Create an interactive ROOT application + if ( !dry_run ) { + pair<int, char**> args(0,0); + TRint app(name, &args.first, args.second); + run_plugin(lcdd,name,args.first,args.second); + app.Run(); + } + else { + cout << "The geometry was loaded. Application now exiting." << endl; + } + if ( destroy ) delete &lcdd; return 0; } - catch(const exception& e) { - cout << e.what() << endl; - } - catch(...) { - cout << "UNKNOWN Exception" << endl; - } - ::exit(EINVAL); - return EINVAL; } - diff --git a/UtilityApps/src/teve_display.cpp b/UtilityApps/src/teve_display.cpp new file mode 100644 index 000000000..5bec5df6d --- /dev/null +++ b/UtilityApps/src/teve_display.cpp @@ -0,0 +1,54 @@ +// $Id: display.cpp 590 2013-06-03 17:02:43Z markus.frank $ +//==================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------- +// +// Generic ROOT based geometry display program +// +// Author : M.Frank +// +//==================================================================== +#include "DD4hep/Factories.h" +#include "DD4hep/LCDD.h" +#include "run_plugin.h" +#include "TRint.h" +#include "TEveGeoNode.h" +//#include "TEveElement.h" +#include "TGLViewer.h" +#include "TGeoManager.h" +//#include "TGLUtil.h" +#include "TGLClip.h" +//#include "TSysEvtHandler.h" +#include "TMap.h" +#include "TObjString.h" + +#define private public +#include "TEveManager.h" + +static long teve_display(LCDD& lcdd, int /* argc */, char** /* argv */) { + TGeoManager* mgr = &lcdd.manager(); + TEveManager::Create(); + gEve->fGeometries->Add(new TObjString("DefaultGeometry"),mgr); + TEveGeoTopNode* tn = new TEveGeoTopNode(mgr, mgr->GetTopNode()); + tn->SetVisLevel(4); + gEve->AddGlobalElement(tn); + + gEve->FullRedraw3D(kTRUE); + + // EClipType not exported to CINT (see TGLUtil.h): + // 0 - no clip, 1 - clip plane, 2 - clip box + TGLViewer *v = gEve->GetDefaultGLViewer(); + v->GetClipSet()->SetClipType(TGLClip::kClipPlane); + v->ColorSet().Background().SetColor(kMagenta+4); + v->SetGuideState(TGLUtil::kAxesEdge, kTRUE, kFALSE, 0); + v->RefreshPadEditor(v); + v->CurrentCamera().RotateRad(-1.2, 0.5); + v->DoDraw(); + return 1; +} +DECLARE_APPLY(DD4hepTEveDisplay,teve_display) + +//______________________________________________________________________________ +int main(int argc,char** argv) { + return main_default("DD4hepTEveDisplay",argc,argv); +} -- GitLab