57 return (stat(fname.c_str(),&FileInfo) == 0);
91 xercesc::DOMElement* element)
93 for(std::vector<G4GDMLAuxStructType>::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); }
127 std::stringstream stream; stream <<
name;
132 nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),
' '),nameOut.end());
140 xercesc::XMLString::transcode(name,
tempStr,9999);
141 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
142 xercesc::XMLString::transcode(value,
tempStr,9999);
150 xercesc::XMLString::transcode(name,
tempStr,9999);
151 xercesc::DOMAttr* att =
doc->createAttribute(
tempStr);
152 std::ostringstream ostream;
153 ostream.precision(15);
156 xercesc::XMLString::transcode(str,
tempStr,9999);
163 xercesc::XMLString::transcode(name,
tempStr,9999);
176 if (depth==0) {
G4cout <<
"G4GDML: Writing '" << fname <<
"'..." <<
G4endl; }
177 else {
G4cout <<
"G4GDML: Writing module '" << fname <<
"'..." <<
G4endl; }
181 G4String ErrorMessage =
"File '"+fname+
"' already exists!";
182 G4Exception(
"G4GDMLWrite::Write()",
"InvalidSetup",
189 xercesc::XMLString::transcode(
"LS",
tempStr, 9999);
190 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
191 xercesc::XMLString::transcode(
"Range",
tempStr, 9999);
192 xercesc::DOMImplementation* impl =
193 xercesc::DOMImplementationRegistry::getDOMImplementation(
tempStr);
194 xercesc::XMLString::transcode(
"gdml",
tempStr, 9999);
196 xercesc::DOMElement* gdml =
doc->getDocumentElement();
198 #if XERCES_VERSION_MAJOR >= 3
200 xercesc::DOMLSSerializer* writer =
201 ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
203 xercesc::DOMConfiguration *dc = writer->getDomConfig();
204 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
208 xercesc::DOMWriter* writer =
209 ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
211 if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true))
212 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint,
true);
217 "http://www.w3.org/2001/XMLSchema-instance"));
218 gdml->setAttributeNode(
NewAttribute(
"xsi:noNamespaceSchemaLocation",
232 xercesc::XMLFormatTarget *myFormTarget =
233 new xercesc::LocalFileFormatTarget(fname.c_str());
237 #if XERCES_VERSION_MAJOR >= 3
239 xercesc::DOMLSOutput *theOutput =
240 ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
241 theOutput->setByteStream(myFormTarget);
242 writer->write(
doc, theOutput);
244 writer->writeNode(myFormTarget, *
doc);
247 catch (
const xercesc::XMLException& toCatch)
249 char*
message = xercesc::XMLString::transcode(toCatch.getMessage());
250 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
251 xercesc::XMLString::release(&message);
254 catch (
const xercesc::DOMException& toCatch)
256 char*
message = xercesc::XMLString::transcode(toCatch.msg);
257 G4cout <<
"G4GDML: Exception message is: " << message <<
G4endl;
258 xercesc::XMLString::release(&message);
272 G4cout <<
"G4GDML: Writing '" << fname <<
"' done !" <<
G4endl;
277 G4cout <<
"G4GDML: Writing module '" << fname <<
"' done !" <<
G4endl;
287 G4cout <<
"G4GDML: Adding module '" << fname <<
"'..." <<
G4endl;
292 "Invalid NULL pointer is specified for modularization!");
295 if (dynamic_cast<const G4PVDivision*>(physvol))
298 "It is not possible to modularize by divisionvol!");
304 "It is not possible to modularize by parameterised volume!");
310 "It is not possible to modularize by replicated volume!");
322 "Depth must be a positive number!");
327 "Adding module(s) at this depth is already requested!");
342 std::stringstream stream;
343 stream <<
"depth" << depth <<
"_module" <<
DepthMap()[depth] <<
".gdml";
DepthMapType & DepthMap()
G4String Modularize(const G4VPhysicalVolume *const topvol, const G4int depth)
void AddModule(const G4VPhysicalVolume *const topVol)
virtual G4bool IsParameterised() const =0
virtual void MaterialsWrite(xercesc::DOMElement *)=0
G4String GenerateName(const G4String &, const void *const)
static void SetAddPointerToName(G4bool)
virtual void SetupWrite(xercesc::DOMElement *, const G4LogicalVolume *const)=0
xercesc::DOMElement * NewElement(const G4String &)
virtual void StructureWrite(xercesc::DOMElement *)=0
void message(RunManager *runmanager)
virtual void DefineWrite(xercesc::DOMElement *)=0
virtual void ExtensionWrite(xercesc::DOMElement *)
virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const, const G4int)=0
G4bool FileExists(const G4String &) const
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
const XML_Char int const XML_Char * value
virtual void SurfacesWrite()=0
G4bool contains(const std::string &) const
std::map< G4int, G4int > DepthMapType
static G4bool addPointerToName
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
xercesc::DOMDocument * doc
std::map< const G4VPhysicalVolume *, G4String > PhysVolumeMapType
VolumeMapType & VolumeMap()
xercesc::DOMElement * userinfoElement
static MCTruthManager * instance
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
virtual void UserinfoWrite(xercesc::DOMElement *)
void AddAuxiliary(G4GDMLAuxStructType myaux)
virtual void AddExtension(xercesc::DOMElement *, const G4LogicalVolume *const)
PhysVolumeMapType & PvolumeMap()
G4GLOB_DLL std::ostream G4cout
virtual G4bool IsReplicated() const =0
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
std::map< const G4LogicalVolume *, G4Transform3D > VolumeMapType
virtual void SolidsWrite(xercesc::DOMElement *)=0
G4Transform3D Write(const G4String &filename, const G4LogicalVolume *const topLog, const G4String &schemaPath, const G4int depth, G4bool storeReferences=true)
const G4String & GetName() const
G4GDMLAuxListType auxList