CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDLPgonGenerator.cc
Go to the documentation of this file.
7 
8 #include <cstddef>
9 #include <map>
10 #include <utility>
11 #include <vector>
12 
13 class DDCompactView;
14 
16 
18  myRegistry_->getElement("XYPoint")->clear();
19  myRegistry_->getElement("ZXYSection")->clear();
20 }
21 
22 // Upon encountering an end Extruded Polygone tag, process the XYPoints
23 // element and extract the x and y std::vectors to feed into DDCore. Then, clear
24 // the XYPoints and clear this element.
26  auto myXYPoints = myRegistry_->getElement("XYPoint");
27  auto myZXYSection = myRegistry_->getElement("ZXYSection");
28 
30  DDXMLAttribute atts;
31 
32  // get x and y
33  std::vector<double> x, y;
34  for (size_t i = 0; i < myXYPoints->size(); ++i) {
35  atts = myXYPoints->getAttributeSet(i);
36  auto xit = atts.find("x");
37  if (xit != atts.end())
38  x.emplace_back(ev.eval(nmspace, xit->second));
39  auto yit = atts.find("y");
40  if (yit != atts.end())
41  y.emplace_back(ev.eval(nmspace, yit->second));
42  }
43  assert(x.size() == y.size());
44 
45  // get zSection information
46  std::vector<double> z, zx, zy, zscale;
47 
48  for (size_t i = 0; i < myZXYSection->size(); ++i) {
49  atts = myZXYSection->getAttributeSet(i);
50  auto zit = atts.find("z");
51  if (zit != atts.end())
52  z.emplace_back(ev.eval(nmspace, zit->second));
53  auto xit = atts.find("x");
54  if (xit != atts.end())
55  zx.emplace_back(ev.eval(nmspace, xit->second));
56  auto yit = atts.find("y");
57  if (yit != atts.end())
58  zy.emplace_back(ev.eval(nmspace, yit->second));
59  auto sit = atts.find("scale");
60  if (sit != atts.end())
61  zscale.emplace_back(std::stod(sit->second));
62  }
63  assert(z.size() == zx.size());
64  assert(z.size() == zy.size());
65  assert(z.size() == zscale.size());
66 
67  atts = getAttributeSet();
68  if (name == "ExtrudedPolygon") {
69  DDSolid extrudedpolygon = DDSolidFactory::extrudedpolygon(getDDName(nmspace), x, y, z, zx, zy, zscale);
70  } else {
71  std::string msg = "\nDDLPgonGenerator::processElement was called with incorrect name of solid: " + name;
72  throwError(msg);
73  }
74  DDLSolid::setReference(nmspace, cpv);
75 
76  // clear out XYPoint element accumulator and ZXYSections
77  myXYPoints->clear();
78  myZXYSection->clear();
79  clear();
80 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
bool ev
assert(be >=bs)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
ClhepEvaluator & evaluator()
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
DDLPgonGenerator(DDLElementRegistry *myreg)
DDLSolid processes Box elements.
Definition: DDLSolid.h:30
static DDSolid extrudedpolygon(const DDName &name, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &zx, const std::vector< double > &zy, const std::vector< double > &zscale)
Definition: DDSolid.cc:584
tuple msg
Definition: mps_check.py:285
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
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:40
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:13