56 return (stat(fname.c_str(),&FileInfo) == 0);
90 xercesc::DOMElement* element)
92 for(std::vector<G4GDMLAuxStructType>::const_iterator
93 iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
95 xercesc::DOMElement* auxiliaryElement =
NewElement(
"auxiliary");
96 element->appendChild(auxiliaryElement);
98 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxtype", (*iaux).type));
99 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxvalue", (*iaux).value));
100 if (((*iaux).unit)!=
"")
102 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxunit", (*iaux).unit));
105 if (iaux->auxList) {
AddAuxInfo(iaux->auxList, auxiliaryElement); }
126 std::stringstream stream; stream <<
name;
130 std::vector<char> toremove = {
' ',
'/',
':',
'#',
'+' };
131 for (
auto c: toremove)
135 std::replace(nameOut.begin(),nameOut.end(),
c,
'_');
144 xercesc::XMLString::transcode(name,
tempStr,9999);
145 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
146 xercesc::XMLString::transcode(value,
tempStr,9999);
154 xercesc::XMLString::transcode(name,
tempStr,9999);
155 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
156 std::ostringstream ostream;
157 ostream.precision(15);
160 xercesc::XMLString::transcode(str,
tempStr,9999);
167 xercesc::XMLString::transcode(name,
tempStr,9999);
180 if (depth==0) {
G4cout <<
"G4GDML: Writing '" << fname <<
"'..." <<
G4endl; }
181 else {
G4cout <<
"G4GDML: Writing module '" << fname <<
"'..." <<
G4endl; }
185 G4String ErrorMessage =
"File '"+fname+
"' already exists!";
186 G4Exception(
"G4GDMLWrite::Write()",
"InvalidSetup",
193 xercesc::XMLString::transcode(
"LS",
tempStr, 9999);
194 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
195 xercesc::XMLString::transcode(
"Range",
tempStr, 9999);
196 xercesc::DOMImplementation* impl =
197 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
198 xercesc::XMLString::transcode(
"gdml",
tempStr, 9999);
200 xercesc::DOMElement* gdml =
doc->getDocumentElement();
202 #if XERCES_VERSION_MAJOR >= 3
204 xercesc::DOMLSSerializer* writer =
205 ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
207 xercesc::DOMConfiguration *dc = writer->getDomConfig();
208 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
212 xercesc::DOMWriter* writer =
213 ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
215 if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
216 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
221 "http://www.w3.org/2001/XMLSchema-instance"));
222 gdml->setAttributeNode(
NewAttribute(
"xsi:noNamespaceSchemaLocation",
236 xercesc::XMLFormatTarget *myFormTarget =
237 new xercesc::LocalFileFormatTarget(fname.c_str());
241 #if XERCES_VERSION_MAJOR >= 3
243 xercesc::DOMLSOutput *theOutput =
244 ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
245 theOutput->setByteStream(myFormTarget);
246 writer->write(
doc, theOutput);
248 writer->writeNode(myFormTarget, *
doc);
251 catch (
const xercesc::XMLException& toCatch)
253 char*
message = xercesc::XMLString::transcode(toCatch.getMessage());
254 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
255 xercesc::XMLString::release(&message);
258 catch (
const xercesc::DOMException& toCatch)
260 char*
message = xercesc::XMLString::transcode(toCatch.msg);
261 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
262 xercesc::XMLString::release(&message);
276 G4cout <<
"G4GDML: Writing '" << fname <<
"' done !" <<
G4endl;
281 G4cout <<
"G4GDML: Writing module '" << fname <<
"' done !" <<
G4endl;
291 G4cout <<
"G4GDML: Adding module '" << fname <<
"'..." <<
G4endl;
296 "Invalid NULL pointer is specified for modularization!");
299 if (dynamic_cast<const G4PVDivision*>(physvol))
302 "It is not possible to modularize by divisionvol!");
308 "It is not possible to modularize by parameterised volume!");
314 "It is not possible to modularize by replicated volume!");
326 "Depth must be a positive number!");
331 "Adding module(s) at this depth is already requested!");
346 std::stringstream stream;
347 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";