CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLSpecPar.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLSpecPar.cc - description
3  -------------------
4  begin : Tue Nov 21 2001
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * *
12  ***************************************************************************/
13 
15 
21 
23 
24 #include <sstream>
25 
27  : DDXMLElement( myreg )
28 {}
29 
31 {}
32 
33 // Process a SpecPar element. We have to assume that
34 // certain things have happened.
35 void
36 DDLSpecPar::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
37 {
38  DCOUT_V('P',"DDLSpecPar::processElement started");
39 
40  // sends the call to the DDD Core OR does nothing if it is a sub-element
41 
42  // What I want to do here is the following:
43  // 1. output PartSelector information.
44  // 2. pass the Path and parameters to DDSpecifics
45  // for each of the above, use the name of the SpecPar, since DDL does not
46  // provide a name for a PartSelector.
47 
48  DDXMLElement* myParameter = myRegistry_->getElement("Parameter");
49  DDXMLElement* myNumeric = myRegistry_->getElement("Numeric");
50  DDXMLElement* myString = myRegistry_->getElement("String");
51  DDXMLElement* myPartSelector = myRegistry_->getElement("PartSelector");
52  DDXMLElement* mySpecParSection = myRegistry_->getElement("SpecParSection");
53 
54  // Because of namespace magic "!" means namespaces should be provided
55  // in the names of the XML elements for the DDD. So if this is
56  // the state/case then we need to force the expression evaluator to
57  // use the namespace of the SpecPar element being processed.
58  // -- Michael Case 2008-11-06
59  std::string ns(nmspace);
61  std::string rn = spatts.find("name")->second;
62  if ( ns == "!" ) {
63  size_t foundColon= rn.find(':');
64  if (foundColon != std::string::npos) {
65  ns = rn.substr(0,foundColon);
66  // rn = rn.substr(foundColon+1);
67  }
68  }
69 
70  // DDPartSelector name comes from DDLSpecPar (this class, there is no analogue to
71  // DDLSpecPar in DDCore)
72  std::vector <std::string> partsels;
73  size_t i;
74 
75  // if (getName("name") == "")
76  // {
77  // std::cout << "ERROR: no name for SpecPar" << std::endl;
78  // partsels = myPartSelector->getVectorAttribute("path");
79  // snames = myParameter->getVectorAttribute("name");
80  // std::cout << "\tParameter Names" << std::endl;
81  // size_t i;
82  // for (i = 0; i < snames.size(); ++i)
83  // {
84  // std::cout << "\t\t" << snames[i] << std::endl;
85  // }
86  // std::cout << "\tPart Selectors:" << std::endl;
87  // for (i = 0; i < partsels.size(); ++i)
88  // {
89  // std::cout << "\t\t" << partsels[i] << std::endl;
90  // }
91  // }
92  // else
93  // {
94 
95  //should i keep this? partsels = myPartSelector->getVectorAttribute("path");
96  //otherise I have to do this block...
97  for (i = 0; i < myPartSelector->size(); ++i)
98  partsels.push_back((myPartSelector->getAttributeSet(i).find("path"))->second);
99  DDsvalues_type svt;
100 
101  // boolean flag to indicate whether the std::vector<DDValuePair> has been evaluated
102  // using the Evaluator
103  typedef std::map<std::string, std::pair<bool,std::vector<DDValuePair> > > vvvpType;
104 
105  vvvpType vvvp;
106 
112  bool doNotEval = true;
113  bool doRegex = true;
114  {
115  // check parent level
116  const DDXMLAttribute & atts = mySpecParSection->getAttributeSet();
117 
118  if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
119  doNotEval = false;
120 
121  if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
122  doRegex = false;
123  }
124  {
125  // check this level
126  const DDXMLAttribute & atts = getAttributeSet();
127 
128  if (atts.find("eval") != atts.end() && atts.find("eval")->second == "true")
129  doNotEval = false;
130  else if (atts.find("eval") != atts.end())
131  doNotEval = true;
132 
133  if (atts.find("regex") != atts.end() && atts.find("regex")->second == "false")
134  doRegex = false;
135  else if (atts.find("regex") != atts.end())
136  doRegex = true;
137  }
138  for (i = 0; i < myParameter->size(); ++i)
139  {
140  const DDXMLAttribute & atts = myParameter->getAttributeSet(i);
141  std::vector <DDValuePair> vvp;
142  vvvpType::iterator itv = vvvp.find((atts.find("name")->second));
143  if (itv != vvvp.end())
144  vvp = itv->second.second;
145  double tval = 0.0;
146  bool isEvaluated = false;
147 
155  // bool notThis = doNotEval myParameter->get(std::string("eval"), i) != "true";
156 
157  // since eval is an optional attribute, we need to check if it exists for
158  // the debug statement. Unfortunately, I see no way to do this internal
159  // to the DCOUT_V statement... ts is a "wasted" variable.
160  std::string ts = "** no eval attribute **";
161  if (atts.find("eval") != atts.end())
162  ts = atts.find("eval")->second;
163  DCOUT_V('P', std::string("about to process ") << atts.find("value")->second << std::string(" eval = ") << ts);
164  if ((atts.find("eval") != atts.end() && atts.find("eval")->second !="false")
165  || (atts.find("eval") == atts.end() && !doNotEval))
166  {
167  tval = ExprEvalSingleton::instance().eval(ns, atts.find("value")->second);
168  isEvaluated=true;
169  DCOUT_V('P', std::string("EVALUATED"));
170  }
171  else
172  {
173  DCOUT_V('P', std::string("NOT Evaluated"));
174  }
175 
176  DDValuePair vp(atts.find("value")->second, tval);
177  vvp.push_back(vp);
178  vvvp[atts.find("name")->second] = make_pair(isEvaluated,vvp);
179  }
180 
181  // Process the String names and values.
182  for (i = 0; i < myString->size(); ++i)
183  {
184  const DDXMLAttribute & atts = myString->getAttributeSet(i);
185  std::vector <DDValuePair> vvp;
186  vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
187  if (itv != vvvp.end())
188  vvp = itv->second.second;
189  DCOUT_V('P', std::string("about to process String ") << (atts.find("name")->second) << " = " << (atts.find("value")->second));
190  DDValuePair vp(atts.find("value")->second, 0.0);
191  vvp.push_back(vp);
192  vvvp[atts.find("name")->second] = make_pair(false,vvp);
193  }
194 
195  // Process the Numeric names and values.
196  for (i = 0; i < myNumeric->size(); ++i)
197  {
198  const DDXMLAttribute & atts = myNumeric->getAttributeSet(i);
199  std::vector <DDValuePair> vvp;
200  vvvpType::iterator itv = vvvp.find(atts.find("name")->second);
201  if (itv != vvvp.end())
202  vvp = itv->second.second;
203  DCOUT_V('P', std::string("about to process String ") << (atts.find("name")->second) << " = " << (atts.find("value")->second));
204  double tval = ExprEvalSingleton::instance().eval(ns, atts.find("value")->second);
205  DCOUT_V('P', std::string("EVALUATED"));
206  DDValuePair vp(atts.find("value")->second, tval);
207  vvp.push_back(vp);
208  vvvp[atts.find("name")->second] = make_pair(true,vvp);
209  }
210 
211  svt.reserve(vvvp.size());
212  for (vvvpType::const_iterator it = vvvp.begin(); it != vvvp.end(); ++it)
213  {
214  DDValue val(it->first, it->second.second);
215  bool isEvaluated = it->second.first;
216  val.setEvalState(isEvaluated);
217  svt.push_back(DDsvalues_Content_type(val,val));
218  }
219  std::sort(svt.begin(),svt.end());
220 
221 
222  DCOUT_V('p', "DDLSpecPar::processElement\n\tname " << getDDName(nmspace) << "\n\tpartsels.size() = " << myPartSelector->size() << "\n\tsvt " << svt);
223 
224  DDSpecifics ds(getDDName(nmspace),
225  partsels,
226  svt,
227  doRegex);
228 
229  myParameter->clear();
230  myPartSelector->clear();
231 
232  // after a SpecPar is done, we can clear
233  clear();
234 
235  DCOUT_V('P',"DDLSpecPar::processElement(...)");
236 }
237 
DDLSpecPar(DDLElementRegistry *myreg)
Constructor.
Definition: DDLSpecPar.cc:26
int i
Definition: DBlmapReader.cc:9
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:187
~DDLSpecPar(void)
Destructor.
Definition: DDLSpecPar.cc:30
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
Definition: DDLSpecPar.cc:36
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:83
void setEvalState(bool newState)
set to true, if the double-values (method DDValue::doubles()) make sense
Definition: DDValue.cc:201
type of data representation of DDCompactView
Definition: DDCompactView.h:81
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:56
U second(std::pair< T, U > const &p)
DDXMLElement * getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
static value_type & instance()
virtual size_t size(void) const
Number of elements accumulated.
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:19
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:59
perl if(1 lt scalar(@::datatypes))
Definition: edlooper.cc:31
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:65
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:91
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:20
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:40