Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:53

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework includes
0015 #include <DD4hep/DD4hepUI.h>
0016 #include <DD4hep/Printout.h>
0017 #include <TRint.h>
0018 
0019 using namespace dd4hep;
0020 
0021 namespace {
0022   std::string _visLevel(int lvl)    {
0023     char text[32];
0024     std::snprintf(text,sizeof(text),"%d",lvl);
0025     return text;
0026   }
0027 }
0028 
0029 /// Default constructor
0030 detail::DD4hepUI::DD4hepUI(Detector& instance) : m_detDesc(instance)  {
0031 }
0032 
0033 /// Default destructor
0034 detail::DD4hepUI::~DD4hepUI()   {
0035 }
0036 
0037 /// Access to the Detector instance
0038 Detector* detail::DD4hepUI::instance()  const   {
0039   return &m_detDesc;
0040 }
0041 
0042 /// Access to the Detector instance
0043 Detector* detail::DD4hepUI::detectorDescription()  const   {
0044   return &m_detDesc;
0045 }
0046 
0047 /// Set the printout level from the interactive prompt
0048 PrintLevel detail::DD4hepUI::setPrintLevel(PrintLevel level)   const   {
0049   return dd4hep::setPrintLevel(level);
0050 }
0051 
0052 /// Set the visualization level when invoking the display
0053 int detail::DD4hepUI::setVisLevel(int value)     {
0054   int old_value = visLevel;
0055   visLevel = value;
0056   return old_value;
0057 }
0058 
0059 /// Install the dd4hep conditions manager object
0060 Handle<NamedObject> detail::DD4hepUI::conditionsMgr()  const  {
0061   if ( !m_condMgr.isValid() )  {
0062     const void* argv[] = {"-handle",&m_condMgr,0};
0063     if ( 1 != apply("DD4hep_ConditionsManagerInstaller",2,(char**)argv) )  {
0064       except("DD4hepUI","Failed to install the conditions manager object.");
0065     }
0066     if ( !m_condMgr.isValid() )  {
0067       except("DD4hepUI","Failed to access the conditions manager object.");
0068     }
0069   }
0070   return m_condMgr;
0071 }
0072 
0073 /// Load conditions from file
0074 long detail::DD4hepUI::loadConditions(const std::string& fname)  const  {
0075   Handle<NamedObject> h = conditionsMgr();
0076   if ( h.isValid() )  {
0077     m_detDesc.fromXML(fname, m_detDesc.buildType());
0078     return 1;
0079   }
0080   return 0;
0081 }
0082 
0083 /// Install the dd4hep alignment manager object
0084 Handle<NamedObject> detail::DD4hepUI::alignmentMgr()  const  {
0085   if ( !m_alignMgr.isValid() )  {
0086     const void* argv[] = {"-handle",&m_alignMgr,0};
0087     if ( 1 != apply("DD4hep_AlignmentsManagerInstaller",2,(char**)argv) )  {
0088       except("DD4hepUI","Failed to install the alignment manager object.");
0089     }
0090     if ( !m_alignMgr.isValid() )  {
0091       except("DD4hepUI","Failed to access the alignment manager object.");
0092     }
0093   }
0094   return m_alignMgr;
0095 }
0096 
0097 /// Detector interface: Manipulate geometry using facroy converter
0098 long detail::DD4hepUI::apply(const char* factory, int argc, char** argv) const   {
0099   return m_detDesc.apply(factory, argc, argv);
0100 }
0101 
0102 /// Detector interface: Read any geometry description or alignment file
0103 void detail::DD4hepUI::fromXML(const std::string& fname, DetectorBuildType type) const  {
0104   return m_detDesc.fromXML(fname, type);
0105 }
0106 
0107 /// Detector interface: Draw the scene on a OpenGL pane
0108 void detail::DD4hepUI::draw() const   {
0109   drawSubtree("/world");
0110 }
0111 
0112 /// Detector interface: Re-draw the entire scene
0113 void detail::DD4hepUI::redraw() const   {
0114   redrawSubtree("/world");
0115 }
0116 
0117 /// Detector interface: Draw detector sub-tree the scene on a OpenGL pane
0118 void detail::DD4hepUI::drawSubtree(const char* path) const    {
0119   std::string vis  = _visLevel(visLevel);
0120   const void* av[] = {"-detector", path, "-option", "ogl", "-level", vis.c_str(), 0};
0121   m_detDesc.apply("DD4hep_GeometryDisplay", 2, (char**)av);
0122 }
0123 
0124 /// Detector interface: Re-draw the entire sub-tree scene
0125 void detail::DD4hepUI::redrawSubtree(const char* path) const    {
0126   std::string vis  = _visLevel(visLevel);
0127   const void* av[] = {"-detector", path, "-option", "oglsame", "-level", vis.c_str(), 0};
0128   m_detDesc.apply("DD4hep_GeometryDisplay", 4, (char**)av);
0129 }
0130 
0131 /// Dump the volume tree
0132 long detail::DD4hepUI::dumpVols(int argc, char** argv)  const   {
0133   if ( argc==0 )  {
0134     const void* av[] = {"-positions","-pointers",0};
0135     return m_detDesc.apply("DD4hep_VolumeDump",2,(char**)av);
0136   }
0137   return m_detDesc.apply("DD4hep_VolumeDump",argc,argv);
0138 }
0139 
0140 /// Dump the DetElement tree with placements
0141 long detail::DD4hepUI::dumpDet(const char* path)  const   {
0142   const void* args[] = {"--detector", path ? path : "/world", 0};
0143   return m_detDesc.apply("DD4hep_DetectorVolumeDump",2,(char**)args);
0144 }
0145 
0146 /// Dump the DetElement tree with placements
0147 long detail::DD4hepUI::dumpDetMaterials(const char* path)  const   {
0148   const void* args[] = {"--detector", path ? path : "/world", "--materials", "--shapes", 0};
0149   return m_detDesc.apply("DD4hep_DetectorVolumeDump",4,(char**)args);
0150 }
0151 
0152 /// Dump the DetElement tree with placements
0153 long detail::DD4hepUI::dumpStructure(const char* path)  const   {
0154   const void* args[] = {"--detector", path ? path : "/world", 0};
0155   return m_detDesc.apply("DD4hep_DetectorDump",2,(char**)args);
0156 }
0157 
0158 /// Dump the entire detector description object to a root file
0159 long detail::DD4hepUI::saveROOT(const char* file_name)    const     {
0160   if ( file_name )  {
0161     const void* av[] = {"-output",file_name,0};
0162     return m_detDesc.apply("DD4hep_Geometry2ROOT",2,(char**)av);
0163   }
0164   printout(WARNING,"DD4hepUI","++ saveROOT: No valid output file name supplied");
0165   return 0;
0166 }
0167 
0168 /// Import the entire detector description object from a root file
0169 long detail::DD4hepUI::importROOT(const char* file_name)    const    {
0170   if ( file_name )  {
0171     const void* av[] = {"-input",file_name,0};
0172     return m_detDesc.apply("DD4hep_RootLoader",2,(char**)av);
0173   }
0174   printout(WARNING,"DD4hepUI","++ importROOT: No valid output file name supplied");
0175   return 0;
0176 }
0177 
0178 /// Create ROOT interpreter instance
0179 long detail::DD4hepUI::createInterpreter(int argc, char** argv)  {
0180   if ( 0 == gApplication )  {
0181     std::pair<int, char**> a(argc,argv);
0182     gApplication = new TRint("DD4hepUI", &a.first, a.second);
0183     printout(INFO,"DD4hepUI","++ Created ROOT interpreter instance for DD4hepUI.");
0184     return 1;
0185   }
0186   printout(WARNING,"DD4hepUI",
0187            "++ Another ROOT application instance already exists. Keep existing instance.");
0188   return 1;
0189 }
0190 
0191 /// Execute ROOT interpreter instance
0192 long detail::DD4hepUI::runInterpreter()  const   {
0193   if ( 0 != gApplication )  {
0194     if ( !gApplication->IsRunning() )  {
0195       gApplication->Run();
0196       return 1;
0197     }
0198     except("DD4hepUI","++ The ROOT application is already running.");
0199   }
0200   except("DD4hepUI","++ No ROOT interpreter instance present!");
0201   return 0;
0202 }
0203