CMS 3D CMS Logo

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