Back to home page

EIC code displayed by LXR

 
 

    


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

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    Plugin invocation:
0015    ==================
0016    This plugin behaves like a main program.
0017    Invoke the plugin with something like this:
0018 
0019    geoPluginRun -destroy -plugin DD4hep_VolumeScannerTest -opt [-opt]
0020 
0021 */
0022 /// Framework include files
0023 #include "DD4hep/Volumes.h"
0024 #include "DD4hep/Detector.h"
0025 #include "DD4hep/Printout.h"
0026 #include "DD4hep/Factories.h"
0027 #include "DD4hep/DetectorTools.h"
0028 #include "DD4hep/VolumeProcessor.h"
0029 #include "TClass.h"
0030 
0031 /// C/C++ include files
0032 #include <iomanip>
0033 
0034 namespace   {
0035   class MyVolumeProcessor : public dd4hep::PlacedVolumeProcessor   {
0036   public:
0037     int count = 0;
0038     std::vector<std::string> volume_stack;
0039   public:
0040     /// Default constructor
0041     MyVolumeProcessor() = default;
0042     /// Default destructir
0043     virtual ~MyVolumeProcessor() = default;
0044     /// Callback to output PlacedVolume information of an entire Placement
0045     virtual int process(dd4hep::PlacedVolume pv, int level, bool recursive)    {
0046       volume_stack.push_back(pv.name());
0047       int ret = this->dd4hep::PlacedVolumeProcessor::process(pv, level, recursive);
0048       volume_stack.pop_back();
0049       return ret;
0050     }
0051     /// Volume callback
0052     virtual int operator()(dd4hep::PlacedVolume pv, int level)   {
0053       dd4hep::Volume vol = pv.volume();
0054       std::cout << "Hierarchical level:" << level << "   Placement:";
0055       for(const auto& i : volume_stack ) std::cout << "/" << i;
0056       std::cout << std::endl
0057                 << "\tMaterial:" << vol.material().name() 
0058                 << "\tSolid:   " << vol.solid().name()
0059                 << " [" << vol.solid()->IsA()->GetName() << "]" << std::endl;
0060       ++count;
0061       return 1;
0062     }
0063   };
0064 }
0065 
0066 using namespace dd4hep;
0067 
0068 /// Plugin function: Test example of the volume scanner using a customized callback functor
0069 /**
0070  *
0071  *  \author  M.Frank
0072  *  \version 1.0
0073  *  \date    20/01/2018
0074  */
0075 static int scan_volumes (Detector& detector, int argc, char** argv)  {
0076   bool help = false;
0077   std::string det_element_path, placed_vol_path;
0078   for(int i=0; i<argc && argv[i]; ++i)  {
0079     if ( 0 == ::strncmp("-help",argv[i],4) )
0080       help = true;
0081     else if ( 0 == ::strncmp("-path",argv[i],4) )
0082       placed_vol_path = argv[++i];
0083     else if ( 0 == ::strncmp("-detector",argv[i],4) )
0084       det_element_path = argv[++i];
0085     else
0086       help = true;
0087   }
0088   if ( help )   {
0089     /// Help printout describing the basic command line interface
0090     std::cout <<
0091       "Usage: -plugin <name> -arg [-arg]                                                  \n"
0092       "     name:   factory name     DD4hep_PlacedVolumeScannerTest                       \n"
0093       "     -detector <name>         Path to the detector element where to start the scan.\n"
0094       "     -path     <name>         Alternatively specify the physical volume path.      \n"
0095       "     -help                    Ahow this help.                                      \n"
0096       "\tArguments given: " << arguments(argc,argv) << std::endl << std::flush;
0097     ::exit(EINVAL);
0098   }
0099 
0100   // Detectine the proper placed volume for the start (default=/world_volume)
0101   PlacedVolume start_pv;
0102   DetElement   start_de, de = detector.world();
0103   if ( !det_element_path.empty() )
0104     start_de = detail::tools::findElement(detector, det_element_path);
0105   else if ( !placed_vol_path.empty() )
0106     start_pv = detail::tools::findNode(de.placement(),placed_vol_path);
0107 
0108   if ( !start_pv.isValid() )   {
0109     if ( !start_de.isValid() )   {      
0110       except("VolumeScanner","Failed to find start conditions for the volume scan");
0111     }
0112     start_pv = start_de.placement();
0113   }
0114 
0115   // Let's scan
0116   MyVolumeProcessor proc;
0117   PlacedVolumeScanner().scanPlacements(proc, start_pv, 0, true);
0118   
0119   printout(ALWAYS,"VolumeScanner","+++ Visited a total of %d placed volumes.",proc.count);
0120   return 1;
0121 }
0122 
0123 DECLARE_APPLY(DD4hep_PlacedVolumeScannerTest,scan_volumes)