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