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;
146 std::vector<char> toremove = {
' ',
'/',
':',
'#',
'+' };
147 for(
auto c : toremove)
151 std::replace(nameOut.begin(), nameOut.end(), c,
'_');
161 XMLCh* tempStr = NULL;
162 tempStr = xercesc::XMLString::transcode(name);
163 xercesc::DOMAttr* att =
doc->createAttribute(tempStr);
164 xercesc::XMLString::release(&tempStr);
166 tempStr = xercesc::XMLString::transcode(value);
167 att->setValue(tempStr);
168 xercesc::XMLString::release(&tempStr);
177 XMLCh* tempStr = NULL;
178 tempStr = xercesc::XMLString::transcode(name);
179 xercesc::DOMAttr* att =
doc->createAttribute(tempStr);
180 xercesc::XMLString::release(&tempStr);
182 std::ostringstream ostream;
183 ostream.precision(15);
187 tempStr = xercesc::XMLString::transcode(str);
188 att->setValue(tempStr);
189 xercesc::XMLString::release(&tempStr);
197 XMLCh* tempStr = NULL;
198 tempStr = xercesc::XMLString::transcode(name);
199 xercesc::DOMElement*
elem =
doc->createElement(tempStr);
200 xercesc::XMLString::release(&tempStr);
216 G4cout <<
"G4GDML: Writing '" << fname <<
"'..." <<
G4endl;
220 G4cout <<
"G4GDML: Writing module '" << fname <<
"'..." <<
G4endl;
225 G4String ErrorMessage =
"File '" + fname +
"' already exists!";
233 XMLCh* tempStr = NULL;
234 tempStr = xercesc::XMLString::transcode(
"LS");
235 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
236 xercesc::XMLString::release(&tempStr);
237 tempStr = xercesc::XMLString::transcode(
"Range");
238 xercesc::DOMImplementation* impl =
239 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
240 xercesc::XMLString::release(&tempStr);
241 tempStr = xercesc::XMLString::transcode(
"gdml");
242 doc = impl->createDocument(0, tempStr, 0);
243 xercesc::XMLString::release(&tempStr);
244 xercesc::DOMElement* gdml =
doc->getDocumentElement();
246#if XERCES_VERSION_MAJOR >= 3
248 xercesc::DOMLSSerializer*
writer =
249 ((xercesc::DOMImplementationLS*) impl)->createLSSerializer();
251 xercesc::DOMConfiguration* dc =
writer->getDomConfig();
252 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
256 xercesc::DOMWriter*
writer =
257 ((xercesc::DOMImplementationLS*) impl)->createDOMWriter();
259 if(
writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
260 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
264 gdml->setAttributeNode(
265 NewAttribute(
"xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance"));
266 gdml->setAttributeNode(
280 xercesc::XMLFormatTarget* myFormTarget =
281 new xercesc::LocalFileFormatTarget(fname.c_str());
285#if XERCES_VERSION_MAJOR >= 3
287 xercesc::DOMLSOutput* theOutput =
288 ((xercesc::DOMImplementationLS*) impl)->createLSOutput();
289 theOutput->setByteStream(myFormTarget);
294 }
catch(
const xercesc::XMLException& toCatch)
296 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
297 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
298 xercesc::XMLString::release(&message);
300 }
catch(
const xercesc::DOMException& toCatch)
302 char* message = xercesc::XMLString::transcode(toCatch.msg);
303 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
304 xercesc::XMLString::release(&message);
317 G4cout <<
"G4GDML: Writing '" << fname <<
"' done !" <<
G4endl;
322 G4cout <<
"G4GDML: Writing module '" << fname <<
"' done !" <<
G4endl;
333 G4cout <<
"G4GDML: Adding module '" << fname <<
"'..." <<
G4endl;
335 if(physvol ==
nullptr)
338 "Invalid NULL pointer is specified for modularization!");
344 "It is not possible to modularize by divisionvol!");
350 "It is not possible to modularize by parameterised volume!");
356 "It is not possible to modularize by replicated volume!");
369 "Depth must be a positive number!");
374 "Adding module(s) at this depth is already requested!");
390 std::stringstream stream;
391 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
G4PVDivision(const G4String &pName, G4LogicalVolume *pLogical, G4LogicalVolume *pMother, const EAxis pAxis, const G4int nReplicas, const G4double width, const G4double offset)
G4PVDivision represents many touchable detector elements differing only in their positioning....
G4TemplateRNGHelper< G4long > * G4TemplateRNGHelper< G4long >::instance
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()
G4LogicalVolume represents a leaf node or unpositioned subtree in the geometry hierarchy....
G4VPhysicalVolume is an abstract base class for the representation of a positioned volume....
virtual G4bool IsReplicated() const =0
const G4String & GetName() const
virtual G4bool IsParameterised() const =0
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.