Warning, file /DD4hep/examples/ClientTests/src/PlacedVolumeScannerTest.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
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
0041 MyVolumeProcessor() = default;
0042
0043 virtual ~MyVolumeProcessor() = default;
0044
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
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
0069
0070
0071
0072
0073
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
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
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
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)