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  DDCompactView& cpv )
22 {
23  myRegistry_->getElement( "rSolid" )->clear();
24 }
25 
26 // To process a MultiUnionSolid we should have in the meantime
27 // hit two rSolid calls and possibly one rRotation and one Translation.
28 // So, retrieve them and make the call to DDCore.
29 void
31  DDCompactView& cpv )
32 {
33  // new DDLMultiUnion will handle:
34  // <MultiUnionSolid> <rSolid...> <Translation...> <rRotation...> <rSolid...> <Translation...> <rRotation...> ... </MultiUnionSolid>
35 
36  auto myrSolids = myRegistry_->getElement( "rSolid" ); // get rSolid children
37  auto myTranslations = myRegistry_->getElement( "Translation" ); // get Translation child
38  auto myrRotations = myRegistry_->getElement( "rRotation" ); // get rRotation child
39 
42 
43  std::vector<DDSolid> solids;
44  std::vector<DDTranslation> translations;
45  std::vector<DDRotation> rotations;
46  for( unsigned int i = 0; i < myrSolids->size(); ++i )
47  {
48  DDName ddname = myrSolids->getDDName( nmspace, "name", i );
49  solids.emplace_back( DDSolid( ddname ));
50  }
51  for( unsigned int i = 0; i < myTranslations->size(); ++i )
52  {
53  double x = 0.0, y = 0.0, z = 0.0;
54  atts = myTranslations->getAttributeSet(i);
55  x = ev.eval(nmspace, atts.find("x")->second);
56  y = ev.eval(nmspace, atts.find("y")->second);
57  z = ev.eval(nmspace, atts.find("z")->second);
58  translations.emplace_back( DDTranslation( x, y, z ));
59  }
60  for( unsigned int i = 0; i < myrRotations->size(); ++i )
61  {
62  DDRotation ddrot = myrRotations->getDDName( nmspace, "name", i );
63  rotations.emplace_back( ddrot );
64  }
65 
66  // Basically check if there are rSolids or Translation or rRotation then we have
67  // should NOT have any of the attributes shown above.
68  if( myrSolids->size() == 0 )
69  {
70  std::string s( "DDLMultiUnionSolid did not find any solids with which to form a multi union solid." );
71  s += dumpMultiUnionSolid(name, nmspace);
72  throwError( s );
73  }
74 
75  DDSolid theSolid;
76 
77  if (name == "MultiUnionSolid") {
78  theSolid = DDSolidFactory::multiUnionSolid( getDDName( nmspace ),
79  solids,
80  translations,
81  rotations );
82  }
83  else {
84  throw cms::Exception("DDException") << "DDLMultiUnionSolid was asked to do something other than MultiUnion-?";
85  }
86 
87  DDLSolid::setReference( nmspace, cpv );
88 
89  // clear all "children" and attributes
90  myTranslations->clear();
91  myrRotations->clear();
92  myrSolids->clear();
93  clear();
94 }
95 
98 {
99  std::string s;
101 
102  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
103  s += ">\n";
104 
105  auto myrSolids = myRegistry_->getElement("rSolid"); // get rSolid children
106  auto myTranslations = myRegistry_->getElement("Translation"); // get Translation child
107  auto myrRotations = myRegistry_->getElement("rRotation"); // get rRotation child
108  if( myrSolids->size() > 0 )
109  {
110  for( size_t i = 0; i < myrSolids->size(); ++i )
111  {
112  atts = myrSolids->getAttributeSet(i);
113  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
114  }
115  }
116 
117  for( size_t i = 0; i < myTranslations->size(); ++i )
118  {
119  atts = myTranslations->getAttributeSet(i);
120  s+= "<Translation";
121  if (atts.find("x") != atts.end())
122  s+=" x=\"" + atts.find("x")->second + "\"";
123  if (atts.find("y") != atts.end())
124  s+= " y=\"" + atts.find("y")->second + "\"";
125  if (atts.find("z") != atts.end())
126  s+= " z=\"" + atts.find("z")->second + "\"";
127  s+="/>\n";
128  }
129 
130  for( size_t i = 0; i < myrRotations->size(); ++i )
131  {
132  atts = myrRotations->getAttributeSet(i);
133  if (atts.find("name") != atts.end())
134  {
135  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
136  }
137  s+= "</" + name + ">\n\n";
138  }
139 
140  return s;
141 }
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:890
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:72
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:67
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:54
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:79
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:16