CMS 3D CMS Logo

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  : DDLSolid( myreg )
17 {}
18 
19 void
21 {
22  myRegistry_->getElement("XYPoint")->clear();
23  myRegistry_->getElement("ZXYSection")->clear();
24 }
25 
26 // Upon encountering an end Extruded Polygone tag, process the XYPoints
27 // element and extract the x and y std::vectors to feed into DDCore. Then, clear
28 // the XYPoints and clear this element.
29 void
31  const std::string& nmspace,
32  DDCompactView& cpv )
33 {
34  auto myXYPoints = myRegistry_->getElement( "XYPoint" );
35  auto myZXYSection = myRegistry_->getElement( "ZXYSection" );
36 
38  DDXMLAttribute atts;
39 
40  // get x and y
41  std::vector<double> x, y;
42  for( size_t i = 0; i < myXYPoints->size(); ++i )
43  {
44  atts = myXYPoints->getAttributeSet( i );
45  auto xit = atts.find( "x" );
46  if( xit != atts.end())
47  x.emplace_back( ev.eval( nmspace, xit->second ));
48  auto yit = atts.find( "y" );
49  if( yit != atts.end())
50  y.emplace_back( ev.eval( nmspace, yit->second ));
51  }
52  assert( x.size() == y.size());
53 
54  // get zSection information
55  std::vector<double> z, zx, zy, zscale;
56 
57  for( size_t i = 0; i < myZXYSection->size(); ++i )
58  {
59  atts = myZXYSection->getAttributeSet( i );
60  auto zit = atts.find( "z" );
61  if( zit != atts.end())
62  z.emplace_back( ev.eval( nmspace, zit->second ));
63  auto xit = atts.find( "x" );
64  if( xit != atts.end())
65  zx.emplace_back( ev.eval( nmspace, xit->second ));
66  auto yit = atts.find( "y" );
67  if( yit != atts.end())
68  zy.emplace_back( ev.eval( nmspace, yit->second ));
69  auto sit = atts.find( "scale" );
70  if( sit != atts.end())
71  zscale.emplace_back( std::stod( sit->second ));
72  }
73  assert( z.size() == zx.size());
74  assert( z.size() == zy.size());
75  assert( z.size() == zscale.size());
76 
77  atts = getAttributeSet();
78  if( name == "ExtrudedPolygon" )
79  {
80  DDSolid extrudedpolygon =
82  x, y,
83  z, zx, zy, zscale );
84  } else
85  {
86  std::string msg = "\nDDLPgonGenerator::processElement was called with incorrect name of solid: " + name;
87  throwError( msg );
88  }
89  DDLSolid::setReference( nmspace, cpv );
90 
91  // clear out XYPoint element accumulator and ZXYSections
92  myXYPoints->clear();
93  myZXYSection->clear();
94  clear();
95 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:72
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
bool ev
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
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:753
tuple msg
Definition: mps_check.py:278
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:54
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:79
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:16