File indexing completed on 2023-03-17 10:51:41
0001 #ifndef DetectorDescription_DDCMS_DDCompactView_h
0002 #define DetectorDescription_DDCMS_DDCompactView_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0025 #include <DD4hep/SpecParRegistry.h>
0026
0027 namespace cms {
0028 using DDSpecParRegistry = dd4hep::SpecParRegistry;
0029 using DDSpecParRefs = dd4hep::SpecParRefs;
0030
0031 class DDCompactView {
0032 public:
0033 DDCompactView(const cms::DDDetector& det) : m_det(det) {}
0034 const cms::DDDetector* detector() const { return &m_det; }
0035 DDSpecParRegistry const& specpars() const { return m_det.specpars(); }
0036 template <typename T>
0037 std::vector<T> getVector(const std::string&) const;
0038
0039 template <typename T>
0040 T const& get(const std::string&) const;
0041 template <typename T>
0042 T const& get(const std::string&, const std::string&) const;
0043
0044 private:
0045 const cms::DDDetector& m_det;
0046 };
0047
0048
0049
0050
0051
0052
0053
0054 template <typename T>
0055 std::vector<T> getAllParameterValuesFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
0056 const std::string& nodePath,
0057 const std::string& parameterName) {
0058 cms::DDSpecParRefs filteredSpecParSections;
0059 allSpecParSections.filter(filteredSpecParSections, parameterName);
0060 for (const auto& mySpecParSection : filteredSpecParSections) {
0061 if (mySpecParSection.second->hasPath(nodePath)) {
0062 return mySpecParSection.second->value<std::vector<T>>(parameterName);
0063 }
0064 }
0065
0066 return std::vector<T>();
0067 }
0068
0069
0070
0071
0072 template <typename T>
0073 T getParameterValueFromSpecParSections(const cms::DDSpecParRegistry& allSpecParSections,
0074 const std::string& nodePath,
0075 const std::string& parameterName,
0076 const unsigned int parameterValueIndex) {
0077 const std::vector<T>& allParameterValues =
0078 getAllParameterValuesFromSpecParSections<T>(allSpecParSections, nodePath, parameterName);
0079 if (parameterValueIndex < allParameterValues.size()) {
0080 return allParameterValues.at(parameterValueIndex);
0081 }
0082 return T();
0083 }
0084
0085 }
0086
0087 #endif