CMS 3D CMS Logo

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