Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:11

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 //
0011 //==========================================================================
0012 
0013 #include <DD4hep/Detector.h>
0014 #include <DD4hep/Factories.h>
0015 #include <DD4hep/Printout.h>
0016 #include <DD4hep/DetectorTools.h>
0017 
0018 // ROOT includes
0019 #include "ROOT/RDirectory.hxx"
0020 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,27,00)
0021 #include "ROOT/RGeomViewer.hxx"
0022 #  if ROOT_VERSION_CODE >= ROOT_VERSION(6,29,00)
0023      using GEOM_VIEWER = ROOT::RGeomViewer;
0024 #  else
0025      using GEOM_VIEWER = ROOT::Experimental::RGeomViewer;
0026 #  endif
0027 #else
0028 #include "ROOT/REveGeomViewer.hxx"
0029 using GEOM_VIEWER = ROOT::Experimental::REveGeomViewer;
0030 #endif
0031 
0032 // C/C++ include files
0033 #include <cerrno>
0034 #include <cstdlib>
0035 #include <fstream>
0036 #include <sstream>
0037 
0038 using namespace std;
0039 using namespace dd4hep;
0040 using namespace dd4hep::detail;
0041 
0042 
0043 /// Basic entry point to display the currently loaded geometry using the ROOT7 jsroot viewer
0044 /**
0045  *  Factory: DD4hep_GeometryWebDisplay
0046  *
0047  */
0048 static long webdisplay(Detector& description, int argc, char** argv) {
0049   TGeoManager& mgr = description.manager();
0050   int vislevel = 6, visopt = 1;
0051   string detector = "/world";
0052   const char* opt = "";
0053   for(int i = 0; i < argc && argv[i]; ++i)  {
0054     if ( 0 == ::strncmp("-option",argv[i],4) )
0055       opt = argv[++i];
0056     else if ( 0 == ::strncmp("-level",argv[i],4) )
0057       vislevel = ::atol(argv[++i]);
0058     else if ( 0 == ::strncmp("-visopt",argv[i],4) )
0059       visopt = ::atol(argv[++i]);
0060     else if ( 0 == ::strncmp("-detector",argv[i],4) )
0061       detector = argv[++i];
0062     else  {
0063       cout <<
0064         "Usage: -plugin <name> -arg [-arg]                                                   \n"
0065         "     -detector <string> Top level DetElement path. Default: '/world'                \n"
0066         "     -option   <string> ROOT Draw option.    Default: ''                            \n"
0067         "     -level    <number> Visualization level  [TGeoManager::SetVisLevel]  Default: 4 \n"
0068         "     -visopt   <number> Visualization option [TGeoManager::SetVisOption] Default: 1 \n"       
0069         "\tArguments given: " << arguments(argc,argv) << endl << flush;
0070       ::exit(EINVAL);
0071     }
0072   }
0073   mgr.SetVisLevel(vislevel);
0074   mgr.SetVisOption(visopt);
0075   TGeoVolume* vol = mgr.GetTopVolume();
0076   if ( detector != "/world" )   {
0077     DetElement elt = detail::tools::findElement(description,detector);
0078     if ( !elt.isValid() )  {
0079       except("DD4hep_GeometryWebDisplay","+++ Invalid DetElement path: %s",detector.c_str());
0080     }
0081     if ( !elt.placement().isValid() )   {
0082       except("DD4hep_GeometryWebDisplay","+++ Invalid DetElement placement: %s",detector.c_str());
0083     }
0084     vol = elt.placement().volume();
0085   }
0086 
0087   if (vol) {
0088     auto viewer = std::make_shared<GEOM_VIEWER>(&mgr);
0089     viewer->SelectVolume(vol->GetName());
0090     viewer->SetLimits();
0091     viewer->SetDrawOptions(opt);
0092     viewer->Show();
0093     // add to global heap to avoid immediate destroy of RGeomViewer
0094     ROOT::Experimental::RDirectory::Heap().Add( "geom_viewer", viewer );
0095     return 1;
0096   }
0097   return 0;
0098 }
0099 DECLARE_APPLY(DD4hep_GeometryWebDisplay,webdisplay)
0100