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";
virtual void ExtensionWrite(xercesc::DOMElement *)
xercesc::DOMDocument * doc
virtual G4bool IsReplicated() const =0
G4bool FileExists(const G4String &) const
PhysVolumeMapType & PvolumeMap()
xercesc::DOMElement * NewElement(const G4String &)
DepthMapType & DepthMap()
G4String Modularize(const G4VPhysicalVolume *const topvol, const G4int depth)
G4Transform3D Write(const G4String &filename, const G4LogicalVolume *const topLog, const G4String &schemaPath, const G4int depth, G4bool storeReferences=true)
virtual void SetupWrite(xercesc::DOMElement *, const G4LogicalVolume *const)=0
G4GLOB_DLL std::ostream G4cout
virtual void StructureWrite(xercesc::DOMElement *)=0
const G4String & GetName() const
virtual void DefineWrite(xercesc::DOMElement *)=0
virtual void MaterialsWrite(xercesc::DOMElement *)=0
G4String GenerateName(const G4String &, const void *const)
static void SetAddPointerToName(G4bool)
static G4bool addPointerToName
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
virtual G4bool IsParameterised() const =0
G4bool contains(const std::string &) const
void AddModule(const G4VPhysicalVolume *const topVol)
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const, const G4int)=0
virtual void SolidsWrite(xercesc::DOMElement *)=0
virtual void AddExtension(xercesc::DOMElement *, const G4LogicalVolume *const)
const XML_Char int const XML_Char * value
virtual void SurfacesWrite()=0
VolumeMapType & VolumeMap()