CMS 3D CMS Logo

DDTestNavigateGeometry.cc
Go to the documentation of this file.
9 #include "DD4hep/Detector.h"
10 #include "DD4hep/DD4hepRootPersistency.h"
11 #include "DD4hep/DetectorTools.h"
12 #include "DD4hep/VolumeProcessor.h"
13 
14 #include <iostream>
15 #include <string>
16 
17 using namespace std;
18 using namespace cms;
19 using namespace dd4hep;
20 
21 namespace {
22 
23  class VolumeProcessor : public dd4hep::PlacedVolumeProcessor {
24  public:
25  VolumeProcessor() = default;
26  ~VolumeProcessor() override = default;
27 
29  int process(dd4hep::PlacedVolume pv, int level, bool recursive) override {
30  m_volumes.emplace_back(pv.name());
31  int ret = dd4hep::PlacedVolumeProcessor::process(pv, level, recursive);
32  m_volumes.pop_back();
33  return ret;
34  }
35 
37  int operator()(dd4hep::PlacedVolume pv, int level) override {
38  dd4hep::Volume vol = pv.volume();
39  cout << "Hierarchical level:" << level << " Placement:";
40  for(const auto& i : m_volumes) cout << "/" << i;
41  cout << "\n\tMaterial:" << vol.material().name()
42  << "\tSolid: " << vol.solid().name()
43  << " [" << vol.solid()->IsA()->GetName() << "]\n";
44  ++m_count;
45  return 1;
46  }
47  int count() const { return m_count; }
48 
49  private:
50  int m_count = 0;
51  vector<string> m_volumes;
52  };
53 }
54 
56 public:
58 
59  void beginJob() override {}
60  void analyze(edm::Event const& iEvent, edm::EventSetup const&) override;
61  void endJob() override {}
62 };
63 
65 {}
66 
67 void
69 {
70  cout << "DDTestNavigateGeometry::analyze:\n";
71 
72  const DDVectorRegistryRcd& regRecord = iEventSetup.get<DDVectorRegistryRcd>();
74  regRecord.get(reg);
75 
76  for( const auto& p: reg->vectors ) {
77  std::cout << " " << p.first << " => ";
78  for( const auto& i : p.second )
79  std::cout << i << ", ";
80  std::cout << '\n';
81  }
82 
83  const DetectorDescriptionRcd& ddRecord = iEventSetup.get<DetectorDescriptionRcd>();
85  ddRecord.get(ddd);
86 
87  dd4hep::Detector& detector = ddd->description();
88 
89  string detElementPath;
90  string placedVolPath;
91 
92  DetElement startDetEl, world = detector.world();
93  PlacedVolume startPVol = world.placement();
94  if( !detElementPath.empty())
95  startDetEl = dd4hep::detail::tools::findElement(detector, detElementPath);
96  else if( !placedVolPath.empty())
97  startPVol = dd4hep::detail::tools::findNode(world.placement(), placedVolPath);
98  if( !startPVol.isValid()) {
99  if( !startDetEl.isValid()) {
100  except("VolumeScanner", "Failed to find start conditions for the volume scan");
101  }
102  startPVol = startDetEl.placement();
103  }
104 
105  VolumeProcessor proc;
106  PlacedVolumeScanner().scanPlacements(proc, startPVol, 0, true);
107 
108  printout(ALWAYS,"VolumeScanner","+++ Visited a total of %d placed volumes.", proc.count());
109 }
110 
TrainProcessor *const proc
Definition: MVATrainer.cc:101
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
int iEvent
Definition: GenABIO.cc:230
def pv(vc)
Definition: MetAnalyzer.py:7
void analyze(edm::Event const &iEvent, edm::EventSetup const &) override
Namespace of DDCMS conversion namespace.
T get() const
Definition: EventSetup.h:68
DDTestNavigateGeometry(const edm::ParameterSet &)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
bool get(HolderT &iHolder) const