CMS 3D CMS Logo

DDLMultiUnionSolid.cc
Go to the documentation of this file.
11 
12 class DDCompactView;
13 
15  : DDLSolid( myreg )
16 {}
17 
18 // Clear out rSolids.
19 void
21 {
22  myRegistry_->getElement( "rSolid" )->clear();
23 }
24 
25 // To process a MultiUnionSolid we should have in the meantime
26 // hit two rSolid calls and possibly one rRotation and one Translation.
27 // So, retrieve them and make the call to DDCore.
28 void
30 {
31  // new DDLMultiUnion will handle:
32  // <MultiUnionSolid> <rSolid...> <Translation...> <rRotation...> <rSolid...> <Translation...> <rRotation...> ... </MultiUnionSolid>
33 
34  auto myrSolids = myRegistry_->getElement( "rSolid" ); // get rSolid children
35  auto myTranslations = myRegistry_->getElement( "Translation" ); // get Translation child
36  auto myrRotations = myRegistry_->getElement( "rRotation" ); // get rRotation child
37 
40 
41  std::vector<DDSolid> solids;
42  std::vector<DDTranslation> translations;
43  std::vector<DDRotation> rotations;
44  for( unsigned int i = 0; i < myrSolids->size(); ++i )
45  {
46  DDName ddname = myrSolids->getDDName( nmspace, "name", i );
47  solids.emplace_back( DDSolid( ddname ));
48  }
49  for( unsigned int i = 0; i < myTranslations->size(); ++i )
50  {
51  double x = 0.0, y = 0.0, z = 0.0;
52  atts = myTranslations->getAttributeSet(i);
53  x = ev.eval(nmspace, atts.find("x")->second);
54  y = ev.eval(nmspace, atts.find("y")->second);
55  z = ev.eval(nmspace, atts.find("z")->second);
56  translations.emplace_back( DDTranslation( x, y, z ));
57  }
58  for( unsigned int i = 0; i < myrRotations->size(); ++i )
59  {
60  DDRotation ddrot = myrRotations->getDDName( nmspace, "name", i );
61  rotations.emplace_back( ddrot );
62  }
63 
64  // Basically check if there are rSolids or Translation or rRotation then we have
65  // should NOT have any of the attributes shown above.
66  if( myrSolids->size() == 0 )
67  {
68  std::string s( "DDLMultiUnionSolid did not find any solids with which to form a multi union solid." );
69  s += dumpMultiUnionSolid(name, nmspace);
70  throwError( s );
71  }
72 
73  DDSolid theSolid;
74 
75  if (name == "MultiUnionSolid") {
76  theSolid = DDSolidFactory::multiUnionSolid( getDDName( nmspace ),
77  solids,
78  translations,
79  rotations );
80  }
81  else {
82  throw cms::Exception("DDException") << "DDLMultiUnionSolid was asked to do something other than MultiUnion-?";
83  }
84 
85  DDLSolid::setReference( nmspace, cpv );
86 
87  // clear all "children" and attributes
88  myTranslations->clear();
89  myrRotations->clear();
90  myrSolids->clear();
91  clear();
92 }
93 
96 {
97  std::string s;
99 
100  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
101  s += ">\n";
102 
103  auto myrSolids = myRegistry_->getElement("rSolid"); // get rSolid children
104  auto myTranslations = myRegistry_->getElement("Translation"); // get Translation child
105  auto myrRotations = myRegistry_->getElement("rRotation"); // get rRotation child
106  if( myrSolids->size() > 0 )
107  {
108  for( size_t i = 0; i < myrSolids->size(); ++i )
109  {
110  atts = myrSolids->getAttributeSet(i);
111  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
112  }
113  }
114 
115  for( size_t i = 0; i < myTranslations->size(); ++i )
116  {
117  atts = myTranslations->getAttributeSet(i);
118  s+= "<Translation";
119  if (atts.find("x") != atts.end())
120  s+=" x=\"" + atts.find("x")->second + "\"";
121  if (atts.find("y") != atts.end())
122  s+= " y=\"" + atts.find("y")->second + "\"";
123  if (atts.find("z") != atts.end())
124  s+= " z=\"" + atts.find("z")->second + "\"";
125  s+="/>\n";
126  }
127 
128  for( size_t i = 0; i < myrRotations->size(); ++i )
129  {
130  atts = myrRotations->getAttributeSet(i);
131  if (atts.find("name") != atts.end())
132  {
133  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
134  }
135  s+= "</" + name + ">\n\n";
136  }
137 
138  return s;
139 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
static DDSolid multiUnionSolid(const DDName &name, const std::vector< DDSolid > &a, const std::vector< DDTranslation > &t, const std::vector< DDRotation > &r)
Definition: DDSolid.cc:887
DDLMultiUnionSolid(DDLElementRegistry *myreg)
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:73
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
bool ev
type of data representation of DDCompactView
Definition: DDCompactView.h:90
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
ClhepEvaluator & evaluator()
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
DDLSolid processes Box elements.
Definition: DDLSolid.h:30
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
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
std::string dumpMultiUnionSolid(const std::string &name, const std::string &nmspace)
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:80
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:17