Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:03:10

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 
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 
0036 using namespace std;
0037 using namespace dd4hep;
0038 using namespace dd4hep::detail;
0039 
0040 
0041 /// Basic entry point to display the currently loaded geometry using the ROOT7 jsroot viewer
0042 /**
0043  *  Factory: DD4hep_GeometryWebDisplay
0044  *
0045  */
0046 static long webdisplay(Detector& description, int argc, char** argv) {
0047   TGeoManager& mgr = description.manager();
0048   int vislevel = 6, visopt = 1;
0049   int maxnodes = -1;
0050   string detector = "/world";
0051   const char* opt = "";
0052   for(int i = 0; i < argc && argv[i]; ++i)  {
0053     if ( 0 == ::strncmp("-option",argv[i],4) )
0054       opt = argv[++i];
0055     else if ( 0 == ::strncmp("-level",argv[i],4) )
0056       vislevel = ::atol(argv[++i]);
0057     else if ( 0 == ::strncmp("-visopt",argv[i],4) )
0058       visopt = ::atol(argv[++i]);
0059     else if ( 0 == ::strncmp("-detector",argv[i],4) )
0060       detector = argv[++i];
0061     else if ( 0 == ::strncmp("-maxnodes",argv[i],4) )
0062       maxnodes = ::atol(argv[++i]);
0063     else  {
0064       cout <<
0065         "Usage: -plugin <name> -arg [-arg]                                                   \n"
0066         "     -detector <string> Top level DetElement path. Default: '/world'                \n"
0067         "     -option   <string> ROOT Draw option.    Default: ''                            \n"
0068         "     -level    <number> Visualization level  [TGeoManager::SetVisLevel]  Default: 4 \n"
0069         "     -visopt   <number> Visualization option [TGeoManager::SetVisOption] Default: 1 \n"       
0070         "\tArguments given: " << arguments(argc,argv) << endl << flush;
0071       ::exit(EINVAL);
0072     }
0073   }
0074   mgr.SetVisLevel(vislevel);
0075   mgr.SetVisOption(visopt);
0076   TGeoVolume* vol = mgr.GetTopVolume();
0077   if ( detector != "/world" )   {
0078     DetElement elt = detail::tools::findElement(description,detector);
0079     if ( !elt.isValid() )  {
0080       except("DD4hep_GeometryWebDisplay","+++ Invalid DetElement path: %s",detector.c_str());
0081     }
0082     if ( !elt.placement().isValid() )   {
0083       except("DD4hep_GeometryWebDisplay","+++ Invalid DetElement placement: %s",detector.c_str());
0084     }
0085     vol = elt.placement().volume();
0086   }
0087 
0088   if (vol) {
0089     // FIXME: avoid leaking memory here, but we don't have a way of storing this in a cleanup way???
0090     auto viewer = new GEOM_VIEWER(&mgr);
0091     viewer->SelectVolume(vol->GetName());
0092     viewer->SetLimits();
0093     viewer->SetDrawOptions(opt);
0094     viewer->Show();
0095     // 5000 is the default
0096     if (mgr.GetNNodes() > (maxnodes > 0 ? maxnodes : 5000)) {
0097       printout(WARNING, "DD4hep_GeometryWebDisplay",
0098                "The geometry has a large number of nodes (%d) and not all of them will be displayed. "
0099                "Consider increasing its number with the -maxnodes option to increase the number of displayed nodes.",
0100                mgr.GetNNodes());
0101     }
0102     if ( maxnodes > 0 )
0103       viewer->SetLimits(maxnodes);
0104     return 1;
0105   }
0106   return 0;
0107 }
0108 DECLARE_APPLY(DD4hep_GeometryWebDisplay,webdisplay)
0109