CMS 3D CMS Logo

DDVolumeProcessor.h
Go to the documentation of this file.
1 #ifndef DETECTOR_DESCRIPTION_DD_VOLUME_PROCESSOR_H
2 #define DETECTOR_DESCRIPTION_DD_VOLUME_PROCESSOR_H
3 
4 #include "DD4hep/VolumeProcessor.h"
7 
8 #include <string>
9 #include <string_view>
10 #include <vector>
11 
12 namespace cms {
13 
14  class DDVolumeProcessor : public dd4hep::PlacedVolumeProcessor {
15  public:
16 
19  using PlacedVolumeProcessor = dd4hep::PlacedVolumeProcessor;
20 
21  DDVolumeProcessor() = default;
22  ~DDVolumeProcessor() override = default;
23 
24  std::string_view stripNamespace(std::string_view v) {
25  auto first = v.find_first_of(":");
26  v.remove_prefix(std::min(first+1, v.size()));
27  return v;
28  }
29 
30  std::string_view stripCopyNo(std::string_view v) {
31  auto found = v.find_last_of("_");
32  if(found != v.npos) {
33  v.remove_suffix(v.size() - found);
34  }
35  return v;
36  }
37 
38  std::vector<std::string_view> split(std::string_view str, const char* delims) {
39  std::vector<std::string_view> ret;
40 
42  auto pos = str.find_first_of(delims, start);
43  while(pos != std::string_view::npos) {
44  if(pos != start) {
45  ret.emplace_back(str.substr(start, pos - start));
46  }
47  start = pos + 1;
48  pos = str.find_first_of(delims, start);
49  }
50  if(start < str.length())
51  ret.emplace_back(str.substr(start, str.length() - start));
52  return ret;
53  }
54 
55  bool compare(std::string_view s1, std::string_view s2) {
56  if(s1 == s2)
57  return true;
58  edm::LogVerbatim("Geometry") << '\"' << s1 << "\" does not match \"" << s2 << "\"\n";
59  return false;
60  }
61 
63  int process(PlacedVolume pv, int level, bool recursive) override {
64  m_volumes.emplace_back(pv.name());
65  int ret = PlacedVolumeProcessor::process(pv, level, recursive);
66  m_volumes.pop_back();
67  return ret;
68  }
69 
71  int operator()(PlacedVolume pv, int level) override {
72  Volume vol = pv.volume();
73  edm::LogVerbatim("Geometry").log([&level, &vol, this](auto& log) {
74  log << "\nHierarchical level:" << level << " Placement:";
75  for(const auto& i : m_volumes)
76  log << "/" << i << ", \n";
77  log << "\n\tMaterial:" << vol.material().name()
78  << "\tSolid: " << vol.solid().name() << "\n";
79  });
80  ++m_count;
81  return 1;
82  }
83  int count() const { return m_count; }
84 
85  private:
86  int m_count = 0;
87  std::vector<std::string_view> m_volumes;
88  };
89 }
90 
91 #endif
Definition: start.py:1
uint16_t size_type
dd4hep::PlacedVolumeProcessor PlacedVolumeProcessor
int operator()(PlacedVolume pv, int level) override
Volume callback.
dd4hep::PlacedVolume PlacedVolume
bool compare(std::string_view s1, std::string_view s2)
def pv(vc)
Definition: MetAnalyzer.py:7
LogVerbatim & log(F &&iF)
T min(T a, T b)
Definition: MathUtil.h:58
std::vector< std::string_view > m_volumes
~DDVolumeProcessor() override=default
std::vector< std::string_view > split(std::string_view str, const char *delims)
dd4hep::Volume Volume
int process(PlacedVolume pv, int level, bool recursive) override
Callback to retrieve PlacedVolume information of an entire Placement.
Namespace of DDCMS conversion namespace.
std::string_view stripNamespace(std::string_view v)
dd4hep::PlacedVolume PlacedVolume
#define str(s)
std::string_view stripCopyNo(std::string_view v)