File indexing completed on 2024-04-06 12:05:33
0001 #include "DetectorDescription/Parser/src/DDLSpecPar.h"
0002 #include "DetectorDescription/Core/interface/DDName.h"
0003 #include "DetectorDescription/Core/interface/DDSpecifics.h"
0004 #include "DetectorDescription/Core/interface/DDValue.h"
0005 #include "DetectorDescription/Core/interface/DDValuePair.h"
0006 #include "DetectorDescription/Core/interface/DDsvalues.h"
0007 #include "DetectorDescription/Core/interface/ClhepEvaluator.h"
0008 #include "DetectorDescription/Parser/interface/DDLElementRegistry.h"
0009 #include "DetectorDescription/Parser/src/DDXMLElement.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011
0012 #include <algorithm>
0013 #include <cstddef>
0014 #include <map>
0015 #include <utility>
0016 #include <vector>
0017
0018 class DDCompactView;
0019
0020 DDLSpecPar::DDLSpecPar(DDLElementRegistry* myreg) : DDXMLElement(myreg) {}
0021
0022
0023
0024 void DDLSpecPar::processElement(const std::string& name, const std::string& nmspace, DDCompactView& cpv) {
0025
0026
0027
0028
0029
0030
0031
0032
0033 auto myParameter = myRegistry_->getElement("Parameter");
0034 auto myNumeric = myRegistry_->getElement("Numeric");
0035 auto myString = myRegistry_->getElement("String");
0036 auto myPartSelector = myRegistry_->getElement("PartSelector");
0037 auto mySpecParSection = myRegistry_->getElement("SpecParSection");
0038
0039
0040
0041
0042
0043
0044 std::string ns(nmspace);
0045 DDXMLAttribute spatts = getAttributeSet();
0046 std::string rn = spatts.find("name")->second;
0047 if (ns == "!") {
0048 size_t foundColon = rn.find(':');
0049 if (foundColon != std::string::npos) {
0050 ns = rn.substr(0, foundColon);
0051
0052 }
0053 }
0054
0055
0056
0057 std::vector<std::string> partsels;
0058 size_t i;
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082 for (i = 0; i < myPartSelector->size(); ++i)
0083 partsels.emplace_back((myPartSelector->getAttributeSet(i).find("path"))->second);
0084 DDsvalues_type svt;
0085
0086
0087
0088 typedef std::map<std::string, std::pair<bool, std::vector<DDValuePair> > > vvvpType;
0089
0090 vvvpType vvvp;
0091
0092
0093
0094
0095
0096
0097 bool doNotEval = true;
0098 bool doRegex = true;
0099 {
0100
0101 const DDXMLAttribute& atts = mySpecParSection->getAttributeSet();
0102
0103 if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
0104 doNotEval = false;
0105
0106 if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
0107 doRegex = false;
0108 }
0109 {
0110
0111 const DDXMLAttribute& atts = getAttributeSet();
0112
0113 if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
0114 doNotEval = false;
0115 else if (atts.find("eval") != atts.end())
0116 doNotEval = true;
0117
0118 if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
0119 doRegex = false;
0120 else if (atts.find("regex") != atts.end())
0121 doRegex = true;
0122 }
0123 for (i = 0; i < myParameter->size(); ++i) {
0124 const DDXMLAttribute& atts = myParameter->getAttributeSet(i);
0125 std::vector<DDValuePair> vvp;
0126 vvvpType::iterator itv = vvvp.find((atts.find("name")->second));
0127 if (itv != vvvp.end())
0128 vvp = itv->second.second;
0129 double tval = 0.0;
0130 bool isEvaluated = false;
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 if ((atts.find("eval") != atts.end() && atts.find("eval")->second != "false") ||
0142 (atts.find("eval") == atts.end() && !doNotEval)) {
0143 tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
0144 isEvaluated = true;
0145 }
0146
0147 DDValuePair vp(atts.find("value")->second, tval);
0148 vvp.emplace_back(vp);
0149 vvvp[atts.find("name")->second] = make_pair(isEvaluated, vvp);
0150 }
0151
0152
0153 for (i = 0; i < myString->size(); ++i) {
0154 const DDXMLAttribute& atts = myString->getAttributeSet(i);
0155 std::vector<DDValuePair> vvp;
0156 vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
0157 if (itv != vvvp.end())
0158 vvp = itv->second.second;
0159
0160 DDValuePair vp(atts.find("value")->second, 0.0);
0161 vvp.emplace_back(vp);
0162 vvvp[atts.find("name")->second] = make_pair(false, vvp);
0163 }
0164
0165
0166 for (i = 0; i < myNumeric->size(); ++i) {
0167 const DDXMLAttribute& atts = myNumeric->getAttributeSet(i);
0168 std::vector<DDValuePair> vvp;
0169 vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
0170 if (itv != vvvp.end())
0171 vvp = itv->second.second;
0172 double tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
0173 DDValuePair vp(atts.find("value")->second, tval);
0174 vvp.emplace_back(vp);
0175 vvvp[atts.find("name")->second] = make_pair(true, vvp);
0176 }
0177
0178 svt.reserve(vvvp.size());
0179 for (vvvpType::const_iterator it = vvvp.begin(); it != vvvp.end(); ++it) {
0180 DDValue val(it->first, it->second.second);
0181 bool isEvaluated = it->second.first;
0182 val.setEvalState(isEvaluated);
0183 svt.emplace_back(DDsvalues_Content_type(val, val));
0184 }
0185 std::sort(svt.begin(), svt.end());
0186
0187 DDSpecifics ds(getDDName(nmspace), partsels, svt, doRegex);
0188
0189 myParameter->clear();
0190 myPartSelector->clear();
0191
0192
0193 clear();
0194 }