CMS 3D CMS Logo

List of all members | Public Member Functions
DDLSpecPar Class Referencefinal

DDLSpecPar processes SpecPar elements. More...

#include <DDLSpecPar.h>

Inheritance diagram for DDLSpecPar:
DDXMLElement

Public Member Functions

 DDLSpecPar (DDLElementRegistry *myreg)
 
void processElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
 Processing the element. More...
 
- Public Member Functions inherited from DDXMLElement
void appendText (const std::string &inText)
 append to the current (i.e. most recently added) More...
 
virtual std::vector< DDXMLAttribute >::const_iterator begin (void)
 
virtual void clear (void)
 clear this element's contents. More...
 
 DDXMLElement (DDLElementRegistry *myreg)
 Constructor. More...
 
 DDXMLElement (DDLElementRegistry *myreg, const bool &clearme)
 Constructor for autoClear element. More...
 
virtual std::vector< DDXMLAttribute >::const_iterator end (void)
 
virtual const std::string & get (const std::string &name, size_t aIndex=0) const
 Returns a specific value from the aIndex set of attributes. More...
 
virtual const std::string & getAttribute (const std::string &name) const
 Access to attributes by name. More...
 
virtual const DDXMLAttributegetAttributeSet (size_t aIndex=0) const
 Get a "row" of attributes, i.e. one attribute set. More...
 
virtual const DDName getDDName (const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
 
const std::string getText (size_t tindex=0) const
 retrieve the text blob. More...
 
virtual std::vector< std::string > getVectorAttribute (const std::string &name)
 Returns a set of values as a std::vector of strings, given the attribute name. More...
 
virtual bool gotText (void) const
 gotText()? kind of like gotMilk? Yes = text has already been encountered. More...
 
virtual bool isEmpty (void) const
 Have any elements of this type been encountered but not processed? More...
 
void loadAttributes (const std::string &elemName, const std::vector< std::string > &names, const std::vector< std::string > &values, const std::string &nmspace, DDCompactView &cpv)
 Load the element attributes. More...
 
void loadText (const std::string &inText)
 Used to load both text and XML comments into this object. More...
 
std::vector< DDXMLAttribute >::const_iterator & operator++ (int inc)
 Allow the elements of this type to be iterated over using ++ operator. More...
 
const std::string & parent (void) const
 access to parent element name More...
 
virtual void preProcessElement (const std::string &name, const std::string &nmspace, DDCompactView &cpv)
 Called by loadAttributes AFTER attributes are loaded. More...
 
void setParent (const std::string &pename)
 Set parent element name to central list of names. More...
 
void setSelf (const std::string &sename)
 Set self element name to central list of names. More...
 
virtual size_t size (void) const
 Number of elements accumulated. More...
 
virtual void stream (std::ostream &os) const
 Allow for the elements to have their own streaming method, but also provide a default. More...
 
void throwError (const std::string &keyMessage) const
 format std::string for throw an error. More...
 
virtual ~DDXMLElement (void)=default
 Destructor. More...
 

Additional Inherited Members

- Protected Attributes inherited from DDXMLElement
DDLElementRegistrymyRegistry_
 

Detailed Description

DDLSpecPar processes SpecPar elements.

Author
Michael Case

DDLSpecPar.h - description

begin: Tue Nov 21 2001 email: case@.nosp@m.ucdh.nosp@m.ep.uc.nosp@m.davi.nosp@m.s.edu

This element is used to specify parameters for a part in the detector. PartSelector provides a way to associate Parameters with specific parts of the detector.

Definition at line 26 of file DDLSpecPar.h.

Constructor & Destructor Documentation

DDLSpecPar::DDLSpecPar ( DDLElementRegistry myreg)

Definition at line 20 of file DDLSpecPar.cc.

21  : DDXMLElement( myreg )
22 {}
DDXMLElement(DDLElementRegistry *myreg)
Constructor.
Definition: DDXMLElement.cc:14

Member Function Documentation

void DDLSpecPar::processElement ( const std::string &  name,
const std::string &  nmspace,
DDCompactView cpv 
)
overridevirtual

Processing the element.

The processElement method completes any necessary work to process the XML element.

For example, this can be used to call the DDCore to make the geometry in memory. There is a default for this so that if not declared in the inheriting class, no processing is done.

08/13/03 doNotEval for Parameter is based on the value of the eval flag. For String it is always false and for Numeric it is always true. But for "legacy" Parameter, remember, we need to check eval. Default is NOT to evaluate.

  1. Check eval flag of each level (SpecParSection, SpecPar and Parameter).
  2. Default is the closest specified eval attribute with any value other than "false".

Reimplemented from DDXMLElement.

Definition at line 27 of file DDLSpecPar.cc.

References DDXMLElement::clear(), ClhepEvaluator::eval(), DDLElementRegistry::evaluator(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDLElementRegistry::getElement(), mps_fire::i, DDXMLElement::myRegistry_, edm::second(), DDValue::setEvalState(), jetUpdater_cfi::sort, AlCaHLTBitMon_QueryRunRegistry::string, and heppy_batch::val.

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 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
DDsvalues_type::value_type DDsvalues_Content_type
Definition: DDsvalues.h:13
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:72
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
Definition: DDsvalues.h:12
double eval(const std::string &ns, const std::string &expr)
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
Interface to attach user specific data to nodes in the expanded-view.
Definition: DDSpecifics.h:41