CMS 3D CMS Logo

DDLSpecPar.cc
Go to the documentation of this file.
11 
12 #include <algorithm>
13 #include <cstddef>
14 #include <map>
15 #include <utility>
16 #include <vector>
17 
18 class DDCompactView;
19 
21 
22 // Process a SpecPar element. We have to assume that
23 // certain things have happened.
25  // sends the call to the DDD Core OR does nothing if it is a sub-element
26 
27  // What I want to do here is the following:
28  // 1. output PartSelector information.
29  // 2. pass the Path and parameters to DDSpecifics
30  // for each of the above, use the name of the SpecPar, since DDL does not
31  // provide a name for a PartSelector.
32 
33  auto myParameter = myRegistry_->getElement("Parameter");
34  auto myNumeric = myRegistry_->getElement("Numeric");
35  auto myString = myRegistry_->getElement("String");
36  auto myPartSelector = myRegistry_->getElement("PartSelector");
37  auto mySpecParSection = myRegistry_->getElement("SpecParSection");
38 
39  // Because of namespace magic "!" means namespaces should be provided
40  // in the names of the XML elements for the DDD. So if this is
41  // the state/case then we need to force the expression evaluator to
42  // use the namespace of the SpecPar element being processed.
43  // -- Michael Case 2008-11-06
44  std::string ns(nmspace);
46  std::string rn = spatts.find("name")->second;
47  if (ns == "!") {
48  size_t foundColon = rn.find(':');
49  if (foundColon != std::string::npos) {
50  ns = rn.substr(0, foundColon);
51  // rn = rn.substr(foundColon+1);
52  }
53  }
54 
55  // DDPartSelector name comes from DDLSpecPar (this class, there is no analogue to
56  // DDLSpecPar in DDCore)
57  std::vector<std::string> partsels;
58  size_t i;
59 
60  // if (getName("name") == "")
61  // {
62  // std::cout << "ERROR: no name for SpecPar" << std::endl;
63  // partsels = myPartSelector->getVectorAttribute("path");
64  // snames = myParameter->getVectorAttribute("name");
65  // std::cout << "\tParameter Names" << std::endl;
66  // size_t i;
67  // for (i = 0; i < snames.size(); ++i)
68  // {
69  // std::cout << "\t\t" << snames[i] << std::endl;
70  // }
71  // std::cout << "\tPart Selectors:" << std::endl;
72  // for (i = 0; i < partsels.size(); ++i)
73  // {
74  // std::cout << "\t\t" << partsels[i] << std::endl;
75  // }
76  // }
77  // else
78  // {
79 
80  //should i keep this? partsels = myPartSelector->getVectorAttribute("path");
81  //otherise I have to do this block...
82  for (i = 0; i < myPartSelector->size(); ++i)
83  partsels.emplace_back((myPartSelector->getAttributeSet(i).find("path"))->second);
84  DDsvalues_type svt;
85 
86  // boolean flag to indicate whether the std::vector<DDValuePair> has been evaluated
87  // using the Evaluator
88  typedef std::map<std::string, std::pair<bool, std::vector<DDValuePair> > > vvvpType;
89 
90  vvvpType vvvp;
91 
97  bool doNotEval = true;
98  bool doRegex = true;
99  {
100  // check parent level
101  const DDXMLAttribute& atts = mySpecParSection->getAttributeSet();
102 
103  if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
104  doNotEval = false;
105 
106  if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
107  doRegex = false;
108  }
109  {
110  // check this level
111  const DDXMLAttribute& atts = getAttributeSet();
112 
113  if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
114  doNotEval = false;
115  else if (atts.find("eval") != atts.end())
116  doNotEval = true;
117 
118  if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
119  doRegex = false;
120  else if (atts.find("regex") != atts.end())
121  doRegex = true;
122  }
123  for (i = 0; i < myParameter->size(); ++i) {
124  const DDXMLAttribute& atts = myParameter->getAttributeSet(i);
125  std::vector<DDValuePair> vvp;
126  vvvpType::iterator itv = vvvp.find((atts.find("name")->second));
127  if (itv != vvvp.end())
128  vvp = itv->second.second;
129  double tval = 0.0;
130  bool isEvaluated = false;
131 
139  // bool notThis = doNotEval myParameter->get(std::string("eval"), i) != "true";
140 
141  if ((atts.find("eval") != atts.end() && atts.find("eval")->second != "false") ||
142  (atts.find("eval") == atts.end() && !doNotEval)) {
143  tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
144  isEvaluated = true;
145  }
146 
147  DDValuePair vp(atts.find("value")->second, tval);
148  vvp.emplace_back(vp);
149  vvvp[atts.find("name")->second] = make_pair(isEvaluated, vvp);
150  }
151 
152  // Process the String names and values.
153  for (i = 0; i < myString->size(); ++i) {
154  const DDXMLAttribute& atts = myString->getAttributeSet(i);
155  std::vector<DDValuePair> vvp;
156  vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
157  if (itv != vvvp.end())
158  vvp = itv->second.second;
159 
160  DDValuePair vp(atts.find("value")->second, 0.0);
161  vvp.emplace_back(vp);
162  vvvp[atts.find("name")->second] = make_pair(false, vvp);
163  }
164 
165  // Process the Numeric names and values.
166  for (i = 0; i < myNumeric->size(); ++i) {
167  const DDXMLAttribute& atts = myNumeric->getAttributeSet(i);
168  std::vector<DDValuePair> vvp;
169  vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
170  if (itv != vvvp.end())
171  vvp = itv->second.second;
172  double tval = myRegistry_->evaluator().eval(ns, atts.find("value")->second);
173  DDValuePair vp(atts.find("value")->second, tval);
174  vvp.emplace_back(vp);
175  vvvp[atts.find("name")->second] = make_pair(true, vvp);
176  }
177 
178  svt.reserve(vvvp.size());
179  for (vvvpType::const_iterator it = vvvp.begin(); it != vvvp.end(); ++it) {
180  DDValue val(it->first, it->second.second);
181  bool isEvaluated = it->second.first;
182  val.setEvalState(isEvaluated);
183  svt.emplace_back(DDsvalues_Content_type(val, val));
184  }
185  std::sort(svt.begin(), svt.end());
186 
187  DDSpecifics ds(getDDName(nmspace), partsels, svt, doRegex);
188 
189  myParameter->clear();
190  myPartSelector->clear();
191 
192  // after a SpecPar is done, we can clear
193  clear();
194 }
DDXMLElement::clear
virtual void clear(void)
clear this element's contents.
Definition: DDXMLElement.cc:40
DDValuePair.h
mps_fire.i
i
Definition: mps_fire.py:428
DDLSpecPar.h
MessageLogger.h
DDValuePair
Definition: DDValuePair.h:8
ClhepEvaluator.h
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
DDLElementRegistry
The main class for processing parsed elements.
Definition: DDLElementRegistry.h:23
DDXMLElement::getAttributeSet
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
DDLElementRegistry::evaluator
ClhepEvaluator & evaluator()
Definition: DDLElementRegistry.h:42
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDLSpecPar::processElement
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
Definition: DDLSpecPar.cc:24
DDSpecifics
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:41
DDValue.h
DDXMLAttribute
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDLSpecPar::DDLSpecPar
DDLSpecPar(DDLElementRegistry *myreg)
Definition: DDLSpecPar.cc:20
DDSpecifics.h
DDXMLElement
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDsvalues_Content_type
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:13
DDLElementRegistry.h
DDXMLElement::getDDName
const virtual DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
DDLElementRegistry::getElement
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
Definition: DDLElementRegistry.cc:42
heppy_batch.val
val
Definition: heppy_batch.py:351
DDValue
Definition: DDValue.h:21
DDXMLElement.h
DDName.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
DDsvalues.h
DDXMLElement::myRegistry_
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
ClhepEvaluator::eval
double eval(const std::string &ns, const std::string &expr)
Definition: ClhepEvaluator.cc:85
DDsvalues_type
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12