56 return (stat(
fname.c_str(), &FileInfo) == 0);
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 XMLCh* tempStr = NULL;
159 tempStr = xercesc::XMLString::transcode(
name);
160 xercesc::DOMAttr* att =
doc->createAttribute(tempStr);
161 xercesc::XMLString::release(&tempStr);
163 tempStr = xercesc::XMLString::transcode(value);
164 att->setValue(tempStr);
165 xercesc::XMLString::release(&tempStr);
174 XMLCh* tempStr = NULL;
175 tempStr = xercesc::XMLString::transcode(
name);
176 xercesc::DOMAttr* att =
doc->createAttribute(tempStr);
177 xercesc::XMLString::release(&tempStr);
179 std::ostringstream ostream;
180 ostream.precision(15);
184 tempStr = xercesc::XMLString::transcode(str);
185 att->setValue(tempStr);
186 xercesc::XMLString::release(&tempStr);
194 XMLCh* tempStr = NULL;
195 tempStr = xercesc::XMLString::transcode(
name);
196 xercesc::DOMElement*
elem =
doc->createElement(tempStr);
197 xercesc::XMLString::release(&tempStr);
222 G4String ErrorMessage =
"File '" +
fname +
"' already exists!";
230 XMLCh* tempStr = NULL;
231 tempStr = xercesc::XMLString::transcode(
"LS");
232 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
233 xercesc::XMLString::release(&tempStr);
234 tempStr = xercesc::XMLString::transcode(
"Range");
235 xercesc::DOMImplementation* impl =
236 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
237 xercesc::XMLString::release(&tempStr);
238 tempStr = xercesc::XMLString::transcode(
"gdml");
239 doc = impl->createDocument(0, tempStr, 0);
240 xercesc::XMLString::release(&tempStr);
241 xercesc::DOMElement* gdml =
doc->getDocumentElement();
243#if XERCES_VERSION_MAJOR >= 3
245 xercesc::DOMLSSerializer* writer =
246 ((xercesc::DOMImplementationLS*) impl)->createLSSerializer();
248 xercesc::DOMConfiguration* dc = writer->getDomConfig();
249 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
253 xercesc::DOMWriter* writer =
254 ((xercesc::DOMImplementationLS*) impl)->createDOMWriter();
256 if(writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
257 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
261 gdml->setAttributeNode(
262 NewAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance"));
263 gdml->setAttributeNode(
277 xercesc::XMLFormatTarget* myFormTarget =
278 new xercesc::LocalFileFormatTarget(
fname.c_str());
282#if XERCES_VERSION_MAJOR >= 3
284 xercesc::DOMLSOutput* theOutput =
285 ((xercesc::DOMImplementationLS*) impl)->createLSOutput();
286 theOutput->setByteStream(myFormTarget);
287 writer->write(
doc, theOutput);
289 writer->writeNode(myFormTarget, *
doc);
291 }
catch(
const xercesc::XMLException& toCatch)
293 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
294 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
295 xercesc::XMLString::release(&message);
297 }
catch(
const xercesc::DOMException& toCatch)
299 char* message = xercesc::XMLString::transcode(toCatch.msg);
300 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
301 xercesc::XMLString::release(&message);
332 if(physvol ==
nullptr)
335 "Invalid NULL pointer is specified for modularization!");
341 "It is not possible to modularize by divisionvol!");
347 "It is not possible to modularize by parameterised volume!");
353 "It is not possible to modularize by replicated volume!");
366 "Depth must be a positive number!");
371 "Adding module(s) at this depth is already requested!");
387 std::stringstream stream;
388 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 &)
std::map< const G4LogicalVolume *, G4Transform3D > VolumeMapType
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
std::map< const G4VPhysicalVolume *, G4String > PhysVolumeMapType
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
std::map< G4int, G4int > DepthMapType
void SetOutputFileOverwrite(G4bool flag)
PhysVolumeMapType & PvolumeMap()
virtual G4bool IsReplicated() const =0
const G4String & GetName() const
virtual G4bool IsParameterised() const =0
const char * name(G4int ptype)
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.