DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DD4hepUI.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework includes
15 #include <DD4hep/DD4hepUI.h>
16 #include <DD4hep/Printout.h>
17 #include <TRint.h>
18 
19 using namespace dd4hep;
20 
21 namespace {
22  std::string _visLevel(int lvl) {
23  char text[32];
24  std::snprintf(text,sizeof(text),"%d",lvl);
25  return text;
26  }
27 }
28 
30 detail::DD4hepUI::DD4hepUI(Detector& instance) : m_detDesc(instance) {
31 }
32 
35 }
36 
39  return &m_detDesc;
40 }
41 
44  return &m_detDesc;
45 }
46 
48 PrintLevel detail::DD4hepUI::setPrintLevel(PrintLevel level) const {
49  return dd4hep::setPrintLevel(level);
50 }
51 
54  int old_value = visLevel;
55  visLevel = value;
56  return old_value;
57 }
58 
61  if ( !m_condMgr.isValid() ) {
62  const void* argv[] = {"-handle",&m_condMgr,0};
63  if ( 1 != apply("DD4hep_ConditionsManagerInstaller",2,(char**)argv) ) {
64  except("DD4hepUI","Failed to install the conditions manager object.");
65  }
66  if ( !m_condMgr.isValid() ) {
67  except("DD4hepUI","Failed to access the conditions manager object.");
68  }
69  }
70  return m_condMgr;
71 }
72 
74 long detail::DD4hepUI::loadConditions(const std::string& fname) const {
75  Handle<NamedObject> h = conditionsMgr();
76  if ( h.isValid() ) {
77  m_detDesc.fromXML(fname, m_detDesc.buildType());
78  return 1;
79  }
80  return 0;
81 }
82 
85  if ( !m_alignMgr.isValid() ) {
86  const void* argv[] = {"-handle",&m_alignMgr,0};
87  if ( 1 != apply("DD4hep_AlignmentsManagerInstaller",2,(char**)argv) ) {
88  except("DD4hepUI","Failed to install the alignment manager object.");
89  }
90  if ( !m_alignMgr.isValid() ) {
91  except("DD4hepUI","Failed to access the alignment manager object.");
92  }
93  }
94  return m_alignMgr;
95 }
96 
98 long detail::DD4hepUI::apply(const char* factory, int argc, char** argv) const {
99  return m_detDesc.apply(factory, argc, argv);
100 }
101 
103 void detail::DD4hepUI::fromXML(const std::string& fname, DetectorBuildType type) const {
104  return m_detDesc.fromXML(fname, type);
105 }
106 
109  drawSubtree("/world");
110 }
111 
114  redrawSubtree("/world");
115 }
116 
118 void detail::DD4hepUI::drawSubtree(const char* path) const {
119  std::string vis = _visLevel(visLevel);
120  const void* av[] = {"-detector", path, "-option", "ogl", "-level", vis.c_str(), 0};
121  m_detDesc.apply("DD4hep_GeometryDisplay", 2, (char**)av);
122 }
123 
125 void detail::DD4hepUI::redrawSubtree(const char* path) const {
126  std::string vis = _visLevel(visLevel);
127  const void* av[] = {"-detector", path, "-option", "oglsame", "-level", vis.c_str(), 0};
128  m_detDesc.apply("DD4hep_GeometryDisplay", 4, (char**)av);
129 }
130 
132 long detail::DD4hepUI::dumpVols(int argc, char** argv) const {
133  if ( argc==0 ) {
134  const void* av[] = {"-positions","-pointers",0};
135  return m_detDesc.apply("DD4hep_VolumeDump",2,(char**)av);
136  }
137  return m_detDesc.apply("DD4hep_VolumeDump",argc,argv);
138 }
139 
141 long detail::DD4hepUI::dumpDet(const char* path) const {
142  const void* args[] = {"--detector", path ? path : "/world", 0};
143  return m_detDesc.apply("DD4hep_DetectorVolumeDump",2,(char**)args);
144 }
145 
147 long detail::DD4hepUI::dumpDetMaterials(const char* path) const {
148  const void* args[] = {"--detector", path ? path : "/world", "--materials", "--shapes", 0};
149  return m_detDesc.apply("DD4hep_DetectorVolumeDump",4,(char**)args);
150 }
151 
153 long detail::DD4hepUI::dumpStructure(const char* path) const {
154  const void* args[] = {"--detector", path ? path : "/world", 0};
155  return m_detDesc.apply("DD4hep_DetectorDump",2,(char**)args);
156 }
157 
159 long detail::DD4hepUI::saveROOT(const char* file_name) const {
160  if ( file_name ) {
161  const void* av[] = {"-output",file_name,0};
162  return m_detDesc.apply("DD4hep_Geometry2ROOT",2,(char**)av);
163  }
164  printout(WARNING,"DD4hepUI","++ saveROOT: No valid output file name supplied");
165  return 0;
166 }
167 
169 long detail::DD4hepUI::importROOT(const char* file_name) const {
170  if ( file_name ) {
171  const void* av[] = {"-input",file_name,0};
172  return m_detDesc.apply("DD4hep_RootLoader",2,(char**)av);
173  }
174  printout(WARNING,"DD4hepUI","++ importROOT: No valid output file name supplied");
175  return 0;
176 }
177 
179 long detail::DD4hepUI::createInterpreter(int argc, char** argv) {
180  if ( 0 == gApplication ) {
181  std::pair<int, char**> a(argc,argv);
182  gApplication = new TRint("DD4hepUI", &a.first, a.second);
183  printout(INFO,"DD4hepUI","++ Created ROOT interpreter instance for DD4hepUI.");
184  return 1;
185  }
186  printout(WARNING,"DD4hepUI",
187  "++ Another ROOT application instance already exists. Keep existing instance.");
188  return 1;
189 }
190 
193  if ( 0 != gApplication ) {
194  if ( !gApplication->IsRunning() ) {
195  gApplication->Run();
196  return 1;
197  }
198  except("DD4hepUI","++ The ROOT application is already running.");
199  }
200  except("DD4hepUI","++ No ROOT interpreter instance present!");
201  return 0;
202 }
203 
dd4hep::detail::DD4hepUI::alignmentMgr
Handle< NamedObject > alignmentMgr() const
Install the dd4hep alignment manager object.
Definition: DD4hepUI.cpp:84
dd4hep::detail::DD4hepUI::importROOT
long importROOT(const char *file_name) const
Import the entire detector description object from a root file.
Definition: DD4hepUI.cpp:169
dd4hep::detail::DD4hepUI::fromXML
virtual void fromXML(const std::string &fname, DetectorBuildType type=BUILD_DEFAULT) const
Detector interface: Read any geometry description or alignment file.
Definition: DD4hepUI.cpp:103
dd4hep::detail::DD4hepUI::redrawSubtree
virtual void redrawSubtree(const char *path) const
Detector interface: Re-draw the entire sub-tree scene.
Definition: DD4hepUI.cpp:125
dd4hep::detail::DD4hepUI::apply
virtual long apply(const char *factory, int argc, char **argv) const
Detector interface: Manipulate geometry using factory converter.
Definition: DD4hepUI.cpp:98
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::Handle< NamedObject >
dd4hep::detail::DD4hepUI::dumpDet
virtual long dumpDet(const char *path=0) const
Dump the DetElement tree with placement volumes.
Definition: DD4hepUI.cpp:141
dd4hep::detail::DD4hepUI::instance
Detector * instance() const
Access to the Detector instance.
Definition: DD4hepUI.cpp:38
dd4hep::detail::DD4hepUI::setPrintLevel
PrintLevel setPrintLevel(PrintLevel level) const
Set the printout level from the interactive prompt.
Definition: DD4hepUI.cpp:48
dd4hep::detail::DD4hepUI::setVisLevel
int setVisLevel(int level)
Set the visualization level when invoking the display.
Definition: DD4hepUI.cpp:53
dd4hep::detail::DD4hepUI::runInterpreter
long runInterpreter() const
Execute ROOT interpreter instance.
Definition: DD4hepUI.cpp:192
dd4hep::detail::DD4hepUI::dumpVols
virtual long dumpVols(int argc=0, char **argv=0) const
Dump the volume tree.
Definition: DD4hepUI.cpp:132
dd4hep::detail::DD4hepUI::drawSubtree
virtual void drawSubtree(const char *path) const
Detector interface: Draw detector sub-tree the scene on a OpenGL pane.
Definition: DD4hepUI.cpp:118
dd4hep::detail::DD4hepUI::DD4hepUI
DD4hepUI(Detector &instance)
Default constructor.
Definition: DD4hepUI.cpp:30
dd4hep::detail::DD4hepUI::redraw
virtual void redraw() const
Detector interface: Re-draw the entire scene.
Definition: DD4hepUI.cpp:113
dd4hep::detail::DD4hepUI::detectorDescription
Detector * detectorDescription() const
Access to the Detector instance.
Definition: DD4hepUI.cpp:43
dd4hep::detail::DD4hepUI::dumpDetMaterials
virtual long dumpDetMaterials(const char *path=0) const
Dump the DetElement tree with volume materials.
Definition: DD4hepUI.cpp:147
dd4hep::detail::DD4hepUI::draw
virtual void draw() const
Detector interface: Draw the scene on a OpenGL pane.
Definition: DD4hepUI.cpp:108
DD4hepUI.h
dd4hep::DetectorBuildType
DetectorBuildType
Detector description build types.
Definition: BuildType.h:34
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::detail::DD4hepUI::~DD4hepUI
virtual ~DD4hepUI()
Default destructor.
Definition: DD4hepUI.cpp:34
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::detail::DD4hepUI::loadConditions
long loadConditions(const std::string &fname) const
Load conditions from file.
Definition: DD4hepUI.cpp:74
dd4hep::detail::DD4hepUI::saveROOT
long saveROOT(const char *file_name) const
Dump the entire detector description object to a root file.
Definition: DD4hepUI.cpp:159
Printout.h
dd4hep::detail::DD4hepUI::conditionsMgr
Handle< NamedObject > conditionsMgr() const
Install the dd4hep conditions manager object.
Definition: DD4hepUI.cpp:60
dd4hep::detail::DD4hepUI::createInterpreter
long createInterpreter(int argc, char **argv)
Create ROOT interpreter instance.
Definition: DD4hepUI.cpp:179
dd4hep::detail::DD4hepUI::dumpStructure
virtual long dumpStructure(const char *path=0) const
Dump the raw DetElement tree.
Definition: DD4hepUI.cpp:153