CMS 3D CMS Logo

DDLDivision.cc
Go to the documentation of this file.
18 
19 #include <cstddef>
20 #include <map>
21 #include <ostream>
22 #include <utility>
23 
24 class DDCompactView;
25 
27  : DDXMLElement( myreg )
28 {}
29 
30 void
32 {}
33 
34 void
36 {
38 
39  DDName parent = getDDName(nmspace, "parent");
41  size_t ax = 0;
42  while (DDAxesNames::name(DDAxes(ax)) != atts.find("axis")->second &&
43  DDAxesNames::name(DDAxes(ax)) != "undefined")
44  ++ax;
45 
46  DDLogicalPart lp(parent);
47  if ( !lp.isDefined().second || !lp.solid().isDefined().second ) {
48  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
49  em += " The solid of the parent logical part MUST be defined before the Division is made.";
50  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
51  em += "\n parent= " + parent.ns() + ":" + parent.name();
52  throwError (em);
53  }
54 
55  DDDivision div;
56 
57  if (atts.find("nReplicas") != atts.end()
58  && atts.find("width") != atts.end()
59  && atts.find("offset") != atts.end())
60  {
61  div = DDDivision(getDDName(nmspace)
62  , parent
63  , DDAxes(ax)
64  , int(ev.eval(nmspace, atts.find("nReplicas")->second))
65  , ev.eval(nmspace, atts.find("width")->second)
66  , ev.eval(nmspace, atts.find("offset")->second));
67  }
68  else if (atts.find("nReplicas") != atts.end()
69  && atts.find("offset") != atts.end())
70  {
71  div = DDDivision(getDDName(nmspace)
72  , parent
73  , DDAxes(ax)
74  , int(ev.eval(nmspace, atts.find("nReplicas")->second))
75  , ev.eval(nmspace, atts.find("offset")->second));
76  }
77  else if (atts.find("width") != atts.end()
78  && atts.find("offset") != atts.end())
79  {
80  div = DDDivision(getDDName(nmspace)
81  , parent
82  , DDAxes(ax)
83  , ev.eval(nmspace, atts.find("width")->second)
84  , ev.eval(nmspace, atts.find("offset")->second));
85  } else {
86  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
87  em += " Allowed combinations are attributes width&offset OR nReplicas&offset OR nReplicas&width&offset.";
88  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
89  em += "\n parent= " + parent.ns() + ":" + parent.name();
90  throwError (em);
91  }
92  DDDividedGeometryObject* dg = makeDivider(div, &cpv);
93  dg->execute();
94  delete dg;
95 
96  clear();
97 }
98 
101 {
102  DDDividedGeometryObject* dg = nullptr;
103 
104  switch (div.parent().solid().shape())
105  {
106  case DDSolidShape::ddbox:
107  if (div.axis() == DDAxes::x)
108  dg = new DDDividedBoxX(div,cpv);
109  else if (div.axis() == DDAxes::y)
110  dg = new DDDividedBoxY(div,cpv);
111  else if (div.axis() == DDAxes::z)
112  dg = new DDDividedBoxZ(div,cpv);
113  else {
114  std::string s = "DDLDivision can not divide a ";
115  s += DDSolidShapesName::name(div.parent().solid().shape());
116  s += " along axis " + DDAxesNames::name(div.axis());
117  s += ".";
118  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
119  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
120  throwError(s);
121  }
122  break;
123 
125  if (div.axis() == DDAxes::rho)
126  dg = new DDDividedTubsRho(div,cpv);
127  else if (div.axis() == DDAxes::phi)
128  dg = new DDDividedTubsPhi(div,cpv);
129  else if (div.axis() == DDAxes::z)
130  dg = new DDDividedTubsZ(div,cpv);
131  else {
132  std::string s = "DDLDivision can not divide a ";
133  s += DDSolidShapesName::name(div.parent().solid().shape());
134  s += " along axis " + DDAxesNames::name(div.axis());
135  s += ".";
136  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
137  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
138  throwError(s);
139  }
140  break;
141 
143  if (div.axis() == DDAxes::x)
144  dg = new DDDividedTrdX(div,cpv);
145  else if (div.axis() == DDAxes::y )
146  dg = new DDDividedTrdY(div,cpv);
147  else if (div.axis() == DDAxes::z )
148  dg = new DDDividedTrdZ(div,cpv);
149  else {
150  std::string s = "DDLDivision can not divide a ";
151  s += DDSolidShapesName::name(div.parent().solid().shape());
152  s += " along axis ";
153  s += DDAxesNames::name(div.axis());
154  s += ".";
155  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
156  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
157  throwError(s);
158  }
159  break;
160 
162  if (div.axis() == DDAxes::rho)
163  dg = new DDDividedConsRho(div,cpv);
164  else if (div.axis() == DDAxes::phi)
165  dg = new DDDividedConsPhi(div,cpv);
166  else if (div.axis() == DDAxes::z)
167  dg = new DDDividedConsZ(div,cpv);
168  else {
169  std::string s = "DDLDivision can not divide a ";
170  s += DDSolidShapesName::name(div.parent().solid().shape());
171  s += " along axis " + DDAxesNames::name(div.axis());
172  s += ".";
173  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
174  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
175  throwError(s);
176  }
177  break;
178 
180  if (div.axis() == DDAxes::rho)
181  dg = new DDDividedPolyconeRho(div,cpv);
182  else if (div.axis() == DDAxes::phi)
183  dg = new DDDividedPolyconePhi(div,cpv);
184  else if (div.axis() == DDAxes::z)
185  dg = new DDDividedPolyconeZ(div,cpv);
186  else {
187  std::string s = "DDLDivision can not divide a ";
188  s += DDSolidShapesName::name(div.parent().solid().shape());
189  s += " along axis ";
190  s += DDAxesNames::name(div.axis());
191  s += ".";
192  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
193  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
194  throwError(s);
195  }
196  break;
197 
199  if (div.axis() == DDAxes::rho)
200  dg = new DDDividedPolyhedraRho(div,cpv);
201  else if (div.axis() == DDAxes::phi)
202  dg = new DDDividedPolyhedraPhi(div,cpv);
203  else if (div.axis() == DDAxes::z)
204  dg = new DDDividedPolyhedraZ(div,cpv);
205  else {
206  std::string s = "DDLDivision can not divide a ";
207  s += DDSolidShapesName::name(div.parent().solid().shape());
208  s += " along axis ";
209  s += DDAxesNames::name(div.axis());
210  s += ".";
211  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
212  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
213  throwError(s);
214  }
215  break;
216 
219  std::string s = "ERROR: A Polycone or Polyhedra can not be divided on any axis if it's\n";
220  s += "original definition used r and z instead of ZSections. This has\n";
221  s += "not (yet) been implemented.";
222  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
223  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
224  }
225  break;
226 
227  case DDSolidShape::ddunion:
234  std::string s = "DDLDivision can not divide a ";
235  s += DDSolidShapesName::name(div.parent().solid().shape());
236  s += " at all (yet?). Requested axis was ";
237  s += DDAxesNames::name(div.axis());
238  s += ".\n";
239  throwError(s);
240  }
241  break;
242  default:
243  break;
244  }
245  return dg;
246 
247 }
def_type isDefined() const
Definition: DDBase.h:110
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
const N & name() const
Definition: DDBase.h:78
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.
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:102
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
const std::string & parent(void) const
access to parent element name
bool ev
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
DDDividedGeometryObject * makeDivider(const DDDivision &div, DDCompactView *cpv)
Definition: DDLDivision.cc:100
static const char *const name(DDSolidShape s)
Definition: DDSolidShapes.h:17
ClhepEvaluator & evaluator()
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:138
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDAxes axis() const
Definition: DDDivision.cc:66
DDAxes
analagous to geant4/source/global/HEPGeometry/include/geomdefs.hh
Definition: DDAxes.h:11
double eval(const std::string &ns, const std::string &expr)
The main class for processing parsed elements.
const DDLogicalPart & parent() const
Definition: DDDivision.cc:86
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:54
static const std::string name(const DDAxes &s)
Definition: DDAxes.cc:29
DDLDivision(DDLElementRegistry *myreg)
Definition: DDLDivision.cc:26
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
Definition: DDLDivision.cc:35
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:79
const std::string & name() const
Returns the name.
Definition: DDName.cc:88
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLDivision.cc:31