Geant4  10.02.p02
G4GDMLReadSolids.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4GDMLReadSolids.cc 97543 2016-06-03 15:49:14Z gcosmo $
27 //
28 // class G4GDMLReadSolids Implementation
29 //
30 // Original author: Zoltan Torzsok, November 2007
31 //
32 // --------------------------------------------------------------------
33 
34 #include "G4GDMLReadSolids.hh"
35 #include "G4Box.hh"
36 #include "G4Cons.hh"
37 #include "G4Ellipsoid.hh"
38 #include "G4EllipticalCone.hh"
39 #include "G4EllipticalTube.hh"
40 #include "G4Hype.hh"
41 #include "G4IntersectionSolid.hh"
42 #include "G4Orb.hh"
43 #include "G4Para.hh"
44 #include "G4Paraboloid.hh"
45 #include "G4Polycone.hh"
46 #include "G4GenericPolycone.hh"
47 #include "G4Polyhedra.hh"
48 #include "G4QuadrangularFacet.hh"
49 #include "G4ReflectedSolid.hh"
50 #include "G4Sphere.hh"
51 #include "G4SolidStore.hh"
52 #include "G4SubtractionSolid.hh"
53 #include "G4GenericTrap.hh"
54 #include "G4TessellatedSolid.hh"
55 #include "G4Tet.hh"
56 #include "G4Torus.hh"
57 #include "G4Transform3D.hh"
58 #include "G4Trap.hh"
59 #include "G4Trd.hh"
60 #include "G4TriangularFacet.hh"
61 #include "G4Tubs.hh"
62 #include "G4CutTubs.hh"
63 #include "G4TwistedBox.hh"
64 #include "G4TwistedTrap.hh"
65 #include "G4TwistedTrd.hh"
66 #include "G4TwistedTubs.hh"
67 #include "G4UnionSolid.hh"
68 #include "G4OpticalSurface.hh"
69 #include "G4UnitsTable.hh"
70 #include "G4SurfaceProperty.hh"
71 
73 {
74 }
75 
77 {
78 }
79 
81 BooleanRead(const xercesc::DOMElement* const booleanElement, const BooleanOp op)
82 {
83  G4String name;
84  G4String first;
85  G4String scnd;
86  G4ThreeVector position(0.0,0.0,0.0);
87  G4ThreeVector rotation(0.0,0.0,0.0);
88  G4ThreeVector firstposition(0.0,0.0,0.0);
89  G4ThreeVector firstrotation(0.0,0.0,0.0);
90 
91  const xercesc::DOMNamedNodeMap* const attributes
92  = booleanElement->getAttributes();
93  XMLSize_t attributeCount = attributes->getLength();
94 
95  for (XMLSize_t attribute_index=0;
96  attribute_index<attributeCount; attribute_index++)
97  {
98  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
99 
100  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
101  { continue; }
102 
103  const xercesc::DOMAttr* const attribute
104  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
105  if (!attribute)
106  {
107  G4Exception("G4GDMLReadSolids::BooleanRead()",
108  "InvalidRead", FatalException, "No attribute found!");
109  return;
110  }
111  const G4String attName = Transcode(attribute->getName());
112  const G4String attValue = Transcode(attribute->getValue());
113 
114  if (attName=="name") { name = GenerateName(attValue); }
115  }
116 
117  for (xercesc::DOMNode* iter = booleanElement->getFirstChild();
118  iter != 0;iter = iter->getNextSibling())
119  {
120  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
121 
122  const xercesc::DOMElement* const child
123  = dynamic_cast<xercesc::DOMElement*>(iter);
124  if (!child)
125  {
126  G4Exception("G4GDMLReadSolids::BooleanRead()",
127  "InvalidRead", FatalException, "No child found!");
128  return;
129  }
130  const G4String tag = Transcode(child->getTagName());
131 
132  if (tag=="first") { first = RefRead(child); } else
133  if (tag=="second") { scnd = RefRead(child); } else
134  if (tag=="position") { VectorRead(child,position); } else
135  if (tag=="rotation") { VectorRead(child,rotation); } else
136  if (tag=="positionref")
137  { position = GetPosition(GenerateName(RefRead(child))); } else
138  if (tag=="rotationref")
139  { rotation = GetRotation(GenerateName(RefRead(child))); } else
140  if (tag=="firstposition") { VectorRead(child,firstposition); } else
141  if (tag=="firstrotation") { VectorRead(child,firstrotation); } else
142  if (tag=="firstpositionref")
143  { firstposition = GetPosition(GenerateName(RefRead(child))); } else
144  if (tag=="firstrotationref")
145  { firstrotation = GetRotation(GenerateName(RefRead(child))); }
146  else
147  {
148  G4String error_msg = "Unknown tag in boolean solid: " + tag;
149  G4Exception("G4GDMLReadSolids::BooleanRead()", "ReadError",
150  FatalException, error_msg);
151  }
152  }
153 
154  G4VSolid* firstSolid = GetSolid(GenerateName(first));
155  G4VSolid* secondSolid = GetSolid(GenerateName(scnd));
156 
157  G4Transform3D transform(GetRotationMatrix(rotation),position);
158 
159  if (( (firstrotation.x()!=0.0) || (firstrotation.y()!=0.0)
160  || (firstrotation.z()!=0.0))
161  || ( (firstposition.x()!=0.0) || (firstposition.y()!=0.0)
162  || (firstposition.z()!=0.0)))
163  {
164  G4Transform3D firsttransform(GetRotationMatrix(firstrotation),
165  firstposition);
166  firstSolid = new G4DisplacedSolid(GenerateName("displaced_"+first),
167  firstSolid, firsttransform);
168  }
169 
170  if (op==UNION)
171  { new G4UnionSolid(name,firstSolid,secondSolid,transform); } else
172  if (op==SUBTRACTION)
173  { new G4SubtractionSolid(name,firstSolid,secondSolid,transform); } else
174  if (op==INTERSECTION)
175  { new G4IntersectionSolid(name,firstSolid,secondSolid,transform); }
176 }
177 
178 void G4GDMLReadSolids::BoxRead(const xercesc::DOMElement* const boxElement)
179 {
180  G4String name;
181  G4double lunit = 1.0;
182  G4double x = 0.0;
183  G4double y = 0.0;
184  G4double z = 0.0;
185 
186  const xercesc::DOMNamedNodeMap* const attributes
187  = boxElement->getAttributes();
188  XMLSize_t attributeCount = attributes->getLength();
189 
190  for (XMLSize_t attribute_index=0;
191  attribute_index<attributeCount; attribute_index++)
192  {
193  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
194 
195  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
196  { continue; }
197 
198  const xercesc::DOMAttr* const attribute
199  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
200  if (!attribute)
201  {
202  G4Exception("G4GDMLReadSolids::BoxRead()",
203  "InvalidRead", FatalException, "No attribute found!");
204  return;
205  }
206  const G4String attName = Transcode(attribute->getName());
207  const G4String attValue = Transcode(attribute->getValue());
208 
209  if (attName=="name") { name = GenerateName(attValue); } else
210  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
211  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
212  G4Exception("G4GDMLReadSolids::BoxRead()", "InvalidRead",
213  FatalException, "Invalid unit for length!"); }
214  }
215  else
216  if (attName=="x") { x = eval.Evaluate(attValue); } else
217  if (attName=="y") { y = eval.Evaluate(attValue); } else
218  if (attName=="z") { z = eval.Evaluate(attValue); }
219  }
220 
221  x *= 0.5*lunit;
222  y *= 0.5*lunit;
223  z *= 0.5*lunit;
224 
225  new G4Box(name,x,y,z);
226 }
227 
228 void G4GDMLReadSolids::ConeRead(const xercesc::DOMElement* const coneElement)
229 {
230  G4String name;
231  G4double lunit = 1.0;
232  G4double aunit = 1.0;
233  G4double rmin1 = 0.0;
234  G4double rmax1 = 0.0;
235  G4double rmin2 = 0.0;
236  G4double rmax2 = 0.0;
237  G4double z = 0.0;
238  G4double startphi = 0.0;
239  G4double deltaphi = 0.0;
240 
241  const xercesc::DOMNamedNodeMap* const attributes
242  = coneElement->getAttributes();
243  XMLSize_t attributeCount = attributes->getLength();
244 
245  for (XMLSize_t attribute_index=0;
246  attribute_index<attributeCount; attribute_index++)
247  {
248  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
249 
250  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
251  { continue; }
252 
253  const xercesc::DOMAttr* const attribute
254  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
255  if (!attribute)
256  {
257  G4Exception("G4GDMLReadSolids::ConeRead()",
258  "InvalidRead", FatalException, "No attribute found!");
259  return;
260  }
261  const G4String attName = Transcode(attribute->getName());
262  const G4String attValue = Transcode(attribute->getValue());
263 
264  if (attName=="name") { name = GenerateName(attValue); } else
265  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
266  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
267  G4Exception("G4GDMLReadSolids::ConeRead()", "InvalidRead",
268  FatalException, "Invalid unit for length!"); }
269  } else
270  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
271  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
272  G4Exception("G4GDMLReadSolids::ConeRead()", "InvalidRead",
273  FatalException, "Invalid unit for angle!"); }
274  } else
275  if (attName=="rmin1") { rmin1 = eval.Evaluate(attValue); } else
276  if (attName=="rmax1") { rmax1 = eval.Evaluate(attValue); } else
277  if (attName=="rmin2") { rmin2 = eval.Evaluate(attValue); } else
278  if (attName=="rmax2") { rmax2 = eval.Evaluate(attValue); } else
279  if (attName=="z") { z = eval.Evaluate(attValue); } else
280  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
281  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); }
282  }
283 
284  rmin1 *= lunit;
285  rmax1 *= lunit;
286  rmin2 *= lunit;
287  rmax2 *= lunit;
288  z *= 0.5*lunit;
289  startphi *= aunit;
290  deltaphi *= aunit;
291 
292  new G4Cons(name,rmin1,rmax1,rmin2,rmax2,z,startphi,deltaphi);
293 }
294 
296 ElconeRead(const xercesc::DOMElement* const elconeElement)
297 {
298  G4String name;
299  G4double lunit = 1.0;
300  G4double dx = 0.0;
301  G4double dy = 0.0;
302  G4double zmax = 0.0;
303  G4double zcut = 0.0;
304 
305  const xercesc::DOMNamedNodeMap* const attributes
306  = elconeElement->getAttributes();
307  XMLSize_t attributeCount = attributes->getLength();
308 
309  for (XMLSize_t attribute_index=0;
310  attribute_index<attributeCount; attribute_index++)
311  {
312  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
313 
314  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
315  { continue; }
316 
317  const xercesc::DOMAttr* const attribute
318  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
319  if (!attribute)
320  {
321  G4Exception("G4GDMLReadSolids::ElconeRead()",
322  "InvalidRead", FatalException, "No attribute found!");
323  return;
324  }
325  const G4String attName = Transcode(attribute->getName());
326  const G4String attValue = Transcode(attribute->getValue());
327 
328  if (attName=="name") { name = GenerateName(attValue); } else
329  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
330  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
331  G4Exception("G4GDMLReadSolids::ElconeRead()", "InvalidRead",
332  FatalException, "Invalid unit for length!"); }
333  } else
334  if (attName=="dx") { dx = eval.Evaluate(attValue); } else
335  if (attName=="dy") { dy = eval.Evaluate(attValue); } else
336  if (attName=="zmax") { zmax = eval.Evaluate(attValue); } else
337  if (attName=="zcut") { zcut = eval.Evaluate(attValue); }
338  }
339 
340  zmax *= lunit;
341  zcut *= lunit;
342 
343  new G4EllipticalCone(name,dx,dy,zmax,zcut);
344 }
345 
347 EllipsoidRead(const xercesc::DOMElement* const ellipsoidElement)
348 {
349  G4String name;
350  G4double lunit = 1.0;
351  G4double ax = 0.0;
352  G4double by = 0.0;
353  G4double cz = 0.0;
354  G4double zcut1 = 0.0;
355  G4double zcut2 = 0.0;
356 
357  const xercesc::DOMNamedNodeMap* const attributes
358  = ellipsoidElement->getAttributes();
359  XMLSize_t attributeCount = attributes->getLength();
360 
361  for (XMLSize_t attribute_index=0;
362  attribute_index<attributeCount; attribute_index++)
363  {
364  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
365 
366  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
367  { continue; }
368 
369  const xercesc::DOMAttr* const attribute
370  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
371  if (!attribute)
372  {
373  G4Exception("G4GDMLReadSolids::EllipsoidRead()",
374  "InvalidRead", FatalException, "No attribute found!");
375  return;
376  }
377  const G4String attName = Transcode(attribute->getName());
378  const G4String attValue = Transcode(attribute->getValue());
379 
380  if (attName=="name") { name = GenerateName(attValue); } else
381  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
382  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
383  G4Exception("G4GDMLReadSolids::EllipsoidRead()", "InvalidRead",
384  FatalException, "Invalid unit for length!"); }
385  } else
386  if (attName=="ax") { ax = eval.Evaluate(attValue); } else
387  if (attName=="by") { by = eval.Evaluate(attValue); } else
388  if (attName=="cz") { cz = eval.Evaluate(attValue); } else
389  if (attName=="zcut1") { zcut1 = eval.Evaluate(attValue); } else
390  if (attName=="zcut2") { zcut2 = eval.Evaluate(attValue); }
391  }
392 
393  ax *= lunit;
394  by *= lunit;
395  cz *= lunit;
396  zcut1 *= lunit;
397  zcut2 *= lunit;
398 
399  new G4Ellipsoid(name,ax,by,cz,zcut1,zcut2);
400 }
401 
403 EltubeRead(const xercesc::DOMElement* const eltubeElement)
404 {
405  G4String name;
406  G4double lunit = 1.0;
407  G4double dx = 0.0;
408  G4double dy = 0.0;
409  G4double dz = 0.0;
410 
411  const xercesc::DOMNamedNodeMap* const attributes
412  = eltubeElement->getAttributes();
413  XMLSize_t attributeCount = attributes->getLength();
414 
415  for (XMLSize_t attribute_index=0;
416  attribute_index<attributeCount; attribute_index++)
417  {
418  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
419 
420  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
421  { continue; }
422 
423  const xercesc::DOMAttr* const attribute
424  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
425  if (!attribute)
426  {
427  G4Exception("G4GDMLReadSolids::EltubeRead()",
428  "InvalidRead", FatalException, "No attribute found!");
429  return;
430  }
431  const G4String attName = Transcode(attribute->getName());
432  const G4String attValue = Transcode(attribute->getValue());
433 
434  if (attName=="name") { name = GenerateName(attValue); } else
435  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
436  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
437  G4Exception("G4GDMLReadSolids::EltubeRead()", "InvalidRead",
438  FatalException, "Invalid unit for length!"); }
439  } else
440  if (attName=="dx") { dx = eval.Evaluate(attValue); } else
441  if (attName=="dy") { dy = eval.Evaluate(attValue); } else
442  if (attName=="dz") { dz = eval.Evaluate(attValue); }
443  }
444 
445  dx *= lunit;
446  dy *= lunit;
447  dz *= lunit;
448 
449  new G4EllipticalTube(name,dx,dy,dz);
450 }
451 
452 void G4GDMLReadSolids::XtruRead(const xercesc::DOMElement* const xtruElement)
453 {
454  G4String name;
455  G4double lunit = 1.0;
456 
457  const xercesc::DOMNamedNodeMap* const attributes
458  = xtruElement->getAttributes();
459  XMLSize_t attributeCount = attributes->getLength();
460 
461  for (XMLSize_t attribute_index=0;
462  attribute_index<attributeCount; attribute_index++)
463  {
464  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
465 
466  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
467  { continue; }
468 
469  const xercesc::DOMAttr* const attribute
470  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
471  if (!attribute)
472  {
473  G4Exception("G4GDMLReadSolids::XtruRead()",
474  "InvalidRead", FatalException, "No attribute found!");
475  return;
476  }
477  const G4String attName = Transcode(attribute->getName());
478  const G4String attValue = Transcode(attribute->getValue());
479 
480  if (attName=="name") { name = GenerateName(attValue); } else
481  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
482  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
483  G4Exception("G4GDMLReadSolids::XtruRead()", "InvalidRead",
484  FatalException, "Invalid unit for length!"); }
485  }
486  }
487 
488  std::vector<G4TwoVector> twoDimVertexList;
489  std::vector<G4ExtrudedSolid::ZSection> sectionList;
490 
491  for (xercesc::DOMNode* iter = xtruElement->getFirstChild();
492  iter != 0; iter = iter->getNextSibling())
493  {
494  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
495 
496  const xercesc::DOMElement* const child
497  = dynamic_cast<xercesc::DOMElement*>(iter);
498  if (!child)
499  {
500  G4Exception("G4GDMLReadSolids::XtruRead()",
501  "InvalidRead", FatalException, "No child found!");
502  return;
503  }
504  const G4String tag = Transcode(child->getTagName());
505 
506  if (tag=="twoDimVertex")
507  { twoDimVertexList.push_back(TwoDimVertexRead(child,lunit)); } else
508  if (tag=="section")
509  { sectionList.push_back(SectionRead(child,lunit)); }
510  }
511 
512  new G4ExtrudedSolid(name,twoDimVertexList,sectionList);
513 }
514 
515 void G4GDMLReadSolids::HypeRead(const xercesc::DOMElement* const hypeElement)
516 {
517  G4String name;
518  G4double lunit = 1.0;
519  G4double aunit = 1.0;
520  G4double rmin = 0.0;
521  G4double rmax = 0.0;
522  G4double inst = 0.0;
523  G4double outst = 0.0;
524  G4double z = 0.0;
525 
526  const xercesc::DOMNamedNodeMap* const attributes
527  = hypeElement->getAttributes();
528  XMLSize_t attributeCount = attributes->getLength();
529 
530  for (XMLSize_t attribute_index=0;
531  attribute_index<attributeCount; attribute_index++)
532  {
533  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
534 
535  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
536  { continue; }
537 
538  const xercesc::DOMAttr* const attribute
539  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
540  if (!attribute)
541  {
542  G4Exception("G4GDMLReadSolids::HypeRead()",
543  "InvalidRead", FatalException, "No attribute found!");
544  return;
545  }
546  const G4String attName = Transcode(attribute->getName());
547  const G4String attValue = Transcode(attribute->getValue());
548 
549  if (attName=="name") { name = GenerateName(attValue); } else
550  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
551  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
552  G4Exception("G4GDMLReadSolids::HypeRead()", "InvalidRead",
553  FatalException, "Invalid unit for length!"); }
554  } else
555  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
556  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
557  G4Exception("G4GDMLReadSolids::HypeRead()", "InvalidRead",
558  FatalException, "Invalid unit for angle!"); }
559  } else
560  if (attName=="rmin") { rmin = eval.Evaluate(attValue); } else
561  if (attName=="rmax") { rmax = eval.Evaluate(attValue); } else
562  if (attName=="inst") { inst = eval.Evaluate(attValue); } else
563  if (attName=="outst") { outst = eval.Evaluate(attValue); } else
564  if (attName=="z") { z = eval.Evaluate(attValue); }
565  }
566 
567  rmin *= lunit;
568  rmax *= lunit;
569  inst *= aunit;
570  outst *= aunit;
571  z *= 0.5*lunit;
572 
573  new G4Hype(name,rmin,rmax,inst,outst,z);
574 }
575 
576 #if !defined(G4GEOM_USE_USOLIDS)
578 MultiUnionNodeRead(const xercesc::DOMElement* const,
579  G4MultiUnion* const)
580 {
581  G4Exception("G4GDMLReadSolids::MultiUnionNodeRead()",
582  "InvalidSetup", FatalException,
583  "Installation with USolids primitives required!");
584  return;
585 }
586 #else
588 MultiUnionNodeRead(const xercesc::DOMElement* const unionNodeElement,
589  G4MultiUnion* const multiUnionSolid)
590 {
591  G4String name;
592  G4String solid;
593  G4ThreeVector position(0.0,0.0,0.0);
594  G4ThreeVector rotation(0.0,0.0,0.0);
595 
596  const xercesc::DOMNamedNodeMap* const attributes
597  = unionNodeElement->getAttributes();
598  XMLSize_t attributeCount = attributes->getLength();
599 
600  for (XMLSize_t attribute_index=0;
601  attribute_index<attributeCount; attribute_index++)
602  {
603  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
604 
605  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
606  { continue; }
607 
608  const xercesc::DOMAttr* const attribute
609  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
610  if (!attribute)
611  {
612  G4Exception("G4GDMLReadSolids::MultiUnionNodeRead()",
613  "InvalidRead", FatalException, "No attribute found!");
614  return;
615  }
616  const G4String attName = Transcode(attribute->getName());
617  const G4String attValue = Transcode(attribute->getValue());
618 
619  if (attName=="name") { name = GenerateName(attValue); }
620  }
621 
622  for (xercesc::DOMNode* iter = unionNodeElement->getFirstChild();
623  iter != 0;iter = iter->getNextSibling())
624  {
625  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
626 
627  const xercesc::DOMElement* const child
628  = dynamic_cast<xercesc::DOMElement*>(iter);
629  if (!child)
630  {
631  G4Exception("G4GDMLReadSolids::MultiUnionNodeRead()",
632  "InvalidRead", FatalException, "No child found!");
633  return;
634  }
635  const G4String tag = Transcode(child->getTagName());
636 
637  if (tag=="position") { VectorRead(child,position); } else
638  if (tag=="rotation") { VectorRead(child,rotation); } else
639  if (tag=="positionref")
640  { position = GetPosition(GenerateName(RefRead(child))); } else
641  if (tag=="rotationref")
642  { rotation = GetRotation(GenerateName(RefRead(child))); } else
643  if (tag=="solid") { solid = RefRead(child); }
644  else
645  {
646  G4String error_msg = "Unknown tag in MultiUnion structure: " + tag;
647  G4Exception("G4GDMLReadSolids::MultiUnionNodeRead()", "ReadError",
648  FatalException, error_msg);
649  }
650  }
651  G4VSolid* solidNode = GetSolid(GenerateName(solid));
652  G4Transform3D transform(GetRotationMatrix(rotation),position);
653  multiUnionSolid->AddNode(*solidNode, transform);
654 }
655 #endif
656 
657 #if !defined(G4GEOM_USE_USOLIDS)
659 MultiUnionRead(const xercesc::DOMElement* const)
660 {
661  G4Exception("G4GDMLReadSolids::MultiUnionRead()",
662  "InvalidSetup", FatalException,
663  "Installation with USolids primitives required!");
664  return;
665 }
666 #else
668 MultiUnionRead(const xercesc::DOMElement* const unionElement)
669 {
670  G4String name;
671 
672  const xercesc::DOMNamedNodeMap* const attributes
673  = unionElement->getAttributes();
674  XMLSize_t attributeCount = attributes->getLength();
675 
676  for (XMLSize_t attribute_index=0;
677  attribute_index<attributeCount; attribute_index++)
678  {
679  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
680 
681  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
682  { continue; }
683 
684  const xercesc::DOMAttr* const attribute
685  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
686  if (!attribute)
687  {
688  G4Exception("G4GDMLReadSolids::MultiUnionRead()",
689  "InvalidRead", FatalException, "No attribute found!");
690  return;
691  }
692  const G4String attName = Transcode(attribute->getName());
693  const G4String attValue = Transcode(attribute->getValue());
694 
695  if (attName=="name") { name = GenerateName(attValue); }
696  }
697 
698  G4MultiUnion* multiUnion = new G4MultiUnion(name);
699 
700  for (xercesc::DOMNode* iter = unionElement->getFirstChild();
701  iter != 0;iter = iter->getNextSibling())
702  {
703  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
704 
705  const xercesc::DOMElement* const child
706  = dynamic_cast<xercesc::DOMElement*>(iter);
707  if (!child)
708  {
709  G4Exception("G4GDMLReadSolids::MultiUnionRead()",
710  "InvalidRead", FatalException, "No child found!");
711  return;
712  }
713  const G4String tag = Transcode(child->getTagName());
714 
715  if (tag=="multiUnionNode") { MultiUnionNodeRead(child, multiUnion); }
716  else
717  {
718  G4String error_msg = "Unknown tag in MultiUnion structure: " + tag;
719  G4Exception("G4GDMLReadSolids::MultiUnionRead()", "ReadError",
720  FatalException, error_msg);
721  }
722  }
723  multiUnion->Voxelize();
724 }
725 #endif
726 
727 void G4GDMLReadSolids::OrbRead(const xercesc::DOMElement* const orbElement)
728 {
729  G4String name;
730  G4double lunit = 1.0;
731  G4double r = 0.0;
732 
733  const xercesc::DOMNamedNodeMap* const attributes
734  = orbElement->getAttributes();
735  XMLSize_t attributeCount = attributes->getLength();
736 
737  for (XMLSize_t attribute_index=0;
738  attribute_index<attributeCount; attribute_index++)
739  {
740  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
741 
742  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
743  { continue; }
744 
745  const xercesc::DOMAttr* const attribute
746  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
747  if (!attribute)
748  {
749  G4Exception("G4GDMLReadSolids::OrbRead()",
750  "InvalidRead", FatalException, "No attribute found!");
751  return;
752  }
753  const G4String attName = Transcode(attribute->getName());
754  const G4String attValue = Transcode(attribute->getValue());
755 
756  if (attName=="name") { name = GenerateName(attValue); } else
757  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
758  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
759  G4Exception("G4GDMLReadSolids::OrbRead()", "InvalidRead",
760  FatalException, "Invalid unit for length!"); }
761  } else
762  if (attName=="r") { r = eval.Evaluate(attValue); }
763  }
764 
765  r *= lunit;
766 
767  new G4Orb(name,r);
768 }
769 
770 void G4GDMLReadSolids::ParaRead(const xercesc::DOMElement* const paraElement)
771 {
772  G4String name;
773  G4double lunit = 1.0;
774  G4double aunit = 1.0;
775  G4double x = 0.0;
776  G4double y = 0.0;
777  G4double z = 0.0;
778  G4double alpha = 0.0;
779  G4double theta = 0.0;
780  G4double phi = 0.0;
781 
782  const xercesc::DOMNamedNodeMap* const attributes
783  = paraElement->getAttributes();
784  XMLSize_t attributeCount = attributes->getLength();
785 
786  for (XMLSize_t attribute_index=0;
787  attribute_index<attributeCount; attribute_index++)
788  {
789  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
790 
791  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
792  { continue; }
793 
794  const xercesc::DOMAttr* const attribute
795  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
796  if (!attribute)
797  {
798  G4Exception("G4GDMLReadSolids::ParaRead()",
799  "InvalidRead", FatalException, "No attribute found!");
800  return;
801  }
802  const G4String attName = Transcode(attribute->getName());
803  const G4String attValue = Transcode(attribute->getValue());
804 
805  if (attName=="name") { name = GenerateName(attValue); } else
806  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
807  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
808  G4Exception("G4GDMLReadSolids::ParaRead()", "InvalidRead",
809  FatalException, "Invalid unit for length!"); }
810  } else
811  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
812  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
813  G4Exception("G4GDMLReadSolids::ParaRead()", "InvalidRead",
814  FatalException, "Invalid unit for angle!"); }
815  } else
816  if (attName=="x") { x = eval.Evaluate(attValue); } else
817  if (attName=="y") { y = eval.Evaluate(attValue); } else
818  if (attName=="z") { z = eval.Evaluate(attValue); } else
819  if (attName=="alpha") { alpha = eval.Evaluate(attValue); } else
820  if (attName=="theta") { theta = eval.Evaluate(attValue); } else
821  if (attName=="phi") { phi = eval.Evaluate(attValue); }
822  }
823 
824  x *= 0.5*lunit;
825  y *= 0.5*lunit;
826  z *= 0.5*lunit;
827  alpha *= aunit;
828  theta *= aunit;
829  phi *= aunit;
830 
831  new G4Para(name,x,y,z,alpha,theta,phi);
832 }
833 
835 ParaboloidRead(const xercesc::DOMElement* const paraElement)
836 {
837  G4String name;
838  G4double lunit = 1.0;
839  G4double rlo = 0.0;
840  G4double rhi = 0.0;
841  G4double dz = 0.0;
842 
843  const xercesc::DOMNamedNodeMap* const attributes
844  = paraElement->getAttributes();
845  XMLSize_t attributeCount = attributes->getLength();
846 
847  for (XMLSize_t attribute_index=0;
848  attribute_index<attributeCount; attribute_index++)
849  {
850  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
851 
852  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
853  { continue; }
854 
855  const xercesc::DOMAttr* const attribute
856  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
857  if (!attribute)
858  {
859  G4Exception("G4GDMLReadSolids::ParaboloidRead()",
860  "InvalidRead", FatalException, "No attribute found!");
861  return;
862  }
863  const G4String attName = Transcode(attribute->getName());
864  const G4String attValue = Transcode(attribute->getValue());
865 
866  if (attName=="name") { name = GenerateName(attValue); } else
867  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
868  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
869  G4Exception("G4GDMLReadSolids::ParaboloidRead()", "InvalidRead",
870  FatalException, "Invalid unit for length!"); }
871  } else
872  if (attName=="rlo") { rlo = eval.Evaluate(attValue); } else
873  if (attName=="rhi") { rhi = eval.Evaluate(attValue); } else
874  if (attName=="dz") { dz = eval.Evaluate(attValue); }
875  }
876 
877  rlo *= 1.*lunit;
878  rhi *= 1.*lunit;
879  dz *= 1.*lunit;
880 
881  new G4Paraboloid(name,dz,rlo,rhi);
882 }
883 
885 PolyconeRead(const xercesc::DOMElement* const polyconeElement)
886 {
887  G4String name;
888  G4double lunit = 1.0;
889  G4double aunit = 1.0;
890  G4double startphi = 0.0;
891  G4double deltaphi = 0.0;
892 
893  const xercesc::DOMNamedNodeMap* const attributes
894  = polyconeElement->getAttributes();
895  XMLSize_t attributeCount = attributes->getLength();
896 
897  for (XMLSize_t attribute_index=0;
898  attribute_index<attributeCount; attribute_index++)
899  {
900  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
901 
902  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
903  { continue; }
904 
905  const xercesc::DOMAttr* const attribute
906  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
907  if (!attribute)
908  {
909  G4Exception("G4GDMLReadSolids::PolyconeRead()",
910  "InvalidRead", FatalException, "No attribute found!");
911  return;
912  }
913  const G4String attName = Transcode(attribute->getName());
914  const G4String attValue = Transcode(attribute->getValue());
915 
916  if (attName=="name") { name = GenerateName(attValue); } else
917  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
918  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
919  G4Exception("G4GDMLReadSolids::PolyconeRead()", "InvalidRead",
920  FatalException, "Invalid unit for length!"); }
921  } else
922  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
923  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
924  G4Exception("G4GDMLReadSolids::PolyconeRead()", "InvalidRead",
925  FatalException, "Invalid unit for angle!"); }
926  } else
927  if (attName=="startphi") { startphi = eval.Evaluate(attValue); }else
928  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); }
929  }
930 
931  startphi *= aunit;
932  deltaphi *= aunit;
933 
934  std::vector<zplaneType> zplaneList;
935 
936  for (xercesc::DOMNode* iter = polyconeElement->getFirstChild();
937  iter != 0; iter = iter->getNextSibling())
938  {
939  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
940 
941  const xercesc::DOMElement* const child
942  = dynamic_cast<xercesc::DOMElement*>(iter);
943  if (!child)
944  {
945  G4Exception("G4GDMLReadSolids::PolyconeRead()",
946  "InvalidRead", FatalException, "No child found!");
947  return;
948  }
949  const G4String tag = Transcode(child->getTagName());
950 
951  if (tag=="zplane") { zplaneList.push_back(ZplaneRead(child)); }
952  }
953 
954  G4int numZPlanes = zplaneList.size();
955 
956  G4double* rmin_array = new G4double[numZPlanes];
957  G4double* rmax_array = new G4double[numZPlanes];
958  G4double* z_array = new G4double[numZPlanes];
959 
960  for (G4int i=0; i<numZPlanes; i++)
961  {
962  rmin_array[i] = zplaneList[i].rmin*lunit;
963  rmax_array[i] = zplaneList[i].rmax*lunit;
964  z_array[i] = zplaneList[i].z*lunit;
965  }
966 
967  new G4Polycone(name,startphi,deltaphi,numZPlanes,
968  z_array,rmin_array,rmax_array);
969 
970  delete [] rmin_array;
971  delete [] rmax_array;
972  delete [] z_array;
973 }
974 
976 GenericPolyconeRead(const xercesc::DOMElement* const polyconeElement)
977 {
978  G4String name;
979  G4double lunit = 1.0;
980  G4double aunit = 1.0;
981  G4double startphi = 0.0;
982  G4double deltaphi = 0.0;
983 
984  const xercesc::DOMNamedNodeMap* const attributes
985  = polyconeElement->getAttributes();
986  XMLSize_t attributeCount = attributes->getLength();
987 
988  for (XMLSize_t attribute_index=0;
989  attribute_index<attributeCount; attribute_index++)
990  {
991  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
992 
993  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
994  { continue; }
995 
996  const xercesc::DOMAttr* const attribute
997  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
998  if (!attribute)
999  {
1000  G4Exception("G4GDMLReadSolids::GenericPolyconeRead()",
1001  "InvalidRead", FatalException, "No attribute found!");
1002  return;
1003  }
1004  const G4String attName = Transcode(attribute->getName());
1005  const G4String attValue = Transcode(attribute->getValue());
1006 
1007  if (attName=="name") { name = GenerateName(attValue); } else
1008  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1009  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1010  G4Exception("G4GDMLReadSolids::GenericPolyconeRead()", "InvalidRead",
1011  FatalException, "Invalid unit for length!"); }
1012  } else
1013  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1014  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1015  G4Exception("G4GDMLReadSolids::GenericPolyconeRead()", "InvalidRead",
1016  FatalException, "Invalid unit for angle!"); }
1017  } else
1018  if (attName=="startphi") { startphi = eval.Evaluate(attValue); }else
1019  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); }
1020  }
1021 
1022  startphi *= aunit;
1023  deltaphi *= aunit;
1024 
1025  std::vector<rzPointType> rzPointList;
1026 
1027  for (xercesc::DOMNode* iter = polyconeElement->getFirstChild();
1028  iter != 0; iter = iter->getNextSibling())
1029  {
1030  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
1031 
1032  const xercesc::DOMElement* const child
1033  = dynamic_cast<xercesc::DOMElement*>(iter);
1034  if (!child)
1035  {
1036  G4Exception("G4GDMLReadSolids::GenericPolyconeRead()",
1037  "InvalidRead", FatalException, "No child found!");
1038  return;
1039  }
1040  const G4String tag = Transcode(child->getTagName());
1041 
1042  if (tag=="rzpoint") { rzPointList.push_back(RZPointRead(child)); }
1043  }
1044 
1045  G4int numRZPoints = rzPointList.size();
1046 
1047  G4double* r_array = new G4double[numRZPoints];
1048  G4double* z_array = new G4double[numRZPoints];
1049 
1050  for (G4int i=0; i<numRZPoints; i++)
1051  {
1052  r_array[i] = rzPointList[i].r*lunit;
1053  z_array[i] = rzPointList[i].z*lunit;
1054  }
1055  new G4GenericPolycone(name,startphi,deltaphi,numRZPoints,
1056  r_array,z_array);
1057  delete [] r_array;
1058  delete [] z_array;
1059 }
1060 
1061 void G4GDMLReadSolids::
1062 PolyhedraRead(const xercesc::DOMElement* const polyhedraElement)
1063 {
1064  G4String name;
1065  G4double lunit = 1.0;
1066  G4double aunit = 1.0;
1067  G4double startphi = 0.0;
1068  G4double deltaphi = 0.0;
1069  G4int numsides = 0;
1070 
1071  const xercesc::DOMNamedNodeMap* const attributes
1072  = polyhedraElement->getAttributes();
1073  XMLSize_t attributeCount = attributes->getLength();
1074 
1075  for (XMLSize_t attribute_index=0;
1076  attribute_index<attributeCount; attribute_index++)
1077  {
1078  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1079 
1080  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1081  { continue; }
1082 
1083  const xercesc::DOMAttr* const attribute
1084  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1085  if (!attribute)
1086  {
1087  G4Exception("G4GDMLReadSolids::PolyhedraRead()",
1088  "InvalidRead", FatalException, "No attribute found!");
1089  return;
1090  }
1091  const G4String attName = Transcode(attribute->getName());
1092  const G4String attValue = Transcode(attribute->getValue());
1093 
1094  if (attName=="name") { name = GenerateName(attValue); } else
1095  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1096  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1097  G4Exception("G4GDMLReadSolids::PolyhedraRead()", "InvalidRead",
1098  FatalException, "Invalid unit for length!"); }
1099  } else
1100  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1101  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1102  G4Exception("G4GDMLReadSolids::PolyhedraRead()", "InvalidRead",
1103  FatalException, "Invalid unit for angle!"); }
1104  } else
1105  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
1106  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); } else
1107  if (attName=="numsides") { numsides = eval.EvaluateInteger(attValue); }
1108  }
1109 
1110  startphi *= aunit;
1111  deltaphi *= aunit;
1112 
1113  std::vector<zplaneType> zplaneList;
1114 
1115  for (xercesc::DOMNode* iter = polyhedraElement->getFirstChild();
1116  iter != 0; iter = iter->getNextSibling())
1117  {
1118  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
1119 
1120  const xercesc::DOMElement* const child
1121  = dynamic_cast<xercesc::DOMElement*>(iter);
1122  if (!child)
1123  {
1124  G4Exception("G4GDMLReadSolids::PolyhedraRead()",
1125  "InvalidRead", FatalException, "No child found!");
1126  return;
1127  }
1128  const G4String tag = Transcode(child->getTagName());
1129 
1130  if (tag=="zplane") { zplaneList.push_back(ZplaneRead(child)); }
1131  }
1132 
1133  G4int numZPlanes = zplaneList.size();
1134 
1135  G4double* rmin_array = new G4double[numZPlanes];
1136  G4double* rmax_array = new G4double[numZPlanes];
1137  G4double* z_array = new G4double[numZPlanes];
1138 
1139  for (G4int i=0; i<numZPlanes; i++)
1140  {
1141  rmin_array[i] = zplaneList[i].rmin*lunit;
1142  rmax_array[i] = zplaneList[i].rmax*lunit;
1143  z_array[i] = zplaneList[i].z*lunit;
1144  }
1145 
1146  new G4Polyhedra(name,startphi,deltaphi,numsides,numZPlanes,
1147  z_array,rmin_array,rmax_array);
1148 
1149  delete [] rmin_array;
1150  delete [] rmax_array;
1151  delete [] z_array;
1152 }
1153 
1154 void G4GDMLReadSolids::
1155 GenericPolyhedraRead(const xercesc::DOMElement* const polyhedraElement)
1156 {
1157  G4String name;
1158  G4double lunit = 1.0;
1159  G4double aunit = 1.0;
1160  G4double startphi = 0.0;
1161  G4double deltaphi = 0.0;
1162  G4int numsides = 0;
1163 
1164  const xercesc::DOMNamedNodeMap* const attributes
1165  = polyhedraElement->getAttributes();
1166  XMLSize_t attributeCount = attributes->getLength();
1167 
1168  for (XMLSize_t attribute_index=0;
1169  attribute_index<attributeCount; attribute_index++)
1170  {
1171  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1172 
1173  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1174  { continue; }
1175 
1176  const xercesc::DOMAttr* const attribute
1177  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1178  if (!attribute)
1179  {
1180  G4Exception("G4GDMLReadSolids::GenericPolyhedraRead()",
1181  "InvalidRead", FatalException, "No attribute found!");
1182  return;
1183  }
1184  const G4String attName = Transcode(attribute->getName());
1185  const G4String attValue = Transcode(attribute->getValue());
1186 
1187  if (attName=="name") { name = GenerateName(attValue); } else
1188  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1189  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1190  G4Exception("G4GDMLReadSolids::GenericPolyhedraRead()", "InvalidRead",
1191  FatalException, "Invalid unit for length!"); }
1192  } else
1193  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1194  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1195  G4Exception("G4GDMLReadSolids::GenericPolyhedraRead()", "InvalidRead",
1196  FatalException, "Invalid unit for angle!"); }
1197  } else
1198  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
1199  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); } else
1200  if (attName=="numsides") { numsides = eval.EvaluateInteger(attValue); }
1201  }
1202 
1203  startphi *= aunit;
1204  deltaphi *= aunit;
1205 
1206  std::vector<rzPointType> rzpointList;
1207 
1208  for (xercesc::DOMNode* iter = polyhedraElement->getFirstChild();
1209  iter != 0; iter = iter->getNextSibling())
1210  {
1211  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
1212 
1213  const xercesc::DOMElement* const child
1214  = dynamic_cast<xercesc::DOMElement*>(iter);
1215  if (!child)
1216  {
1217  G4Exception("G4GDMLReadSolids::GenericPolyhedraRead()",
1218  "InvalidRead", FatalException, "No child found!");
1219  return;
1220  }
1221  const G4String tag = Transcode(child->getTagName());
1222 
1223  if (tag=="rzpoint") { rzpointList.push_back(RZPointRead(child)); }
1224  }
1225 
1226  G4int numRZPoints = rzpointList.size();
1227 
1228  G4double* r_array = new G4double[numRZPoints];
1229  G4double* z_array = new G4double[numRZPoints];
1230 
1231  for (G4int i=0; i<numRZPoints; i++)
1232  {
1233  r_array[i] = rzpointList[i].r*lunit;
1234  z_array[i] = rzpointList[i].z*lunit;
1235  }
1236 
1237  new G4Polyhedra(name,startphi,deltaphi,numsides,numRZPoints,
1238  r_array,z_array);
1239 
1240  delete [] r_array;
1241  delete [] z_array;
1242 }
1243 
1245 QuadrangularRead(const xercesc::DOMElement* const quadrangularElement)
1246 {
1247  G4ThreeVector vertex1;
1248  G4ThreeVector vertex2;
1249  G4ThreeVector vertex3;
1250  G4ThreeVector vertex4;
1251  G4FacetVertexType type = ABSOLUTE;
1252  G4double lunit = 1.0;
1253 
1254  const xercesc::DOMNamedNodeMap* const attributes
1255  = quadrangularElement->getAttributes();
1256  XMLSize_t attributeCount = attributes->getLength();
1257 
1258  for (XMLSize_t attribute_index=0;
1259  attribute_index<attributeCount; attribute_index++)
1260  {
1261  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1262 
1263  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1264  { continue; }
1265 
1266  const xercesc::DOMAttr* const attribute
1267  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1268  if (!attribute)
1269  {
1270  G4Exception("G4GDMLReadSolids::QuadrangularRead()",
1271  "InvalidRead", FatalException, "No attribute found!");
1272  return 0;
1273  }
1274  const G4String attName = Transcode(attribute->getName());
1275  const G4String attValue = Transcode(attribute->getValue());
1276 
1277  if (attName=="vertex1")
1278  { vertex1 = GetPosition(GenerateName(attValue)); } else
1279  if (attName=="vertex2")
1280  { vertex2 = GetPosition(GenerateName(attValue)); } else
1281  if (attName=="vertex3")
1282  { vertex3 = GetPosition(GenerateName(attValue)); } else
1283  if (attName=="vertex4")
1284  { vertex4 = GetPosition(GenerateName(attValue)); } else
1285  if (attName=="lunit")
1286  { lunit = G4UnitDefinition::GetValueOf(attValue);
1287  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1288  G4Exception("G4GDMLReadSolids::QuadrangularRead()", "InvalidRead",
1289  FatalException, "Invalid unit for length!"); }
1290  } else
1291  if (attName=="type")
1292  { if (attValue=="RELATIVE") { type = RELATIVE; } }
1293  }
1294 
1295  return new G4QuadrangularFacet(vertex1*lunit,vertex2*lunit,
1296  vertex3*lunit,vertex4*lunit,type);
1297 }
1298 
1299 void G4GDMLReadSolids::
1300 ReflectedSolidRead(const xercesc::DOMElement* const reflectedSolidElement)
1301 {
1302  G4String name;
1303  G4double lunit = 1.0;
1304  G4double aunit = 1.0;
1305  G4String solid;
1306  G4ThreeVector scale(1.0,1.0,1.0);
1307  G4ThreeVector rotation;
1309 
1310  const xercesc::DOMNamedNodeMap* const attributes
1311  = reflectedSolidElement->getAttributes();
1312  XMLSize_t attributeCount = attributes->getLength();
1313 
1314  for (XMLSize_t attribute_index=0;
1315  attribute_index<attributeCount; attribute_index++)
1316  {
1317  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1318 
1319  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1320  { continue; }
1321 
1322  const xercesc::DOMAttr* const attribute
1323  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1324  if (!attribute)
1325  {
1326  G4Exception("G4GDMLReadSolids::ReflectedSolidRead()",
1327  "InvalidRead", FatalException, "No attribute found!");
1328  return;
1329  }
1330  const G4String attName = Transcode(attribute->getName());
1331  const G4String attValue = Transcode(attribute->getValue());
1332 
1333  if (attName=="name") { name = GenerateName(attValue); } else
1334  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1335  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1336  G4Exception("G4GDMLReadSolids::ReflectedSolidRead()", "InvalidRead",
1337  FatalException, "Invalid unit for length!"); }
1338  } else
1339  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1340  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1341  G4Exception("G4GDMLReadSolids::ReflectedSolidRead()", "InvalidRead",
1342  FatalException, "Invalid unit for angle!"); }
1343  } else
1344  if (attName=="solid") { solid = GenerateName(attValue); } else
1345  if (attName=="sx") { scale.setX(eval.Evaluate(attValue)); } else
1346  if (attName=="sy") { scale.setY(eval.Evaluate(attValue)); } else
1347  if (attName=="sz") { scale.setZ(eval.Evaluate(attValue)); } else
1348  if (attName=="rx") { rotation.setX(eval.Evaluate(attValue)); } else
1349  if (attName=="ry") { rotation.setY(eval.Evaluate(attValue)); } else
1350  if (attName=="rz") { rotation.setZ(eval.Evaluate(attValue)); } else
1351  if (attName=="dx") { position.setX(eval.Evaluate(attValue)); } else
1352  if (attName=="dy") { position.setY(eval.Evaluate(attValue)); } else
1353  if (attName=="dz") { position.setZ(eval.Evaluate(attValue)); }
1354  }
1355 
1356  rotation *= aunit;
1357  position *= lunit;
1358 
1359  G4Transform3D transform(GetRotationMatrix(rotation),position);
1360  transform = transform*G4Scale3D(scale.x(),scale.y(),scale.z());
1361 
1362  new G4ReflectedSolid(name,GetSolid(solid),transform);
1363 }
1364 
1366 SectionRead(const xercesc::DOMElement* const sectionElement,G4double lunit)
1367 {
1368  G4double zPosition = 0.0;
1369  G4TwoVector Offset;
1370  G4double scalingFactor = 1.0;
1371 
1372  const xercesc::DOMNamedNodeMap* const attributes
1373  = sectionElement->getAttributes();
1374  XMLSize_t attributeCount = attributes->getLength();
1375 
1376  for (XMLSize_t attribute_index=0;
1377  attribute_index<attributeCount; attribute_index++)
1378  {
1379  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1380 
1381  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1382  { continue; }
1383 
1384  const xercesc::DOMAttr* const attribute
1385  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1386  if (!attribute)
1387  {
1388  G4Exception("G4GDMLReadSolids::SectionRead()",
1389  "InvalidRead", FatalException, "No attribute found!");
1390  return G4ExtrudedSolid::ZSection(zPosition,Offset,scalingFactor);
1391  }
1392  const G4String attName = Transcode(attribute->getName());
1393  const G4String attValue = Transcode(attribute->getValue());
1394 
1395  if (attName=="zPosition")
1396  { zPosition = eval.Evaluate(attValue)*lunit; } else
1397  if (attName=="xOffset")
1398  { Offset.setX(eval.Evaluate(attValue)*lunit); } else
1399  if (attName=="yOffset")
1400  { Offset.setY(eval.Evaluate(attValue)*lunit); } else
1401  if (attName=="scalingFactor")
1402  { scalingFactor = eval.Evaluate(attValue); }
1403  }
1404 
1405  return G4ExtrudedSolid::ZSection(zPosition,Offset,scalingFactor);
1406 }
1407 
1408 void G4GDMLReadSolids::
1409 SphereRead(const xercesc::DOMElement* const sphereElement)
1410 {
1411  G4String name;
1412  G4double lunit = 1.0;
1413  G4double aunit = 1.0;
1414  G4double rmin = 0.0;
1415  G4double rmax = 0.0;
1416  G4double startphi = 0.0;
1417  G4double deltaphi = 0.0;
1418  G4double starttheta = 0.0;
1419  G4double deltatheta = 0.0;
1420 
1421  const xercesc::DOMNamedNodeMap* const attributes
1422  = sphereElement->getAttributes();
1423  XMLSize_t attributeCount = attributes->getLength();
1424 
1425  for (XMLSize_t attribute_index=0;
1426  attribute_index<attributeCount; attribute_index++)
1427  {
1428  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1429 
1430  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1431  { continue; }
1432 
1433  const xercesc::DOMAttr* const attribute
1434  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1435  if (!attribute)
1436  {
1437  G4Exception("G4GDMLReadSolids::SphereRead()",
1438  "InvalidRead", FatalException, "No attribute found!");
1439  return;
1440  }
1441  const G4String attName = Transcode(attribute->getName());
1442  const G4String attValue = Transcode(attribute->getValue());
1443 
1444  if (attName=="name") { name = GenerateName(attValue); } else
1445  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1446  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1447  G4Exception("G4GDMLReadSolids::SphereRead()", "InvalidRead",
1448  FatalException, "Invalid unit for length!"); }
1449  } else
1450  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1451  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1452  G4Exception("G4GDMLReadSolids::SphereRead()", "InvalidRead",
1453  FatalException, "Invalid unit for angle!"); }
1454  } else
1455  if (attName=="rmin") { rmin = eval.Evaluate(attValue); } else
1456  if (attName=="rmax") { rmax = eval.Evaluate(attValue); } else
1457  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
1458  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); } else
1459  if (attName=="starttheta") { starttheta = eval.Evaluate(attValue); } else
1460  if (attName=="deltatheta") { deltatheta = eval.Evaluate(attValue); }
1461  }
1462 
1463  rmin *= lunit;
1464  rmax *= lunit;
1465  startphi *= aunit;
1466  deltaphi *= aunit;
1467  starttheta *= aunit;
1468  deltatheta *= aunit;
1469 
1470  new G4Sphere(name,rmin,rmax,startphi,deltaphi,starttheta,deltatheta);
1471 }
1472 
1473 void G4GDMLReadSolids::
1474 TessellatedRead(const xercesc::DOMElement* const tessellatedElement)
1475 {
1476  G4String name;
1477 
1478  const xercesc::DOMNamedNodeMap* const attributes
1479  = tessellatedElement->getAttributes();
1480  XMLSize_t attributeCount = attributes->getLength();
1481 
1482  for (XMLSize_t attribute_index=0;
1483  attribute_index<attributeCount; attribute_index++)
1484  {
1485  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1486 
1487  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1488  { continue; }
1489 
1490  const xercesc::DOMAttr* const attribute
1491  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1492  if (!attribute)
1493  {
1494  G4Exception("G4GDMLReadSolids::TessellatedRead()",
1495  "InvalidRead", FatalException, "No attribute found!");
1496  return;
1497  }
1498  const G4String attName = Transcode(attribute->getName());
1499  const G4String attValue = Transcode(attribute->getValue());
1500 
1501  if (attName=="name") { name = GenerateName(attValue); }
1502  }
1503 
1504  G4TessellatedSolid *tessellated = new G4TessellatedSolid(name);
1505 
1506  for (xercesc::DOMNode* iter = tessellatedElement->getFirstChild();
1507  iter != 0; iter = iter->getNextSibling())
1508  {
1509  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
1510 
1511  const xercesc::DOMElement* const child
1512  = dynamic_cast<xercesc::DOMElement*>(iter);
1513  if (!child)
1514  {
1515  G4Exception("G4GDMLReadSolids::TessellatedRead()",
1516  "InvalidRead", FatalException, "No child found!");
1517  return;
1518  }
1519  const G4String tag = Transcode(child->getTagName());
1520 
1521  if (tag=="triangular")
1522  { tessellated->AddFacet(TriangularRead(child)); } else
1523  if (tag=="quadrangular")
1524  { tessellated->AddFacet(QuadrangularRead(child)); }
1525  }
1526 
1527  tessellated->SetSolidClosed(true);
1528 }
1529 
1530 void G4GDMLReadSolids::TetRead(const xercesc::DOMElement* const tetElement)
1531 {
1532  G4String name;
1533  G4ThreeVector vertex1;
1534  G4ThreeVector vertex2;
1535  G4ThreeVector vertex3;
1536  G4ThreeVector vertex4;
1537  G4double lunit = 1.0;
1538 
1539  const xercesc::DOMNamedNodeMap* const attributes
1540  = tetElement->getAttributes();
1541  XMLSize_t attributeCount = attributes->getLength();
1542 
1543  for (XMLSize_t attribute_index=0;
1544  attribute_index<attributeCount;attribute_index++)
1545  {
1546  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1547 
1548  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1549  { continue; }
1550 
1551  const xercesc::DOMAttr* const attribute
1552  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1553  if (!attribute)
1554  {
1555  G4Exception("G4GDMLReadSolids::TetRead()",
1556  "InvalidRead", FatalException, "No attribute found!");
1557  return;
1558  }
1559  const G4String attName = Transcode(attribute->getName());
1560  const G4String attValue = Transcode(attribute->getValue());
1561 
1562  if (attName=="name")
1563  { name = GenerateName(attValue); } else
1564  if (attName=="lunit")
1565  { lunit = G4UnitDefinition::GetValueOf(attValue);
1566  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1567  G4Exception("G4GDMLReadSolids::TetRead()", "InvalidRead",
1568  FatalException, "Invalid unit for length!"); }
1569  } else
1570  if (attName=="vertex1")
1571  { vertex1 = GetPosition(GenerateName(attValue)); } else
1572  if (attName=="vertex2")
1573  { vertex2 = GetPosition(GenerateName(attValue)); } else
1574  if (attName=="vertex3")
1575  { vertex3 = GetPosition(GenerateName(attValue)); } else
1576  if (attName=="vertex4")
1577  { vertex4 = GetPosition(GenerateName(attValue)); }
1578  }
1579 
1580  new G4Tet(name,vertex1*lunit,vertex2*lunit,vertex3*lunit,vertex4*lunit);
1581 }
1582 
1583 void G4GDMLReadSolids::TorusRead(const xercesc::DOMElement* const torusElement)
1584 {
1585  G4String name;
1586  G4double lunit = 1.0;
1587  G4double aunit = 1.0;
1588  G4double rmin = 0.0;
1589  G4double rmax = 0.0;
1590  G4double rtor = 0.0;
1591  G4double startphi = 0.0;
1592  G4double deltaphi = 0.0;
1593 
1594  const xercesc::DOMNamedNodeMap* const attributes
1595  = torusElement->getAttributes();
1596  XMLSize_t attributeCount = attributes->getLength();
1597 
1598  for (XMLSize_t attribute_index=0;
1599  attribute_index<attributeCount; attribute_index++)
1600  {
1601  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1602 
1603  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1604  { continue; }
1605 
1606  const xercesc::DOMAttr* const attribute
1607  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1608  if (!attribute)
1609  {
1610  G4Exception("G4GDMLReadSolids::TorusRead()",
1611  "InvalidRead", FatalException, "No attribute found!");
1612  return;
1613  }
1614  const G4String attName = Transcode(attribute->getName());
1615  const G4String attValue = Transcode(attribute->getValue());
1616 
1617  if (attName=="name") { name = GenerateName(attValue); } else
1618  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1619  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1620  G4Exception("G4GDMLReadSolids::TorusRead()", "InvalidRead",
1621  FatalException, "Invalid unit for length!"); }
1622  } else
1623  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1624  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1625  G4Exception("G4GDMLReadSolids::TorusRead()", "InvalidRead",
1626  FatalException, "Invalid unit for angle!"); }
1627  } else
1628  if (attName=="rmin") { rmin = eval.Evaluate(attValue); } else
1629  if (attName=="rmax") { rmax = eval.Evaluate(attValue); } else
1630  if (attName=="rtor") { rtor = eval.Evaluate(attValue); } else
1631  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
1632  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); }
1633  }
1634 
1635  rmin *= lunit;
1636  rmax *= lunit;
1637  rtor *= lunit;
1638  startphi *= aunit;
1639  deltaphi *= aunit;
1640 
1641  new G4Torus(name,rmin,rmax,rtor,startphi,deltaphi);
1642 }
1643 
1644 void G4GDMLReadSolids::
1645 GenTrapRead(const xercesc::DOMElement* const gtrapElement)
1646 {
1647  G4String name;
1648  G4double lunit = 1.0;
1649  G4double dz =0.0;
1650  G4double v1x=0.0, v1y=0.0, v2x=0.0, v2y=0.0, v3x=0.0, v3y=0.0,
1651  v4x=0.0, v4y=0.0, v5x=0.0, v5y=0.0, v6x=0.0, v6y=0.0,
1652  v7x=0.0, v7y=0.0, v8x=0.0, v8y=0.0;
1653 
1654  const xercesc::DOMNamedNodeMap* const attributes
1655  = gtrapElement->getAttributes();
1656  XMLSize_t attributeCount = attributes->getLength();
1657 
1658  for (XMLSize_t attribute_index=0;
1659  attribute_index<attributeCount; attribute_index++)
1660  {
1661  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1662 
1663  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1664  { continue; }
1665 
1666  const xercesc::DOMAttr* const attribute
1667  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1668  if (!attribute)
1669  {
1670  G4Exception("G4GDMLReadSolids::GenTrapRead()",
1671  "InvalidRead", FatalException, "No attribute found!");
1672  return;
1673  }
1674  const G4String attName = Transcode(attribute->getName());
1675  const G4String attValue = Transcode(attribute->getValue());
1676 
1677  if (attName=="name") { name = GenerateName(attValue); } else
1678  if (attName=="lunit") { G4UnitDefinition::GetValueOf(attValue);
1679  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1680  G4Exception("G4GDMLReadSolids::GenTrapRead()", "InvalidRead",
1681  FatalException, "Invalid unit for length!"); }
1682  } else
1683  if (attName=="dz") { dz = eval.Evaluate(attValue); } else
1684  if (attName=="v1x") { v1x = eval.Evaluate(attValue); } else
1685  if (attName=="v1y") { v1y = eval.Evaluate(attValue); } else
1686  if (attName=="v2x") { v2x = eval.Evaluate(attValue); } else
1687  if (attName=="v2y") { v2y = eval.Evaluate(attValue); } else
1688  if (attName=="v3x") { v3x = eval.Evaluate(attValue); } else
1689  if (attName=="v3y") { v3y = eval.Evaluate(attValue); } else
1690  if (attName=="v4x") { v4x = eval.Evaluate(attValue); } else
1691  if (attName=="v4y") { v4y = eval.Evaluate(attValue); } else
1692  if (attName=="v5x") { v5x = eval.Evaluate(attValue); } else
1693  if (attName=="v5y") { v5y = eval.Evaluate(attValue); } else
1694  if (attName=="v6x") { v6x = eval.Evaluate(attValue); } else
1695  if (attName=="v6y") { v6y = eval.Evaluate(attValue); } else
1696  if (attName=="v7x") { v7x = eval.Evaluate(attValue); } else
1697  if (attName=="v7y") { v7y = eval.Evaluate(attValue); } else
1698  if (attName=="v8x") { v8x = eval.Evaluate(attValue); } else
1699  if (attName=="v8y") { v8y = eval.Evaluate(attValue); }
1700  }
1701 
1702  dz *= lunit;
1703  std::vector<G4TwoVector> vertices;
1704  vertices.push_back(G4TwoVector(v1x*lunit,v1y*lunit));
1705  vertices.push_back(G4TwoVector(v2x*lunit,v2y*lunit));
1706  vertices.push_back(G4TwoVector(v3x*lunit,v3y*lunit));
1707  vertices.push_back(G4TwoVector(v4x*lunit,v4y*lunit));
1708  vertices.push_back(G4TwoVector(v5x*lunit,v5y*lunit));
1709  vertices.push_back(G4TwoVector(v6x*lunit,v6y*lunit));
1710  vertices.push_back(G4TwoVector(v7x*lunit,v7y*lunit));
1711  vertices.push_back(G4TwoVector(v8x*lunit,v8y*lunit));
1712  new G4GenericTrap(name,dz,vertices);
1713 }
1714 
1715 void G4GDMLReadSolids::TrapRead(const xercesc::DOMElement* const trapElement)
1716 {
1717  G4String name;
1718  G4double lunit = 1.0;
1719  G4double aunit = 1.0;
1720  G4double z = 0.0;
1721  G4double theta = 0.0;
1722  G4double phi = 0.0;
1723  G4double y1 = 0.0;
1724  G4double x1 = 0.0;
1725  G4double x2 = 0.0;
1726  G4double alpha1 = 0.0;
1727  G4double y2 = 0.0;
1728  G4double x3 = 0.0;
1729  G4double x4 = 0.0;
1730  G4double alpha2 = 0.0;
1731 
1732  const xercesc::DOMNamedNodeMap* const attributes
1733  = trapElement->getAttributes();
1734  XMLSize_t attributeCount = attributes->getLength();
1735 
1736  for (XMLSize_t attribute_index=0;
1737  attribute_index<attributeCount; attribute_index++)
1738  {
1739  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1740 
1741  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1742  { continue; }
1743 
1744  const xercesc::DOMAttr* const attribute
1745  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1746  if (!attribute)
1747  {
1748  G4Exception("G4GDMLReadSolids::TrapRead()",
1749  "InvalidRead", FatalException, "No attribute found!");
1750  return;
1751  }
1752  const G4String attName = Transcode(attribute->getName());
1753  const G4String attValue = Transcode(attribute->getValue());
1754 
1755  if (attName=="name") { name = GenerateName(attValue); } else
1756  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1757  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1758  G4Exception("G4GDMLReadSolids::TrapRead()", "InvalidRead",
1759  FatalException, "Invalid unit for length!"); }
1760  } else
1761  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1762  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1763  G4Exception("G4GDMLReadSolids::TrapRead()", "InvalidRead",
1764  FatalException, "Invalid unit for angle!"); }
1765  } else
1766  if (attName=="z") { z = eval.Evaluate(attValue); } else
1767  if (attName=="theta") { theta = eval.Evaluate(attValue); } else
1768  if (attName=="phi") { phi = eval.Evaluate(attValue); } else
1769  if (attName=="y1") { y1 = eval.Evaluate(attValue); } else
1770  if (attName=="x1") { x1 = eval.Evaluate(attValue); } else
1771  if (attName=="x2") { x2 = eval.Evaluate(attValue); } else
1772  if (attName=="alpha1") { alpha1 = eval.Evaluate(attValue); } else
1773  if (attName=="y2") { y2 = eval.Evaluate(attValue); } else
1774  if (attName=="x3") { x3 = eval.Evaluate(attValue); } else
1775  if (attName=="x4") { x4 = eval.Evaluate(attValue); } else
1776  if (attName=="alpha2") { alpha2 = eval.Evaluate(attValue); }
1777  }
1778 
1779  z *= 0.5*lunit;
1780  theta *= aunit;
1781  phi *= aunit;
1782  y1 *= 0.5*lunit;
1783  x1 *= 0.5*lunit;
1784  x2 *= 0.5*lunit;
1785  alpha1 *= aunit;
1786  y2 *= 0.5*lunit;
1787  x3 *= 0.5*lunit;
1788  x4 *= 0.5*lunit;
1789  alpha2 *= aunit;
1790 
1791  new G4Trap(name,z,theta,phi,y1,x1,x2,alpha1,y2,x3,x4,alpha2);
1792 }
1793 
1794 void G4GDMLReadSolids::TrdRead(const xercesc::DOMElement* const trdElement)
1795 {
1796  G4String name;
1797  G4double lunit = 1.0;
1798  G4double x1 = 0.0;
1799  G4double x2 = 0.0;
1800  G4double y1 = 0.0;
1801  G4double y2 = 0.0;
1802  G4double z = 0.0;
1803 
1804  const xercesc::DOMNamedNodeMap* const attributes = trdElement->getAttributes();
1805  XMLSize_t attributeCount = attributes->getLength();
1806 
1807  for (XMLSize_t attribute_index=0;
1808  attribute_index<attributeCount; attribute_index++)
1809  {
1810  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1811 
1812  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1813  { continue; }
1814 
1815  const xercesc::DOMAttr* const attribute
1816  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1817  if (!attribute)
1818  {
1819  G4Exception("G4GDMLReadSolids::TrdRead()",
1820  "InvalidRead", FatalException, "No attribute found!");
1821  return;
1822  }
1823  const G4String attName = Transcode(attribute->getName());
1824  const G4String attValue = Transcode(attribute->getValue());
1825 
1826  if (attName=="name") { name = GenerateName(attValue); } else
1827  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1828  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1829  G4Exception("G4GDMLReadSolids::TrdRead()", "InvalidRead",
1830  FatalException, "Invalid unit for length!"); }
1831  } else
1832  if (attName=="x1") { x1 = eval.Evaluate(attValue); } else
1833  if (attName=="x2") { x2 = eval.Evaluate(attValue); } else
1834  if (attName=="y1") { y1 = eval.Evaluate(attValue); } else
1835  if (attName=="y2") { y2 = eval.Evaluate(attValue); } else
1836  if (attName=="z") { z = eval.Evaluate(attValue); }
1837  }
1838 
1839  x1 *= 0.5*lunit;
1840  x2 *= 0.5*lunit;
1841  y1 *= 0.5*lunit;
1842  y2 *= 0.5*lunit;
1843  z *= 0.5*lunit;
1844 
1845  new G4Trd(name,x1,x2,y1,y2,z);
1846 }
1847 
1849 TriangularRead(const xercesc::DOMElement* const triangularElement)
1850 {
1851  G4ThreeVector vertex1;
1852  G4ThreeVector vertex2;
1853  G4ThreeVector vertex3;
1854  G4FacetVertexType type = ABSOLUTE;
1855  G4double lunit = 1.0;
1856 
1857  const xercesc::DOMNamedNodeMap* const attributes
1858  = triangularElement->getAttributes();
1859  XMLSize_t attributeCount = attributes->getLength();
1860 
1861  for (XMLSize_t attribute_index=0;
1862  attribute_index<attributeCount; attribute_index++)
1863  {
1864  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1865 
1866  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1867  { continue; }
1868 
1869  const xercesc::DOMAttr* const attribute
1870  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1871  if (!attribute)
1872  {
1873  G4Exception("G4GDMLReadSolids::TriangularRead()",
1874  "InvalidRead", FatalException, "No attribute found!");
1875  return 0;
1876  }
1877  const G4String attName = Transcode(attribute->getName());
1878  const G4String attValue = Transcode(attribute->getValue());
1879 
1880  if (attName=="vertex1")
1881  { vertex1 = GetPosition(GenerateName(attValue)); } else
1882  if (attName=="vertex2")
1883  { vertex2 = GetPosition(GenerateName(attValue)); } else
1884  if (attName=="vertex3")
1885  { vertex3 = GetPosition(GenerateName(attValue)); } else
1886  if (attName=="lunit")
1887  { lunit = G4UnitDefinition::GetValueOf(attValue);
1888  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1889  G4Exception("G4GDMLReadSolids::TriangularRead()", "InvalidRead",
1890  FatalException, "Invalid unit for length!"); }
1891  } else
1892  if (attName=="type")
1893  { if (attValue=="RELATIVE") { type = RELATIVE; } }
1894  }
1895 
1896  return new G4TriangularFacet(vertex1*lunit,vertex2*lunit,vertex3*lunit,type);
1897 }
1898 
1899 void G4GDMLReadSolids::TubeRead(const xercesc::DOMElement* const tubeElement)
1900 {
1901  G4String name;
1902  G4double lunit = 1.0;
1903  G4double aunit = 1.0;
1904  G4double rmin = 0.0;
1905  G4double rmax = 0.0;
1906  G4double z = 0.0;
1907  G4double startphi = 0.0;
1908  G4double deltaphi = 0.0;
1909 
1910  const xercesc::DOMNamedNodeMap* const attributes
1911  = tubeElement->getAttributes();
1912  XMLSize_t attributeCount = attributes->getLength();
1913 
1914  for (XMLSize_t attribute_index=0;
1915  attribute_index<attributeCount; attribute_index++)
1916  {
1917  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1918 
1919  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1920  { continue; }
1921 
1922  const xercesc::DOMAttr* const attribute
1923  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1924  if (!attribute)
1925  {
1926  G4Exception("G4GDMLReadSolids::TubeRead()",
1927  "InvalidRead", FatalException, "No attribute found!");
1928  return;
1929  }
1930  const G4String attName = Transcode(attribute->getName());
1931  const G4String attValue = Transcode(attribute->getValue());
1932 
1933  if (attName=="name") { name = GenerateName(attValue); } else
1934  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1935  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1936  G4Exception("G4GDMLReadSolids::TubeRead()", "InvalidRead",
1937  FatalException, "Invalid unit for length!"); }
1938  } else
1939  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
1940  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
1941  G4Exception("G4GDMLReadSolids::TubeRead()", "InvalidRead",
1942  FatalException, "Invalid unit for angle!"); }
1943  } else
1944  if (attName=="rmin") { rmin = eval.Evaluate(attValue); } else
1945  if (attName=="rmax") { rmax = eval.Evaluate(attValue); } else
1946  if (attName=="z") { z = eval.Evaluate(attValue); } else
1947  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
1948  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); }
1949  }
1950 
1951  rmin *= lunit;
1952  rmax *= lunit;
1953  z *= 0.5*lunit;
1954  startphi *= aunit;
1955  deltaphi *= aunit;
1956 
1957  new G4Tubs(name,rmin,rmax,z,startphi,deltaphi);
1958 }
1959 
1960 void G4GDMLReadSolids::CutTubeRead(const xercesc::DOMElement* const cuttubeElement)
1961 {
1962  G4String name;
1963  G4double lunit = 1.0;
1964  G4double aunit = 1.0;
1965  G4double rmin = 0.0;
1966  G4double rmax = 0.0;
1967  G4double z = 0.0;
1968  G4double startphi = 0.0;
1969  G4double deltaphi = 0.0;
1970  G4ThreeVector lowNorm(0);
1971  G4ThreeVector highNorm(0);
1972 
1973  const xercesc::DOMNamedNodeMap* const attributes
1974  = cuttubeElement->getAttributes();
1975  XMLSize_t attributeCount = attributes->getLength();
1976 
1977  for (XMLSize_t attribute_index=0;
1978  attribute_index<attributeCount; attribute_index++)
1979  {
1980  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
1981 
1982  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
1983  { continue; }
1984 
1985  const xercesc::DOMAttr* const attribute
1986  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
1987  if (!attribute)
1988  {
1989  G4Exception("G4GDMLReadSolids::CutTubeRead()",
1990  "InvalidRead", FatalException, "No attribute found!");
1991  return;
1992  }
1993  const G4String attName = Transcode(attribute->getName());
1994  const G4String attValue = Transcode(attribute->getValue());
1995 
1996  if (attName=="name") { name = GenerateName(attValue); } else
1997  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
1998  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
1999  G4Exception("G4GDMLReadSolids::CutTubeRead()", "InvalidRead",
2000  FatalException, "Invalid unit for length!"); }
2001  } else
2002  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
2003  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
2004  G4Exception("G4GDMLReadSolids::CutTubeRead()", "InvalidRead",
2005  FatalException, "Invalid unit for angle!"); }
2006  } else
2007  if (attName=="rmin") { rmin = eval.Evaluate(attValue); } else
2008  if (attName=="rmax") { rmax = eval.Evaluate(attValue); } else
2009  if (attName=="z") { z = eval.Evaluate(attValue); } else
2010  if (attName=="startphi") { startphi = eval.Evaluate(attValue); } else
2011  if (attName=="deltaphi") { deltaphi = eval.Evaluate(attValue); } else
2012  if (attName=="lowX") { lowNorm.setX (eval.Evaluate(attValue)); } else
2013  if (attName=="lowY") { lowNorm.setY (eval.Evaluate(attValue)); } else
2014  if (attName=="lowZ") { lowNorm.setZ (eval.Evaluate(attValue)); } else
2015  if (attName=="highX") { highNorm.setX (eval.Evaluate(attValue)); } else
2016  if (attName=="highY") { highNorm.setY (eval.Evaluate(attValue)); } else
2017  if (attName=="highZ") { highNorm.setZ (eval.Evaluate(attValue)); }
2018 
2019  }
2020 
2021  rmin *= lunit;
2022  rmax *= lunit;
2023  z *= 0.5*lunit;
2024  startphi *= aunit;
2025  deltaphi *= aunit;
2026 
2027  new G4CutTubs(name,rmin,rmax,z,startphi,deltaphi,lowNorm,highNorm);
2028 }
2029 
2030 void G4GDMLReadSolids::
2031 TwistedboxRead(const xercesc::DOMElement* const twistedboxElement)
2032 {
2033  G4String name;
2034  G4double lunit = 1.0;
2035  G4double aunit = 1.0;
2036  G4double PhiTwist = 0.0;
2037  G4double x = 0.0;
2038  G4double y = 0.0;
2039  G4double z = 0.0;
2040 
2041  const xercesc::DOMNamedNodeMap* const attributes
2042  = twistedboxElement->getAttributes();
2043  XMLSize_t attributeCount = attributes->getLength();
2044 
2045  for (XMLSize_t attribute_index=0;
2046  attribute_index<attributeCount; attribute_index++)
2047  {
2048  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2049 
2050  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2051  { continue; }
2052 
2053  const xercesc::DOMAttr* const attribute
2054  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2055  if (!attribute)
2056  {
2057  G4Exception("G4GDMLReadSolids::TwistedboxRead()",
2058  "InvalidRead", FatalException, "No attribute found!");
2059  return;
2060  }
2061  const G4String attName = Transcode(attribute->getName());
2062  const G4String attValue = Transcode(attribute->getValue());
2063 
2064  if (attName=="name") { name = GenerateName(attValue); } else
2065  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
2066  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
2067  G4Exception("G4GDMLReadSolids::TwistedBoxRead()", "InvalidRead",
2068  FatalException, "Invalid unit for length!"); }
2069  } else
2070  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
2071  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
2072  G4Exception("G4GDMLReadSolids::TwistedboxRead()", "InvalidRead",
2073  FatalException, "Invalid unit for angle!"); }
2074  } else
2075  if (attName=="PhiTwist") { PhiTwist = eval.Evaluate(attValue); } else
2076  if (attName=="x") { x = eval.Evaluate(attValue); } else
2077  if (attName=="y") { y = eval.Evaluate(attValue); } else
2078  if (attName=="z") { z = eval.Evaluate(attValue); }
2079  }
2080 
2081  PhiTwist *= aunit;
2082  x *= 0.5*lunit;
2083  y *= 0.5*lunit;
2084  z *= 0.5*lunit;
2085 
2086  new G4TwistedBox(name,PhiTwist,x,y,z);
2087 }
2088 
2089 void G4GDMLReadSolids::
2090 TwistedtrapRead(const xercesc::DOMElement* const twistedtrapElement)
2091 {
2092  G4String name;
2093  G4double lunit = 1.0;
2094  G4double aunit = 1.0;
2095  G4double PhiTwist = 0.0;
2096  G4double z = 0.0;
2097  G4double Theta = 0.0;
2098  G4double Phi = 0.0;
2099  G4double y1 = 0.0;
2100  G4double x1 = 0.0;
2101  G4double x2 = 0.0;
2102  G4double y2 = 0.0;
2103  G4double x3 = 0.0;
2104  G4double x4 = 0.0;
2105  G4double Alph = 0.0;
2106 
2107  const xercesc::DOMNamedNodeMap* const attributes
2108  = twistedtrapElement->getAttributes();
2109  XMLSize_t attributeCount = attributes->getLength();
2110 
2111  for (XMLSize_t attribute_index=0;
2112  attribute_index<attributeCount; attribute_index++)
2113  {
2114  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2115 
2116  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2117  { continue; }
2118 
2119  const xercesc::DOMAttr* const attribute
2120  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2121  if (!attribute)
2122  {
2123  G4Exception("G4GDMLReadSolids::TwistedtrapRead()",
2124  "InvalidRead", FatalException, "No attribute found!");
2125  return;
2126  }
2127  const G4String attName = Transcode(attribute->getName());
2128  const G4String attValue = Transcode(attribute->getValue());
2129 
2130  if (attName=="name") { name = GenerateName(attValue); } else
2131  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
2132  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
2133  G4Exception("G4GDMLReadSolids::TwistedtrapRead()", "InvalidRead",
2134  FatalException, "Invalid unit for length!"); }
2135  } else
2136  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
2137  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
2138  G4Exception("G4GDMLReadSolids::TwistedtrapRead()", "InvalidRead",
2139  FatalException, "Invalid unit for angle!"); }
2140  } else
2141  if (attName=="PhiTwist") { PhiTwist = eval.Evaluate(attValue); } else
2142  if (attName=="z") { z = eval.Evaluate(attValue); } else
2143  if (attName=="Theta") { Theta = eval.Evaluate(attValue); } else
2144  if (attName=="Phi") { Phi = eval.Evaluate(attValue); } else
2145  if (attName=="y1") { y1 = eval.Evaluate(attValue); } else
2146  if (attName=="x1") { x1 = eval.Evaluate(attValue); } else
2147  if (attName=="x2") { x2 = eval.Evaluate(attValue); } else
2148  if (attName=="y2") { y2 = eval.Evaluate(attValue); } else
2149  if (attName=="x3") { x3 = eval.Evaluate(attValue); } else
2150  if (attName=="x4") { x4 = eval.Evaluate(attValue); } else
2151  if (attName=="Alph") { Alph = eval.Evaluate(attValue); }
2152  }
2153 
2154 
2155  PhiTwist *= aunit;
2156  z *= 0.5*lunit;
2157  Theta *= aunit;
2158  Phi *= aunit;
2159  Alph *= aunit;
2160  y1 *= 0.5*lunit;
2161  x1 *= 0.5*lunit;
2162  x2 *= 0.5*lunit;
2163  y2 *= 0.5*lunit;
2164  x3 *= 0.5*lunit;
2165  x4 *= 0.5*lunit;
2166 
2167  new G4TwistedTrap(name,PhiTwist,z,Theta,Phi,y1,x1,x2,y2,x3,x4,Alph);
2168 }
2169 
2170 void G4GDMLReadSolids::
2171 TwistedtrdRead(const xercesc::DOMElement* const twistedtrdElement)
2172 {
2173  G4String name;
2174  G4double lunit = 1.0;
2175  G4double aunit = 1.0;
2176  G4double x1 = 0.0;
2177  G4double x2 = 0.0;
2178  G4double y1 = 0.0;
2179  G4double y2 = 0.0;
2180  G4double z = 0.0;
2181  G4double PhiTwist = 0.0;
2182 
2183  const xercesc::DOMNamedNodeMap* const attributes
2184  = twistedtrdElement->getAttributes();
2185  XMLSize_t attributeCount = attributes->getLength();
2186 
2187  for (XMLSize_t attribute_index=0;
2188  attribute_index<attributeCount; attribute_index++)
2189  {
2190  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2191 
2192  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2193  { continue; }
2194 
2195  const xercesc::DOMAttr* const attribute
2196  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2197  if (!attribute)
2198  {
2199  G4Exception("G4GDMLReadSolids::TwistedtrdRead()",
2200  "InvalidRead", FatalException, "No attribute found!");
2201  return;
2202  }
2203  const G4String attName = Transcode(attribute->getName());
2204  const G4String attValue = Transcode(attribute->getValue());
2205 
2206  if (attName=="name") { name = GenerateName(attValue); } else
2207  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
2208  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
2209  G4Exception("G4GDMLReadSolids::TwistedtrdRead()", "InvalidRead",
2210  FatalException, "Invalid unit for length!"); }
2211  } else
2212  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
2213  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
2214  G4Exception("G4GDMLReadSolids::TwistedtrdRead()", "InvalidRead",
2215  FatalException, "Invalid unit for angle!"); }
2216  } else
2217  if (attName=="x1") { x1 = eval.Evaluate(attValue); } else
2218  if (attName=="x2") { x2 = eval.Evaluate(attValue); } else
2219  if (attName=="y1") { y1 = eval.Evaluate(attValue); } else
2220  if (attName=="y2") { y2 = eval.Evaluate(attValue); } else
2221  if (attName=="z") { z = eval.Evaluate(attValue); } else
2222  if (attName=="PhiTwist") { PhiTwist = eval.Evaluate(attValue); }
2223  }
2224 
2225  x1 *= 0.5*lunit;
2226  x2 *= 0.5*lunit;
2227  y1 *= 0.5*lunit;
2228  y2 *= 0.5*lunit;
2229  z *= 0.5*lunit;
2230  PhiTwist *= aunit;
2231 
2232  new G4TwistedTrd(name,x1,x2,y1,y2,z,PhiTwist);
2233 }
2234 
2235 void G4GDMLReadSolids::
2236 TwistedtubsRead(const xercesc::DOMElement* const twistedtubsElement)
2237 {
2238  G4String name;
2239  G4double lunit = 1.0;
2240  G4double aunit = 1.0;
2241  G4double twistedangle = 0.0;
2242  G4double endinnerrad = 0.0;
2243  G4double endouterrad = 0.0;
2244  G4double zlen = 0.0;
2245  G4double phi = 0.0;
2246 
2247  const xercesc::DOMNamedNodeMap* const attributes
2248  = twistedtubsElement->getAttributes();
2249  XMLSize_t attributeCount = attributes->getLength();
2250 
2251  for (XMLSize_t attribute_index=0;
2252  attribute_index<attributeCount; attribute_index++)
2253  {
2254  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2255 
2256  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2257  { continue; }
2258 
2259  const xercesc::DOMAttr* const attribute
2260  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2261  if (!attribute)
2262  {
2263  G4Exception("G4GDMLReadSolids::TwistedtubsRead()",
2264  "InvalidRead", FatalException, "No attribute found!");
2265  return;
2266  }
2267  const G4String attName = Transcode(attribute->getName());
2268  const G4String attValue = Transcode(attribute->getValue());
2269 
2270  if (attName=="name") { name = GenerateName(attValue); } else
2271  if (attName=="lunit") { lunit = G4UnitDefinition::GetValueOf(attValue);
2272  if (G4UnitDefinition::GetCategory(attValue)!="Length") {
2273  G4Exception("G4GDMLReadSolids::TwistedtubsRead()", "InvalidRead",
2274  FatalException, "Invalid unit for length!"); }
2275  } else
2276  if (attName=="aunit") { aunit = G4UnitDefinition::GetValueOf(attValue);
2277  if (G4UnitDefinition::GetCategory(attValue)!="Angle") {
2278  G4Exception("G4GDMLReadSolids::TwistedtubsRead()", "InvalidRead",
2279  FatalException, "Invalid unit for angle!"); }
2280  } else
2281  if (attName=="twistedangle") { twistedangle=eval.Evaluate(attValue); } else
2282  if (attName=="endinnerrad") { endinnerrad=eval.Evaluate(attValue); } else
2283  if (attName=="endouterrad") { endouterrad=eval.Evaluate(attValue); } else
2284  if (attName=="zlen") { zlen = eval.Evaluate(attValue); } else
2285  if (attName=="phi") { phi = eval.Evaluate(attValue); }
2286  }
2287 
2288  twistedangle *= aunit;
2289  endinnerrad *= lunit;
2290  endouterrad *= lunit;
2291  zlen *= 0.5*lunit;
2292  phi *= aunit;
2293 
2294  new G4TwistedTubs(name,twistedangle,endinnerrad,endouterrad,zlen,phi);
2295 }
2296 
2298 TwoDimVertexRead(const xercesc::DOMElement* const element, G4double lunit)
2299 {
2300  G4TwoVector vec;
2301 
2302  const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
2303  XMLSize_t attributeCount = attributes->getLength();
2304 
2305  for (XMLSize_t attribute_index=0;
2306  attribute_index<attributeCount; attribute_index++)
2307  {
2308  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2309 
2310  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2311  { continue; }
2312 
2313  const xercesc::DOMAttr* const attribute
2314  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2315  if (!attribute)
2316  {
2317  G4Exception("G4GDMLReadSolids::TwoDimVertexRead()",
2318  "InvalidRead", FatalException, "No attribute found!");
2319  return vec;
2320  }
2321  const G4String attName = Transcode(attribute->getName());
2322  const G4String attValue = Transcode(attribute->getValue());
2323 
2324  if (attName=="x") { vec.setX(eval.Evaluate(attValue)*lunit); } else
2325  if (attName=="y") { vec.setY(eval.Evaluate(attValue)*lunit); }
2326  }
2327 
2328  return vec;
2329 }
2330 
2332 ZplaneRead(const xercesc::DOMElement* const zplaneElement)
2333 {
2334  zplaneType zplane = {0.,0.,0.};
2335 
2336  const xercesc::DOMNamedNodeMap* const attributes
2337  = zplaneElement->getAttributes();
2338  XMLSize_t attributeCount = attributes->getLength();
2339 
2340  for (XMLSize_t attribute_index=0;
2341  attribute_index<attributeCount; attribute_index++)
2342  {
2343  xercesc::DOMNode* node = attributes->item(attribute_index);
2344 
2345  if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; }
2346 
2347  const xercesc::DOMAttr* const attribute
2348  = dynamic_cast<xercesc::DOMAttr*>(node);
2349  if (!attribute)
2350  {
2351  G4Exception("G4GDMLReadSolids::ZplaneRead()",
2352  "InvalidRead", FatalException, "No attribute found!");
2353  return zplane;
2354  }
2355  const G4String attName = Transcode(attribute->getName());
2356  const G4String attValue = Transcode(attribute->getValue());
2357 
2358  if (attName=="rmin") { zplane.rmin = eval.Evaluate(attValue); } else
2359  if (attName=="rmax") { zplane.rmax = eval.Evaluate(attValue); } else
2360  if (attName=="z") { zplane.z = eval.Evaluate(attValue); }
2361  }
2362 
2363  return zplane;
2364 }
2366 RZPointRead(const xercesc::DOMElement* const zplaneElement)
2367 {
2368  rzPointType rzpoint = {0.,0.};
2369 
2370  const xercesc::DOMNamedNodeMap* const attributes
2371  = zplaneElement->getAttributes();
2372  XMLSize_t attributeCount = attributes->getLength();
2373 
2374  for (XMLSize_t attribute_index=0;
2375  attribute_index<attributeCount; attribute_index++)
2376  {
2377  xercesc::DOMNode* node = attributes->item(attribute_index);
2378 
2379  if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; }
2380 
2381  const xercesc::DOMAttr* const attribute
2382  = dynamic_cast<xercesc::DOMAttr*>(node);
2383  if (!attribute)
2384  {
2385  G4Exception("G4GDMLReadSolids::RZPointRead()",
2386  "InvalidRead", FatalException, "No attribute found!");
2387  return rzpoint;
2388  }
2389  const G4String attName = Transcode(attribute->getName());
2390  const G4String attValue = Transcode(attribute->getValue());
2391 
2392  if (attName=="r") { rzpoint.r = eval.Evaluate(attValue); } else
2393  if (attName=="z") { rzpoint.z = eval.Evaluate(attValue); }
2394  }
2395 
2396  return rzpoint;
2397 
2398 }
2399 
2400 void G4GDMLReadSolids::
2401 OpticalSurfaceRead(const xercesc::DOMElement* const opticalsurfaceElement)
2402 {
2403  G4String name;
2404  G4String smodel;
2405  G4String sfinish;
2406  G4String stype;
2407  G4double value = 0.0;
2408 
2409  const xercesc::DOMNamedNodeMap* const attributes
2410  = opticalsurfaceElement->getAttributes();
2411  XMLSize_t attributeCount = attributes->getLength();
2412 
2413  for (XMLSize_t attribute_index=0;
2414  attribute_index<attributeCount; attribute_index++)
2415  {
2416  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
2417 
2418  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
2419  { continue; }
2420 
2421  const xercesc::DOMAttr* const attribute
2422  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
2423  if (!attribute)
2424  {
2425  G4Exception("G4GDMLReadSolids::OpticalSurfaceRead()",
2426  "InvalidRead", FatalException, "No attribute found!");
2427  return;
2428  }
2429  const G4String attName = Transcode(attribute->getName());
2430  const G4String attValue = Transcode(attribute->getValue());
2431 
2432  if (attName=="name") { name = GenerateName(attValue); } else
2433  if (attName=="model") { smodel = attValue; } else
2434  if (attName=="finish") { sfinish = attValue; } else
2435  if (attName=="type") { stype = attValue; } else
2436  if (attName=="value") { value = eval.Evaluate(attValue); }
2437  }
2438 
2439  G4OpticalSurfaceModel model;
2440  G4OpticalSurfaceFinish finish;
2441  G4SurfaceType type;
2442 
2443  if ((smodel=="glisur") || (smodel=="0")) { model = glisur; } else
2444  if ((smodel=="unified") || (smodel=="1")) { model = unified; } else
2445  if ((smodel=="LUT") || (smodel=="2")) { model = LUT; }
2446  else { model = dichroic; }
2447 
2448  if ((sfinish=="polished") || (sfinish=="0"))
2449  { finish = polished; } else
2450  if ((sfinish=="polishedfrontpainted") || (sfinish=="1"))
2451  { finish = polishedfrontpainted; } else
2452  if ((sfinish=="polishedbackpainted") || (sfinish=="2"))
2453  { finish = polishedbackpainted; } else
2454  if ((sfinish=="ground") || (sfinish=="3"))
2455  { finish = ground; } else
2456  if ((sfinish=="groundfrontpainted") || (sfinish=="4"))
2457  { finish = groundfrontpainted; } else
2458  if ((sfinish=="groundbackpainted") || (sfinish=="5"))
2459  { finish = groundbackpainted; } else
2460  if ((sfinish=="polishedlumirrorair") || (sfinish=="6"))
2461  { finish = polishedlumirrorair; } else
2462  if ((sfinish=="polishedlumirrorglue") || (sfinish=="7"))
2463  { finish = polishedlumirrorglue; } else
2464  if ((sfinish=="polishedair") || (sfinish=="8"))
2465  { finish = polishedair; } else
2466  if ((sfinish=="polishedteflonair") || (sfinish=="9"))
2467  { finish = polishedteflonair; } else
2468  if ((sfinish=="polishedtioair") || (sfinish=="10"))
2469  { finish = polishedtioair; } else
2470  if ((sfinish=="polishedtyvekair") || (sfinish=="11"))
2471  { finish = polishedtyvekair; } else
2472  if ((sfinish=="polishedvm2000air") || (sfinish=="12"))
2473  { finish = polishedvm2000air; } else
2474  if ((sfinish=="polishedvm2000glue") || (sfinish=="13"))
2475  { finish = polishedvm2000glue; } else
2476  if ((sfinish=="etchedlumirrorair") || (sfinish=="14"))
2477  { finish = etchedlumirrorair; } else
2478  if ((sfinish=="etchedlumirrorglue") || (sfinish=="15"))
2479  { finish = etchedlumirrorglue; } else
2480  if ((sfinish=="etchedair") || (sfinish=="16"))
2481  { finish = etchedair; } else
2482  if ((sfinish=="etchedteflonair") || (sfinish=="17"))
2483  { finish = etchedteflonair; } else
2484  if ((sfinish=="etchedtioair") || (sfinish=="18"))
2485  { finish = etchedtioair; } else
2486  if ((sfinish=="etchedtyvekair") || (sfinish=="19"))
2487  { finish = etchedtyvekair; } else
2488  if ((sfinish=="etchedvm2000air") || (sfinish=="20"))
2489  { finish = etchedvm2000air; } else
2490  if ((sfinish=="etchedvm2000glue") || (sfinish=="21"))
2491  { finish = etchedvm2000glue; } else
2492  if ((sfinish=="groundlumirrorair") || (sfinish=="22"))
2493  { finish = groundlumirrorair; } else
2494  if ((sfinish=="groundlumirrorglue") || (sfinish=="23"))
2495  { finish = groundlumirrorglue; } else
2496  if ((sfinish=="groundair") || (sfinish=="24"))
2497  { finish = groundair; } else
2498  if ((sfinish=="groundteflonair") || (sfinish=="25"))
2499  { finish = groundteflonair; } else
2500  if ((sfinish=="groundtioair") || (sfinish=="26"))
2501  { finish = groundtioair; } else
2502  if ((sfinish=="groundtyvekair") || (sfinish=="27"))
2503  { finish = groundtyvekair; } else
2504  if ((sfinish=="groundvm2000air") || (sfinish=="28"))
2505  { finish = groundvm2000air; }
2506  else { finish = groundvm2000glue; }
2507 
2508  if ((stype=="dielectric_metal") || (stype=="0"))
2509  { type = dielectric_metal; } else
2510  if ((stype=="dielectric_dielectric") || (stype=="1"))
2511  { type = dielectric_dielectric; } else
2512  if ((stype=="dielectric_LUT") || (stype=="2"))
2513  { type = dielectric_LUT; } else
2514  if ((stype=="dielectric_dichroic") || (stype=="3"))
2515  { type = dielectric_dichroic; } else
2516  if ((stype=="firsov") || (stype=="4"))
2517  { type = firsov; }
2518  else { type = x_ray; }
2519 
2520  new G4OpticalSurface(name,model,finish,type,value);
2521 }
2522 
2523 void G4GDMLReadSolids::SolidsRead(const xercesc::DOMElement* const solidsElement)
2524 {
2525  G4cout << "G4GDML: Reading solids..." << G4endl;
2526 
2527  for (xercesc::DOMNode* iter = solidsElement->getFirstChild();
2528  iter != 0; iter = iter->getNextSibling())
2529  {
2530  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
2531 
2532  const xercesc::DOMElement* const child
2533  = dynamic_cast<xercesc::DOMElement*>(iter);
2534  if (!child)
2535  {
2536  G4Exception("G4GDMLReadSolids::SolidsRead()",
2537  "InvalidRead", FatalException, "No child found!");
2538  return;
2539  }
2540  const G4String tag = Transcode(child->getTagName());
2541  if (tag=="define") { DefineRead(child); } else
2542  if (tag=="box") { BoxRead(child); } else
2543  if (tag=="cone") { ConeRead(child); } else
2544  if (tag=="elcone") { ElconeRead(child); } else
2545  if (tag=="ellipsoid") { EllipsoidRead(child); }else
2546  if (tag=="eltube") { EltubeRead(child); } else
2547  if (tag=="xtru") { XtruRead(child); } else
2548  if (tag=="hype") { HypeRead(child); } else
2549  if (tag=="intersection") { BooleanRead(child,INTERSECTION); } else
2550  if (tag=="multiUnion") { MultiUnionRead(child); } else
2551  if (tag=="orb") { OrbRead(child); } else
2552  if (tag=="para") { ParaRead(child); } else
2553  if (tag=="paraboloid") { ParaboloidRead(child); } else
2554  if (tag=="polycone") { PolyconeRead(child); } else
2555  if (tag=="genericPolycone") { GenericPolyconeRead(child); } else
2556  if (tag=="polyhedra") { PolyhedraRead(child); } else
2557  if (tag=="genericPolyhedra") { GenericPolyhedraRead(child); } else
2558  if (tag=="reflectedSolid") { ReflectedSolidRead(child); } else
2559  if (tag=="sphere") { SphereRead(child); } else
2560  if (tag=="subtraction") { BooleanRead(child,SUBTRACTION); } else
2561  if (tag=="tessellated") { TessellatedRead(child); } else
2562  if (tag=="tet") { TetRead(child); } else
2563  if (tag=="torus") { TorusRead(child); } else
2564  if (tag=="arb8") { GenTrapRead(child); } else
2565  if (tag=="trap") { TrapRead(child); } else
2566  if (tag=="trd") { TrdRead(child); } else
2567  if (tag=="tube") { TubeRead(child); } else
2568  if (tag=="cutTube") { CutTubeRead(child); } else
2569  if (tag=="twistedbox") { TwistedboxRead(child); } else
2570  if (tag=="twistedtrap") { TwistedtrapRead(child); } else
2571  if (tag=="twistedtrd") { TwistedtrdRead(child); } else
2572  if (tag=="twistedtubs") { TwistedtubsRead(child); } else
2573  if (tag=="union") { BooleanRead(child,UNION); } else
2574  if (tag=="opticalsurface") { OpticalSurfaceRead(child); } else
2575  if (tag=="loop") { LoopRead(child,&G4GDMLRead::SolidsRead); }
2576  else
2577  {
2578  G4String error_msg = "Unknown tag in solids: " + tag;
2579  G4Exception("G4GDMLReadSolids::SolidsRead()", "ReadError",
2580  FatalException, error_msg);
2581  }
2582  }
2583 }
2584 
2586 {
2587  G4VSolid* solidPtr = G4SolidStore::GetInstance()->GetSolid(ref,false);
2588 
2589  if (!solidPtr)
2590  {
2591  G4String error_msg = "Referenced solid '" + ref + "' was not found!";
2592  G4Exception("G4GDMLReadSolids::GetSolid()", "ReadError",
2593  FatalException, error_msg);
2594  }
2595 
2596  return solidPtr;
2597 }
2598 
2600 GetSurfaceProperty(const G4String& ref) const
2601 {
2602  const G4SurfacePropertyTable* surfaceList
2604  const size_t surfaceCount = surfaceList->size();
2605 
2606  for (size_t i=0; i<surfaceCount; i++)
2607  {
2608  if ((*surfaceList)[i]->GetName() == ref) { return (*surfaceList)[i]; }
2609  }
2610 
2611  G4String error_msg = "Referenced optical surface '" + ref + "' was not found!";
2612  G4Exception("G4GDMLReadSolids::GetSurfaceProperty()", "ReadError",
2613  FatalException, error_msg);
2614 
2615  return 0;
2616 }
zplaneType ZplaneRead(const xercesc::DOMElement *const)
void TubeRead(const xercesc::DOMElement *const)
void TwistedtrapRead(const xercesc::DOMElement *const)
G4int EvaluateInteger(const G4String &)
Definition: G4Para.hh:77
void SetSolidClosed(const G4bool t)
void BoxRead(const xercesc::DOMElement *const)
G4VSolid * GetSolid(const G4String &name, G4bool verbose=true) const
G4GDMLEvaluator eval
Definition: G4GDMLRead.hh:155
void OpticalSurfaceRead(const xercesc::DOMElement *const)
CLHEP::Hep3Vector G4ThreeVector
G4double z
Definition: TRTMaterials.hh:39
virtual void DefineRead(const xercesc::DOMElement *const)
Definition: G4Box.hh:64
void TwistedboxRead(const xercesc::DOMElement *const)
G4String name
Definition: TRTMaterials.hh:40
Definition: G4Tubs.hh:85
Definition: xmlparse.cc:187
void MultiUnionRead(const xercesc::DOMElement *const)
void TorusRead(const xercesc::DOMElement *const)
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
void TetRead(const xercesc::DOMElement *const)
G4TwoVector TwoDimVertexRead(const xercesc::DOMElement *const, G4double)
G4SurfaceProperty * GetSurfaceProperty(const G4String &) const
void GenericPolyhedraRead(const xercesc::DOMElement *const)
Definition: G4Trd.hh:72
G4SurfaceType
G4TriangularFacet * TriangularRead(const xercesc::DOMElement *const)
int G4int
Definition: G4Types.hh:78
G4VSolid * GetSolid(const G4String &) const
void TwistedtubsRead(const xercesc::DOMElement *const)
void TrapRead(const xercesc::DOMElement *const)
void ConeRead(const xercesc::DOMElement *const)
G4String RefRead(const xercesc::DOMElement *const)
void LoopRead(const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
Definition: G4GDMLRead.cc:176
void SphereRead(const xercesc::DOMElement *const)
static G4double GetValueOf(const G4String &)
void OrbRead(const xercesc::DOMElement *const)
#define position
Definition: xmlparse.cc:622
G4ExtrudedSolid::ZSection SectionRead(const xercesc::DOMElement *const, G4double)
G4GLOB_DLL std::ostream G4cout
void BooleanRead(const xercesc::DOMElement *const, const BooleanOp)
G4FacetVertexType
Definition: G4VFacet.hh:56
Definition: G4Tet.hh:65
Definition: G4Hype.hh:67
void ReflectedSolidRead(const xercesc::DOMElement *const)
void EllipsoidRead(const xercesc::DOMElement *const)
Definition: G4Cons.hh:83
G4bool AddFacet(G4VFacet *aFacet)
void GenTrapRead(const xercesc::DOMElement *const)
static G4SolidStore * GetInstance()
void TrdRead(const xercesc::DOMElement *const)
virtual ~G4GDMLReadSolids()
HepGeom::Transform3D G4Transform3D
HepGeom::Scale3D G4Scale3D
Definition: G4Orb.hh:61
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void SolidsRead(const xercesc::DOMElement *const)
void EltubeRead(const xercesc::DOMElement *const)
rzPointType RZPointRead(const xercesc::DOMElement *const)
void G4MultiUnion
Definition: G4MultiUnion.hh:53
static G4String GetCategory(const G4String &)
std::vector< G4SurfaceProperty * > G4SurfacePropertyTable
G4String GenerateName(const G4String &name, G4bool strip=false)
Definition: G4GDMLRead.cc:68
void TessellatedRead(const xercesc::DOMElement *const)
void PolyhedraRead(const xercesc::DOMElement *const)
void XtruRead(const xercesc::DOMElement *const)
void CutTubeRead(const xercesc::DOMElement *const)
G4OpticalSurfaceFinish
const G4double x[NPOINTSGL]
void VectorRead(const xercesc::DOMElement *const, G4ThreeVector &)
void ParaboloidRead(const xercesc::DOMElement *const)
CLHEP::Hep2Vector G4TwoVector
Definition: G4TwoVector.hh:42
void GenericPolyconeRead(const xercesc::DOMElement *const)
G4OpticalSurfaceModel
void ElconeRead(const xercesc::DOMElement *const)
#define G4endl
Definition: G4ios.hh:61
G4ThreeVector GetRotation(const G4String &)
G4RotationMatrix GetRotationMatrix(const G4ThreeVector &)
void ParaRead(const xercesc::DOMElement *const)
double G4double
Definition: G4Types.hh:76
void HypeRead(const xercesc::DOMElement *const)
static const G4double alpha
void PolyconeRead(const xercesc::DOMElement *const)
G4QuadrangularFacet * QuadrangularRead(const xercesc::DOMElement *const)
void MultiUnionNodeRead(const xercesc::DOMElement *const, G4MultiUnion *const)
static const G4SurfacePropertyTable * GetSurfacePropertyTable()
virtual void SolidsRead(const xercesc::DOMElement *const)=0
void TwistedtrdRead(const xercesc::DOMElement *const)
G4double Evaluate(const G4String &)
G4ThreeVector GetPosition(const G4String &)