37 #include <Geant4/G4LogicalVolume.hh>
38 #include <Geant4/G4PVDivision.hh>
39 #include <Geant4/G4Transform3D.hh>
57 return (stat(fname.c_str(),&FileInfo) == 0);
91 xercesc::DOMElement* element)
93 for(std::vector<PHG4GDMLAuxStructType>::const_iterator
94 iaux = auxInfoList->begin(); iaux != auxInfoList->end(); ++iaux )
96 xercesc::DOMElement* auxiliaryElement =
NewElement(
"auxiliary");
97 element->appendChild(auxiliaryElement);
99 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxtype", (*iaux).type));
100 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxvalue", (*iaux).value));
101 if (((*iaux).unit)!=
"")
103 auxiliaryElement->setAttributeNode(
NewAttribute(
"auxunit", (*iaux).unit));
106 if (iaux->auxList) {
AddAuxInfo(iaux->auxList, auxiliaryElement); }
115 std::cout <<
"PHG4GDML: Writing userinfo..." << std::endl;
126 std::stringstream stream; stream <<
name;
131 nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),
' '),nameOut.end());
139 xercesc::XMLString::transcode(name,
tempStr,9999);
140 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
141 xercesc::XMLString::transcode(value,
tempStr,9999);
149 xercesc::XMLString::transcode(name,
tempStr,9999);
150 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
151 std::ostringstream ostream;
152 ostream.precision(15);
155 xercesc::XMLString::transcode(str,
tempStr,9999);
162 xercesc::XMLString::transcode(name,
tempStr,9999);
175 if (depth==0) { std::cout <<
"PHG4GDML: Writing '" << fname <<
"'..." << std::endl; }
176 else { std::cout <<
"PHG4GDML: Writing module '" << fname <<
"'..." << std::endl; }
180 G4String ErrorMessage =
"File '"+fname+
"' already exists!";
181 G4Exception(
"PHG4GDMLWrite::Write()",
"InvalidSetup",
188 xercesc::XMLString::transcode(
"LS",
tempStr, 9999);
189 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
190 xercesc::XMLString::transcode(
"Range",
tempStr, 9999);
191 xercesc::DOMImplementation* impl =
192 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
193 xercesc::XMLString::transcode(
"gdml",
tempStr, 9999);
195 xercesc::DOMElement* gdml =
doc->getDocumentElement();
197 #if XERCES_VERSION_MAJOR >= 3
199 xercesc::DOMLSSerializer* writer =
200 ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
202 xercesc::DOMConfiguration *dc = writer->getDomConfig();
203 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
207 xercesc::DOMWriter* writer =
208 ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
210 if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
211 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
216 "http://www.w3.org/2001/XMLSchema-instance"));
217 gdml->setAttributeNode(
NewAttribute(
"xsi:noNamespaceSchemaLocation",
231 xercesc::XMLFormatTarget *myFormTarget =
232 new xercesc::LocalFileFormatTarget(fname.c_str());
236 #if XERCES_VERSION_MAJOR >= 3
238 xercesc::DOMLSOutput *theOutput =
239 ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
240 theOutput->setByteStream(myFormTarget);
241 writer->write(
doc, theOutput);
243 writer->writeNode(myFormTarget, *
doc);
246 catch (
const xercesc::XMLException& toCatch)
248 char*
message = xercesc::XMLString::transcode(toCatch.getMessage());
249 std::cout <<
"PHG4GDML: Exception message is: " << message << std::endl;
250 xercesc::XMLString::release(&message);
253 catch (
const xercesc::DOMException& toCatch)
255 char*
message = xercesc::XMLString::transcode(toCatch.msg);
256 std::cout <<
"PHG4GDML: Exception message is: " << message << std::endl;
257 xercesc::XMLString::release(&message);
262 std::cout <<
"PHG4GDML: Unexpected Exception!" << std::endl;
271 std::cout <<
"PHG4GDML: Writing '" << fname <<
"' done !" << std::endl;
275 std::cout <<
"PHG4GDML: Writing module '" << fname <<
"' done !" << std::endl;
286 "Invalid NULL pointer is specified for modularization!");
290 std::cout <<
"PHG4GDML: Adding module '" << fname <<
"'..." << std::endl;
292 if (dynamic_cast<const G4PVDivision*>(physvol))
295 "It is not possible to modularize by divisionvol!");
301 "It is not possible to modularize by parameterised volume!");
307 "It is not possible to modularize by replicated volume!");
319 "Depth must be a positive number!");
324 "Adding module(s) at this depth is already requested!");
339 std::stringstream stream;
340 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";