56 return (stat(fname.c_str(), &FileInfo) == 0);
62 static VolumeMapType instance;
68 static PhysVolumeMapType instance;
75 static DepthMapType instance;
95 xercesc::DOMElement* element)
97 for(
auto iaux = auxInfoList->cbegin(); iaux != auxInfoList->cend(); ++iaux)
99 xercesc::DOMElement* auxiliaryElement =
NewElement(
"auxiliary");
100 element->appendChild(auxiliaryElement);
102 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxtype", (*iaux).type));
103 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxvalue", (*iaux).value));
104 if(((*iaux).unit) !=
"")
106 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxunit", (*iaux).unit));
135 std::stringstream stream;
143 std::vector<char> toremove = {
' ',
'/',
':',
'#',
'+' };
144 for(
auto c : toremove)
148 std::replace(nameOut.begin(), nameOut.end(), c,
'_');
158 xercesc::XMLString::transcode(name,
tempStr, 9999);
159 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
160 xercesc::XMLString::transcode(value,
tempStr, 9999);
169 xercesc::XMLString::transcode(name,
tempStr, 9999);
170 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
171 std::ostringstream ostream;
172 ostream.precision(15);
175 xercesc::XMLString::transcode(str,
tempStr, 9999);
183 xercesc::XMLString::transcode(name,
tempStr, 9999);
198 G4cout <<
"G4GDML: Writing '" << fname <<
"'..." <<
G4endl;
202 G4cout <<
"G4GDML: Writing module '" << fname <<
"'..." <<
G4endl;
207 G4String ErrorMessage =
"File '" + fname +
"' already exists!";
215 xercesc::XMLString::transcode(
"LS",
tempStr, 9999);
216 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
217 xercesc::XMLString::transcode(
"Range",
tempStr, 9999);
218 xercesc::DOMImplementation* impl =
219 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
220 xercesc::XMLString::transcode(
"gdml",
tempStr, 9999);
222 xercesc::DOMElement* gdml =
doc->getDocumentElement();
224#if XERCES_VERSION_MAJOR >= 3
226 xercesc::DOMLSSerializer* writer =
227 ((xercesc::DOMImplementationLS*) impl)->createLSSerializer();
229 xercesc::DOMConfiguration* dc = writer->getDomConfig();
230 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
234 xercesc::DOMWriter* writer =
235 ((xercesc::DOMImplementationLS*) impl)->createDOMWriter();
237 if(writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
238 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
242 gdml->setAttributeNode(
243 NewAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance"));
244 gdml->setAttributeNode(
258 xercesc::XMLFormatTarget* myFormTarget =
259 new xercesc::LocalFileFormatTarget(fname.c_str());
263#if XERCES_VERSION_MAJOR >= 3
265 xercesc::DOMLSOutput* theOutput =
266 ((xercesc::DOMImplementationLS*) impl)->createLSOutput();
267 theOutput->setByteStream(myFormTarget);
268 writer->write(
doc, theOutput);
270 writer->writeNode(myFormTarget, *
doc);
272 }
catch(
const xercesc::XMLException& toCatch)
274 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
275 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
276 xercesc::XMLString::release(&message);
278 }
catch(
const xercesc::DOMException& toCatch)
280 char* message = xercesc::XMLString::transcode(toCatch.msg);
281 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
282 xercesc::XMLString::release(&message);
295 G4cout <<
"G4GDML: Writing '" << fname <<
"' done !" <<
G4endl;
300 G4cout <<
"G4GDML: Writing module '" << fname <<
"' done !" <<
G4endl;
311 G4cout <<
"G4GDML: Adding module '" << fname <<
"'..." <<
G4endl;
313 if(physvol ==
nullptr)
316 "Invalid NULL pointer is specified for modularization!");
322 "It is not possible to modularize by divisionvol!");
328 "It is not possible to modularize by parameterised volume!");
334 "It is not possible to modularize by replicated volume!");
347 "Depth must be a positive number!");
352 "Adding module(s) at this depth is already requested!");
368 std::stringstream stream;
369 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
G4GLOB_DLL std::ostream G4cout
virtual void SurfacesWrite()=0
virtual void MaterialsWrite(xercesc::DOMElement *)=0
DepthMapType & DepthMap()
G4bool FileExists(const G4String &) const
static void SetAddPointerToName(G4bool)
G4GDMLAuxListType auxList
void AddModule(const G4VPhysicalVolume *const topVol)
xercesc::DOMElement * NewElement(const G4String &)
G4String GenerateName(const G4String &, const void *const)
void AddAuxiliary(G4GDMLAuxStructType myaux)
G4String Modularize(const G4VPhysicalVolume *const topvol, const G4int depth)
virtual void AddExtension(xercesc::DOMElement *, const G4LogicalVolume *const)
virtual void SetupWrite(xercesc::DOMElement *, const G4LogicalVolume *const)=0
G4Transform3D Write(const G4String &filename, const G4LogicalVolume *const topLog, const G4String &schemaPath, const G4int depth, G4bool storeReferences=true)
virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const, const G4int)=0
virtual void DefineWrite(xercesc::DOMElement *)=0
xercesc::DOMDocument * doc
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
virtual void UserinfoWrite(xercesc::DOMElement *)
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
static G4bool addPointerToName
xercesc::DOMElement * userinfoElement
virtual void ExtensionWrite(xercesc::DOMElement *)
virtual void SolidsWrite(xercesc::DOMElement *)=0
VolumeMapType & VolumeMap()
virtual void StructureWrite(xercesc::DOMElement *)=0
G4bool overwriteOutputFile
void SetOutputFileOverwrite(G4bool flag)
PhysVolumeMapType & PvolumeMap()
G4bool contains(const std::string &) const
virtual G4bool IsReplicated() const =0
const G4String & GetName() const
virtual G4bool IsParameterised() const =0