Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/persistency/gdml/src/G4GDMLWriteSolids.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /persistency/gdml/src/G4GDMLWriteSolids.cc (Version 11.3.0) and /persistency/gdml/src/G4GDMLWriteSolids.cc (Version 10.4.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4GDMLWriteSolids implementation            << 
 27 //                                                 26 //
 28 // Author: Zoltan Torzsok, November 2007       <<  27 // $Id: G4GDMLWriteSolids.cc 110108 2018-05-15 11:46:54Z gcosmo $
                                                   >>  28 //
                                                   >>  29 // class G4GDMLWriteSolids Implementation
                                                   >>  30 //
                                                   >>  31 // Original author: Zoltan Torzsok, November 2007
                                                   >>  32 //
 29 // -------------------------------------------     33 // --------------------------------------------------------------------
 30                                                    34 
 31 #include "G4GDMLWriteSolids.hh"                    35 #include "G4GDMLWriteSolids.hh"
 32                                                    36 
 33 #include "G4SystemOfUnits.hh"                      37 #include "G4SystemOfUnits.hh"
 34 #include "G4BooleanSolid.hh"                       38 #include "G4BooleanSolid.hh"
 35 #include "G4ScaledSolid.hh"                        39 #include "G4ScaledSolid.hh"
 36 #include "G4Box.hh"                                40 #include "G4Box.hh"
 37 #include "G4Cons.hh"                               41 #include "G4Cons.hh"
 38 #include "G4Ellipsoid.hh"                          42 #include "G4Ellipsoid.hh"
 39 #include "G4EllipticalCone.hh"                     43 #include "G4EllipticalCone.hh"
 40 #include "G4EllipticalTube.hh"                     44 #include "G4EllipticalTube.hh"
 41 #include "G4ExtrudedSolid.hh"                      45 #include "G4ExtrudedSolid.hh"
 42 #include "G4Hype.hh"                               46 #include "G4Hype.hh"
 43 #include "G4Orb.hh"                                47 #include "G4Orb.hh"
 44 #include "G4Para.hh"                               48 #include "G4Para.hh"
 45 #include "G4Paraboloid.hh"                         49 #include "G4Paraboloid.hh"
 46 #include "G4IntersectionSolid.hh"                  50 #include "G4IntersectionSolid.hh"
 47 #include "G4Polycone.hh"                           51 #include "G4Polycone.hh"
 48 #include "G4GenericPolycone.hh"                    52 #include "G4GenericPolycone.hh"
 49 #include "G4Polyhedra.hh"                          53 #include "G4Polyhedra.hh"
 50 #include "G4ReflectedSolid.hh"                     54 #include "G4ReflectedSolid.hh"
 51 #include "G4Sphere.hh"                             55 #include "G4Sphere.hh"
 52 #include "G4SubtractionSolid.hh"                   56 #include "G4SubtractionSolid.hh"
 53 #include "G4GenericTrap.hh"                        57 #include "G4GenericTrap.hh"
 54 #include "G4TessellatedSolid.hh"                   58 #include "G4TessellatedSolid.hh"
 55 #include "G4Tet.hh"                                59 #include "G4Tet.hh"
 56 #include "G4Torus.hh"                              60 #include "G4Torus.hh"
 57 #include "G4Trap.hh"                               61 #include "G4Trap.hh"
 58 #include "G4Trd.hh"                                62 #include "G4Trd.hh"
 59 #include "G4Tubs.hh"                               63 #include "G4Tubs.hh"
 60 #include "G4CutTubs.hh"                            64 #include "G4CutTubs.hh"
 61 #include "G4TwistedBox.hh"                         65 #include "G4TwistedBox.hh"
 62 #include "G4TwistedTrap.hh"                        66 #include "G4TwistedTrap.hh"
 63 #include "G4TwistedTrd.hh"                         67 #include "G4TwistedTrd.hh"
 64 #include "G4TwistedTubs.hh"                        68 #include "G4TwistedTubs.hh"
 65 #include "G4UnionSolid.hh"                         69 #include "G4UnionSolid.hh"
 66 #include "G4OpticalSurface.hh"                     70 #include "G4OpticalSurface.hh"
 67 #include "G4SurfaceProperty.hh"                    71 #include "G4SurfaceProperty.hh"
 68 #include "G4MaterialPropertiesTable.hh"            72 #include "G4MaterialPropertiesTable.hh"
 69                                                    73 
 70 // ------------------------------------------- << 
 71 G4GDMLWriteSolids::G4GDMLWriteSolids()             74 G4GDMLWriteSolids::G4GDMLWriteSolids()
 72   : G4GDMLWriteMaterials()                     <<  75   : G4GDMLWriteMaterials(), solidsElement(0)
 73 {                                                  76 {
 74 }                                                  77 }
 75                                                    78 
 76 // ------------------------------------------- << 
 77 G4GDMLWriteSolids::~G4GDMLWriteSolids()            79 G4GDMLWriteSolids::~G4GDMLWriteSolids()
 78 {                                                  80 {
 79 }                                                  81 }
 80                                                    82 
 81 // ------------------------------------------- <<  83 void G4GDMLWriteSolids::
 82 void G4GDMLWriteSolids::MultiUnionWrite(xerces <<  84 MultiUnionWrite(xercesc::DOMElement* solElement,
 83                                         const  <<  85                 const G4MultiUnion* const munionSolid)
 84 {                                              <<  86 {
 85   G4int numSolids = munionSolid->GetNumberOfSo <<  87    G4int numSolids=munionSolid->GetNumberOfSolids();
 86   G4String tag("multiUnion");                  <<  88    G4String tag("multiUnion");
 87                                                <<  89    
 88   G4VSolid* solid;                             <<  90    G4VSolid* solid;
 89   G4Transform3D transform;                     <<  91    G4Transform3D transform;
 90                                                <<  92 
 91   const G4String& name = GenerateName(munionSo <<  93    const G4String& name = GenerateName(munionSolid->GetName(),munionSolid);
 92   xercesc::DOMElement* multiUnionElement = New <<  94    xercesc::DOMElement* multiUnionElement = NewElement(tag);
 93   multiUnionElement->setAttributeNode(NewAttri <<  95    multiUnionElement->setAttributeNode(NewAttribute("name",name));
 94                                                <<  96 
 95   for(G4int i = 0; i < numSolids; ++i)         <<  97    for (G4int i=0; i<numSolids; ++i)
 96   {                                            <<  98    {
 97     solid     = munionSolid->GetSolid(i);      <<  99       solid = munionSolid->GetSolid(i);
 98     transform = munionSolid->GetTransformation << 100       transform = munionSolid->GetTransformation(i);
 99                                                << 101 
100     HepGeom::Rotate3D rot3d;                   << 102       HepGeom::Rotate3D rot3d;
101     HepGeom::Translate3D transl;               << 103       HepGeom::Translate3D transl ;
102     HepGeom::Scale3D scale;                    << 104       HepGeom::Scale3D scale;
103     transform.getDecomposition(scale, rot3d, t << 105       transform.getDecomposition(scale,rot3d,transl); 
104                                                << 106 
105     G4ThreeVector pos = transl.getTranslation( << 107       G4ThreeVector pos = transl.getTranslation();
106     G4RotationMatrix rotm(CLHEP::HepRep3x3(rot << 108       G4RotationMatrix 
107                                            rot << 109         rotm(CLHEP::HepRep3x3(rot3d.xx(), rot3d.xy(), rot3d.xz(),
108                                            rot << 110                               rot3d.yx(), rot3d.yy(), rot3d.yz(),
109     G4ThreeVector rot = GetAngles(rotm);       << 111                               rot3d.zx(), rot3d.zy(), rot3d.zz()));
110                                                << 112       G4ThreeVector rot = GetAngles(rotm);
111     AddSolid(solid);                           << 113 
112     const G4String& solidref = GenerateName(so << 114       AddSolid(solid);
113     std::ostringstream os;                     << 115       const G4String& solidref = GenerateName(solid->GetName(),solid);
114     os << i + 1;                               << 116       std::ostringstream os; os << i+1;
115     const G4String& nodeName          = "Node- << 117       const G4String& nodeName = "Node-" + G4String(os.str());
116     xercesc::DOMElement* solidElement = NewEle << 118       xercesc::DOMElement* solidElement = NewElement("solid");
117     solidElement->setAttributeNode(NewAttribut << 119       solidElement->setAttributeNode(NewAttribute("ref",solidref));
118     xercesc::DOMElement* multiUnionNodeElement << 120       xercesc::DOMElement* multiUnionNodeElement = NewElement("multiUnionNode");
119     multiUnionNodeElement->setAttributeNode(Ne << 121       multiUnionNodeElement->setAttributeNode(NewAttribute("name", nodeName));
120     multiUnionNodeElement->appendChild(solidEl << 122       multiUnionNodeElement->appendChild(solidElement); // Append solid to node
121     if((std::fabs(pos.x()) > kLinearPrecision) << 123       if ( (std::fabs(pos.x()) > kLinearPrecision)
122        (std::fabs(pos.y()) > kLinearPrecision) << 124         || (std::fabs(pos.y()) > kLinearPrecision)
123        (std::fabs(pos.z()) > kLinearPrecision) << 125         || (std::fabs(pos.z()) > kLinearPrecision) )
124     {                                          << 126       {
125       PositionWrite(multiUnionNodeElement,name << 127         PositionWrite(multiUnionNodeElement,name+"_pos",pos);
126     }                                          << 128       }
127     if((std::fabs(rot.x()) > kAngularPrecision << 129       if ( (std::fabs(rot.x()) > kAngularPrecision)
128        (std::fabs(rot.y()) > kAngularPrecision << 130         || (std::fabs(rot.y()) > kAngularPrecision)
129        (std::fabs(rot.z()) > kAngularPrecision << 131         || (std::fabs(rot.z()) > kAngularPrecision) )
130     {                                          << 132       {
131       RotationWrite(multiUnionNodeElement,name << 133         RotationWrite(multiUnionNodeElement,name+"_rot",rot);
132     }                                          << 134       }
133     multiUnionElement->appendChild(multiUnionN << 135       multiUnionElement->appendChild(multiUnionNodeElement); // Append node
134   }                                            << 136    }
135                                                << 
136   solElement->appendChild(multiUnionElement);  << 
137   // Add the multiUnion solid AFTER the consti << 
138 }                                              << 
139                                                << 
140 // ------------------------------------------- << 
141 void G4GDMLWriteSolids::BooleanWrite(xercesc:: << 
142                                      const G4B << 
143 {                                              << 
144   G4int displaced = 0;                         << 
145                                                << 
146   G4String tag("undefined");                   << 
147   if(dynamic_cast<const G4IntersectionSolid*>( << 
148   {                                            << 
149     tag = "intersection";                      << 
150   }                                            << 
151   else if(dynamic_cast<const G4SubtractionSoli << 
152   {                                            << 
153     tag = "subtraction";                       << 
154   }                                            << 
155   else if(dynamic_cast<const G4UnionSolid*>(bo << 
156   {                                            << 
157     tag = "union";                             << 
158   }                                            << 
159                                                << 
160   G4VSolid* firstPtr  = const_cast<G4VSolid*>( << 
161   G4VSolid* secondPtr = const_cast<G4VSolid*>( << 
162                                                << 
163   G4ThreeVector firstpos, firstrot, pos, rot;  << 
164                                                << 
165   // Solve possible displacement of referenced << 
166   //                                           << 
167   while(true)                                  << 
168   {                                            << 
169     if(displaced > 8)                          << 
170     {                                          << 
171       G4String ErrorMessage = "The referenced  << 
172                               +"in the Boolean << 
173                               +"' was displace << 
174       G4Exception("G4GDMLWriteSolids::BooleanW << 
175                   FatalException, ErrorMessage << 
176     }                                          << 
177                                                << 
178     if(G4DisplacedSolid* disp = dynamic_cast<G << 
179     {                                          << 
180       firstpos += disp->GetObjectTranslation() << 
181       firstrot += GetAngles(disp->GetObjectRot << 
182       firstPtr = disp->GetConstituentMovedSoli << 
183       ++displaced;                             << 
184       continue;                                << 
185     }                                          << 
186     break;                                     << 
187   }                                            << 
188   displaced = 0;                               << 
189   while(true)                                  << 
190   {                                            << 
191     if(displaced > maxTransforms)              << 
192     {                                          << 
193       G4String ErrorMessage = "The referenced  << 
194                               +"in the Boolean << 
195                               +"' was displace << 
196       G4Exception("G4GDMLWriteSolids::BooleanW << 
197                   FatalException, ErrorMessage << 
198     }                                          << 
199                                                << 
200     if(G4DisplacedSolid* disp = dynamic_cast<G << 
201     {                                          << 
202       pos += disp->GetObjectTranslation();     << 
203       rot += GetAngles(disp->GetObjectRotation << 
204       secondPtr = disp->GetConstituentMovedSol << 
205       ++displaced;                             << 
206       continue;                                << 
207     }                                          << 
208     break;                                     << 
209   }                                            << 
210                                                << 
211   AddSolid(firstPtr);  // At first add the con << 
212   AddSolid(secondPtr);                         << 
213                                                << 
214   const G4String& name      = GenerateName(boo << 
215   const G4String& firstref  = GenerateName(fir << 
216   const G4String& secondref = GenerateName(sec << 
217                                                << 
218   xercesc::DOMElement* booleanElement = NewEle << 
219   booleanElement->setAttributeNode(NewAttribut << 
220   xercesc::DOMElement* firstElement = NewEleme << 
221   firstElement->setAttributeNode(NewAttribute( << 
222   booleanElement->appendChild(firstElement);   << 
223   xercesc::DOMElement* secondElement = NewElem << 
224   secondElement->setAttributeNode(NewAttribute << 
225   booleanElement->appendChild(secondElement);  << 
226   solElement->appendChild(booleanElement);     << 
227   // Add the boolean solid AFTER the constitue << 
228                                                << 
229   if((std::fabs(pos.x()) > kLinearPrecision) | << 
230      (std::fabs(pos.y()) > kLinearPrecision) | << 
231      (std::fabs(pos.z()) > kLinearPrecision))  << 
232   {                                            << 
233     PositionWrite(booleanElement, name + "_pos << 
234   }                                            << 
235                                                << 
236   if((std::fabs(rot.x()) > kAngularPrecision)  << 
237      (std::fabs(rot.y()) > kAngularPrecision)  << 
238      (std::fabs(rot.z()) > kAngularPrecision)) << 
239   {                                            << 
240     RotationWrite(booleanElement, name + "_rot << 
241   }                                            << 
242                                                << 
243   if((std::fabs(firstpos.x()) > kLinearPrecisi << 
244      (std::fabs(firstpos.y()) > kLinearPrecisi << 
245      (std::fabs(firstpos.z()) > kLinearPrecisi << 
246   {                                            << 
247     FirstpositionWrite(booleanElement, name +  << 
248   }                                            << 
249                                                << 
250   if((std::fabs(firstrot.x()) > kAngularPrecis << 
251      (std::fabs(firstrot.y()) > kAngularPrecis << 
252      (std::fabs(firstrot.z()) > kAngularPrecis << 
253   {                                            << 
254     FirstrotationWrite(booleanElement, name +  << 
255   }                                            << 
256 }                                              << 
257                                                << 
258 // ------------------------------------------- << 
259 void G4GDMLWriteSolids::ScaledWrite(xercesc::D << 
260                                     const G4Sc << 
261 {                                              << 
262   G4String tag("scaledSolid");                 << 
263                                                << 
264   G4VSolid* solid         = const_cast<G4VSoli << 
265   G4Scale3D scale         = scaled->GetScaleTr << 
266   G4ThreeVector sclVector = G4ThreeVector(scal << 
267                                                << 
268   AddSolid(solid);  // Add the constituent sol << 
269                                                << 
270   const G4String& name     = GenerateName(scal << 
271   const G4String& solidref = GenerateName(soli << 
272                                                << 
273   xercesc::DOMElement* scaledElement = NewElem << 
274   scaledElement->setAttributeNode(NewAttribute << 
275                                                << 
276   xercesc::DOMElement* solidElement = NewEleme << 
277   solidElement->setAttributeNode(NewAttribute( << 
278   scaledElement->appendChild(solidElement);    << 
279                                                << 
280   if((std::fabs(scale.xx()) > kLinearPrecision << 
281      (std::fabs(scale.yy()) > kLinearPrecision << 
282      (std::fabs(scale.zz()) > kLinearPrecision << 
283   {                                            << 
284     ScaleWrite(scaledElement, name + "_scl", s << 
285   }                                            << 
286                                                << 
287   solElement->appendChild(scaledElement);      << 
288   // Add the scaled solid AFTER its constituen << 
289 }                                              << 
290                                                << 
291 // ------------------------------------------- << 
292 void G4GDMLWriteSolids::BoxWrite(xercesc::DOME << 
293                                  const G4Box*  << 
294 {                                              << 
295   const G4String& name = GenerateName(box->Get << 
296                                                << 
297   xercesc::DOMElement* boxElement = NewElement << 
298   boxElement->setAttributeNode(NewAttribute("n << 
299   boxElement->setAttributeNode(                << 
300     NewAttribute("x", 2.0 * box->GetXHalfLengt << 
301   boxElement->setAttributeNode(                << 
302     NewAttribute("y", 2.0 * box->GetYHalfLengt << 
303   boxElement->setAttributeNode(                << 
304     NewAttribute("z", 2.0 * box->GetZHalfLengt << 
305   boxElement->setAttributeNode(NewAttribute("l << 
306   solElement->appendChild(boxElement);         << 
307 }                                              << 
308                                                << 
309 // ------------------------------------------- << 
310 void G4GDMLWriteSolids::ConeWrite(xercesc::DOM << 
311                                   const G4Cons << 
312 {                                              << 
313   const G4String& name = GenerateName(cone->Ge << 
314                                                << 
315   xercesc::DOMElement* coneElement = NewElemen << 
316   coneElement->setAttributeNode(NewAttribute(" << 
317   coneElement->setAttributeNode(               << 
318     NewAttribute("rmin1", cone->GetInnerRadius << 
319   coneElement->setAttributeNode(               << 
320     NewAttribute("rmax1", cone->GetOuterRadius << 
321   coneElement->setAttributeNode(               << 
322     NewAttribute("rmin2", cone->GetInnerRadius << 
323   coneElement->setAttributeNode(               << 
324     NewAttribute("rmax2", cone->GetOuterRadius << 
325   coneElement->setAttributeNode(               << 
326     NewAttribute("z", 2.0 * cone->GetZHalfLeng << 
327   coneElement->setAttributeNode(               << 
328     NewAttribute("startphi", cone->GetStartPhi << 
329   coneElement->setAttributeNode(               << 
330     NewAttribute("deltaphi", cone->GetDeltaPhi << 
331   coneElement->setAttributeNode(NewAttribute(" << 
332   coneElement->setAttributeNode(NewAttribute(" << 
333   solElement->appendChild(coneElement);        << 
334 }                                              << 
335                                                << 
336 // ------------------------------------------- << 
337 void G4GDMLWriteSolids::ElconeWrite(xercesc::D << 
338                                     const G4El << 
339 {                                              << 
340   const G4String& name = GenerateName(elcone-> << 
341                                                << 
342   xercesc::DOMElement* elconeElement = NewElem << 
343   elconeElement->setAttributeNode(NewAttribute << 
344   elconeElement->setAttributeNode(             << 
345     NewAttribute("dx", elcone->GetSemiAxisX()  << 
346   elconeElement->setAttributeNode(             << 
347     NewAttribute("dy", elcone->GetSemiAxisY()  << 
348   elconeElement->setAttributeNode(NewAttribute << 
349   elconeElement->setAttributeNode(             << 
350     NewAttribute("zcut", elcone->GetZTopCut()  << 
351   elconeElement->setAttributeNode(NewAttribute << 
352   solElement->appendChild(elconeElement);      << 
353 }                                              << 
354                                                << 
355 // ------------------------------------------- << 
356 void G4GDMLWriteSolids::EllipsoidWrite(xercesc << 
357                                        const G << 
358 {                                              << 
359   const G4String& name = GenerateName(ellipsoi << 
360                                                << 
361   xercesc::DOMElement* ellipsoidElement = NewE << 
362   ellipsoidElement->setAttributeNode(NewAttrib << 
363   ellipsoidElement->setAttributeNode(          << 
364     NewAttribute("ax", ellipsoid->GetSemiAxisM << 
365   ellipsoidElement->setAttributeNode(          << 
366     NewAttribute("by", ellipsoid->GetSemiAxisM << 
367   ellipsoidElement->setAttributeNode(          << 
368     NewAttribute("cz", ellipsoid->GetSemiAxisM << 
369   ellipsoidElement->setAttributeNode(          << 
370     NewAttribute("zcut1", ellipsoid->GetZBotto << 
371   ellipsoidElement->setAttributeNode(          << 
372     NewAttribute("zcut2", ellipsoid->GetZTopCu << 
373   ellipsoidElement->setAttributeNode(NewAttrib << 
374   solElement->appendChild(ellipsoidElement);   << 
375 }                                              << 
376                                                << 
377 // ------------------------------------------- << 
378 void G4GDMLWriteSolids::EltubeWrite(xercesc::D << 
379                                     const G4El << 
380 {                                              << 
381   const G4String& name = GenerateName(eltube-> << 
382                                                << 
383   xercesc::DOMElement* eltubeElement = NewElem << 
384   eltubeElement->setAttributeNode(NewAttribute << 
385   eltubeElement->setAttributeNode(NewAttribute << 
386   eltubeElement->setAttributeNode(NewAttribute << 
387   eltubeElement->setAttributeNode(NewAttribute << 
388   eltubeElement->setAttributeNode(NewAttribute << 
389   solElement->appendChild(eltubeElement);      << 
390 }                                              << 
391                                                << 
392 // ------------------------------------------- << 
393 void G4GDMLWriteSolids::XtruWrite(xercesc::DOM << 
394                                   const G4Extr << 
395 {                                              << 
396   const G4String& name = GenerateName(xtru->Ge << 
397                                                << 
398   xercesc::DOMElement* xtruElement = NewElemen << 
399   xtruElement->setAttributeNode(NewAttribute(" << 
400   xtruElement->setAttributeNode(NewAttribute(" << 
401   solElement->appendChild(xtruElement);        << 
402                                                << 
403   const G4int NumVertex = xtru->GetNofVertices << 
404                                                << 
405   for(G4int i = 0; i < NumVertex; ++i)         << 
406   {                                            << 
407     xercesc::DOMElement* twoDimVertexElement = << 
408     xtruElement->appendChild(twoDimVertexEleme << 
409                                                << 
410     const G4TwoVector& vertex = xtru->GetVerte << 
411                                                << 
412     twoDimVertexElement->setAttributeNode(NewA << 
413     twoDimVertexElement->setAttributeNode(NewA << 
414   }                                            << 
415                                                << 
416   const G4int NumSection = xtru->GetNofZSectio << 
417                                                << 
418   for(G4int i = 0; i < NumSection; ++i)        << 
419   {                                            << 
420     xercesc::DOMElement* sectionElement = NewE << 
421     xtruElement->appendChild(sectionElement);  << 
422                                                << 
423     const G4ExtrudedSolid::ZSection section =  << 
424                                                << 
425     sectionElement->setAttributeNode(NewAttrib << 
426     sectionElement->setAttributeNode(          << 
427       NewAttribute("zPosition", section.fZ / m << 
428     sectionElement->setAttributeNode(          << 
429       NewAttribute("xOffset", section.fOffset. << 
430     sectionElement->setAttributeNode(          << 
431       NewAttribute("yOffset", section.fOffset. << 
432     sectionElement->setAttributeNode(          << 
433       NewAttribute("scalingFactor", section.fS << 
434   }                                            << 
435 }                                              << 
436                                                << 
437 // ------------------------------------------- << 
438 void G4GDMLWriteSolids::HypeWrite(xercesc::DOM << 
439                                   const G4Hype << 
440 {                                              << 
441   const G4String& name = GenerateName(hype->Ge << 
442                                                << 
443   xercesc::DOMElement* hypeElement = NewElemen << 
444   hypeElement->setAttributeNode(NewAttribute(" << 
445   hypeElement->setAttributeNode(               << 
446     NewAttribute("rmin", hype->GetInnerRadius( << 
447   hypeElement->setAttributeNode(               << 
448     NewAttribute("rmax", hype->GetOuterRadius( << 
449   hypeElement->setAttributeNode(               << 
450     NewAttribute("inst", hype->GetInnerStereo( << 
451   hypeElement->setAttributeNode(               << 
452     NewAttribute("outst", hype->GetOuterStereo << 
453   hypeElement->setAttributeNode(               << 
454     NewAttribute("z", 2.0 * hype->GetZHalfLeng << 
455   hypeElement->setAttributeNode(NewAttribute(" << 
456   hypeElement->setAttributeNode(NewAttribute(" << 
457   solElement->appendChild(hypeElement);        << 
458 }                                              << 
459                                                << 
460 // ------------------------------------------- << 
461 void G4GDMLWriteSolids::OrbWrite(xercesc::DOME << 
462                                  const G4Orb*  << 
463 {                                              << 
464   const G4String& name = GenerateName(orb->Get << 
465                                                << 
466   xercesc::DOMElement* orbElement = NewElement << 
467   orbElement->setAttributeNode(NewAttribute("n << 
468   orbElement->setAttributeNode(NewAttribute("r << 
469   orbElement->setAttributeNode(NewAttribute("l << 
470   solElement->appendChild(orbElement);         << 
471 }                                              << 
472                                                << 
473 // ------------------------------------------- << 
474 void G4GDMLWriteSolids::ParaWrite(xercesc::DOM << 
475                                   const G4Para << 
476 {                                              << 
477   const G4String& name = GenerateName(para->Ge << 
478                                                << 
479   const G4ThreeVector simaxis = para->GetSymAx << 
480   const G4double alpha        = std::atan(para << 
481   const G4double phi          = simaxis.phi(); << 
482   const G4double theta        = simaxis.theta( << 
483                                                << 
484   xercesc::DOMElement* paraElement = NewElemen << 
485   paraElement->setAttributeNode(NewAttribute(" << 
486   paraElement->setAttributeNode(               << 
487     NewAttribute("x", 2.0 * para->GetXHalfLeng << 
488   paraElement->setAttributeNode(               << 
489     NewAttribute("y", 2.0 * para->GetYHalfLeng << 
490   paraElement->setAttributeNode(               << 
491     NewAttribute("z", 2.0 * para->GetZHalfLeng << 
492   paraElement->setAttributeNode(NewAttribute(" << 
493   paraElement->setAttributeNode(NewAttribute(" << 
494   paraElement->setAttributeNode(NewAttribute(" << 
495   paraElement->setAttributeNode(NewAttribute(" << 
496   paraElement->setAttributeNode(NewAttribute(" << 
497   solElement->appendChild(paraElement);        << 
498 }                                              << 
499                                                << 
500 // ------------------------------------------- << 
501 void G4GDMLWriteSolids::ParaboloidWrite(xerces << 
502                                         const  << 
503 {                                              << 
504   const G4String& name = GenerateName(parabolo << 
505                                                   137 
506   xercesc::DOMElement* paraboloidElement = New << 138    solElement->appendChild(multiUnionElement);
507   paraboloidElement->setAttributeNode(NewAttri << 139      // Add the multiUnion solid AFTER the constituent nodes!
508   paraboloidElement->setAttributeNode(         << 
509     NewAttribute("rlo", paraboloid->GetRadiusM << 
510   paraboloidElement->setAttributeNode(         << 
511     NewAttribute("rhi", paraboloid->GetRadiusP << 
512   paraboloidElement->setAttributeNode(         << 
513     NewAttribute("dz", paraboloid->GetZHalfLen << 
514   paraboloidElement->setAttributeNode(NewAttri << 
515   solElement->appendChild(paraboloidElement);  << 
516 }                                                 140 }
517                                                   141 
518 // ------------------------------------------- << 142 void G4GDMLWriteSolids::
519 void G4GDMLWriteSolids::PolyconeWrite(xercesc: << 143 BooleanWrite(xercesc::DOMElement* solElement,
520                                       const G4 << 144              const G4BooleanSolid* const boolean)
521 {                                              << 145 {
522   const G4String& name = GenerateName(polycone << 146    G4int displaced=0;
523                                                << 147 
524   xercesc::DOMElement* polyconeElement = NewEl << 148    G4String tag("undefined");
525   polyconeElement->setAttributeNode(NewAttribu << 149    if (dynamic_cast<const G4IntersectionSolid*>(boolean))
526   polyconeElement->setAttributeNode(NewAttribu << 150      { tag = "intersection"; } else
527     "startphi", polycone->GetOriginalParameter << 151    if (dynamic_cast<const G4SubtractionSolid*>(boolean))
528   polyconeElement->setAttributeNode(NewAttribu << 152      { tag = "subtraction"; } else
529     "deltaphi", polycone->GetOriginalParameter << 153    if (dynamic_cast<const G4UnionSolid*>(boolean))
530   polyconeElement->setAttributeNode(NewAttribu << 154      { tag = "union"; }
531   polyconeElement->setAttributeNode(NewAttribu << 155    
532   solElement->appendChild(polyconeElement);    << 156    G4VSolid* firstPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(0));
533                                                << 157    G4VSolid* secondPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(1));
534   const std::size_t num_zplanes                << 158    
535         = polycone->GetOriginalParameters()->N << 159    G4ThreeVector firstpos,firstrot,pos,rot;
536   const G4double* z_array    = polycone->GetOr << 160 
537   const G4double* rmin_array = polycone->GetOr << 161    // Solve possible displacement of referenced solids!
538   const G4double* rmax_array = polycone->GetOr << 162    //
539                                                << 163    while (true)
540   for(std::size_t i = 0; i < num_zplanes; ++i) << 164    {
541   {                                            << 165       if ( displaced>8 )
542     ZplaneWrite(polyconeElement, z_array[i], r << 166       {
543   }                                            << 167         G4String ErrorMessage = "The referenced solid '"
544 }                                              << 168                               + firstPtr->GetName() +
                                                   >> 169                               + "in the Boolean shape '" +
                                                   >> 170                               + boolean->GetName() +
                                                   >> 171                               + "' was displaced too many times!";
                                                   >> 172         G4Exception("G4GDMLWriteSolids::BooleanWrite()",
                                                   >> 173                     "InvalidSetup", FatalException, ErrorMessage);
                                                   >> 174       }
545                                                   175 
546 // ------------------------------------------- << 176       if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(firstPtr))
547 void G4GDMLWriteSolids::GenericPolyconeWrite(  << 177       {
548   xercesc::DOMElement* solElement, const G4Gen << 178          firstpos += disp->GetObjectTranslation();
549 {                                              << 179          firstrot += GetAngles(disp->GetObjectRotation());
550   const G4String& name = GenerateName(polycone << 180          firstPtr = disp->GetConstituentMovedSolid();
551   xercesc::DOMElement* polyconeElement = NewEl << 181          displaced++;
552   const G4double startPhi              = polyc << 182          continue;
553   polyconeElement->setAttributeNode(NewAttribu << 183       }
554   polyconeElement->setAttributeNode(           << 184       break;
555     NewAttribute("startphi", startPhi / degree << 185    }
556   polyconeElement->setAttributeNode(           << 186    displaced = 0;
557     NewAttribute("deltaphi", (polycone->GetEnd << 187    while (true)
558   polyconeElement->setAttributeNode(NewAttribu << 188    {
559   polyconeElement->setAttributeNode(NewAttribu << 189       if ( displaced>maxTransforms )
560   solElement->appendChild(polyconeElement);    << 190       {
561                                                << 191         G4String ErrorMessage = "The referenced solid '"
562   const G4int num_rzpoints = (G4int)polycone-> << 192                               + secondPtr->GetName() +
563   for(G4int i = 0; i < num_rzpoints; ++i)      << 193                               + "in the Boolean shape '" +
564   {                                            << 194                               + boolean->GetName() +
565     const G4double r_point = polycone->GetCorn << 195                               + "' was displaced too many times!";
566     const G4double z_point = polycone->GetCorn << 196         G4Exception("G4GDMLWriteSolids::BooleanWrite()",
567     RZPointWrite(polyconeElement, r_point, z_p << 197                     "InvalidSetup", FatalException, ErrorMessage);
568   }                                            << 198       }
569 }                                              << 
570                                                   199 
571 // ------------------------------------------- << 200       if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(secondPtr))
572 void G4GDMLWriteSolids::PolyhedraWrite(xercesc << 201       {
573                                        const G << 202          pos += disp->GetObjectTranslation();
574 {                                              << 203          rot += GetAngles(disp->GetObjectRotation());
575   const G4String& name = GenerateName(polyhedr << 204          secondPtr = disp->GetConstituentMovedSolid();
576   if(polyhedra->IsGeneric() == false)          << 205          displaced++;
577   {                                            << 206          continue;
578     xercesc::DOMElement* polyhedraElement = Ne << 207       }
579     polyhedraElement->setAttributeNode(NewAttr << 208       break;
580     polyhedraElement->setAttributeNode(NewAttr << 209    }
581       "startphi", polyhedra->GetOriginalParame << 
582     polyhedraElement->setAttributeNode(NewAttr << 
583       "deltaphi", polyhedra->GetOriginalParame << 
584     polyhedraElement->setAttributeNode(        << 
585       NewAttribute("numsides", polyhedra->GetO << 
586     polyhedraElement->setAttributeNode(NewAttr << 
587     polyhedraElement->setAttributeNode(NewAttr << 
588     solElement->appendChild(polyhedraElement); << 
589                                                << 
590     const std::size_t num_zplanes              << 
591           = polyhedra->GetOriginalParameters() << 
592     const G4double* z_array  = polyhedra->GetO << 
593     const G4double* rmin_array = polyhedra->Ge << 
594     const G4double* rmax_array = polyhedra->Ge << 
595                                                << 
596     const G4double convertRad =                << 
597       std::cos(0.5 * polyhedra->GetOriginalPar << 
598                polyhedra->GetOriginalParameter << 
599                                                   210 
600     for(std::size_t i = 0; i < num_zplanes; ++ << 211    AddSolid(firstPtr);   // At first add the constituent solids!
601     {                                          << 212    AddSolid(secondPtr);
602       ZplaneWrite(polyhedraElement, z_array[i] << 
603                   rmax_array[i] * convertRad); << 
604     }                                          << 
605   }                                            << 
606   else  // generic polyhedra                   << 
607   {                                            << 
608     xercesc::DOMElement* polyhedraElement = Ne << 
609     polyhedraElement->setAttributeNode(NewAttr << 
610     polyhedraElement->setAttributeNode(NewAttr << 
611       "startphi", polyhedra->GetOriginalParame << 
612     polyhedraElement->setAttributeNode(NewAttr << 
613       "deltaphi", polyhedra->GetOriginalParame << 
614     polyhedraElement->setAttributeNode(        << 
615       NewAttribute("numsides", polyhedra->GetO << 
616     polyhedraElement->setAttributeNode(NewAttr << 
617     polyhedraElement->setAttributeNode(NewAttr << 
618     solElement->appendChild(polyhedraElement); << 
619                                                   213 
620     const G4int num_rzpoints = (G4int)polyhedr << 214    const G4String& name = GenerateName(boolean->GetName(),boolean);
                                                   >> 215    const G4String& firstref = GenerateName(firstPtr->GetName(),firstPtr);
                                                   >> 216    const G4String& secondref = GenerateName(secondPtr->GetName(),secondPtr);
                                                   >> 217 
                                                   >> 218    xercesc::DOMElement* booleanElement = NewElement(tag);
                                                   >> 219    booleanElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 220    xercesc::DOMElement* firstElement = NewElement("first");
                                                   >> 221    firstElement->setAttributeNode(NewAttribute("ref",firstref));
                                                   >> 222    booleanElement->appendChild(firstElement);
                                                   >> 223    xercesc::DOMElement* secondElement = NewElement("second");
                                                   >> 224    secondElement->setAttributeNode(NewAttribute("ref",secondref));
                                                   >> 225    booleanElement->appendChild(secondElement);
                                                   >> 226    solElement->appendChild(booleanElement);
                                                   >> 227      // Add the boolean solid AFTER the constituent solids!
                                                   >> 228 
                                                   >> 229    if ( (std::fabs(pos.x()) > kLinearPrecision)
                                                   >> 230      || (std::fabs(pos.y()) > kLinearPrecision)
                                                   >> 231      || (std::fabs(pos.z()) > kLinearPrecision) )
                                                   >> 232    {
                                                   >> 233      PositionWrite(booleanElement,name+"_pos",pos);
                                                   >> 234    }
                                                   >> 235 
                                                   >> 236    if ( (std::fabs(rot.x()) > kAngularPrecision)
                                                   >> 237      || (std::fabs(rot.y()) > kAngularPrecision)
                                                   >> 238      || (std::fabs(rot.z()) > kAngularPrecision) )
                                                   >> 239    {
                                                   >> 240      RotationWrite(booleanElement,name+"_rot",rot);
                                                   >> 241    }
                                                   >> 242 
                                                   >> 243    if ( (std::fabs(firstpos.x()) > kLinearPrecision)
                                                   >> 244      || (std::fabs(firstpos.y()) > kLinearPrecision)
                                                   >> 245      || (std::fabs(firstpos.z()) > kLinearPrecision) )
                                                   >> 246    {
                                                   >> 247      FirstpositionWrite(booleanElement,name+"_fpos",firstpos);
                                                   >> 248    }
                                                   >> 249 
                                                   >> 250    if ( (std::fabs(firstrot.x()) > kAngularPrecision)
                                                   >> 251      || (std::fabs(firstrot.y()) > kAngularPrecision)
                                                   >> 252      || (std::fabs(firstrot.z()) > kAngularPrecision) )
                                                   >> 253    {
                                                   >> 254      FirstrotationWrite(booleanElement,name+"_frot",firstrot);
                                                   >> 255    }
                                                   >> 256 }
                                                   >> 257 
                                                   >> 258 void G4GDMLWriteSolids::
                                                   >> 259 ScaledWrite(xercesc::DOMElement* solElement,
                                                   >> 260             const G4ScaledSolid* const scaled)
                                                   >> 261 {
                                                   >> 262    G4String tag("scaledSolid");
                                                   >> 263    
                                                   >> 264    G4VSolid* solid = const_cast<G4VSolid*>(scaled->GetUnscaledSolid());
                                                   >> 265    G4Scale3D scale = scaled->GetScaleTransform();
                                                   >> 266    G4ThreeVector sclVector = G4ThreeVector(scale.xx(), scale.yy(), scale.zz());
                                                   >> 267 
                                                   >> 268    AddSolid(solid);   // Add the constituent solid!
                                                   >> 269 
                                                   >> 270    const G4String& name = GenerateName(scaled->GetName(),scaled);
                                                   >> 271    const G4String& solidref = GenerateName(solid->GetName(),solid);
                                                   >> 272 
                                                   >> 273    xercesc::DOMElement* scaledElement = NewElement(tag);
                                                   >> 274    scaledElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 275 
                                                   >> 276    xercesc::DOMElement* solidElement = NewElement("solidref");
                                                   >> 277    solidElement->setAttributeNode(NewAttribute("ref",solidref));
                                                   >> 278    scaledElement->appendChild(solidElement);
                                                   >> 279 
                                                   >> 280    if ( (std::fabs(scale.xx()) > kLinearPrecision)
                                                   >> 281      && (std::fabs(scale.yy()) > kLinearPrecision)
                                                   >> 282      && (std::fabs(scale.zz()) > kLinearPrecision) )
                                                   >> 283    {
                                                   >> 284      ScaleWrite(scaledElement, name+"_scl", sclVector);
                                                   >> 285    }
                                                   >> 286 
                                                   >> 287    solElement->appendChild(scaledElement);
                                                   >> 288      // Add the scaled solid AFTER its constituent solid!
                                                   >> 289 }
                                                   >> 290 
                                                   >> 291 void G4GDMLWriteSolids::
                                                   >> 292 BoxWrite(xercesc::DOMElement* solElement, const G4Box* const box)
                                                   >> 293 {
                                                   >> 294    const G4String& name = GenerateName(box->GetName(),box);
                                                   >> 295 
                                                   >> 296    xercesc::DOMElement* boxElement = NewElement("box");
                                                   >> 297    boxElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 298    boxElement->setAttributeNode(NewAttribute("x",2.0*box->GetXHalfLength()/mm));
                                                   >> 299    boxElement->setAttributeNode(NewAttribute("y",2.0*box->GetYHalfLength()/mm));
                                                   >> 300    boxElement->setAttributeNode(NewAttribute("z",2.0*box->GetZHalfLength()/mm));
                                                   >> 301    boxElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 302    solElement->appendChild(boxElement);
                                                   >> 303 }
                                                   >> 304 
                                                   >> 305 void G4GDMLWriteSolids::
                                                   >> 306 ConeWrite(xercesc::DOMElement* solElement, const G4Cons* const cone)
                                                   >> 307 {
                                                   >> 308    const G4String& name = GenerateName(cone->GetName(),cone);
                                                   >> 309 
                                                   >> 310    xercesc::DOMElement* coneElement = NewElement("cone");
                                                   >> 311    coneElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 312    coneElement->
                                                   >> 313      setAttributeNode(NewAttribute("rmin1",cone->GetInnerRadiusMinusZ()/mm));
                                                   >> 314    coneElement->
                                                   >> 315      setAttributeNode(NewAttribute("rmax1",cone->GetOuterRadiusMinusZ()/mm));
                                                   >> 316    coneElement->
                                                   >> 317      setAttributeNode(NewAttribute("rmin2",cone->GetInnerRadiusPlusZ()/mm));
                                                   >> 318    coneElement->
                                                   >> 319      setAttributeNode(NewAttribute("rmax2",cone->GetOuterRadiusPlusZ()/mm));
                                                   >> 320    coneElement->
                                                   >> 321      setAttributeNode(NewAttribute("z",2.0*cone->GetZHalfLength()/mm));
                                                   >> 322    coneElement->
                                                   >> 323      setAttributeNode(NewAttribute("startphi",cone->GetStartPhiAngle()/degree));
                                                   >> 324    coneElement->
                                                   >> 325      setAttributeNode(NewAttribute("deltaphi",cone->GetDeltaPhiAngle()/degree));
                                                   >> 326    coneElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 327    coneElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 328    solElement->appendChild(coneElement);
                                                   >> 329 }
                                                   >> 330 
                                                   >> 331 void G4GDMLWriteSolids::
                                                   >> 332 ElconeWrite(xercesc::DOMElement* solElement,
                                                   >> 333             const G4EllipticalCone* const elcone)
                                                   >> 334 {
                                                   >> 335    const G4String& name = GenerateName(elcone->GetName(),elcone);
                                                   >> 336 
                                                   >> 337    xercesc::DOMElement* elconeElement = NewElement("elcone");
                                                   >> 338    elconeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 339    elconeElement->setAttributeNode(NewAttribute("dx",elcone->GetSemiAxisX()/mm));
                                                   >> 340    elconeElement->setAttributeNode(NewAttribute("dy",elcone->GetSemiAxisY()/mm));
                                                   >> 341    elconeElement->setAttributeNode(NewAttribute("zmax",elcone->GetZMax()/mm));
                                                   >> 342    elconeElement->setAttributeNode(NewAttribute("zcut",elcone->GetZTopCut()/mm));
                                                   >> 343    elconeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 344    solElement->appendChild(elconeElement);
                                                   >> 345 }
                                                   >> 346 
                                                   >> 347 void G4GDMLWriteSolids::
                                                   >> 348 EllipsoidWrite(xercesc::DOMElement* solElement,
                                                   >> 349                const G4Ellipsoid* const ellipsoid)
                                                   >> 350 {
                                                   >> 351    const G4String& name = GenerateName(ellipsoid->GetName(),ellipsoid);
                                                   >> 352 
                                                   >> 353    xercesc::DOMElement* ellipsoidElement = NewElement("ellipsoid");
                                                   >> 354    ellipsoidElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 355    ellipsoidElement->
                                                   >> 356      setAttributeNode(NewAttribute("ax",ellipsoid->GetSemiAxisMax(0)/mm));
                                                   >> 357    ellipsoidElement->
                                                   >> 358      setAttributeNode(NewAttribute("by",ellipsoid->GetSemiAxisMax(1)/mm));
                                                   >> 359    ellipsoidElement->
                                                   >> 360      setAttributeNode(NewAttribute("cz",ellipsoid->GetSemiAxisMax(2)/mm));
                                                   >> 361    ellipsoidElement->
                                                   >> 362      setAttributeNode(NewAttribute("zcut1",ellipsoid->GetZBottomCut()/mm));
                                                   >> 363    ellipsoidElement->
                                                   >> 364      setAttributeNode(NewAttribute("zcut2",ellipsoid->GetZTopCut()/mm));
                                                   >> 365    ellipsoidElement->
                                                   >> 366      setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 367    solElement->appendChild(ellipsoidElement);
                                                   >> 368 }
                                                   >> 369 
                                                   >> 370 void G4GDMLWriteSolids::
                                                   >> 371 EltubeWrite(xercesc::DOMElement* solElement,
                                                   >> 372             const G4EllipticalTube* const eltube)
                                                   >> 373 {
                                                   >> 374    const G4String& name = GenerateName(eltube->GetName(),eltube);
                                                   >> 375 
                                                   >> 376    xercesc::DOMElement* eltubeElement = NewElement("eltube");
                                                   >> 377    eltubeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 378    eltubeElement->setAttributeNode(NewAttribute("dx",eltube->GetDx()/mm));
                                                   >> 379    eltubeElement->setAttributeNode(NewAttribute("dy",eltube->GetDy()/mm));
                                                   >> 380    eltubeElement->setAttributeNode(NewAttribute("dz",eltube->GetDz()/mm));
                                                   >> 381    eltubeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 382    solElement->appendChild(eltubeElement);
                                                   >> 383 }
                                                   >> 384 
                                                   >> 385 void G4GDMLWriteSolids::
                                                   >> 386 XtruWrite(xercesc::DOMElement* solElement,
                                                   >> 387           const G4ExtrudedSolid* const xtru)
                                                   >> 388 {
                                                   >> 389    const G4String& name = GenerateName(xtru->GetName(),xtru);
                                                   >> 390 
                                                   >> 391    xercesc::DOMElement* xtruElement = NewElement("xtru");
                                                   >> 392    xtruElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 393    xtruElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 394    solElement->appendChild(xtruElement);
                                                   >> 395 
                                                   >> 396    const G4int NumVertex = xtru->GetNofVertices();
                                                   >> 397    
                                                   >> 398    for (G4int i=0;i<NumVertex;i++)
                                                   >> 399    {
                                                   >> 400       xercesc::DOMElement* twoDimVertexElement = NewElement("twoDimVertex");
                                                   >> 401       xtruElement->appendChild(twoDimVertexElement);
                                                   >> 402 
                                                   >> 403       const G4TwoVector& vertex = xtru->GetVertex(i);
                                                   >> 404 
                                                   >> 405       twoDimVertexElement->setAttributeNode(NewAttribute("x",vertex.x()/mm));
                                                   >> 406       twoDimVertexElement->setAttributeNode(NewAttribute("y",vertex.y()/mm));
                                                   >> 407    }
                                                   >> 408 
                                                   >> 409    const G4int NumSection = xtru->GetNofZSections();
                                                   >> 410 
                                                   >> 411    for (G4int i=0;i<NumSection;i++)
                                                   >> 412    {
                                                   >> 413       xercesc::DOMElement* sectionElement = NewElement("section");
                                                   >> 414       xtruElement->appendChild(sectionElement);
                                                   >> 415 
                                                   >> 416       const G4ExtrudedSolid::ZSection section = xtru->GetZSection(i);
                                                   >> 417 
                                                   >> 418       sectionElement->setAttributeNode(NewAttribute("zOrder",i));
                                                   >> 419       sectionElement->setAttributeNode(NewAttribute("zPosition",section.fZ/mm));
                                                   >> 420       sectionElement->
                                                   >> 421         setAttributeNode(NewAttribute("xOffset",section.fOffset.x()/mm));
                                                   >> 422       sectionElement->
                                                   >> 423         setAttributeNode(NewAttribute("yOffset",section.fOffset.y()/mm));
                                                   >> 424       sectionElement->
                                                   >> 425         setAttributeNode(NewAttribute("scalingFactor",section.fScale));
                                                   >> 426    }
                                                   >> 427 }
                                                   >> 428 
                                                   >> 429 void G4GDMLWriteSolids::
                                                   >> 430 HypeWrite(xercesc::DOMElement* solElement, const G4Hype* const hype)
                                                   >> 431 {
                                                   >> 432    const G4String& name = GenerateName(hype->GetName(),hype);
                                                   >> 433 
                                                   >> 434    xercesc::DOMElement* hypeElement = NewElement("hype");
                                                   >> 435    hypeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 436    hypeElement->setAttributeNode(NewAttribute("rmin",
                                                   >> 437                 hype->GetInnerRadius()/mm));
                                                   >> 438    hypeElement->setAttributeNode(NewAttribute("rmax",
                                                   >> 439                 hype->GetOuterRadius()/mm));
                                                   >> 440    hypeElement->setAttributeNode(NewAttribute("inst",
                                                   >> 441                 hype->GetInnerStereo()/degree));
                                                   >> 442    hypeElement->setAttributeNode(NewAttribute("outst",
                                                   >> 443                 hype->GetOuterStereo()/degree));
                                                   >> 444    hypeElement->setAttributeNode(NewAttribute("z",
                                                   >> 445                 2.0*hype->GetZHalfLength()/mm));
                                                   >> 446    hypeElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 447    hypeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 448    solElement->appendChild(hypeElement);
                                                   >> 449 }
                                                   >> 450 
                                                   >> 451 void G4GDMLWriteSolids::
                                                   >> 452 OrbWrite(xercesc::DOMElement* solElement, const G4Orb* const orb)
                                                   >> 453 {
                                                   >> 454    const G4String& name = GenerateName(orb->GetName(),orb);
                                                   >> 455 
                                                   >> 456    xercesc::DOMElement* orbElement = NewElement("orb");
                                                   >> 457    orbElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 458    orbElement->setAttributeNode(NewAttribute("r",orb->GetRadius()/mm));
                                                   >> 459    orbElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 460    solElement->appendChild(orbElement);
                                                   >> 461 }
                                                   >> 462 
                                                   >> 463 void G4GDMLWriteSolids::
                                                   >> 464 ParaWrite(xercesc::DOMElement* solElement, const G4Para* const para)
                                                   >> 465 {
                                                   >> 466    const G4String& name = GenerateName(para->GetName(),para);
                                                   >> 467 
                                                   >> 468    const G4ThreeVector simaxis = para->GetSymAxis();
                                                   >> 469    const G4double alpha = std::atan(para->GetTanAlpha());
                                                   >> 470    const G4double phi = simaxis.phi();
                                                   >> 471    const G4double theta = simaxis.theta();
                                                   >> 472 
                                                   >> 473    xercesc::DOMElement* paraElement = NewElement("para");
                                                   >> 474    paraElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 475    paraElement->setAttributeNode(NewAttribute("x",
                                                   >> 476                 2.0*para->GetXHalfLength()/mm));
                                                   >> 477    paraElement->setAttributeNode(NewAttribute("y",
                                                   >> 478                 2.0*para->GetYHalfLength()/mm));
                                                   >> 479    paraElement->setAttributeNode(NewAttribute("z",
                                                   >> 480                 2.0*para->GetZHalfLength()/mm));
                                                   >> 481    paraElement->setAttributeNode(NewAttribute("alpha",alpha/degree));
                                                   >> 482    paraElement->setAttributeNode(NewAttribute("theta",theta/degree));
                                                   >> 483    paraElement->setAttributeNode(NewAttribute("phi",phi/degree));
                                                   >> 484    paraElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 485    paraElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 486    solElement->appendChild(paraElement);
                                                   >> 487 }
                                                   >> 488 
                                                   >> 489 void G4GDMLWriteSolids::
                                                   >> 490 ParaboloidWrite(xercesc::DOMElement* solElement,
                                                   >> 491                 const G4Paraboloid* const paraboloid)
                                                   >> 492 {
                                                   >> 493    const G4String& name = GenerateName(paraboloid->GetName(),paraboloid);
                                                   >> 494 
                                                   >> 495    xercesc::DOMElement* paraboloidElement = NewElement("paraboloid");
                                                   >> 496    paraboloidElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 497    paraboloidElement->setAttributeNode(NewAttribute("rlo",
                                                   >> 498                       paraboloid->GetRadiusMinusZ()/mm));
                                                   >> 499    paraboloidElement->setAttributeNode(NewAttribute("rhi",
                                                   >> 500                       paraboloid->GetRadiusPlusZ()/mm));
                                                   >> 501    paraboloidElement->setAttributeNode(NewAttribute("dz",
                                                   >> 502                       paraboloid->GetZHalfLength()/mm));
                                                   >> 503    paraboloidElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 504    solElement->appendChild(paraboloidElement);
                                                   >> 505 }
                                                   >> 506 void G4GDMLWriteSolids::
                                                   >> 507 PolyconeWrite(xercesc::DOMElement* solElement,
                                                   >> 508               const G4Polycone* const polycone)
                                                   >> 509 {
                                                   >> 510    const G4String& name = GenerateName(polycone->GetName(),polycone);
                                                   >> 511   
                                                   >> 512     xercesc::DOMElement* polyconeElement = NewElement("polycone");
                                                   >> 513     polyconeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 514     polyconeElement->setAttributeNode(NewAttribute("startphi",
                                                   >> 515                     polycone->GetOriginalParameters()->Start_angle/degree));
                                                   >> 516     polyconeElement->setAttributeNode(NewAttribute("deltaphi",
                                                   >> 517                     polycone->GetOriginalParameters()->Opening_angle/degree));
                                                   >> 518     polyconeElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 519     polyconeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 520     solElement->appendChild(polyconeElement);
                                                   >> 521 
                                                   >> 522     const size_t num_zplanes = polycone->GetOriginalParameters()->Num_z_planes;
                                                   >> 523     const G4double* z_array = polycone->GetOriginalParameters()->Z_values;
                                                   >> 524     const G4double* rmin_array = polycone->GetOriginalParameters()->Rmin;
                                                   >> 525     const G4double* rmax_array = polycone->GetOriginalParameters()->Rmax;
621                                                   526 
622     for(G4int i = 0; i < num_rzpoints; ++i)    << 527     for (size_t i=0; i<num_zplanes; i++)
623     {                                             528     {
624       const G4double r_point = polyhedra->GetC << 529       ZplaneWrite(polyconeElement,z_array[i],rmin_array[i],rmax_array[i]);
625       const G4double z_point = polyhedra->GetC << 
626       RZPointWrite(polyhedraElement, r_point,  << 
627     }                                             530     }
628   }                                            << 531    
629 }                                              << 532   
630                                                << 
631 // ------------------------------------------- << 
632 void G4GDMLWriteSolids::SphereWrite(xercesc::D << 
633                                     const G4Sp << 
634 {                                              << 
635   const G4String& name = GenerateName(sphere-> << 
636                                                << 
637   xercesc::DOMElement* sphereElement = NewElem << 
638   sphereElement->setAttributeNode(NewAttribute << 
639   sphereElement->setAttributeNode(             << 
640     NewAttribute("rmin", sphere->GetInnerRadiu << 
641   sphereElement->setAttributeNode(             << 
642     NewAttribute("rmax", sphere->GetOuterRadiu << 
643   sphereElement->setAttributeNode(             << 
644     NewAttribute("startphi", sphere->GetStartP << 
645   sphereElement->setAttributeNode(             << 
646     NewAttribute("deltaphi", sphere->GetDeltaP << 
647   sphereElement->setAttributeNode(             << 
648     NewAttribute("starttheta", sphere->GetStar << 
649   sphereElement->setAttributeNode(             << 
650     NewAttribute("deltatheta", sphere->GetDelt << 
651   sphereElement->setAttributeNode(NewAttribute << 
652   sphereElement->setAttributeNode(NewAttribute << 
653   solElement->appendChild(sphereElement);      << 
654 }                                                 533 }
655                                                   534 
656 // ------------------------------------------- << 535 void G4GDMLWriteSolids::
657 void G4GDMLWriteSolids::TessellatedWrite(      << 536 GenericPolyconeWrite(xercesc::DOMElement* solElement,
658   xercesc::DOMElement* solElement, const G4Tes << 537               const G4GenericPolycone* const polycone)
659 {                                              << 538 {
660   const G4String& solid_name = tessellated->Ge << 539    const G4String& name = GenerateName(polycone->GetName(),polycone);
661   const G4String& name       = GenerateName(so << 540    xercesc::DOMElement* polyconeElement = NewElement("genericPolycone");
662                                                << 541    const G4double startPhi=polycone->GetStartPhi();
663   xercesc::DOMElement* tessellatedElement = Ne << 542     polyconeElement->setAttributeNode(NewAttribute("name",name));
664   tessellatedElement->setAttributeNode(NewAttr << 543     polyconeElement->setAttributeNode(NewAttribute("startphi",
665   tessellatedElement->setAttributeNode(NewAttr << 544         startPhi/degree));
666   tessellatedElement->setAttributeNode(NewAttr << 545     polyconeElement->setAttributeNode(NewAttribute("deltaphi",
667   solElement->appendChild(tessellatedElement); << 546         (polycone->GetEndPhi()-startPhi)/degree));
668                                                << 547     polyconeElement->setAttributeNode(NewAttribute("aunit","deg"));
669   std::map<G4ThreeVector, G4String, G4ThreeVec << 548     polyconeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 549     solElement->appendChild(polyconeElement);
670                                                   550 
671   const std::size_t NumFacets = tessellated->G << 551     const size_t num_rzpoints = polycone->GetNumRZCorner();
672   std::size_t NumVertex = 0;                   << 552     for (size_t i=0; i<num_rzpoints; i++)
673                                                << 
674   for(std::size_t i = 0; i < NumFacets; ++i)   << 
675   {                                            << 
676     const G4VFacet* facet          = tessellat << 
677     const size_t NumVertexPerFacet = facet->Ge << 
678                                                << 
679     G4String FacetTag;                         << 
680                                                << 
681     if(NumVertexPerFacet == 3)                 << 
682     {                                          << 
683       FacetTag = "triangular";                 << 
684     }                                          << 
685     else if(NumVertexPerFacet == 4)            << 
686     {                                          << 
687       FacetTag = "quadrangular";               << 
688     }                                          << 
689     else                                       << 
690     {                                             553     {
691       G4Exception("G4GDMLWriteSolids::Tessella << 554       const G4double r_point=polycone->GetCorner(i).r;
692                   FatalException, "Facet shoul << 555       const G4double z_point=polycone->GetCorner(i).z;
                                                   >> 556       RZPointWrite(polyconeElement,r_point,z_point);
693     }                                             557     }
                                                   >> 558 }
694                                                   559 
695     xercesc::DOMElement* facetElement = NewEle << 560 void G4GDMLWriteSolids::
696     tessellatedElement->appendChild(facetEleme << 561 PolyhedraWrite(xercesc::DOMElement* solElement,
697                                                << 562                const G4Polyhedra* const polyhedra)
698     for(std::size_t j = 0; j < NumVertexPerFac << 563 {
699     {                                          << 564    const G4String& name = GenerateName(polyhedra->GetName(),polyhedra);
700       std::stringstream name_stream;           << 565    if(polyhedra->IsGeneric() == false)
701       std::stringstream ref_stream;            << 566    {
702                                                << 567      xercesc::DOMElement* polyhedraElement = NewElement("polyhedra");
703       name_stream << "vertex" << (j + 1);      << 568      polyhedraElement->setAttributeNode(NewAttribute("name",name));
704       ref_stream << solid_name << "_v" << NumV << 569      polyhedraElement->setAttributeNode(NewAttribute("startphi",
705                                                << 570                      polyhedra->GetOriginalParameters()->Start_angle/degree));
706       const G4String& fname = name_stream.str( << 571      polyhedraElement->setAttributeNode(NewAttribute("deltaphi",
707       G4String ref          = ref_stream.str() << 572                      polyhedra->GetOriginalParameters()->Opening_angle/degree));
708                                                << 573      polyhedraElement->setAttributeNode(NewAttribute("numsides",
709       // Now search for the existance of the c << 574                      polyhedra->GetOriginalParameters()->numSide));
710       // map of cached vertices. If existing,  << 575      polyhedraElement->setAttributeNode(NewAttribute("aunit","deg"));
711       // position in the GDML file, so avoidin << 576      polyhedraElement->setAttributeNode(NewAttribute("lunit","mm"));
712       // cache it in the local map and add it  << 577      solElement->appendChild(polyhedraElement);
713       // "define" section of the GDML file.    << 578 
714                                                << 579      const size_t num_zplanes =
715       const G4ThreeVector& vertex = facet->Get << 580            polyhedra->GetOriginalParameters()->Num_z_planes;
716                                                << 581      const G4double* z_array =
717       if(vertexMap.find(vertex) != vertexMap.c << 582            polyhedra->GetOriginalParameters()->Z_values;
718       {                                        << 583      const G4double* rmin_array = polyhedra->GetOriginalParameters()->Rmin;
719         ref = vertexMap[vertex];  // Set the p << 584      const G4double* rmax_array = polyhedra->GetOriginalParameters()->Rmax;
720       }                                        << 585 
721       else  // Vertex not found                << 586      const G4double convertRad =
                                                   >> 587            std::cos(0.5*polyhedra->GetOriginalParameters()->Opening_angle
                                                   >> 588            / polyhedra->GetOriginalParameters()->numSide);
                                                   >> 589 
                                                   >> 590      for (size_t i=0;i<num_zplanes;i++)
                                                   >> 591      {
                                                   >> 592        ZplaneWrite(polyhedraElement,z_array[i],
                                                   >> 593                    rmin_array[i]*convertRad, rmax_array[i]*convertRad);
                                                   >> 594      }
                                                   >> 595    }
                                                   >> 596    else  // generic polyhedra
                                                   >> 597    {
                                                   >> 598      xercesc::DOMElement* polyhedraElement = NewElement("genericPolyhedra");
                                                   >> 599      polyhedraElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 600      polyhedraElement->setAttributeNode(NewAttribute("startphi",
                                                   >> 601                      polyhedra->GetOriginalParameters()->Start_angle/degree));
                                                   >> 602      polyhedraElement->setAttributeNode(NewAttribute("deltaphi",
                                                   >> 603                      polyhedra->GetOriginalParameters()->Opening_angle/degree));
                                                   >> 604      polyhedraElement->setAttributeNode(NewAttribute("numsides",
                                                   >> 605                      polyhedra->GetOriginalParameters()->numSide));
                                                   >> 606      polyhedraElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 607      polyhedraElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 608      solElement->appendChild(polyhedraElement);
                                                   >> 609 
                                                   >> 610      const size_t num_rzpoints = polyhedra->GetNumRZCorner();
                                                   >> 611     
                                                   >> 612      for (size_t i=0;i<num_rzpoints;i++)
                                                   >> 613      {
                                                   >> 614        const G4double r_point = polyhedra->GetCorner(i).r;
                                                   >> 615        const G4double z_point = polyhedra->GetCorner(i).z;
                                                   >> 616        RZPointWrite(polyhedraElement,r_point,z_point);
                                                   >> 617      }
                                                   >> 618    }
                                                   >> 619 }
                                                   >> 620 
                                                   >> 621 void G4GDMLWriteSolids::
                                                   >> 622 SphereWrite(xercesc::DOMElement* solElement, const G4Sphere* const sphere)
                                                   >> 623 {
                                                   >> 624    const G4String& name = GenerateName(sphere->GetName(),sphere);
                                                   >> 625 
                                                   >> 626    xercesc::DOMElement* sphereElement = NewElement("sphere");
                                                   >> 627    sphereElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 628    sphereElement->setAttributeNode(NewAttribute("rmin",
                                                   >> 629                   sphere->GetInnerRadius()/mm));
                                                   >> 630    sphereElement->setAttributeNode(NewAttribute("rmax",
                                                   >> 631                   sphere->GetOuterRadius()/mm));
                                                   >> 632    sphereElement->setAttributeNode(NewAttribute("startphi",
                                                   >> 633                   sphere->GetStartPhiAngle()/degree));
                                                   >> 634    sphereElement->setAttributeNode(NewAttribute("deltaphi",
                                                   >> 635                   sphere->GetDeltaPhiAngle()/degree));
                                                   >> 636    sphereElement->setAttributeNode(NewAttribute("starttheta",
                                                   >> 637                   sphere->GetStartThetaAngle()/degree));
                                                   >> 638    sphereElement->setAttributeNode(NewAttribute("deltatheta",
                                                   >> 639                   sphere->GetDeltaThetaAngle()/degree));
                                                   >> 640    sphereElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 641    sphereElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 642    solElement->appendChild(sphereElement);
                                                   >> 643 }
                                                   >> 644 
                                                   >> 645 void G4GDMLWriteSolids::
                                                   >> 646 TessellatedWrite(xercesc::DOMElement* solElement,
                                                   >> 647                  const G4TessellatedSolid* const tessellated)
                                                   >> 648 {
                                                   >> 649    const G4String& solid_name = tessellated->GetName();
                                                   >> 650    const G4String& name = GenerateName(solid_name, tessellated);
                                                   >> 651 
                                                   >> 652    xercesc::DOMElement* tessellatedElement = NewElement("tessellated");
                                                   >> 653    tessellatedElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 654    tessellatedElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 655    tessellatedElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 656    solElement->appendChild(tessellatedElement);
                                                   >> 657 
                                                   >> 658    std::map<G4ThreeVector, G4String, G4ThreeVectorCompare> vertexMap;
                                                   >> 659 
                                                   >> 660    const size_t NumFacets = tessellated->GetNumberOfFacets();
                                                   >> 661    size_t NumVertex = 0;
                                                   >> 662    
                                                   >> 663    for (size_t i=0;i<NumFacets;i++)
                                                   >> 664    {
                                                   >> 665       const G4VFacet* facet = tessellated->GetFacet(i);
                                                   >> 666       const size_t NumVertexPerFacet = facet->GetNumberOfVertices();
                                                   >> 667 
                                                   >> 668       G4String FacetTag;
                                                   >> 669       
                                                   >> 670       if (NumVertexPerFacet==3) { FacetTag="triangular"; } else
                                                   >> 671       if (NumVertexPerFacet==4) { FacetTag="quadrangular"; }
                                                   >> 672       else
722       {                                           673       {
723         if ( ! vertexMap.insert(std::make_pair << 674         G4Exception("G4GDMLWriteSolids::TessellatedWrite()", "InvalidSetup",
724         {                                      << 675                     FatalException, "Facet should contain 3 or 4 vertices!");
725           G4ExceptionDescription description;  << 
726           description << "Failed to insert [ve << 
727                       << ref << " in map.";    << 
728           G4Exception("G4GDMLWriteSolids::Tess << 
729                        JustWarning, descriptio << 
730         }                                      << 
731         AddPosition(ref, vertex);  // ... add  << 
732         ++NumVertex;                           << 
733       }                                           676       }
734                                                   677 
735       // Now create association of the vertex  << 678       xercesc::DOMElement* facetElement = NewElement(FacetTag);
736       //                                       << 679       tessellatedElement->appendChild(facetElement);
737       facetElement->setAttributeNode(NewAttrib << 
738     }                                          << 
739   }                                            << 
740 }                                              << 
741                                                << 
742 // ------------------------------------------- << 
743 void G4GDMLWriteSolids::TetWrite(xercesc::DOME << 
744                                  const G4Tet*  << 
745 {                                              << 
746   const G4String& solid_name = tet->GetName(); << 
747   const G4String& name       = GenerateName(so << 
748                                                << 
749   std::vector<G4ThreeVector> vertexList = tet- << 
750                                                << 
751   xercesc::DOMElement* tetElement = NewElement << 
752   tetElement->setAttributeNode(NewAttribute("n << 
753   tetElement->setAttributeNode(NewAttribute("v << 
754   tetElement->setAttributeNode(NewAttribute("v << 
755   tetElement->setAttributeNode(NewAttribute("v << 
756   tetElement->setAttributeNode(NewAttribute("v << 
757   tetElement->setAttributeNode(NewAttribute("l << 
758   solElement->appendChild(tetElement);         << 
759                                                << 
760   AddPosition(solid_name + "_v1", vertexList[0 << 
761   AddPosition(solid_name + "_v2", vertexList[1 << 
762   AddPosition(solid_name + "_v3", vertexList[2 << 
763   AddPosition(solid_name + "_v4", vertexList[3 << 
764 }                                              << 
765                                                << 
766 // ------------------------------------------- << 
767 void G4GDMLWriteSolids::TorusWrite(xercesc::DO << 
768                                    const G4Tor << 
769 {                                              << 
770   const G4String& name = GenerateName(torus->G << 
771                                                << 
772   xercesc::DOMElement* torusElement = NewEleme << 
773   torusElement->setAttributeNode(NewAttribute( << 
774   torusElement->setAttributeNode(NewAttribute( << 
775   torusElement->setAttributeNode(NewAttribute( << 
776   torusElement->setAttributeNode(NewAttribute( << 
777   torusElement->setAttributeNode(              << 
778     NewAttribute("startphi", torus->GetSPhi()  << 
779   torusElement->setAttributeNode(              << 
780     NewAttribute("deltaphi", torus->GetDPhi()  << 
781   torusElement->setAttributeNode(NewAttribute( << 
782   torusElement->setAttributeNode(NewAttribute( << 
783   solElement->appendChild(torusElement);       << 
784 }                                              << 
785                                                << 
786 // ------------------------------------------- << 
787 void G4GDMLWriteSolids::GenTrapWrite(xercesc:: << 
788                                      const G4G << 
789 {                                              << 
790   const G4String& name = GenerateName(gtrap->G << 
791                                                << 
792   std::vector<G4TwoVector> vertices = gtrap->G << 
793                                                << 
794   xercesc::DOMElement* gtrapElement = NewEleme << 
795   gtrapElement->setAttributeNode(NewAttribute( << 
796   gtrapElement->setAttributeNode(              << 
797     NewAttribute("dz", gtrap->GetZHalfLength() << 
798   gtrapElement->setAttributeNode(NewAttribute( << 
799   gtrapElement->setAttributeNode(NewAttribute( << 
800   gtrapElement->setAttributeNode(NewAttribute( << 
801   gtrapElement->setAttributeNode(NewAttribute( << 
802   gtrapElement->setAttributeNode(NewAttribute( << 
803   gtrapElement->setAttributeNode(NewAttribute( << 
804   gtrapElement->setAttributeNode(NewAttribute( << 
805   gtrapElement->setAttributeNode(NewAttribute( << 
806   gtrapElement->setAttributeNode(NewAttribute( << 
807   gtrapElement->setAttributeNode(NewAttribute( << 
808   gtrapElement->setAttributeNode(NewAttribute( << 
809   gtrapElement->setAttributeNode(NewAttribute( << 
810   gtrapElement->setAttributeNode(NewAttribute( << 
811   gtrapElement->setAttributeNode(NewAttribute( << 
812   gtrapElement->setAttributeNode(NewAttribute( << 
813   gtrapElement->setAttributeNode(NewAttribute( << 
814   gtrapElement->setAttributeNode(NewAttribute( << 
815   solElement->appendChild(gtrapElement);       << 
816 }                                              << 
817                                                << 
818 // ------------------------------------------- << 
819 void G4GDMLWriteSolids::TrapWrite(xercesc::DOM << 
820                                   const G4Trap << 
821 {                                              << 
822   const G4String& name = GenerateName(trap->Ge << 
823                                                << 
824   const G4ThreeVector& simaxis = trap->GetSymA << 
825   const G4double phi           = simaxis.phi() << 
826   const G4double theta         = simaxis.theta << 
827   const G4double alpha1        = std::atan(tra << 
828   const G4double alpha2        = std::atan(tra << 
829                                                << 
830   xercesc::DOMElement* trapElement = NewElemen << 
831   trapElement->setAttributeNode(NewAttribute(" << 
832   trapElement->setAttributeNode(               << 
833     NewAttribute("z", 2.0 * trap->GetZHalfLeng << 
834   trapElement->setAttributeNode(NewAttribute(" << 
835   trapElement->setAttributeNode(NewAttribute(" << 
836   trapElement->setAttributeNode(               << 
837     NewAttribute("y1", 2.0 * trap->GetYHalfLen << 
838   trapElement->setAttributeNode(               << 
839     NewAttribute("x1", 2.0 * trap->GetXHalfLen << 
840   trapElement->setAttributeNode(               << 
841     NewAttribute("x2", 2.0 * trap->GetXHalfLen << 
842   trapElement->setAttributeNode(NewAttribute(" << 
843   trapElement->setAttributeNode(               << 
844     NewAttribute("y2", 2.0 * trap->GetYHalfLen << 
845   trapElement->setAttributeNode(               << 
846     NewAttribute("x3", 2.0 * trap->GetXHalfLen << 
847   trapElement->setAttributeNode(               << 
848     NewAttribute("x4", 2.0 * trap->GetXHalfLen << 
849   trapElement->setAttributeNode(NewAttribute(" << 
850   trapElement->setAttributeNode(NewAttribute(" << 
851   trapElement->setAttributeNode(NewAttribute(" << 
852   solElement->appendChild(trapElement);        << 
853 }                                              << 
854                                                   680 
855 // ------------------------------------------- << 681       for (size_t j=0; j<NumVertexPerFacet; j++)
856 void G4GDMLWriteSolids::TrdWrite(xercesc::DOME << 682       {
857                                  const G4Trd*  << 683          std::stringstream name_stream;
858 {                                              << 684          std::stringstream ref_stream;
859   const G4String& name = GenerateName(trd->Get << 
860                                                << 
861   xercesc::DOMElement* trdElement = NewElement << 
862   trdElement->setAttributeNode(NewAttribute("n << 
863   trdElement->setAttributeNode(                << 
864     NewAttribute("x1", 2.0 * trd->GetXHalfLeng << 
865   trdElement->setAttributeNode(                << 
866     NewAttribute("x2", 2.0 * trd->GetXHalfLeng << 
867   trdElement->setAttributeNode(                << 
868     NewAttribute("y1", 2.0 * trd->GetYHalfLeng << 
869   trdElement->setAttributeNode(                << 
870     NewAttribute("y2", 2.0 * trd->GetYHalfLeng << 
871   trdElement->setAttributeNode(                << 
872     NewAttribute("z", 2.0 * trd->GetZHalfLengt << 
873   trdElement->setAttributeNode(NewAttribute("l << 
874   solElement->appendChild(trdElement);         << 
875 }                                              << 
876                                                << 
877 // ------------------------------------------- << 
878 void G4GDMLWriteSolids::TubeWrite(xercesc::DOM << 
879                                   const G4Tubs << 
880 {                                              << 
881   const G4String& name = GenerateName(tube->Ge << 
882                                                << 
883   xercesc::DOMElement* tubeElement = NewElemen << 
884   tubeElement->setAttributeNode(NewAttribute(" << 
885   tubeElement->setAttributeNode(               << 
886     NewAttribute("rmin", tube->GetInnerRadius( << 
887   tubeElement->setAttributeNode(               << 
888     NewAttribute("rmax", tube->GetOuterRadius( << 
889   tubeElement->setAttributeNode(               << 
890     NewAttribute("z", 2.0 * tube->GetZHalfLeng << 
891   tubeElement->setAttributeNode(               << 
892     NewAttribute("startphi", tube->GetStartPhi << 
893   tubeElement->setAttributeNode(               << 
894     NewAttribute("deltaphi", tube->GetDeltaPhi << 
895   tubeElement->setAttributeNode(NewAttribute(" << 
896   tubeElement->setAttributeNode(NewAttribute(" << 
897   solElement->appendChild(tubeElement);        << 
898 }                                              << 
899                                                << 
900 // ------------------------------------------- << 
901 void G4GDMLWriteSolids::CutTubeWrite(xercesc:: << 
902                                      const G4C << 
903 {                                              << 
904   const G4String& name = GenerateName(cuttube- << 
905                                                << 
906   xercesc::DOMElement* cuttubeElement = NewEle << 
907   cuttubeElement->setAttributeNode(NewAttribut << 
908   cuttubeElement->setAttributeNode(            << 
909     NewAttribute("rmin", cuttube->GetInnerRadi << 
910   cuttubeElement->setAttributeNode(            << 
911     NewAttribute("rmax", cuttube->GetOuterRadi << 
912   cuttubeElement->setAttributeNode(            << 
913     NewAttribute("z", 2.0 * cuttube->GetZHalfL << 
914   cuttubeElement->setAttributeNode(            << 
915     NewAttribute("startphi", cuttube->GetStart << 
916   cuttubeElement->setAttributeNode(            << 
917     NewAttribute("deltaphi", cuttube->GetDelta << 
918   cuttubeElement->setAttributeNode(            << 
919     NewAttribute("lowX", cuttube->GetLowNorm() << 
920   cuttubeElement->setAttributeNode(            << 
921     NewAttribute("lowY", cuttube->GetLowNorm() << 
922   cuttubeElement->setAttributeNode(            << 
923     NewAttribute("lowZ", cuttube->GetLowNorm() << 
924   cuttubeElement->setAttributeNode(            << 
925     NewAttribute("highX", cuttube->GetHighNorm << 
926   cuttubeElement->setAttributeNode(            << 
927     NewAttribute("highY", cuttube->GetHighNorm << 
928   cuttubeElement->setAttributeNode(            << 
929     NewAttribute("highZ", cuttube->GetHighNorm << 
930   cuttubeElement->setAttributeNode(NewAttribut << 
931   cuttubeElement->setAttributeNode(NewAttribut << 
932   solElement->appendChild(cuttubeElement);     << 
933 }                                              << 
934                                                << 
935 // ------------------------------------------- << 
936 void G4GDMLWriteSolids::TwistedboxWrite(xerces << 
937                                         const  << 
938 {                                              << 
939   const G4String& name = GenerateName(twistedb << 
940                                                << 
941   xercesc::DOMElement* twistedboxElement = New << 
942   twistedboxElement->setAttributeNode(NewAttri << 
943   twistedboxElement->setAttributeNode(         << 
944     NewAttribute("x", 2.0 * twistedbox->GetXHa << 
945   twistedboxElement->setAttributeNode(         << 
946     NewAttribute("y", 2.0 * twistedbox->GetYHa << 
947   twistedboxElement->setAttributeNode(         << 
948     NewAttribute("z", 2.0 * twistedbox->GetZHa << 
949   twistedboxElement->setAttributeNode(         << 
950     NewAttribute("PhiTwist", twistedbox->GetPh << 
951   twistedboxElement->setAttributeNode(NewAttri << 
952   twistedboxElement->setAttributeNode(NewAttri << 
953   solElement->appendChild(twistedboxElement);  << 
954 }                                              << 
955                                                << 
956 // ------------------------------------------- << 
957 void G4GDMLWriteSolids::TwistedtrapWrite(xerce << 
958                                          const << 
959 {                                              << 
960   const G4String& name = GenerateName(twistedt << 
961                                                << 
962   xercesc::DOMElement* twistedtrapElement = Ne << 
963   twistedtrapElement->setAttributeNode(NewAttr << 
964   twistedtrapElement->setAttributeNode(        << 
965     NewAttribute("y1", 2.0 * twistedtrap->GetY << 
966   twistedtrapElement->setAttributeNode(        << 
967     NewAttribute("x1", 2.0 * twistedtrap->GetX << 
968   twistedtrapElement->setAttributeNode(        << 
969     NewAttribute("x2", 2.0 * twistedtrap->GetX << 
970   twistedtrapElement->setAttributeNode(        << 
971     NewAttribute("y2", 2.0 * twistedtrap->GetY << 
972   twistedtrapElement->setAttributeNode(        << 
973     NewAttribute("x3", 2.0 * twistedtrap->GetX << 
974   twistedtrapElement->setAttributeNode(        << 
975     NewAttribute("x4", 2.0 * twistedtrap->GetX << 
976   twistedtrapElement->setAttributeNode(        << 
977     NewAttribute("z", 2.0 * twistedtrap->GetZH << 
978   twistedtrapElement->setAttributeNode(        << 
979     NewAttribute("Alph", twistedtrap->GetTiltA << 
980   twistedtrapElement->setAttributeNode(        << 
981     NewAttribute("Theta", twistedtrap->GetPola << 
982   twistedtrapElement->setAttributeNode(        << 
983     NewAttribute("Phi", twistedtrap->GetAzimut << 
984   twistedtrapElement->setAttributeNode(        << 
985     NewAttribute("PhiTwist", twistedtrap->GetP << 
986   twistedtrapElement->setAttributeNode(NewAttr << 
987   twistedtrapElement->setAttributeNode(NewAttr << 
988                                                << 
989   solElement->appendChild(twistedtrapElement); << 
990 }                                              << 
991                                                << 
992 // ------------------------------------------- << 
993 void G4GDMLWriteSolids::TwistedtrdWrite(xerces << 
994                                         const  << 
995 {                                              << 
996   const G4String& name = GenerateName(twistedt << 
997                                                   685 
998   xercesc::DOMElement* twistedtrdElement = New << 686          name_stream << "vertex" << (j+1);
999   twistedtrdElement->setAttributeNode(NewAttri << 687          ref_stream << solid_name << "_v" << NumVertex;
1000   twistedtrdElement->setAttributeNode(        << 
1001     NewAttribute("x1", 2.0 * twistedtrd->GetX << 
1002   twistedtrdElement->setAttributeNode(        << 
1003     NewAttribute("x2", 2.0 * twistedtrd->GetX << 
1004   twistedtrdElement->setAttributeNode(        << 
1005     NewAttribute("y1", 2.0 * twistedtrd->GetY << 
1006   twistedtrdElement->setAttributeNode(        << 
1007     NewAttribute("y2", 2.0 * twistedtrd->GetY << 
1008   twistedtrdElement->setAttributeNode(        << 
1009     NewAttribute("z", 2.0 * twistedtrd->GetZH << 
1010   twistedtrdElement->setAttributeNode(        << 
1011     NewAttribute("PhiTwist", twistedtrd->GetP << 
1012   twistedtrdElement->setAttributeNode(NewAttr << 
1013   twistedtrdElement->setAttributeNode(NewAttr << 
1014   solElement->appendChild(twistedtrdElement); << 
1015 }                                             << 
1016                                                  688 
1017 // ------------------------------------------ << 689          const G4String& fname = name_stream.str();  // facet's tag variable
1018 void G4GDMLWriteSolids::TwistedtubsWrite(xerc << 690          G4String ref = ref_stream.str();     // vertex tag to be associated
1019                                          cons << 
1020 {                                             << 
1021   const G4String& name = GenerateName(twisted << 
1022                                               << 
1023   xercesc::DOMElement* twistedtubsElement = N << 
1024   twistedtubsElement->setAttributeNode(NewAtt << 
1025   twistedtubsElement->setAttributeNode(       << 
1026     NewAttribute("twistedangle", twistedtubs- << 
1027   twistedtubsElement->setAttributeNode(       << 
1028     NewAttribute("midinnerrad", twistedtubs-> << 
1029   twistedtubsElement->setAttributeNode(       << 
1030     NewAttribute("midouterrad", twistedtubs-> << 
1031   twistedtubsElement->setAttributeNode(       << 
1032     NewAttribute("negativeEndz", twistedtubs- << 
1033   twistedtubsElement->setAttributeNode(       << 
1034     NewAttribute("positiveEndz", twistedtubs- << 
1035   twistedtubsElement->setAttributeNode(       << 
1036     NewAttribute("phi", twistedtubs->GetDPhi( << 
1037   twistedtubsElement->setAttributeNode(NewAtt << 
1038   twistedtubsElement->setAttributeNode(NewAtt << 
1039   solElement->appendChild(twistedtubsElement) << 
1040 }                                             << 
1041                                                  691 
1042 // ------------------------------------------ << 692          // Now search for the existance of the current vertex in the
1043 void G4GDMLWriteSolids::ZplaneWrite(xercesc:: << 693          // map of cached vertices. If existing, do NOT store it as
1044                                     const G4d << 694          // position in the GDML file, so avoiding duplication; otherwise
1045                                     const G4d << 695          // cache it in the local map and add it as position in the
1046 {                                             << 696          // "define" section of the GDML file.
1047   xercesc::DOMElement* zplaneElement = NewEle << 697 
1048   zplaneElement->setAttributeNode(NewAttribut << 698          const G4ThreeVector& vertex = facet->GetVertex(j);
1049   zplaneElement->setAttributeNode(NewAttribut << 699 
1050   zplaneElement->setAttributeNode(NewAttribut << 700          if(vertexMap.find(vertex) != vertexMap.end())  // Vertex is cached
1051   element->appendChild(zplaneElement);        << 701          {
                                                   >> 702            ref = vertexMap[vertex];     // Set the proper tag for it
                                                   >> 703          }
                                                   >> 704          else                                           // Vertex not found
                                                   >> 705          {
                                                   >> 706            vertexMap.insert(std::make_pair(vertex,ref)); // Cache vertex and ...
                                                   >> 707            AddPosition(ref, vertex);    // ... add it to define section!
                                                   >> 708            NumVertex++;
                                                   >> 709          }
                                                   >> 710 
                                                   >> 711          // Now create association of the vertex with its facet
                                                   >> 712          //
                                                   >> 713          facetElement->setAttributeNode(NewAttribute(fname,ref));
                                                   >> 714       }
                                                   >> 715    }
1052 }                                                716 }
1053                                                  717 
1054 // ------------------------------------------ << 718 void G4GDMLWriteSolids::
1055 void G4GDMLWriteSolids::RZPointWrite(xercesc: << 719 TetWrite(xercesc::DOMElement* solElement, const G4Tet* const tet)
1056                                      const G4 << 
1057 {                                                720 {
1058   xercesc::DOMElement* rzpointElement = NewEl << 721    const G4String& solid_name = tet->GetName();
1059   rzpointElement->setAttributeNode(NewAttribu << 722    const G4String& name = GenerateName(solid_name, tet);
1060   rzpointElement->setAttributeNode(NewAttribu << 
1061   element->appendChild(rzpointElement);       << 
1062 }                                             << 
1063                                                  723 
1064 // ------------------------------------------ << 724    std::vector<G4ThreeVector> vertexList = tet->GetVertices();
1065 void G4GDMLWriteSolids::OpticalSurfaceWrite(x << 725 
1066                                             c << 726    xercesc::DOMElement* tetElement = NewElement("tet");
1067 {                                             << 727    tetElement->setAttributeNode(NewAttribute("name",name));
1068   xercesc::DOMElement* optElement = NewElemen << 728    tetElement->setAttributeNode(NewAttribute("vertex1",solid_name+"_v1"));
1069   G4OpticalSurfaceModel smodel    = surf->Get << 729    tetElement->setAttributeNode(NewAttribute("vertex2",solid_name+"_v2"));
1070   G4double sval =                             << 730    tetElement->setAttributeNode(NewAttribute("vertex3",solid_name+"_v3"));
1071     (smodel == glisur) ? surf->GetPolish() :  << 731    tetElement->setAttributeNode(NewAttribute("vertex4",solid_name+"_v4"));
1072   const G4String& name = GenerateName(surf->G << 732    tetElement->setAttributeNode(NewAttribute("lunit","mm"));
1073                                               << 733    solElement->appendChild(tetElement);
1074   optElement->setAttributeNode(NewAttribute(" << 734 
1075   optElement->setAttributeNode(NewAttribute(" << 735    AddPosition(solid_name+"_v1",vertexList[0]);
1076   optElement->setAttributeNode(NewAttribute(" << 736    AddPosition(solid_name+"_v2",vertexList[1]);
1077   optElement->setAttributeNode(NewAttribute(" << 737    AddPosition(solid_name+"_v3",vertexList[2]);
1078   optElement->setAttributeNode(NewAttribute(" << 738    AddPosition(solid_name+"_v4",vertexList[3]);
1079                                               << 739 }
1080   // Write any property attached to the optic << 740 
1081   //                                          << 741 void G4GDMLWriteSolids::
1082   if(surf->GetMaterialPropertiesTable())      << 742 TorusWrite(xercesc::DOMElement* solElement, const G4Torus* const torus)
1083   {                                           << 743 {
1084     PropertyWrite(optElement, surf);          << 744    const G4String& name = GenerateName(torus->GetName(),torus);
1085   }                                           << 745 
                                                   >> 746    xercesc::DOMElement* torusElement = NewElement("torus");
                                                   >> 747    torusElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 748    torusElement->setAttributeNode(NewAttribute("rmin",torus->GetRmin()/mm));
                                                   >> 749    torusElement->setAttributeNode(NewAttribute("rmax",torus->GetRmax()/mm));
                                                   >> 750    torusElement->setAttributeNode(NewAttribute("rtor",torus->GetRtor()/mm));
                                                   >> 751    torusElement->
                                                   >> 752      setAttributeNode(NewAttribute("startphi",torus->GetSPhi()/degree));
                                                   >> 753    torusElement->
                                                   >> 754      setAttributeNode(NewAttribute("deltaphi",torus->GetDPhi()/degree));
                                                   >> 755    torusElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 756    torusElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 757    solElement->appendChild(torusElement);
                                                   >> 758 }
                                                   >> 759 
                                                   >> 760 void G4GDMLWriteSolids::
                                                   >> 761 GenTrapWrite(xercesc::DOMElement* solElement,
                                                   >> 762              const G4GenericTrap* const gtrap)
                                                   >> 763 {
                                                   >> 764    const G4String& name = GenerateName(gtrap->GetName(),gtrap);
                                                   >> 765 
                                                   >> 766    std::vector<G4TwoVector> vertices = gtrap->GetVertices();
                                                   >> 767 
                                                   >> 768    xercesc::DOMElement* gtrapElement = NewElement("arb8");
                                                   >> 769    gtrapElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 770    gtrapElement->setAttributeNode(NewAttribute("dz",
                                                   >> 771                                            gtrap->GetZHalfLength()/mm));
                                                   >> 772    gtrapElement->setAttributeNode(NewAttribute("v1x", vertices[0].x()));
                                                   >> 773    gtrapElement->setAttributeNode(NewAttribute("v1y", vertices[0].y()));
                                                   >> 774    gtrapElement->setAttributeNode(NewAttribute("v2x", vertices[1].x()));
                                                   >> 775    gtrapElement->setAttributeNode(NewAttribute("v2y", vertices[1].y()));
                                                   >> 776    gtrapElement->setAttributeNode(NewAttribute("v3x", vertices[2].x()));
                                                   >> 777    gtrapElement->setAttributeNode(NewAttribute("v3y", vertices[2].y()));
                                                   >> 778    gtrapElement->setAttributeNode(NewAttribute("v4x", vertices[3].x()));
                                                   >> 779    gtrapElement->setAttributeNode(NewAttribute("v4y", vertices[3].y()));
                                                   >> 780    gtrapElement->setAttributeNode(NewAttribute("v5x", vertices[4].x()));
                                                   >> 781    gtrapElement->setAttributeNode(NewAttribute("v5y", vertices[4].y()));
                                                   >> 782    gtrapElement->setAttributeNode(NewAttribute("v6x", vertices[5].x()));
                                                   >> 783    gtrapElement->setAttributeNode(NewAttribute("v6y", vertices[5].y()));
                                                   >> 784    gtrapElement->setAttributeNode(NewAttribute("v7x", vertices[6].x()));
                                                   >> 785    gtrapElement->setAttributeNode(NewAttribute("v7y", vertices[6].y()));
                                                   >> 786    gtrapElement->setAttributeNode(NewAttribute("v8x", vertices[7].x()));
                                                   >> 787    gtrapElement->setAttributeNode(NewAttribute("v8y", vertices[7].y()));
                                                   >> 788    gtrapElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 789    solElement->appendChild(gtrapElement);
                                                   >> 790 }
                                                   >> 791 
                                                   >> 792 void G4GDMLWriteSolids::
                                                   >> 793 TrapWrite(xercesc::DOMElement* solElement, const G4Trap* const trap)
                                                   >> 794 {
                                                   >> 795    const G4String& name = GenerateName(trap->GetName(),trap);
                                                   >> 796 
                                                   >> 797    const G4ThreeVector& simaxis = trap->GetSymAxis();
                                                   >> 798    const G4double phi = simaxis.phi();
                                                   >> 799    const G4double theta = simaxis.theta();
                                                   >> 800    const G4double alpha1 = std::atan(trap->GetTanAlpha1());
                                                   >> 801    const G4double alpha2 = std::atan(trap->GetTanAlpha2());
                                                   >> 802 
                                                   >> 803    xercesc::DOMElement* trapElement = NewElement("trap");
                                                   >> 804    trapElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 805    trapElement->setAttributeNode(NewAttribute("z",
                                                   >> 806                 2.0*trap->GetZHalfLength()/mm));
                                                   >> 807    trapElement->setAttributeNode(NewAttribute("theta",theta/degree));
                                                   >> 808    trapElement->setAttributeNode(NewAttribute("phi",phi/degree));
                                                   >> 809    trapElement->setAttributeNode(NewAttribute("y1",
                                                   >> 810                 2.0*trap->GetYHalfLength1()/mm));
                                                   >> 811    trapElement->setAttributeNode(NewAttribute("x1",
                                                   >> 812                 2.0*trap->GetXHalfLength1()/mm));
                                                   >> 813    trapElement->setAttributeNode(NewAttribute("x2",
                                                   >> 814                 2.0*trap->GetXHalfLength2()/mm));
                                                   >> 815    trapElement->setAttributeNode(NewAttribute("alpha1",alpha1/degree));
                                                   >> 816    trapElement->setAttributeNode(NewAttribute("y2",
                                                   >> 817                 2.0*trap->GetYHalfLength2()/mm));
                                                   >> 818    trapElement->setAttributeNode(NewAttribute("x3",
                                                   >> 819                 2.0*trap->GetXHalfLength3()/mm));
                                                   >> 820    trapElement->setAttributeNode(NewAttribute("x4",
                                                   >> 821                 2.0*trap->GetXHalfLength4()/mm));
                                                   >> 822    trapElement->setAttributeNode(NewAttribute("alpha2",alpha2/degree));
                                                   >> 823    trapElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 824    trapElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 825    solElement->appendChild(trapElement);
                                                   >> 826 }
                                                   >> 827 
                                                   >> 828 void G4GDMLWriteSolids::
                                                   >> 829 TrdWrite(xercesc::DOMElement* solElement, const G4Trd* const trd)
                                                   >> 830 {
                                                   >> 831    const G4String& name = GenerateName(trd->GetName(),trd);
                                                   >> 832 
                                                   >> 833    xercesc::DOMElement* trdElement = NewElement("trd");
                                                   >> 834    trdElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 835    trdElement->setAttributeNode(NewAttribute("x1",
                                                   >> 836                2.0*trd->GetXHalfLength1()/mm));
                                                   >> 837    trdElement->setAttributeNode(NewAttribute("x2",
                                                   >> 838                2.0*trd->GetXHalfLength2()/mm));
                                                   >> 839    trdElement->setAttributeNode(NewAttribute("y1",
                                                   >> 840                2.0*trd->GetYHalfLength1()/mm));
                                                   >> 841    trdElement->setAttributeNode(NewAttribute("y2",
                                                   >> 842                2.0*trd->GetYHalfLength2()/mm));
                                                   >> 843    trdElement->setAttributeNode(NewAttribute("z",
                                                   >> 844                2.0*trd->GetZHalfLength()/mm));
                                                   >> 845    trdElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 846    solElement->appendChild(trdElement);
                                                   >> 847 }
                                                   >> 848 
                                                   >> 849 void G4GDMLWriteSolids::
                                                   >> 850 TubeWrite(xercesc::DOMElement* solElement, const G4Tubs* const tube)
                                                   >> 851 {
                                                   >> 852    const G4String& name = GenerateName(tube->GetName(),tube);
                                                   >> 853 
                                                   >> 854    xercesc::DOMElement* tubeElement = NewElement("tube");
                                                   >> 855    tubeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 856    tubeElement->setAttributeNode(NewAttribute("rmin",
                                                   >> 857                 tube->GetInnerRadius()/mm));
                                                   >> 858    tubeElement->setAttributeNode(NewAttribute("rmax",
                                                   >> 859                 tube->GetOuterRadius()/mm));
                                                   >> 860    tubeElement->setAttributeNode(NewAttribute("z",
                                                   >> 861                 2.0*tube->GetZHalfLength()/mm));
                                                   >> 862    tubeElement->setAttributeNode(NewAttribute("startphi",
                                                   >> 863                 tube->GetStartPhiAngle()/degree));
                                                   >> 864    tubeElement->setAttributeNode(NewAttribute("deltaphi",
                                                   >> 865                 tube->GetDeltaPhiAngle()/degree));
                                                   >> 866    tubeElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 867    tubeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 868    solElement->appendChild(tubeElement);
                                                   >> 869 }
                                                   >> 870 
                                                   >> 871 void G4GDMLWriteSolids::
                                                   >> 872 CutTubeWrite(xercesc::DOMElement* solElement, const G4CutTubs* const cuttube)
                                                   >> 873 {
                                                   >> 874    const G4String& name = GenerateName(cuttube->GetName(),cuttube);
                                                   >> 875 
                                                   >> 876    xercesc::DOMElement* cuttubeElement = NewElement("cutTube");
                                                   >> 877    cuttubeElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 878    cuttubeElement->setAttributeNode(NewAttribute("rmin",
                                                   >> 879                 cuttube->GetInnerRadius()/mm));
                                                   >> 880    cuttubeElement->setAttributeNode(NewAttribute("rmax",
                                                   >> 881                 cuttube->GetOuterRadius()/mm));
                                                   >> 882    cuttubeElement->setAttributeNode(NewAttribute("z",
                                                   >> 883                 2.0*cuttube->GetZHalfLength()/mm));
                                                   >> 884    cuttubeElement->setAttributeNode(NewAttribute("startphi",
                                                   >> 885                 cuttube->GetStartPhiAngle()/degree));
                                                   >> 886    cuttubeElement->setAttributeNode(NewAttribute("deltaphi",
                                                   >> 887                 cuttube->GetDeltaPhiAngle()/degree));
                                                   >> 888    cuttubeElement->setAttributeNode(NewAttribute("lowX",
                                                   >> 889                 cuttube->GetLowNorm().getX()/mm));
                                                   >> 890    cuttubeElement->setAttributeNode(NewAttribute("lowY",
                                                   >> 891                 cuttube->GetLowNorm().getY()/mm));
                                                   >> 892    cuttubeElement->setAttributeNode(NewAttribute("lowZ",
                                                   >> 893                 cuttube->GetLowNorm().getZ()/mm));
                                                   >> 894    cuttubeElement->setAttributeNode(NewAttribute("highX",
                                                   >> 895                 cuttube->GetHighNorm().getX()/mm));
                                                   >> 896    cuttubeElement->setAttributeNode(NewAttribute("highY",
                                                   >> 897                 cuttube->GetHighNorm().getY()/mm));
                                                   >> 898    cuttubeElement->setAttributeNode(NewAttribute("highZ",
                                                   >> 899                 cuttube->GetHighNorm().getZ()/mm));
                                                   >> 900    cuttubeElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 901    cuttubeElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 902    solElement->appendChild(cuttubeElement);
                                                   >> 903 }
                                                   >> 904 
                                                   >> 905 void G4GDMLWriteSolids::
                                                   >> 906 TwistedboxWrite(xercesc::DOMElement* solElement,
                                                   >> 907                 const G4TwistedBox* const twistedbox)
                                                   >> 908 {
                                                   >> 909    const G4String& name = GenerateName(twistedbox->GetName(),twistedbox);
                                                   >> 910 
                                                   >> 911    xercesc::DOMElement* twistedboxElement = NewElement("twistedbox");
                                                   >> 912    twistedboxElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 913    twistedboxElement->setAttributeNode(NewAttribute("x",
                                                   >> 914                       2.0*twistedbox->GetXHalfLength()/mm));
                                                   >> 915    twistedboxElement->setAttributeNode(NewAttribute("y",
                                                   >> 916                       2.0*twistedbox->GetYHalfLength()/mm));
                                                   >> 917    twistedboxElement->setAttributeNode(NewAttribute("z",
                                                   >> 918                       2.0*twistedbox->GetZHalfLength()/mm));
                                                   >> 919    twistedboxElement->setAttributeNode(NewAttribute("PhiTwist",
                                                   >> 920                       twistedbox->GetPhiTwist()/degree));
                                                   >> 921    twistedboxElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 922    twistedboxElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 923    solElement->appendChild(twistedboxElement);
                                                   >> 924 }
                                                   >> 925 
                                                   >> 926 void G4GDMLWriteSolids::
                                                   >> 927 TwistedtrapWrite(xercesc::DOMElement* solElement,
                                                   >> 928                  const G4TwistedTrap* const twistedtrap)
                                                   >> 929 {
                                                   >> 930    const G4String& name = GenerateName(twistedtrap->GetName(),twistedtrap);
                                                   >> 931 
                                                   >> 932    xercesc::DOMElement* twistedtrapElement = NewElement("twistedtrap");
                                                   >> 933    twistedtrapElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 934    twistedtrapElement->setAttributeNode(NewAttribute("y1",
                                                   >> 935                        2.0*twistedtrap->GetY1HalfLength()/mm));
                                                   >> 936    twistedtrapElement->setAttributeNode(NewAttribute("x1",
                                                   >> 937                        2.0*twistedtrap->GetX1HalfLength()/mm));
                                                   >> 938    twistedtrapElement->setAttributeNode(NewAttribute("x2",
                                                   >> 939                        2.0*twistedtrap->GetX2HalfLength()/mm));
                                                   >> 940    twistedtrapElement->setAttributeNode(NewAttribute("y2",
                                                   >> 941                        2.0*twistedtrap->GetY2HalfLength()/mm));
                                                   >> 942    twistedtrapElement->setAttributeNode(NewAttribute("x3",
                                                   >> 943                        2.0*twistedtrap->GetX3HalfLength()/mm));
                                                   >> 944    twistedtrapElement->setAttributeNode(NewAttribute("x4",
                                                   >> 945                        2.0*twistedtrap->GetX4HalfLength()/mm));
                                                   >> 946    twistedtrapElement->setAttributeNode(NewAttribute("z",
                                                   >> 947                        2.0*twistedtrap->GetZHalfLength()/mm));
                                                   >> 948    twistedtrapElement->setAttributeNode(NewAttribute("Alph",
                                                   >> 949                        twistedtrap->GetTiltAngleAlpha()/degree));
                                                   >> 950    twistedtrapElement->setAttributeNode(NewAttribute("Theta",
                                                   >> 951                        twistedtrap->GetPolarAngleTheta()/degree));
                                                   >> 952    twistedtrapElement->setAttributeNode(NewAttribute("Phi",
                                                   >> 953                        twistedtrap->GetAzimuthalAnglePhi()/degree));
                                                   >> 954    twistedtrapElement->setAttributeNode(NewAttribute("PhiTwist",
                                                   >> 955                        twistedtrap->GetPhiTwist()/degree));
                                                   >> 956    twistedtrapElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 957    twistedtrapElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 958    
                                                   >> 959    solElement->appendChild(twistedtrapElement);
                                                   >> 960 }
                                                   >> 961 
                                                   >> 962 void G4GDMLWriteSolids::
                                                   >> 963 TwistedtrdWrite(xercesc::DOMElement* solElement,
                                                   >> 964                 const G4TwistedTrd* const twistedtrd)
                                                   >> 965 {
                                                   >> 966    const G4String& name = GenerateName(twistedtrd->GetName(),twistedtrd);
                                                   >> 967 
                                                   >> 968    xercesc::DOMElement* twistedtrdElement = NewElement("twistedtrd");
                                                   >> 969    twistedtrdElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 970    twistedtrdElement->setAttributeNode(NewAttribute("x1",
                                                   >> 971                       2.0*twistedtrd->GetX1HalfLength()/mm));
                                                   >> 972    twistedtrdElement->setAttributeNode(NewAttribute("x2",
                                                   >> 973                       2.0*twistedtrd->GetX2HalfLength()/mm));
                                                   >> 974    twistedtrdElement->setAttributeNode(NewAttribute("y1",
                                                   >> 975                       2.0*twistedtrd->GetY1HalfLength()/mm));
                                                   >> 976    twistedtrdElement->setAttributeNode(NewAttribute("y2",
                                                   >> 977                       2.0*twistedtrd->GetY2HalfLength()/mm));
                                                   >> 978    twistedtrdElement->setAttributeNode(NewAttribute("z",
                                                   >> 979                       2.0*twistedtrd->GetZHalfLength()/mm));
                                                   >> 980    twistedtrdElement->setAttributeNode(NewAttribute("PhiTwist",
                                                   >> 981                       twistedtrd->GetPhiTwist()/degree));
                                                   >> 982    twistedtrdElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 983    twistedtrdElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 984    solElement->appendChild(twistedtrdElement);
                                                   >> 985 }
                                                   >> 986 
                                                   >> 987 void G4GDMLWriteSolids::
                                                   >> 988 TwistedtubsWrite(xercesc::DOMElement* solElement,
                                                   >> 989                  const G4TwistedTubs* const twistedtubs)
                                                   >> 990 {
                                                   >> 991    const G4String& name = GenerateName(twistedtubs->GetName(),twistedtubs);
                                                   >> 992 
                                                   >> 993    xercesc::DOMElement* twistedtubsElement = NewElement("twistedtubs");
                                                   >> 994    twistedtubsElement->setAttributeNode(NewAttribute("name",name));
                                                   >> 995    twistedtubsElement->setAttributeNode(NewAttribute("twistedangle",
                                                   >> 996                        twistedtubs->GetPhiTwist()/degree));
                                                   >> 997    twistedtubsElement->setAttributeNode(NewAttribute("midinnerrad",
                                                   >> 998                        twistedtubs->GetInnerRadius()/mm));
                                                   >> 999    twistedtubsElement->setAttributeNode(NewAttribute("midouterrad",
                                                   >> 1000                        twistedtubs->GetOuterRadius()/mm));
                                                   >> 1001    twistedtubsElement->setAttributeNode(NewAttribute("negativeEndz",
                                                   >> 1002                        twistedtubs->GetEndZ(0)/mm));
                                                   >> 1003    twistedtubsElement->setAttributeNode(NewAttribute("positiveEndz",
                                                   >> 1004                        twistedtubs->GetEndZ(1)/mm));
                                                   >> 1005    twistedtubsElement->setAttributeNode(NewAttribute("phi",
                                                   >> 1006                        twistedtubs->GetDPhi()/degree));
                                                   >> 1007    twistedtubsElement->setAttributeNode(NewAttribute("aunit","deg"));
                                                   >> 1008    twistedtubsElement->setAttributeNode(NewAttribute("lunit","mm"));
                                                   >> 1009    solElement->appendChild(twistedtubsElement);
                                                   >> 1010 }
                                                   >> 1011 
                                                   >> 1012 void G4GDMLWriteSolids::
                                                   >> 1013 ZplaneWrite(xercesc::DOMElement* element, const G4double& z,
                                                   >> 1014             const G4double& rmin, const G4double& rmax)
                                                   >> 1015 {
                                                   >> 1016    xercesc::DOMElement* zplaneElement = NewElement("zplane");
                                                   >> 1017    zplaneElement->setAttributeNode(NewAttribute("z",z/mm));
                                                   >> 1018    zplaneElement->setAttributeNode(NewAttribute("rmin",rmin/mm));
                                                   >> 1019    zplaneElement->setAttributeNode(NewAttribute("rmax",rmax/mm));
                                                   >> 1020    element->appendChild(zplaneElement);
                                                   >> 1021 }
                                                   >> 1022 
                                                   >> 1023 void G4GDMLWriteSolids::
                                                   >> 1024 RZPointWrite(xercesc::DOMElement* element, const G4double& r,
                                                   >> 1025             const G4double& z)
                                                   >> 1026 {
                                                   >> 1027    xercesc::DOMElement* rzpointElement = NewElement("rzpoint");
                                                   >> 1028    rzpointElement->setAttributeNode(NewAttribute("r",r/mm));
                                                   >> 1029    rzpointElement->setAttributeNode(NewAttribute("z",z/mm));
                                                   >> 1030    element->appendChild(rzpointElement);
                                                   >> 1031 }
                                                   >> 1032 
                                                   >> 1033 void G4GDMLWriteSolids::
                                                   >> 1034 OpticalSurfaceWrite(xercesc::DOMElement* solElement,
                                                   >> 1035                     const G4OpticalSurface* const surf)
                                                   >> 1036 {
                                                   >> 1037    xercesc::DOMElement* optElement = NewElement("opticalsurface");
                                                   >> 1038    G4OpticalSurfaceModel smodel = surf->GetModel();
                                                   >> 1039    G4double sval = (smodel==glisur) ? surf->GetPolish() : surf->GetSigmaAlpha();
                                                   >> 1040 
                                                   >> 1041    optElement->setAttributeNode(NewAttribute("name", surf->GetName()));
                                                   >> 1042    optElement->setAttributeNode(NewAttribute("model", smodel));
                                                   >> 1043    optElement->setAttributeNode(NewAttribute("finish", surf->GetFinish()));
                                                   >> 1044    optElement->setAttributeNode(NewAttribute("type", surf->GetType()));
                                                   >> 1045    optElement->setAttributeNode(NewAttribute("value", sval));
                                                   >> 1046 
                                                   >> 1047    // Write any property attached to the optical surface...
                                                   >> 1048    //
                                                   >> 1049    if (surf->GetMaterialPropertiesTable())
                                                   >> 1050    {
                                                   >> 1051      PropertyWrite(optElement, surf);
                                                   >> 1052    }
1086                                                  1053 
1087   solElement->appendChild(optElement);        << 1054    solElement->appendChild(optElement);
1088 }                                                1055 }
1089                                                  1056 
1090 // ------------------------------------------ << 
1091 void G4GDMLWriteSolids::PropertyWrite(xercesc    1057 void G4GDMLWriteSolids::PropertyWrite(xercesc::DOMElement* optElement,
1092                                       const G << 1058                                          const G4OpticalSurface* const surf)
1093 {                                                1059 {
1094   xercesc::DOMElement* propElement;           << 1060    xercesc::DOMElement* propElement;
1095   G4MaterialPropertiesTable* ptable = surf->G << 1061    G4MaterialPropertiesTable* ptable = surf->GetMaterialPropertiesTable();
1096   auto pvec = ptable->GetProperties();        << 1062    const std::map< G4int, G4PhysicsOrderedFreeVector*,
1097   auto cvec = ptable->GetConstProperties();   << 1063                  std::less<G4int> >* pmap = ptable->GetPropertyMap();
1098                                               << 1064    const std::map< G4int, G4double,
1099   for(size_t i = 0; i < pvec.size(); ++i)     << 1065                  std::less<G4int> >* cmap = ptable->GetConstPropertyMap();
1100   {                                           << 1066    std::map< G4int, G4PhysicsOrderedFreeVector*,
1101     if(pvec[i] != nullptr) {                  << 1067                  std::less<G4int> >::const_iterator mpos;
                                                   >> 1068    std::map< G4int, G4double,
                                                   >> 1069                  std::less<G4int> >::const_iterator cpos;
                                                   >> 1070    for (mpos=pmap->begin(); mpos!=pmap->end(); mpos++)
                                                   >> 1071    {
1102       propElement = NewElement("property");      1072       propElement = NewElement("property");
1103       propElement->setAttributeNode(          << 1073       propElement->setAttributeNode(NewAttribute("name", 
1104         NewAttribute("name", ptable->GetMater << 1074                             ptable->GetMaterialPropertyNames()[mpos->first]));
1105       propElement->setAttributeNode(NewAttrib << 1075       propElement->setAttributeNode(NewAttribute("ref",
1106         "ref", GenerateName(ptable->GetMateri << 1076                  GenerateName(ptable->GetMaterialPropertyNames()[mpos->first], 
1107                             pvec[i])));       << 1077                                                  mpos->second)));
1108       PropertyVectorWrite(ptable->GetMaterial << 1078       if (mpos->second)
1109                           pvec[i]);           << 1079       {
1110       optElement->appendChild(propElement);   << 1080          PropertyVectorWrite(ptable->GetMaterialPropertyNames()[mpos->first],
1111     }                                         << 1081                              mpos->second);
1112   }                                           << 1082          optElement->appendChild(propElement);
1113   for(size_t i = 0; i < cvec.size(); ++i)     << 1083       }
1114   {                                           << 1084       else
1115     if (cvec[i].second == true) {             << 1085       {
                                                   >> 1086          G4String warn_message = "Null pointer for material property -"
                                                   >> 1087                   + ptable->GetMaterialPropertyNames()[mpos->first] 
                                                   >> 1088                   + "- of optical surface -" + surf->GetName() + "- !";
                                                   >> 1089          G4Exception("G4GDMLWriteSolids::PropertyWrite()", "NullPointer",
                                                   >> 1090                      JustWarning, warn_message);
                                                   >> 1091          continue;
                                                   >> 1092       }
                                                   >> 1093    }
                                                   >> 1094    for (cpos=cmap->begin(); cpos!=cmap->end(); cpos++)
                                                   >> 1095    {
1116       propElement = NewElement("property");      1096       propElement = NewElement("property");
1117       propElement->setAttributeNode(NewAttrib << 1097       propElement->setAttributeNode(NewAttribute("name", 
1118         "name", ptable->GetMaterialConstPrope << 1098                         ptable->GetMaterialConstPropertyNames()[cpos->first]));
1119       propElement->setAttributeNode(NewAttrib << 1099       propElement->setAttributeNode(NewAttribute("ref", 
1120         "ref", ptable->GetMaterialConstProper << 1100                         ptable->GetMaterialConstPropertyNames()[cpos->first]));
1121       xercesc::DOMElement* constElement = New    1101       xercesc::DOMElement* constElement = NewElement("constant");
1122       constElement->setAttributeNode(NewAttri << 1102       constElement->setAttributeNode(NewAttribute("name", 
1123         "name", ptable->GetMaterialConstPrope << 1103                         ptable->GetMaterialConstPropertyNames()[cpos->first]));
1124       constElement->setAttributeNode(NewAttri << 1104       constElement->setAttributeNode(NewAttribute("value", cpos->second));
1125       defineElement->appendChild(constElement    1105       defineElement->appendChild(constElement);
1126       optElement->appendChild(propElement);      1106       optElement->appendChild(propElement);
1127     }                                         << 1107    }
1128   }                                           << 
1129 }                                                1108 }
1130                                                  1109 
1131 // ------------------------------------------ << 
1132 void G4GDMLWriteSolids::SolidsWrite(xercesc::    1110 void G4GDMLWriteSolids::SolidsWrite(xercesc::DOMElement* gdmlElement)
1133 {                                                1111 {
1134 #ifdef G4VERBOSE                                 1112 #ifdef G4VERBOSE
1135   G4cout << "G4GDML: Writing solids..." << G4 << 1113    G4cout << "G4GDML: Writing solids..." << G4endl;
1136 #endif                                           1114 #endif
1137   solidsElement = NewElement("solids");       << 1115    solidsElement = NewElement("solids");
1138   gdmlElement->appendChild(solidsElement);    << 1116    gdmlElement->appendChild(solidsElement);
1139                                                  1117 
1140   solidList.clear();                          << 1118    solidList.clear();
1141 }                                                1119 }
1142                                                  1120 
1143 // ------------------------------------------ << 
1144 void G4GDMLWriteSolids::AddSolid(const G4VSol    1121 void G4GDMLWriteSolids::AddSolid(const G4VSolid* const solidPtr)
1145 {                                                1122 {
1146   for(std::size_t i = 0; i < solidList.size() << 1123    for (size_t i=0; i<solidList.size(); i++)   // Check if solid is
1147   {                                           << 1124    {                                           // already in the list!
1148     if(solidList[i] == solidPtr)              << 1125       if (solidList[i] == solidPtr)  { return; }
1149     {                                         << 1126    }
1150       return;                                 << 1127 
1151     }                                         << 1128    solidList.push_back(solidPtr);
1152   }                                           << 1129 
1153                                               << 1130    if (const G4BooleanSolid* const booleanPtr
1154   solidList.push_back(solidPtr);              << 1131      = dynamic_cast<const G4BooleanSolid*>(solidPtr))
1155                                               << 1132      { BooleanWrite(solidsElement,booleanPtr); } else
1156   if(const G4BooleanSolid* const booleanPtr = << 1133    if (const G4ScaledSolid* const scaledPtr
1157        dynamic_cast<const G4BooleanSolid*>(so << 1134      = dynamic_cast<const G4ScaledSolid*>(solidPtr))
1158   {                                           << 1135      { ScaledWrite(solidsElement,scaledPtr); } else
1159     BooleanWrite(solidsElement, booleanPtr);  << 1136    if (solidPtr->GetEntityType()=="G4MultiUnion")
1160   }                                           << 1137      { const G4MultiUnion* const munionPtr
1161   else if(const G4ScaledSolid* const scaledPt << 1138      = static_cast<const G4MultiUnion*>(solidPtr);
1162             dynamic_cast<const G4ScaledSolid* << 1139        MultiUnionWrite(solidsElement,munionPtr); } else
1163   {                                           << 1140    if (solidPtr->GetEntityType()=="G4Box")
1164     ScaledWrite(solidsElement, scaledPtr);    << 1141      { const G4Box* const boxPtr
1165   }                                           << 1142      = static_cast<const G4Box*>(solidPtr);
1166   else if(solidPtr->GetEntityType() == "G4Mul << 1143        BoxWrite(solidsElement,boxPtr); } else
1167   {                                           << 1144    if (solidPtr->GetEntityType()=="G4Cons")
1168     const G4MultiUnion* const munionPtr =     << 1145      { const G4Cons* const conePtr
1169       static_cast<const G4MultiUnion*>(solidP << 1146      = static_cast<const G4Cons*>(solidPtr);
1170     MultiUnionWrite(solidsElement, munionPtr) << 1147        ConeWrite(solidsElement,conePtr); } else
1171   }                                           << 1148    if (solidPtr->GetEntityType()=="G4EllipticalCone")
1172   else if(solidPtr->GetEntityType() == "G4Box << 1149      { const G4EllipticalCone* const elconePtr
1173   {                                           << 1150      = static_cast<const G4EllipticalCone*>(solidPtr);
1174     const G4Box* const boxPtr = static_cast<c << 1151        ElconeWrite(solidsElement,elconePtr); } else
1175     BoxWrite(solidsElement, boxPtr);          << 1152    if (solidPtr->GetEntityType()=="G4Ellipsoid")
1176   }                                           << 1153      { const G4Ellipsoid* const ellipsoidPtr
1177   else if(solidPtr->GetEntityType() == "G4Con << 1154      = static_cast<const G4Ellipsoid*>(solidPtr);
1178   {                                           << 1155        EllipsoidWrite(solidsElement,ellipsoidPtr); } else
1179     const G4Cons* const conePtr = static_cast << 1156    if (solidPtr->GetEntityType()=="G4EllipticalTube")
1180     ConeWrite(solidsElement, conePtr);        << 1157      { const G4EllipticalTube* const eltubePtr
1181   }                                           << 1158      = static_cast<const G4EllipticalTube*>(solidPtr);
1182   else if(solidPtr->GetEntityType() == "G4Ell << 1159        EltubeWrite(solidsElement,eltubePtr); } else
1183   {                                           << 1160    if (solidPtr->GetEntityType()=="G4ExtrudedSolid")
1184     const G4EllipticalCone* const elconePtr = << 1161      { const G4ExtrudedSolid* const xtruPtr
1185       static_cast<const G4EllipticalCone*>(so << 1162      = static_cast<const G4ExtrudedSolid*>(solidPtr);
1186     ElconeWrite(solidsElement, elconePtr);    << 1163        XtruWrite(solidsElement,xtruPtr); } else
1187   }                                           << 1164    if (solidPtr->GetEntityType()=="G4Hype")
1188   else if(solidPtr->GetEntityType() == "G4Ell << 1165      { const G4Hype* const hypePtr
1189   {                                           << 1166      = static_cast<const G4Hype*>(solidPtr);
1190     const G4Ellipsoid* const ellipsoidPtr =   << 1167        HypeWrite(solidsElement,hypePtr); } else
1191       static_cast<const G4Ellipsoid*>(solidPt << 1168    if (solidPtr->GetEntityType()=="G4Orb")
1192     EllipsoidWrite(solidsElement, ellipsoidPt << 1169      { const G4Orb* const orbPtr
1193   }                                           << 1170      = static_cast<const G4Orb*>(solidPtr);
1194   else if(solidPtr->GetEntityType() == "G4Ell << 1171        OrbWrite(solidsElement,orbPtr); } else
1195   {                                           << 1172    if (solidPtr->GetEntityType()=="G4Para")
1196     const G4EllipticalTube* const eltubePtr = << 1173      { const G4Para* const paraPtr
1197       static_cast<const G4EllipticalTube*>(so << 1174      = static_cast<const G4Para*>(solidPtr);
1198     EltubeWrite(solidsElement, eltubePtr);    << 1175        ParaWrite(solidsElement,paraPtr); } else
1199   }                                           << 1176    if (solidPtr->GetEntityType()=="G4Paraboloid")
1200   else if(solidPtr->GetEntityType() == "G4Ext << 1177      { const G4Paraboloid* const paraboloidPtr
1201   {                                           << 1178      = static_cast<const G4Paraboloid*>(solidPtr);
1202     const G4ExtrudedSolid* const xtruPtr =    << 1179        ParaboloidWrite(solidsElement,paraboloidPtr); } else
1203       static_cast<const G4ExtrudedSolid*>(sol << 1180    if (solidPtr->GetEntityType()=="G4Polycone")
1204     XtruWrite(solidsElement, xtruPtr);        << 1181      { const G4Polycone* const polyconePtr
1205   }                                           << 1182      = static_cast<const G4Polycone*>(solidPtr);
1206   else if(solidPtr->GetEntityType() == "G4Hyp << 1183        PolyconeWrite(solidsElement,polyconePtr); } else
1207   {                                           << 1184    if (solidPtr->GetEntityType()=="G4GenericPolycone")
1208     const G4Hype* const hypePtr = static_cast << 1185      { const G4GenericPolycone* const genpolyconePtr
1209     HypeWrite(solidsElement, hypePtr);        << 1186      = static_cast<const G4GenericPolycone*>(solidPtr);
1210   }                                           << 1187        GenericPolyconeWrite(solidsElement,genpolyconePtr); } else
1211   else if(solidPtr->GetEntityType() == "G4Orb << 1188    if (solidPtr->GetEntityType()=="G4Polyhedra")
1212   {                                           << 1189      { const G4Polyhedra* const polyhedraPtr
1213     const G4Orb* const orbPtr = static_cast<c << 1190      = static_cast<const G4Polyhedra*>(solidPtr);
1214     OrbWrite(solidsElement, orbPtr);          << 1191        PolyhedraWrite(solidsElement,polyhedraPtr); } else
1215   }                                           << 1192    if (solidPtr->GetEntityType()=="G4Sphere")
1216   else if(solidPtr->GetEntityType() == "G4Par << 1193      { const G4Sphere* const spherePtr
1217   {                                           << 1194      = static_cast<const G4Sphere*>(solidPtr);
1218     const G4Para* const paraPtr = static_cast << 1195        SphereWrite(solidsElement,spherePtr); } else
1219     ParaWrite(solidsElement, paraPtr);        << 1196    if (solidPtr->GetEntityType()=="G4TessellatedSolid")
1220   }                                           << 1197      { const G4TessellatedSolid* const tessellatedPtr
1221   else if(solidPtr->GetEntityType() == "G4Par << 1198      = static_cast<const G4TessellatedSolid*>(solidPtr);
1222   {                                           << 1199        TessellatedWrite(solidsElement,tessellatedPtr); } else
1223     const G4Paraboloid* const paraboloidPtr = << 1200    if (solidPtr->GetEntityType()=="G4Tet")
1224       static_cast<const G4Paraboloid*>(solidP << 1201      { const G4Tet* const tetPtr
1225     ParaboloidWrite(solidsElement, paraboloid << 1202      = static_cast<const G4Tet*>(solidPtr);
1226   }                                           << 1203        TetWrite(solidsElement,tetPtr); } else
1227   else if(solidPtr->GetEntityType() == "G4Pol << 1204    if (solidPtr->GetEntityType()=="G4Torus")
1228   {                                           << 1205      { const G4Torus* const torusPtr
1229     const G4Polycone* const polyconePtr =     << 1206      = static_cast<const G4Torus*>(solidPtr);
1230       static_cast<const G4Polycone*>(solidPtr << 1207        TorusWrite(solidsElement,torusPtr); } else
1231     PolyconeWrite(solidsElement, polyconePtr) << 1208    if (solidPtr->GetEntityType()=="G4GenericTrap")
1232   }                                           << 1209      { const G4GenericTrap* const gtrapPtr
1233   else if(solidPtr->GetEntityType() == "G4Gen << 1210      = static_cast<const G4GenericTrap*>(solidPtr);
1234   {                                           << 1211        GenTrapWrite(solidsElement,gtrapPtr); } else
1235     const G4GenericPolycone* const genpolycon << 1212    if (solidPtr->GetEntityType()=="G4Trap")
1236       static_cast<const G4GenericPolycone*>(s << 1213      { const G4Trap* const trapPtr
1237     GenericPolyconeWrite(solidsElement, genpo << 1214      = static_cast<const G4Trap*>(solidPtr);
1238   }                                           << 1215        TrapWrite(solidsElement,trapPtr); } else
1239   else if(solidPtr->GetEntityType() == "G4Pol << 1216    if (solidPtr->GetEntityType()=="G4Trd")
1240   {                                           << 1217      { const G4Trd* const trdPtr
1241     const G4Polyhedra* const polyhedraPtr =   << 1218      = static_cast<const G4Trd*>(solidPtr);
1242       static_cast<const G4Polyhedra*>(solidPt << 1219        TrdWrite(solidsElement,trdPtr); } else
1243     PolyhedraWrite(solidsElement, polyhedraPt << 1220    if (solidPtr->GetEntityType()=="G4Tubs")
1244   }                                           << 1221      { const G4Tubs* const tubePtr
1245   else if(solidPtr->GetEntityType() == "G4Sph << 1222      = static_cast<const G4Tubs*>(solidPtr);
1246   {                                           << 1223        TubeWrite(solidsElement,tubePtr); } else
1247     const G4Sphere* const spherePtr = static_ << 1224    if (solidPtr->GetEntityType()=="G4CutTubs")
1248     SphereWrite(solidsElement, spherePtr);    << 1225      { const G4CutTubs* const cuttubePtr
1249   }                                           << 1226      = static_cast<const G4CutTubs*>(solidPtr);
1250   else if(solidPtr->GetEntityType() == "G4Tes << 1227        CutTubeWrite(solidsElement,cuttubePtr); } else
1251   {                                           << 1228    if (solidPtr->GetEntityType()=="G4TwistedBox")
1252     const G4TessellatedSolid* const tessellat << 1229      { const G4TwistedBox* const twistedboxPtr
1253       static_cast<const G4TessellatedSolid*>( << 1230      = static_cast<const G4TwistedBox*>(solidPtr);
1254     TessellatedWrite(solidsElement, tessellat << 1231        TwistedboxWrite(solidsElement,twistedboxPtr); } else
1255   }                                           << 1232    if (solidPtr->GetEntityType()=="G4TwistedTrap")
1256   else if(solidPtr->GetEntityType() == "G4Tet << 1233      { const G4TwistedTrap* const twistedtrapPtr
1257   {                                           << 1234      = static_cast<const G4TwistedTrap*>(solidPtr);
1258     const G4Tet* const tetPtr = static_cast<c << 1235        TwistedtrapWrite(solidsElement,twistedtrapPtr); } else
1259     TetWrite(solidsElement, tetPtr);          << 1236    if (solidPtr->GetEntityType()=="G4TwistedTrd")
1260   }                                           << 1237      { const G4TwistedTrd* const twistedtrdPtr
1261   else if(solidPtr->GetEntityType() == "G4Tor << 1238      = static_cast<const G4TwistedTrd*>(solidPtr);
1262   {                                           << 1239        TwistedtrdWrite(solidsElement,twistedtrdPtr); } else
1263     const G4Torus* const torusPtr = static_ca << 1240    if (solidPtr->GetEntityType()=="G4TwistedTubs")
1264     TorusWrite(solidsElement, torusPtr);      << 1241      { const G4TwistedTubs* const twistedtubsPtr
1265   }                                           << 1242      = static_cast<const G4TwistedTubs*>(solidPtr);
1266   else if(solidPtr->GetEntityType() == "G4Gen << 1243        TwistedtubsWrite(solidsElement,twistedtubsPtr); }
1267   {                                           << 1244    else
1268     const G4GenericTrap* const gtrapPtr =     << 1245    {
1269       static_cast<const G4GenericTrap*>(solid << 1246      G4String error_msg = "Unknown solid: " + solidPtr->GetName()
1270     GenTrapWrite(solidsElement, gtrapPtr);    << 1247                         + "; Type: " + solidPtr->GetEntityType();
1271   }                                           << 1248      G4Exception("G4GDMLWriteSolids::AddSolid()", "WriteError",
1272   else if(solidPtr->GetEntityType() == "G4Tra << 1249                  FatalException, error_msg);
1273   {                                           << 1250    }
1274     const G4Trap* const trapPtr = static_cast << 
1275     TrapWrite(solidsElement, trapPtr);        << 
1276   }                                           << 
1277   else if(solidPtr->GetEntityType() == "G4Trd << 
1278   {                                           << 
1279     const G4Trd* const trdPtr = static_cast<c << 
1280     TrdWrite(solidsElement, trdPtr);          << 
1281   }                                           << 
1282   else if(solidPtr->GetEntityType() == "G4Tub << 
1283   {                                           << 
1284     const G4Tubs* const tubePtr = static_cast << 
1285     TubeWrite(solidsElement, tubePtr);        << 
1286   }                                           << 
1287   else if(solidPtr->GetEntityType() == "G4Cut << 
1288   {                                           << 
1289     const G4CutTubs* const cuttubePtr = stati << 
1290     CutTubeWrite(solidsElement, cuttubePtr);  << 
1291   }                                           << 
1292   else if(solidPtr->GetEntityType() == "G4Twi << 
1293   {                                           << 
1294     const G4TwistedBox* const twistedboxPtr = << 
1295       static_cast<const G4TwistedBox*>(solidP << 
1296     TwistedboxWrite(solidsElement, twistedbox << 
1297   }                                           << 
1298   else if(solidPtr->GetEntityType() == "G4Twi << 
1299   {                                           << 
1300     const G4TwistedTrap* const twistedtrapPtr << 
1301       static_cast<const G4TwistedTrap*>(solid << 
1302     TwistedtrapWrite(solidsElement, twistedtr << 
1303   }                                           << 
1304   else if(solidPtr->GetEntityType() == "G4Twi << 
1305   {                                           << 
1306     const G4TwistedTrd* const twistedtrdPtr = << 
1307       static_cast<const G4TwistedTrd*>(solidP << 
1308     TwistedtrdWrite(solidsElement, twistedtrd << 
1309   }                                           << 
1310   else if(solidPtr->GetEntityType() == "G4Twi << 
1311   {                                           << 
1312     const G4TwistedTubs* const twistedtubsPtr << 
1313       static_cast<const G4TwistedTubs*>(solid << 
1314     TwistedtubsWrite(solidsElement, twistedtu << 
1315   }                                           << 
1316   else                                        << 
1317   {                                           << 
1318     G4String error_msg = "Unknown solid: " +  << 
1319                          "; Type: " + solidPt << 
1320     G4Exception("G4GDMLWriteSolids::AddSolid( << 
1321                 error_msg);                   << 
1322   }                                           << 
1323 }                                                1251 }
1324                                                  1252