CMS 3D CMS Logo

DDCompactView.h
Go to the documentation of this file.
1 #ifndef DetectorDescription_DDCMS_DDCompactView_h
2 #define DetectorDescription_DDCMS_DDCompactView_h
3 
4 // -*- C++ -*-
5 //
6 // Package: DetectorDescription/Core
7 // Class: DDCompactView
8 //
18 //
19 // Original Author: Ianna Osborne
20 // Created: Wed, 22 May 2019 12:51:22 GMT
21 //
22 //
23 
25 #include <DD4hep/SpecParRegistry.h>
26 
27 namespace cms {
28  using DDSpecParRegistry = dd4hep::SpecParRegistry;
29  using DDSpecParRefs = dd4hep::SpecParRefs;
30 
31  class DDCompactView {
32  public:
33  DDCompactView(const cms::DDDetector& det) : m_det(det) {}
34  const cms::DDDetector* detector() const { return &m_det; }
35  DDSpecParRegistry const& specpars() const { return m_det.specpars(); }
36  template <typename T>
37  std::vector<T> getVector(const std::string&) const;
38 
39  template <typename T>
40  T const& get(const std::string&) const;
41  template <typename T>
42  T const& get(const std::string&, const std::string&) const;
43 
44  private:
46  };
47 
48  /* Helper: For a given node, get the values associated to a given parameter, from the XMLs SpecPar sections.
49  * NB: The same parameter can appear several times WITHIN the same SpecPar section (hence, we have a std::vector).
50  * WARNING: This stops at the first relevant SpecPar section encountered.
51  * Hence, if A GIVEN NODE HAS SEVERAL SPECPAR XML SECTIONS RE-DEFINING THE SAME PARAMETER,
52  * only the first XML SpecPar block will be considered.
53  */
54  template <typename T>
55  std::vector<T> getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
56  const std::string& nodePath,
57  const std::string& parameterName) {
58  cms::DDSpecParRefs filteredSpecParSections;
59  allSpecParSections.filter(filteredSpecParSections, parameterName);
60  for (const auto& mySpecParSection : filteredSpecParSections) {
61  if (mySpecParSection.second->hasPath(nodePath)) {
62  return mySpecParSection.second->value<std::vector<T>>(parameterName);
63  }
64  }
65 
66  return std::vector<T>();
67  }
68 
69  /* Helper: For a given node, get the value associated to a given parameter, from the XMLs SpecPar sections.
70  * This is the parameterValueIndex-th value (within a XML SpecPar block.) of the desired parameter.
71  */
72  template <typename T>
74  const std::string& nodePath,
75  const std::string& parameterName,
76  const unsigned int parameterValueIndex) {
77  const std::vector<T>& allParameterValues =
78  getAllParameterValuesFromSpecParSections<T>(allSpecParSections, nodePath, parameterName);
79  if (parameterValueIndex < allParameterValues.size()) {
80  return allParameterValues.at(parameterValueIndex);
81  }
82  return T();
83  }
84 
85 } // namespace cms
86 
87 #endif
cms::DDDetector::specpars
dd4hep::SpecParRegistry const & specpars() const
Definition: DDDetector.h:21
cms::DDSpecParRefs
dd4hep::SpecParRefs DDSpecParRefs
Definition: DDCompactView.h:29
cms::DDCompactView::m_det
const cms::DDDetector & m_det
Definition: DDCompactView.h:45
DDDetector.h
cms::DDSpecParRegistry
dd4hep::SpecParRegistry DDSpecParRegistry
Definition: DDCompactView.h:28
cms::DDCompactView::DDCompactView
DDCompactView(const cms::DDDetector &det)
Definition: DDCompactView.h:33
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cms::DDCompactView::getVector
std::vector< T > getVector(const std::string &) const
cms::DDCompactView::specpars
DDSpecParRegistry const & specpars() const
Definition: DDCompactView.h:35
cms::getAllParameterValuesFromSpecParSections
std::vector< T > getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry &allSpecParSections, const std::string &nodePath, const std::string &parameterName)
Definition: DDCompactView.h:55
T
long double T
Definition: Basic3DVectorLD.h:48
cms::DDDetector
Definition: DDDetector.h:12
cms::DDCompactView
Definition: DDCompactView.h:31
cms::DDCompactView::get
T const & get(const std::string &) const
cms::DDCompactView::detector
const cms::DDDetector * detector() const
Definition: DDCompactView.h:34
cms::getParameterValueFromSpecParSections
T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry &allSpecParSections, const std::string &nodePath, const std::string &parameterName, const unsigned int parameterValueIndex)
Definition: DDCompactView.h:73
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21