57 return (stat(fname.c_str(),&FileInfo) == 0);
62 static VolumeMapType instance;
68 static PhysVolumeMapType instance;
74 static DepthMapType instance;
93 std::stringstream stream; stream <<
name;
98 nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),
' '),nameOut.end());
106 xercesc::XMLString::transcode(name,
tempStr,99);
107 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
108 xercesc::XMLString::transcode(value,
tempStr,99);
116 xercesc::XMLString::transcode(name,
tempStr,99);
117 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
118 std::ostringstream ostream;
119 ostream.precision(15);
122 xercesc::XMLString::transcode(str,
tempStr,99);
129 xercesc::XMLString::transcode(name,
tempStr,99);
142 if (depth==0) {
G4cout <<
"G4GDML: Writing '" << fname <<
"'..." <<
G4endl; }
143 else {
G4cout <<
"G4GDML: Writing module '" << fname <<
"'..." <<
G4endl; }
147 G4String ErrorMessage =
"File '"+fname+
"' already exists!";
148 G4Exception(
"G4GDMLWrite::Write()",
"InvalidSetup",
155 xercesc::XMLString::transcode(
"LS",
tempStr, 99);
156 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
157 xercesc::XMLString::transcode(
"Range",
tempStr, 99);
158 xercesc::DOMImplementation* impl =
159 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
160 xercesc::XMLString::transcode(
"gdml",
tempStr, 99);
162 xercesc::DOMElement* gdml =
doc->getDocumentElement();
164 #if XERCES_VERSION_MAJOR >= 3
166 xercesc::DOMLSSerializer* writer =
167 ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
169 xercesc::DOMConfiguration *dc = writer->getDomConfig();
170 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
174 xercesc::DOMWriter* writer =
175 ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
177 if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
178 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
183 "http://www.w3.org/2001/XMLSchema-instance"));
184 gdml->setAttributeNode(
NewAttribute(
"xsi:noNamespaceSchemaLocation",
197 xercesc::XMLFormatTarget *myFormTarget =
198 new xercesc::LocalFileFormatTarget(fname.c_str());
202 #if XERCES_VERSION_MAJOR >= 3
204 xercesc::DOMLSOutput *theOutput =
205 ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
206 theOutput->setByteStream(myFormTarget);
207 writer->write(
doc, theOutput);
209 writer->writeNode(myFormTarget, *
doc);
212 catch (
const xercesc::XMLException& toCatch)
214 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
215 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
216 xercesc::XMLString::release(&message);
219 catch (
const xercesc::DOMException& toCatch)
221 char* message = xercesc::XMLString::transcode(toCatch.msg);
222 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
223 xercesc::XMLString::release(&message);
237 G4cout <<
"G4GDML: Writing '" << fname <<
"' done !" <<
G4endl;
241 G4cout <<
"G4GDML: Writing module '" << fname <<
"' done !" <<
G4endl;
250 G4cout <<
"G4GDML: Adding module '" << fname <<
"'..." <<
G4endl;
255 "Invalid NULL pointer is specified for modularization!");
258 if (dynamic_cast<const G4PVDivision*>(physvol))
261 "It is not possible to modularize by divisionvol!");
267 "It is not possible to modularize by parameterised volume!");
273 "It is not possible to modularize by replicated volume!");
285 "Depth must be a positive number!");
290 "Adding module(s) at this depth is already requested!");
305 std::stringstream stream;
306 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";