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 
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 
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 ";
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 ";
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 ";
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 ";
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 ";
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 ";
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 ";
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 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDAxes axis() const
Definition: DDDivision.cc:49
const DDLogicalPart & parent() const
Definition: DDDivision.cc:57
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
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
ClhepEvaluator & evaluator()
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
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
const N & name() const
Definition: DDBase.h:58
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:48
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
DDAxes
analagous to geant4/source/global/HEPGeometry/include/geomdefs.hh
Definition: DDAxes.h:11
const std::string & parent(void) const
access to parent element name
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:40
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
static const std::string name(const DDAxes &s)
Definition: DDAxes.cc:24
def_type isDefined() const
Definition: DDBase.h:89
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
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLDivision.cc:28
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:52