Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/persistency/gdml/src/G4GDMLWrite.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/G4GDMLWrite.cc (Version 11.3.0) and /persistency/gdml/src/G4GDMLWrite.cc (Version 9.6.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 // G4GDMLWrite implementation                  << 
 27 //                                                 26 //
 28 // Author: Zoltan Torzsok, November 2007       <<  27 // $Id$
                                                   >>  28 //
                                                   >>  29 // class G4GDMLWrite Implementation
                                                   >>  30 //
                                                   >>  31 // Original author: Zoltan Torzsok, November 2007
                                                   >>  32 //
 29 // -------------------------------------------     33 // --------------------------------------------------------------------
 30                                                    34 
 31 #include <sys/stat.h>                              35 #include <sys/stat.h>
 32 #include <iostream>                                36 #include <iostream>
 33                                                    37 
 34 #include "G4GDMLWrite.hh"                          38 #include "G4GDMLWrite.hh"
 35                                                    39 
 36 #include "G4LogicalVolume.hh"                      40 #include "G4LogicalVolume.hh"
 37 #include "G4Transform3D.hh"                        41 #include "G4Transform3D.hh"
 38 #include "G4PVDivision.hh"                         42 #include "G4PVDivision.hh"
 39                                                    43 
 40 G4bool G4GDMLWrite::addPointerToName = true;       44 G4bool G4GDMLWrite::addPointerToName = true;
 41                                                    45 
 42 // ------------------------------------------- <<  46 G4GDMLWrite::G4GDMLWrite() : doc(0), extElement(0)
 43 G4GDMLWrite::G4GDMLWrite()                     << 
 44 {                                                  47 {
 45 }                                                  48 }
 46                                                    49 
 47 // ------------------------------------------- << 
 48 G4GDMLWrite::~G4GDMLWrite()                        50 G4GDMLWrite::~G4GDMLWrite()
 49 {                                                  51 {
 50 }                                                  52 }
 51                                                    53 
 52 // ------------------------------------------- << 
 53 G4bool G4GDMLWrite::FileExists(const G4String&     54 G4bool G4GDMLWrite::FileExists(const G4String& fname) const
 54 {                                                  55 {
 55   struct stat FileInfo;                            56   struct stat FileInfo;
 56   return (stat(fname.c_str(), &FileInfo) == 0) <<  57   return (stat(fname.c_str(),&FileInfo) == 0); 
 57 }                                                  58 }
 58                                                    59 
 59 // ------------------------------------------- << 
 60 G4GDMLWrite::VolumeMapType& G4GDMLWrite::Volum     60 G4GDMLWrite::VolumeMapType& G4GDMLWrite::VolumeMap()
 61 {                                                  61 {
 62   static VolumeMapType instance;               <<  62    static VolumeMapType instance;
 63   return instance;                             <<  63    return instance;
 64 }                                                  64 }
 65                                                    65 
 66 G4GDMLWrite::PhysVolumeMapType& G4GDMLWrite::P     66 G4GDMLWrite::PhysVolumeMapType& G4GDMLWrite::PvolumeMap()
 67 {                                                  67 {
 68   static PhysVolumeMapType instance;           <<  68    static PhysVolumeMapType instance;
 69   return instance;                             <<  69    return instance;
 70 }                                                  70 }
 71                                                    71 
 72 // ------------------------------------------- << 
 73 G4GDMLWrite::DepthMapType& G4GDMLWrite::DepthM     72 G4GDMLWrite::DepthMapType& G4GDMLWrite::DepthMap()
 74 {                                                  73 {
 75   static DepthMapType instance;                <<  74    static DepthMapType instance;
 76   return instance;                             <<  75    return instance;
 77 }                                                  76 }
 78                                                    77 
 79 // ------------------------------------------- << 
 80 void G4GDMLWrite::AddExtension(xercesc::DOMEle     78 void G4GDMLWrite::AddExtension(xercesc::DOMElement*,
 81                                const G4Logical     79                                const G4LogicalVolume* const)
 82 {                                                  80 {
 83   // Empty implementation. To be overwritten b <<  81    // Empty implementation. To be overwritten by user for specific extensions
 84   // related to attributes associated to volum <<  82    // related to attributes associated to volumes
 85 }                                                  83 }
 86                                                    84 
 87 // ------------------------------------------- << 
 88 void G4GDMLWrite::ExtensionWrite(xercesc::DOME     85 void G4GDMLWrite::ExtensionWrite(xercesc::DOMElement*)
 89 {                                                  86 {
 90   // Empty implementation. To be overwritten b <<  87    // Empty implementation. To be overwritten by user for specific extensions
 91 }                                                  88 }
 92                                                    89 
 93 // ------------------------------------------- << 
 94 void G4GDMLWrite::AddAuxInfo(G4GDMLAuxListType << 
 95                              xercesc::DOMEleme << 
 96 {                                              << 
 97   for(auto iaux = auxInfoList->cbegin(); iaux  << 
 98   {                                            << 
 99     xercesc::DOMElement* auxiliaryElement = Ne << 
100     element->appendChild(auxiliaryElement);    << 
101                                                << 
102     auxiliaryElement->setAttributeNode(NewAttr << 
103     auxiliaryElement->setAttributeNode(NewAttr << 
104     if(((*iaux).unit) != "")                   << 
105     {                                          << 
106       auxiliaryElement->setAttributeNode(NewAt << 
107     }                                          << 
108                                                << 
109     if(iaux->auxList)                          << 
110     {                                          << 
111       AddAuxInfo(iaux->auxList, auxiliaryEleme << 
112     }                                          << 
113   }                                            << 
114   return;                                      << 
115 }                                              << 
116                                                << 
117 // ------------------------------------------- << 
118 void G4GDMLWrite::UserinfoWrite(xercesc::DOMEl << 
119 {                                              << 
120   if(auxList.size() > 0)                       << 
121   {                                            << 
122 #ifdef G4VERBOSE                               << 
123     G4cout << "G4GDML: Writing userinfo..." << << 
124 #endif                                         << 
125     userinfoElement = NewElement("userinfo");  << 
126     gdmlElement->appendChild(userinfoElement); << 
127     AddAuxInfo(&auxList, userinfoElement);     << 
128   }                                            << 
129 }                                              << 
130                                                << 
131 // ------------------------------------------- << 
132 G4String G4GDMLWrite::GenerateName(const G4Str     90 G4String G4GDMLWrite::GenerateName(const G4String& name, const void* const ptr)
133 {                                                  91 {
134   G4String nameOut;                            <<  92    G4String nameOut;
135   std::stringstream stream;                    <<  93    std::stringstream stream; stream << name;
136   stream << name;                              <<  94    if (addPointerToName) { stream << ptr; };
137   if(addPointerToName)                         <<  95 
138   {                                            <<  96    nameOut=G4String(stream.str());
139     stream << ptr;                             <<  97    if(nameOut.contains(' '))
140   };                                           <<  98    nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),' '),nameOut.end());
141                                                <<  99 
142   nameOut = G4String(stream.str());            << 100    return nameOut;
143   std::vector<char> toremove = { ' ', '/', ':' << 
144   for(auto c : toremove)                       << 
145   {                                            << 
146     if(G4StrUtil::contains(nameOut, c))        << 
147     {                                          << 
148       std::replace(nameOut.begin(), nameOut.en << 
149     }                                          << 
150   }                                            << 
151   return nameOut;                              << 
152 }                                                 101 }
153                                                   102 
154 // ------------------------------------------- << 
155 xercesc::DOMAttr* G4GDMLWrite::NewAttribute(co    103 xercesc::DOMAttr* G4GDMLWrite::NewAttribute(const G4String& name,
156                                             co    104                                             const G4String& value)
157 {                                                 105 {
158   XMLCh* tempStr = NULL;                       << 106    xercesc::XMLString::transcode(name,tempStr,99);
159   tempStr = xercesc::XMLString::transcode(name << 107    xercesc::DOMAttr* att = doc->createAttribute(tempStr);
160   xercesc::DOMAttr* att = doc->createAttribute << 108    xercesc::XMLString::transcode(value,tempStr,99);
161   xercesc::XMLString::release(&tempStr);       << 109    att->setValue(tempStr);
162                                                << 110    return att;
163   tempStr = xercesc::XMLString::transcode(valu << 
164   att->setValue(tempStr);                      << 
165   xercesc::XMLString::release(&tempStr);       << 
166                                                << 
167   return att;                                  << 
168 }                                                 111 }
169                                                   112 
170 // ------------------------------------------- << 
171 xercesc::DOMAttr* G4GDMLWrite::NewAttribute(co    113 xercesc::DOMAttr* G4GDMLWrite::NewAttribute(const G4String& name,
172                                             co    114                                             const G4double& value)
173 {                                                 115 {
174   XMLCh* tempStr = NULL;                       << 116    xercesc::XMLString::transcode(name,tempStr,99);
175   tempStr = xercesc::XMLString::transcode(name << 117    xercesc::DOMAttr* att = doc->createAttribute(tempStr);
176   xercesc::DOMAttr* att = doc->createAttribute << 118    std::ostringstream ostream;
177   xercesc::XMLString::release(&tempStr);       << 119    ostream.precision(15);
178                                                << 120    ostream << value;
179   std::ostringstream ostream;                  << 121    G4String str = ostream.str();
180   ostream.precision(15);                       << 122    xercesc::XMLString::transcode(str,tempStr,99);
181   ostream << value;                            << 123    att->setValue(tempStr);
182   G4String str = ostream.str();                << 124    return att;
183                                                << 
184   tempStr = xercesc::XMLString::transcode(str) << 
185   att->setValue(tempStr);                      << 
186   xercesc::XMLString::release(&tempStr);       << 
187                                                << 
188   return att;                                  << 
189 }                                                 125 }
190                                                   126 
191 // ------------------------------------------- << 
192 xercesc::DOMElement* G4GDMLWrite::NewElement(c    127 xercesc::DOMElement* G4GDMLWrite::NewElement(const G4String& name)
193 {                                                 128 {
194   XMLCh* tempStr = NULL;                       << 129    xercesc::XMLString::transcode(name,tempStr,99);
195   tempStr = xercesc::XMLString::transcode(name << 130    return doc->createElement(tempStr);
196   xercesc::DOMElement* elem = doc->createEleme << 
197   xercesc::XMLString::release(&tempStr);       << 
198                                                << 
199   return elem;                                 << 
200 }                                                 131 }
201                                                   132 
202 // ------------------------------------------- << 
203 G4Transform3D G4GDMLWrite::Write(const G4Strin    133 G4Transform3D G4GDMLWrite::Write(const G4String& fname,
204                                  const G4Logic    134                                  const G4LogicalVolume* const logvol,
205                                  const G4Strin    135                                  const G4String& setSchemaLocation,
206                                  const G4int d << 136                                  const G4int depth,
                                                   >> 137                                        G4bool refs)
207 {                                                 138 {
208   SchemaLocation   = setSchemaLocation;        << 139    SchemaLocation = setSchemaLocation;
209   addPointerToName = refs;                     << 140    addPointerToName = refs;
210 #ifdef G4VERBOSE                               << 
211   if(depth == 0)                               << 
212   {                                            << 
213     G4cout << "G4GDML: Writing '" << fname <<  << 
214   }                                            << 
215   else                                         << 
216   {                                            << 
217     G4cout << "G4GDML: Writing module '" << fn << 
218   }                                            << 
219 #endif                                         << 
220   if(!overwriteOutputFile && FileExists(fname) << 
221   {                                            << 
222     G4String ErrorMessage = "File '" + fname + << 
223     G4Exception("G4GDMLWrite::Write()", "Inval << 
224                 ErrorMessage);                 << 
225   }                                            << 
226                                                   141 
227   VolumeMap().clear();  // The module map is g << 142    if (depth==0) { G4cout << "G4GDML: Writing '" << fname << "'..." << G4endl; }
                                                   >> 143    else   { G4cout << "G4GDML: Writing module '" << fname << "'..." << G4endl; }
                                                   >> 144    
                                                   >> 145    if (FileExists(fname))
                                                   >> 146    {
                                                   >> 147      G4String ErrorMessage = "File '"+fname+"' already exists!";
                                                   >> 148      G4Exception("G4GDMLWrite::Write()", "InvalidSetup",
                                                   >> 149                  FatalException, ErrorMessage);
                                                   >> 150    }
                                                   >> 151    
                                                   >> 152    VolumeMap().clear(); // The module map is global for all modules,
228                         // so clear it only at    153                         // so clear it only at once!
229                                                   154 
230   XMLCh* tempStr = NULL;                       << 155    xercesc::XMLString::transcode("LS", tempStr, 99);
231   tempStr = xercesc::XMLString::transcode("LS" << 156      xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
232   xercesc::DOMImplementationRegistry::getDOMIm << 157    xercesc::XMLString::transcode("Range", tempStr, 99);
233   xercesc::XMLString::release(&tempStr);       << 158    xercesc::DOMImplementation* impl =
234   tempStr = xercesc::XMLString::transcode("Ran << 159      xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
235   xercesc::DOMImplementation* impl =           << 160    xercesc::XMLString::transcode("gdml", tempStr, 99);
236     xercesc::DOMImplementationRegistry::getDOM << 161    doc = impl->createDocument(0,tempStr,0);
237   xercesc::XMLString::release(&tempStr);       << 162    xercesc::DOMElement* gdml = doc->getDocumentElement();
238   tempStr = xercesc::XMLString::transcode("gdm << 
239   doc                       = impl->createDocu << 
240   xercesc::XMLString::release(&tempStr);       << 
241   xercesc::DOMElement* gdml = doc->getDocument << 
242                                                   163 
243 #if XERCES_VERSION_MAJOR >= 3                     164 #if XERCES_VERSION_MAJOR >= 3
244   // DOM L3 as per Xerces 3.0 API              << 165                                              // DOM L3 as per Xerces 3.0 API
245   xercesc::DOMLSSerializer* writer =           << 166     xercesc::DOMLSSerializer* writer =
246     ((xercesc::DOMImplementationLS*) impl)->cr << 167       ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
247                                                   168 
248   xercesc::DOMConfiguration* dc = writer->getD << 169     xercesc::DOMConfiguration *dc = writer->getDomConfig();
249   dc->setParameter(xercesc::XMLUni::fgDOMWRTFo << 170     dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
250                                                   171 
251 #else                                             172 #else
252                                                   173 
253   xercesc::DOMWriter* writer =                 << 174    xercesc::DOMWriter* writer =
254     ((xercesc::DOMImplementationLS*) impl)->cr << 175      ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
255                                                   176 
256   if(writer->canSetFeature(xercesc::XMLUni::fg << 177    if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true))
257     writer->setFeature(xercesc::XMLUni::fgDOMW << 178        writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
258                                                   179 
259 #endif                                            180 #endif
260                                                   181 
261   gdml->setAttributeNode(                      << 182    gdml->setAttributeNode(NewAttribute("xmlns:xsi",
262     NewAttribute("xmlns:xsi", "http://www.w3.o << 183                           "http://www.w3.org/2001/XMLSchema-instance"));
263   gdml->setAttributeNode(                      << 184    gdml->setAttributeNode(NewAttribute("xsi:noNamespaceSchemaLocation",
264     NewAttribute("xsi:noNamespaceSchemaLocatio << 185                           SchemaLocation));
265                                                << 186 
266   ExtensionWrite(gdml);                        << 187    ExtensionWrite(gdml);
267   DefineWrite(gdml);                           << 188    DefineWrite(gdml);
268   MaterialsWrite(gdml);                        << 189    MaterialsWrite(gdml);
269   SolidsWrite(gdml);                           << 190    SolidsWrite(gdml);
270   StructureWrite(gdml);                        << 191    StructureWrite(gdml);
271   UserinfoWrite(gdml);                         << 192    SetupWrite(gdml,logvol);
272   SetupWrite(gdml, logvol);                    << 193 
273                                                << 194    G4Transform3D R = TraverseVolumeTree(logvol,depth);
274   G4Transform3D R = TraverseVolumeTree(logvol, << 195 
275                                                << 196    SurfacesWrite();
276   SurfacesWrite();                             << 197    xercesc::XMLFormatTarget *myFormTarget =
277   xercesc::XMLFormatTarget* myFormTarget =     << 198      new xercesc::LocalFileFormatTarget(fname.c_str());
278     new xercesc::LocalFileFormatTarget(fname.c << 
279                                                   199 
280   try                                          << 200    try
281   {                                            << 201    {
282 #if XERCES_VERSION_MAJOR >= 3                     202 #if XERCES_VERSION_MAJOR >= 3
283     // DOM L3 as per Xerces 3.0 API            << 203                                             // DOM L3 as per Xerces 3.0 API
284     xercesc::DOMLSOutput* theOutput =          << 204       xercesc::DOMLSOutput *theOutput =
285       ((xercesc::DOMImplementationLS*) impl)-> << 205         ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
286     theOutput->setByteStream(myFormTarget);    << 206       theOutput->setByteStream(myFormTarget);
287     writer->write(doc, theOutput);             << 207       writer->write(doc, theOutput);
288 #else                                             208 #else
289     writer->writeNode(myFormTarget, *doc);     << 209       writer->writeNode(myFormTarget, *doc);
290 #endif                                            210 #endif
291   } catch(const xercesc::XMLException& toCatch << 211    }
292   {                                            << 212    catch (const xercesc::XMLException& toCatch)
293     char* message = xercesc::XMLString::transc << 213    {
294     G4cout << "G4GDML: Exception message is: " << 214       char* message = xercesc::XMLString::transcode(toCatch.getMessage());
295     xercesc::XMLString::release(&message);     << 215       G4cout << "G4GDML: Exception message is: " << message << G4endl;
296     return G4Transform3D::Identity;            << 216       xercesc::XMLString::release(&message);
297   } catch(const xercesc::DOMException& toCatch << 217       return G4Transform3D::Identity;
298   {                                            << 218    }
299     char* message = xercesc::XMLString::transc << 219    catch (const xercesc::DOMException& toCatch)
300     G4cout << "G4GDML: Exception message is: " << 220    {
301     xercesc::XMLString::release(&message);     << 221       char* message = xercesc::XMLString::transcode(toCatch.msg);
302     return G4Transform3D::Identity;            << 222       G4cout << "G4GDML: Exception message is: " << message << G4endl;
303   } catch(...)                                 << 223       xercesc::XMLString::release(&message);
304   {                                            << 224       return G4Transform3D::Identity;
305     G4cout << "G4GDML: Unexpected Exception!"  << 225    }
306     return G4Transform3D::Identity;            << 226    catch (...)
307   }                                            << 227    {   
308                                                << 228       G4cout << "G4GDML: Unexpected Exception!" << G4endl;
309   delete myFormTarget;                         << 229       return G4Transform3D::Identity;
310   writer->release();                           << 230    }        
311                                                << 231 
312   if(depth == 0)                               << 232    delete myFormTarget;
313   {                                            << 233    writer->release();
314     G4cout << "G4GDML: Writing '" << fname <<  << 234 
315   }                                            << 235    if (depth==0)
316   else                                         << 236    {
317   {                                            << 237      G4cout << "G4GDML: Writing '" << fname << "' done !" << G4endl;
318 #ifdef G4VERBOSE                               << 238    }
319     G4cout << "G4GDML: Writing module '" << fn << 239    else
320 #endif                                         << 240    {
321   }                                            << 241      G4cout << "G4GDML: Writing module '" << fname << "' done !" << G4endl;
                                                   >> 242    }
322                                                   243 
323   return R;                                    << 244    return R;
324 }                                                 245 }
325                                                   246 
326 // ------------------------------------------- << 
327 void G4GDMLWrite::AddModule(const G4VPhysicalV    247 void G4GDMLWrite::AddModule(const G4VPhysicalVolume* const physvol)
328 {                                                 248 {
329   G4String fname = GenerateName(physvol->GetNa << 249    G4String fname = GenerateName(physvol->GetName(),physvol);
330   G4cout << "G4GDML: Adding module '" << fname << 250    G4cout << "G4GDML: Adding module '" << fname << "'..." << G4endl;
331                                                   251 
332   if(physvol == nullptr)                       << 252    if (physvol == 0)
333   {                                            << 253    {
334     G4Exception("G4GDMLWrite::AddModule()", "I << 254      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
335                 "Invalid NULL pointer is speci << 255                  "Invalid NULL pointer is specified for modularization!");
336     return;                                    << 256      return;
337   }                                            << 257    }
338   if(dynamic_cast<const G4PVDivision*>(physvol << 258    if (dynamic_cast<const G4PVDivision*>(physvol))
339   {                                            << 259    {
340     G4Exception("G4GDMLWrite::AddModule()", "I << 260      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
341                 "It is not possible to modular << 261                  "It is not possible to modularize by divisionvol!");
342     return;                                    << 262      return;
343   }                                            << 263    }
344   if(physvol->IsParameterised())               << 264    if (physvol->IsParameterised())
345   {                                            << 265    {
346     G4Exception("G4GDMLWrite::AddModule()", "I << 266      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
347                 "It is not possible to modular << 267                  "It is not possible to modularize by parameterised volume!");
348     return;                                    << 268      return;
349   }                                            << 269    }
350   if(physvol->IsReplicated())                  << 270    if (physvol->IsReplicated())
351   {                                            << 271    {
352     G4Exception("G4GDMLWrite::AddModule()", "I << 272      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
353                 "It is not possible to modular << 273                  "It is not possible to modularize by replicated volume!");
354     return;                                    << 274      return;
355   }                                            << 275    }
356                                                   276 
357   PvolumeMap()[physvol] = fname;               << 277    PvolumeMap()[physvol] = fname;
358 }                                                 278 }
359                                                   279 
360 // ------------------------------------------- << 
361 void G4GDMLWrite::AddModule(const G4int depth)    280 void G4GDMLWrite::AddModule(const G4int depth)
362 {                                                 281 {
363   if(depth < 0)                                << 282    if (depth<0)
364   {                                            << 283    {
365     G4Exception("G4GDMLWrite::AddModule()", "I << 284      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
366                 "Depth must be a positive numb << 285                  "Depth must be a positive number!");
367   }                                            << 286    }
368   if(DepthMap().find(depth) != DepthMap().end( << 287    if (DepthMap().find(depth) != DepthMap().end())
369   {                                            << 288    {
370     G4Exception("G4GDMLWrite::AddModule()", "I << 289      G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
371                 "Adding module(s) at this dept << 290                  "Adding module(s) at this depth is already requested!");
372   }                                            << 291    }
373   DepthMap()[depth] = 0;                       << 292    DepthMap()[depth] = 0;
374 }                                              << 293 }
375                                                << 294 
376 // ------------------------------------------- << 295 G4String G4GDMLWrite::Modularize( const G4VPhysicalVolume* const physvol,
377 G4String G4GDMLWrite::Modularize(const G4VPhys << 296                                   const G4int depth )
378                                  const G4int d << 297 {
379 {                                              << 298    if (PvolumeMap().find(physvol) != PvolumeMap().end())
380   if(PvolumeMap().find(physvol) != PvolumeMap( << 299    {
381   {                                            << 300      return PvolumeMap()[physvol]; // Modularize via physvol
382     return PvolumeMap()[physvol];  // Modulari << 301    }
383   }                                            << 302 
384                                                << 303    if (DepthMap().find(depth) != DepthMap().end()) // Modularize via depth
385   if(DepthMap().find(depth) != DepthMap().cend << 304    {
386   {                                            << 305      std::stringstream stream;
387     std::stringstream stream;                  << 306      stream << "depth" << depth << "_module" << DepthMap()[depth] << ".gdml";
388     stream << "depth" << depth << "_module" << << 307      DepthMap()[depth]++;           // There can be more modules at this depth!
389     DepthMap()[depth]++;  // There can be more << 308      return G4String(stream.str());
390     return G4String(stream.str());             << 309    }
391   }                                            << 
392                                                   310 
393   return G4String("");  // Empty string for mo << 311    return G4String(""); // Empty string for module name = no modularization
394                         // was requested at th    312                         // was requested at that level/physvol!
395 }                                                 313 }
396                                                   314 
397 // ------------------------------------------- << 
398 void G4GDMLWrite::AddAuxiliary(G4GDMLAuxStruct << 
399 {                                              << 
400   auxList.push_back(myaux);                    << 
401 }                                              << 
402                                                << 
403 // ------------------------------------------- << 
404 void G4GDMLWrite::SetOutputFileOverwrite(G4boo << 
405 {                                              << 
406   overwriteOutputFile = flag;                  << 
407 }                                              << 
408                                                << 
409 // ------------------------------------------- << 
410 void G4GDMLWrite::SetAddPointerToName(G4bool s    315 void G4GDMLWrite::SetAddPointerToName(G4bool set)
411 {                                                 316 {
412   addPointerToName = set;                      << 317    addPointerToName = set;
413 }                                                 318 }
414                                                   319