CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLDivision.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLDivision.cc - description
3  -------------------
4  begin : Friday, April 23, 2004
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * *
12  ***************************************************************************/
13 
21 
28 
30 
32  : DDXMLElement( myreg )
33 {}
34 
36 {}
37 
38 void
40 {}
41 
42 void
44 {
45  DCOUT_V('P', "DDLDivision::processElement started");
46 
48 
49  DDName parent = getDDName(nmspace, "parent");
51  size_t ax = 0;
52  while (DDAxesNames::name(DDAxes(ax)) != atts.find("axis")->second &&
53  DDAxesNames::name(DDAxes(ax)) != "undefined")
54  ++ax;
55 
56  DDLogicalPart lp(parent);
57  if ( !lp.isDefined().second || !lp.solid().isDefined().second ) {
58  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
59  em += " The solid of the parent logical part MUST be defined before the Division is made.";
60  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
61  em += "\n parent= " + parent.ns() + ":" + parent.name();
62  throwError (em);
63  }
64 
65  DDDivision div;
66 
67  if (atts.find("nReplicas") != atts.end()
68  && atts.find("width") != 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("width")->second)
76  , ev.eval(nmspace, atts.find("offset")->second));
77  }
78  else if (atts.find("nReplicas") != atts.end()
79  && atts.find("offset") != atts.end())
80  {
81  div = DDDivision(getDDName(nmspace)
82  , parent
83  , DDAxes(ax)
84  , int(ev.eval(nmspace, atts.find("nReplicas")->second))
85  , ev.eval(nmspace, atts.find("offset")->second));
86  }
87  else if (atts.find("width") != atts.end()
88  && atts.find("offset") != atts.end())
89  {
90  DCOUT_V ('D', " width = " << ev.eval(nmspace, atts.find("width")->second) << std::endl);
91  DCOUT_V ('D', " offset = " << ev.eval(nmspace, atts.find("offset")->second) << std::endl);
92  div = DDDivision(getDDName(nmspace)
93  , parent
94  , DDAxes(ax)
95  , ev.eval(nmspace, atts.find("width")->second)
96  , ev.eval(nmspace, atts.find("offset")->second));
97  } else {
98  std::string em("DetectorDescription Parser DDLDivision::processElement(...) failed.");
99  em += " Allowed combinations are attributes width&offset OR nReplicas&offset OR nReplicas&width&offset.";
100  em += "\n name= " + getDDName(nmspace).ns() + ":" + getDDName(nmspace).name() ;
101  em += "\n parent= " + parent.ns() + ":" + parent.name();
102  throwError (em);
103  }
104  DDDividedGeometryObject* dg = makeDivider(div, &cpv);
105  dg->execute();
106  delete dg;
107 
108  clear();
109 
110  DCOUT_V('P', "DDLDivision::processElement completed");
111 }
112 
115 {
117 
118  switch (div.parent().solid().shape())
119  {
120  case ddbox:
121  if (div.axis() == x)
122  dg = new DDDividedBoxX(div,cpv);
123  else if (div.axis() == y)
124  dg = new DDDividedBoxY(div,cpv);
125  else if (div.axis() == z)
126  dg = new DDDividedBoxZ(div,cpv);
127  else {
128  std::string s = "DDLDivision can not divide a ";
129  s += DDSolidShapesName::name(div.parent().solid().shape());
130  s += " along axis " + DDAxesNames::name(div.axis());
131  s += ".";
132  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
133  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
134  throwError(s);
135  }
136  break;
137 
138  case ddtubs:
139  if (div.axis() == rho)
140  dg = new DDDividedTubsRho(div,cpv);
141  else if (div.axis() == phi)
142  dg = new DDDividedTubsPhi(div,cpv);
143  else if (div.axis() == z)
144  dg = new DDDividedTubsZ(div,cpv);
145  else {
146  std::string s = "DDLDivision can not divide a ";
147  s += DDSolidShapesName::name(div.parent().solid().shape());
148  s += " along axis " + DDAxesNames::name(div.axis());
149  s += ".";
150  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
151  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
152  throwError(s);
153  }
154  break;
155 
156  case ddtrap:
157  if (div.axis() == x)
158  dg = new DDDividedTrdX(div,cpv);
159  else if (div.axis() == y )
160  dg = new DDDividedTrdY(div,cpv);
161  else if (div.axis() == z )
162  dg = new DDDividedTrdZ(div,cpv);
163  else {
164  std::string s = "DDLDivision can not divide a ";
165  s += DDSolidShapesName::name(div.parent().solid().shape());
166  s += " along axis ";
167  s += DDAxesNames::name(div.axis());
168  s += ".";
169  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
170  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
171  throwError(s);
172  }
173  break;
174 
175  case ddcons:
176  if (div.axis() == rho)
177  dg = new DDDividedConsRho(div,cpv);
178  else if (div.axis() == phi)
179  dg = new DDDividedConsPhi(div,cpv);
180  else if (div.axis() == z)
181  dg = new DDDividedConsZ(div,cpv);
182  else {
183  std::string s = "DDLDivision can not divide a ";
184  s += DDSolidShapesName::name(div.parent().solid().shape());
185  s += " along axis " + DDAxesNames::name(div.axis());
186  s += ".";
187  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
188  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
189  throwError(s);
190  }
191  break;
192 
193  case ddpolycone_rrz:
194  if (div.axis() == rho)
195  dg = new DDDividedPolyconeRho(div,cpv);
196  else if (div.axis() == phi)
197  dg = new DDDividedPolyconePhi(div,cpv);
198  else if (div.axis() == z)
199  dg = new DDDividedPolyconeZ(div,cpv);
200  else {
201  std::string s = "DDLDivision can not divide a ";
202  s += DDSolidShapesName::name(div.parent().solid().shape());
203  s += " along axis ";
204  s += DDAxesNames::name(div.axis());
205  s += ".";
206  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
207  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
208  throwError(s);
209  }
210  break;
211 
212  case ddpolyhedra_rrz:
213  if (div.axis() == rho)
214  dg = new DDDividedPolyhedraRho(div,cpv);
215  else if (div.axis() == phi)
216  dg = new DDDividedPolyhedraPhi(div,cpv);
217  else if (div.axis() == z)
218  dg = new DDDividedPolyhedraZ(div,cpv);
219  else {
220  std::string s = "DDLDivision can not divide a ";
221  s += DDSolidShapesName::name(div.parent().solid().shape());
222  s += " along axis ";
223  s += DDAxesNames::name(div.axis());
224  s += ".";
225  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
226  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
227  throwError(s);
228  }
229  break;
230 
231  case ddpolycone_rz:
232  case ddpolyhedra_rz: {
233  std::string s = "ERROR: A Polycone or Polyhedra can not be divided on any axis if it's\n";
234  s += "original definition used r and z instead of ZSections. This has\n";
235  s += "not (yet) been implemented.";
236  s += "\n name= " + div.name().ns() + ":" + div.name().name() ;
237  s += "\n parent= " + div.parent().name().ns() + ":" + div.parent().name().name();
238  }
239  break;
240 
241  case ddunion:
242  case ddsubtraction:
243  case ddintersection:
244  case ddreflected:
245  case ddshapeless:
246  case ddpseudotrap:
247  case ddtrunctubs:
248  case dd_not_init: {
249  std::string s = "DDLDivision can not divide a ";
250  s += DDSolidShapesName::name(div.parent().solid().shape());
251  s += " at all (yet?). Requested axis was ";
252  s += DDAxesNames::name(div.axis());
253  s += ".\n";
254  throwError(s);
255  }
256  break;
257  default:
258  break;
259  }
260  return dg;
261 
262 }
def_type isDefined() const
Definition: DDBase.h:115
const N & name() const
Definition: DDBase.h:82
Definition: DDAxes.h:10
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:79
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:101
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:18
#define NULL
Definition: scimark2.h:8
const std::string & parent(void) const
access to parent element name
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:77
float float float z
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:55
DDDividedGeometryObject * makeDivider(const DDDivision &div, DDCompactView *cpv)
Definition: DDLDivision.cc:114
static value_type & instance()
static const char * name(DDSolidShape s)
Definition: DDSolidShapes.h:21
Interface of an Expression Evaluator.
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:144
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
virtual double eval(const std::string &ns, const std::string &expr)=0
evaluate an expression expr inside the local namespace
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
Definition: DDLDivision.cc:39
DDAxes axis() const
Definition: DDDivision.cc:85
~DDLDivision(void)
Destructor.
Definition: DDLDivision.cc:35
DDAxes
analagous to geant4/source/global/HEPGeometry/include/geomdefs.hh
Definition: DDAxes.h:10
The main class for processing parsed elements.
const DDLogicalPart & parent() const
Definition: DDDivision.cc:105
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:61
Definition: DDAxes.h:10
static const std::string name(const DDAxes &s)
Definition: DDAxes.cc:37
DDLDivision(DDLElementRegistry *myreg)
Constructor.
Definition: DDLDivision.cc:31
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:86
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
Definition: DDLDivision.cc:43
Definition: DDAxes.h:10