CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
29 
32 
33  DDName parent = getDDName(nmspace, "parent");
35  size_t ax = 0;
36  while (DDAxesNames::name(DDAxes(ax)) != atts.find("axis")->second && DDAxesNames::name(DDAxes(ax)) != "undefined")
37  ++ax;
38 
39  DDLogicalPart lp(parent);
40  if (!lp.isDefined().second || !lp.solid().isDefined().second) {
41  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
42  em += " The solid of the parent logical part MUST be defined before the Division is made.";
43  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name();
44  em += "\n parent= " + parent.ns() + ":" + parent.name();
45  throwError(em);
46  }
47 
48  DDDivision div;
49 
50  if (atts.find("nReplicas") != atts.end() && atts.find("width") != atts.end() && atts.find("offset") != atts.end()) {
51  div = DDDivision(getDDName(nmspace),
52  parent,
53  DDAxes(ax),
54  int(ev.eval(nmspace, atts.find("nReplicas")->second)),
55  ev.eval(nmspace, atts.find("width")->second),
56  ev.eval(nmspace, atts.find("offset")->second));
57  } else if (atts.find("nReplicas") != atts.end() && atts.find("offset") != atts.end()) {
58  div = DDDivision(getDDName(nmspace),
59  parent,
60  DDAxes(ax),
61  int(ev.eval(nmspace, atts.find("nReplicas")->second)),
62  ev.eval(nmspace, atts.find("offset")->second));
63  } else if (atts.find("width") != atts.end() && atts.find("offset") != atts.end()) {
64  div = DDDivision(getDDName(nmspace),
65  parent,
66  DDAxes(ax),
67  ev.eval(nmspace, atts.find("width")->second),
68  ev.eval(nmspace, atts.find("offset")->second));
69  } else {
70  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
71  em += " Allowed combinations are attributes width&offset OR nReplicas&offset OR nReplicas&width&offset.";
72  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name();
73  em += "\n parent= " + parent.ns() + ":" + parent.name();
74  throwError(em);
75  }
76  DDDividedGeometryObject* dg = makeDivider(div, &cpv);
77  dg->execute();
78  delete dg;
79 
80  clear();
81 }
82 
84  DDDividedGeometryObject* dg = nullptr;
85 
86  switch (div.parent().solid().shape()) {
88  if (div.axis() == DDAxes::x)
89  dg = new DDDividedBoxX(div, cpv);
90  else if (div.axis() == DDAxes::y)
91  dg = new DDDividedBoxY(div, cpv);
92  else if (div.axis() == DDAxes::z)
93  dg = new DDDividedBoxZ(div, cpv);
94  else {
95  std::string s = "DDLDivision can not divide a ";
96  s += DDSolidShapesName::name(div.parent().solid().shape());
97  s += " along axis " + DDAxesNames::name(div.axis());
98  s += ".";
99  s += "\n name= " + div.name().ns() + ":" + div.name().name();
100  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
101  throwError(s);
102  }
103  break;
104 
106  if (div.axis() == DDAxes::rho)
107  dg = new DDDividedTubsRho(div, cpv);
108  else if (div.axis() == DDAxes::phi)
109  dg = new DDDividedTubsPhi(div, cpv);
110  else if (div.axis() == DDAxes::z)
111  dg = new DDDividedTubsZ(div, cpv);
112  else {
113  std::string s = "DDLDivision can not divide a ";
114  s += DDSolidShapesName::name(div.parent().solid().shape());
115  s += " along axis " + DDAxesNames::name(div.axis());
116  s += ".";
117  s += "\n name= " + div.name().ns() + ":" + div.name().name();
118  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
119  throwError(s);
120  }
121  break;
122 
124  if (div.axis() == DDAxes::x)
125  dg = new DDDividedTrdX(div, cpv);
126  else if (div.axis() == DDAxes::y)
127  dg = new DDDividedTrdY(div, cpv);
128  else if (div.axis() == DDAxes::z)
129  dg = new DDDividedTrdZ(div, cpv);
130  else {
131  std::string s = "DDLDivision can not divide a ";
132  s += DDSolidShapesName::name(div.parent().solid().shape());
133  s += " along axis ";
134  s += 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::rho)
144  dg = new DDDividedConsRho(div, cpv);
145  else if (div.axis() == DDAxes::phi)
146  dg = new DDDividedConsPhi(div, cpv);
147  else if (div.axis() == DDAxes::z)
148  dg = new DDDividedConsZ(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 " + DDAxesNames::name(div.axis());
153  s += ".";
154  s += "\n name= " + div.name().ns() + ":" + div.name().name();
155  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
156  throwError(s);
157  }
158  break;
159 
161  if (div.axis() == DDAxes::rho)
162  dg = new DDDividedPolyconeRho(div, cpv);
163  else if (div.axis() == DDAxes::phi)
164  dg = new DDDividedPolyconePhi(div, cpv);
165  else if (div.axis() == DDAxes::z)
166  dg = new DDDividedPolyconeZ(div, cpv);
167  else {
168  std::string s = "DDLDivision can not divide a ";
169  s += DDSolidShapesName::name(div.parent().solid().shape());
170  s += " along axis ";
171  s += 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 DDDividedPolyhedraRho(div, cpv);
182  else if (div.axis() == DDAxes::phi)
183  dg = new DDDividedPolyhedraPhi(div, cpv);
184  else if (div.axis() == DDAxes::z)
185  dg = new DDDividedPolyhedraZ(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 
200  std::string s = "ERROR: A Polycone or Polyhedra can not be divided on any axis if it's\n";
201  s += "original definition used r and z instead of ZSections. This has\n";
202  s += "not (yet) been implemented.";
203  s += "\n name= " + div.name().ns() + ":" + div.name().name();
204  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
205  } break;
206 
214  std::string s = "DDLDivision can not divide a ";
215  s += DDSolidShapesName::name(div.parent().solid().shape());
216  s += " at all (yet?). Requested axis was ";
217  s += DDAxesNames::name(div.axis());
218  s += ".\n";
219  throwError(s);
220  } break;
221  default:
222  break;
223  }
224  return dg;
225 }
def_type isDefined() const
Definition: DDBase.h:90
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
const N & name() const
Definition: DDBase.h:59
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.
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:52
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
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:81
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
DDDividedGeometryObject * makeDivider(const DDDivision &div, DDCompactView *cpv)
Definition: DDLDivision.cc:83
static const char *const name(DDSolidShape s)
Definition: DDSolidShapes.h:33
ClhepEvaluator & evaluator()
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
static const std::string name(const DDAxes &s)
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
DDAxes axis() const
Definition: DDDivision.cc:49
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:57
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:40
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:30
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:56
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLDivision.cc:28