Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GDMLWrite Class Referenceabstract

#include <G4GDMLWrite.hh>

+ Inheritance diagram for G4GDMLWrite:

Public Member Functions

G4Transform3D Write (const G4String &filename, const G4LogicalVolume *const topLog, const G4String &schemaPath, const G4int depth, G4bool storeReferences=true)
 
void AddModule (const G4VPhysicalVolume *const topVol)
 
void AddModule (const G4int depth)
 
void AddAuxiliary (G4GDMLAuxStructType myaux)
 
void SetOutputFileOverwrite (G4bool flag)
 
virtual void DefineWrite (xercesc::DOMElement *)=0
 
virtual void MaterialsWrite (xercesc::DOMElement *)=0
 
virtual void SolidsWrite (xercesc::DOMElement *)=0
 
virtual void StructureWrite (xercesc::DOMElement *)=0
 
virtual G4Transform3D TraverseVolumeTree (const G4LogicalVolume *const, const G4int)=0
 
virtual void SurfacesWrite ()=0
 
virtual void SetupWrite (xercesc::DOMElement *, const G4LogicalVolume *const)=0
 
virtual void ExtensionWrite (xercesc::DOMElement *)
 
virtual void UserinfoWrite (xercesc::DOMElement *)
 
virtual void AddExtension (xercesc::DOMElement *, const G4LogicalVolume *const)
 
G4String GenerateName (const G4String &, const void *const)
 

Static Public Member Functions

static void SetAddPointerToName (G4bool)
 

Protected Member Functions

 G4GDMLWrite ()
 
virtual ~G4GDMLWrite ()
 
VolumeMapType & VolumeMap ()
 
xercesc::DOMAttr * NewAttribute (const G4String &, const G4String &)
 
xercesc::DOMAttr * NewAttribute (const G4String &, const G4double &)
 
xercesc::DOMElement * NewElement (const G4String &)
 
G4String Modularize (const G4VPhysicalVolume *const topvol, const G4int depth)
 
void AddAuxInfo (G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
 
G4bool FileExists (const G4String &) const
 
PhysVolumeMapType & PvolumeMap ()
 
DepthMapType & DepthMap ()
 

Protected Attributes

G4String SchemaLocation
 
xercesc::DOMDocument * doc = nullptr
 
xercesc::DOMElement * extElement = nullptr
 
xercesc::DOMElement * userinfoElement = nullptr
 
XMLCh tempStr [10000]
 
G4GDMLAuxListType auxList
 
G4bool overwriteOutputFile = false
 

Static Protected Attributes

static G4bool addPointerToName = true
 

Detailed Description

Definition at line 51 of file G4GDMLWrite.hh.

Constructor & Destructor Documentation

◆ G4GDMLWrite()

G4GDMLWrite::G4GDMLWrite ( )
protected

Definition at line 43 of file G4GDMLWrite.cc.

44{
45}

◆ ~G4GDMLWrite()

G4GDMLWrite::~G4GDMLWrite ( )
protectedvirtual

Definition at line 48 of file G4GDMLWrite.cc.

49{
50}

Member Function Documentation

◆ AddAuxiliary()

void G4GDMLWrite::AddAuxiliary ( G4GDMLAuxStructType  myaux)

Definition at line 379 of file G4GDMLWrite.cc.

380{
381 auxList.push_back(myaux);
382}
G4GDMLAuxListType auxList
Definition: G4GDMLWrite.hh:136

◆ AddAuxInfo()

void G4GDMLWrite::AddAuxInfo ( G4GDMLAuxListType auxInfoList,
xercesc::DOMElement *  element 
)
protected

Definition at line 94 of file G4GDMLWrite.cc.

96{
97 for(auto iaux = auxInfoList->cbegin(); iaux != auxInfoList->cend(); ++iaux)
98 {
99 xercesc::DOMElement* auxiliaryElement = NewElement("auxiliary");
100 element->appendChild(auxiliaryElement);
101
102 auxiliaryElement->setAttributeNode(NewAttribute("auxtype", (*iaux).type));
103 auxiliaryElement->setAttributeNode(NewAttribute("auxvalue", (*iaux).value));
104 if(((*iaux).unit) != "")
105 {
106 auxiliaryElement->setAttributeNode(NewAttribute("auxunit", (*iaux).unit));
107 }
108
109 if(iaux->auxList)
110 {
111 AddAuxInfo(iaux->auxList, auxiliaryElement);
112 }
113 }
114 return;
115}
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:181
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:155
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
Definition: G4GDMLWrite.cc:94

Referenced by AddAuxInfo(), G4GDMLWriteStructure::TraverseVolumeTree(), and UserinfoWrite().

◆ AddExtension()

void G4GDMLWrite::AddExtension ( xercesc::DOMElement *  ,
const G4LogicalVolume * const   
)
virtual

Definition at line 80 of file G4GDMLWrite.cc.

82{
83 // Empty implementation. To be overwritten by user for specific extensions
84 // related to attributes associated to volumes
85}

Referenced by G4GDMLWriteStructure::TraverseVolumeTree().

◆ AddModule() [1/2]

void G4GDMLWrite::AddModule ( const G4int  depth)

Definition at line 342 of file G4GDMLWrite.cc.

343{
344 if(depth < 0)
345 {
346 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
347 "Depth must be a positive number!");
348 }
349 if(DepthMap().find(depth) != DepthMap().end())
350 {
351 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
352 "Adding module(s) at this depth is already requested!");
353 }
354 DepthMap()[depth] = 0;
355}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
DepthMapType & DepthMap()
Definition: G4GDMLWrite.cc:73

◆ AddModule() [2/2]

void G4GDMLWrite::AddModule ( const G4VPhysicalVolume *const  topVol)

Definition at line 308 of file G4GDMLWrite.cc.

309{
310 G4String fname = GenerateName(physvol->GetName(), physvol);
311 G4cout << "G4GDML: Adding module '" << fname << "'..." << G4endl;
312
313 if(physvol == nullptr)
314 {
315 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
316 "Invalid NULL pointer is specified for modularization!");
317 return;
318 }
319 if(dynamic_cast<const G4PVDivision*>(physvol))
320 {
321 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
322 "It is not possible to modularize by divisionvol!");
323 return;
324 }
325 if(physvol->IsParameterised())
326 {
327 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
328 "It is not possible to modularize by parameterised volume!");
329 return;
330 }
331 if(physvol->IsReplicated())
332 {
333 G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
334 "It is not possible to modularize by replicated volume!");
335 return;
336 }
337
338 PvolumeMap()[physvol] = fname;
339}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:132
PhysVolumeMapType & PvolumeMap()
Definition: G4GDMLWrite.cc:66

◆ DefineWrite()

virtual void G4GDMLWrite::DefineWrite ( xercesc::DOMElement *  )
pure virtual

Implemented in G4GDMLWriteDefine.

Referenced by Write().

◆ DepthMap()

G4GDMLWrite::DepthMapType & G4GDMLWrite::DepthMap ( )
protected

Definition at line 73 of file G4GDMLWrite.cc.

74{
75 static DepthMapType instance;
76 return instance;
77}

Referenced by AddModule(), and Modularize().

◆ ExtensionWrite()

void G4GDMLWrite::ExtensionWrite ( xercesc::DOMElement *  )
virtual

Definition at line 88 of file G4GDMLWrite.cc.

89{
90 // Empty implementation. To be overwritten by user for specific extensions
91}

Referenced by Write().

◆ FileExists()

G4bool G4GDMLWrite::FileExists ( const G4String fname) const
protected

Definition at line 53 of file G4GDMLWrite.cc.

54{
55 struct stat FileInfo;
56 return (stat(fname.c_str(), &FileInfo) == 0);
57}

Referenced by Write().

◆ GenerateName()

G4String G4GDMLWrite::GenerateName ( const G4String name,
const void * const  ptr 
)

Definition at line 132 of file G4GDMLWrite.cc.

133{
134 G4String nameOut;
135 std::stringstream stream;
136 stream << name;
138 {
139 stream << ptr;
140 };
141
142 nameOut = G4String(stream.str());
143 std::vector<char> toremove = { ' ', '/', ':', '#', '+' };
144 for(auto c : toremove)
145 {
146 if(nameOut.contains(c))
147 {
148 std::replace(nameOut.begin(), nameOut.end(), c, '_');
149 }
150 }
151 return nameOut;
152}
static G4bool addPointerToName
Definition: G4GDMLWrite.hh:131
G4bool contains(const std::string &) const
const char * name(G4int ptype)

Referenced by AddModule(), G4GDMLWriteStructure::AssemblyWrite(), G4GDMLWriteSolids::BooleanWrite(), G4GDMLWriteStructure::BorderSurfaceCache(), G4GDMLWriteSolids::BoxWrite(), G4GDMLWriteSolids::ConeWrite(), G4GDMLWriteSolids::CutTubeWrite(), G4GDMLWriteStructure::DivisionvolWrite(), G4GDMLWriteSolids::ElconeWrite(), G4GDMLWriteMaterials::ElementWrite(), G4GDMLWriteSolids::EllipsoidWrite(), G4GDMLWriteSolids::EltubeWrite(), G4GDMLWriteSolids::GenericPolyconeWrite(), G4GDMLWriteSolids::GenTrapWrite(), G4GDMLWriteSolids::HypeWrite(), G4GDMLWriteMaterials::IsotopeWrite(), G4GDMLWriteMaterials::MaterialWrite(), G4GDMLWriteSolids::MultiUnionWrite(), G4GDMLWriteSolids::OpticalSurfaceWrite(), G4GDMLWriteSolids::OrbWrite(), G4GDMLWriteSolids::ParaboloidWrite(), G4GDMLWriteParamvol::ParametersWrite(), G4GDMLWriteParamvol::ParamvolAlgorithmWrite(), G4GDMLWriteParamvol::ParamvolWrite(), G4GDMLWriteSolids::ParaWrite(), G4GDMLWriteStructure::PhysvolWrite(), G4GDMLWriteSolids::PolyconeWrite(), G4GDMLWriteSolids::PolyhedraWrite(), G4GDMLWriteMaterials::PropertyConstWrite(), G4GDMLWriteMaterials::PropertyVectorWrite(), G4GDMLWriteMaterials::PropertyWrite(), G4GDMLWriteSolids::PropertyWrite(), G4GDMLWriteStructure::ReplicavolWrite(), G4GDMLWriteSolids::ScaledWrite(), G4GDMLWriteSetup::SetupWrite(), G4GDMLWriteStructure::SkinSurfaceCache(), G4GDMLWriteSolids::SphereWrite(), G4GDMLWriteSolids::TessellatedWrite(), G4GDMLWriteSolids::TetWrite(), G4GDMLWriteSolids::TorusWrite(), G4GDMLWriteSolids::TrapWrite(), G4GDMLWriteStructure::TraverseVolumeTree(), G4GDMLWriteSolids::TrdWrite(), G4GDMLWriteSolids::TubeWrite(), G4GDMLWriteSolids::TwistedboxWrite(), G4GDMLWriteSolids::TwistedtrapWrite(), G4GDMLWriteSolids::TwistedtrdWrite(), G4GDMLWriteSolids::TwistedtubsWrite(), and G4GDMLWriteSolids::XtruWrite().

◆ MaterialsWrite()

virtual void G4GDMLWrite::MaterialsWrite ( xercesc::DOMElement *  )
pure virtual

Implemented in G4GDMLWriteMaterials.

Referenced by Write().

◆ Modularize()

G4String G4GDMLWrite::Modularize ( const G4VPhysicalVolume *const  topvol,
const G4int  depth 
)
protected

Definition at line 358 of file G4GDMLWrite.cc.

360{
361 if(PvolumeMap().find(physvol) != PvolumeMap().cend())
362 {
363 return PvolumeMap()[physvol]; // Modularize via physvol
364 }
365
366 if(DepthMap().find(depth) != DepthMap().cend()) // Modularize via depth
367 {
368 std::stringstream stream;
369 stream << "depth" << depth << "_module" << DepthMap()[depth] << ".gdml";
370 DepthMap()[depth]++; // There can be more modules at this depth!
371 return G4String(stream.str());
372 }
373
374 return G4String(""); // Empty string for module name = no modularization
375 // was requested at that level/physvol!
376}

Referenced by G4GDMLWriteStructure::TraverseVolumeTree().

◆ NewAttribute() [1/2]

xercesc::DOMAttr * G4GDMLWrite::NewAttribute ( const G4String name,
const G4double value 
)
protected

Definition at line 166 of file G4GDMLWrite.cc.

168{
169 xercesc::XMLString::transcode(name, tempStr, 9999);
170 xercesc::DOMAttr* att = doc->createAttribute(tempStr);
171 std::ostringstream ostream;
172 ostream.precision(15);
173 ostream << value;
174 G4String str = ostream.str();
175 xercesc::XMLString::transcode(str, tempStr, 9999);
176 att->setValue(tempStr);
177 return att;
178}
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:132
XMLCh tempStr[10000]
Definition: G4GDMLWrite.hh:135

◆ NewAttribute() [2/2]

xercesc::DOMAttr * G4GDMLWrite::NewAttribute ( const G4String name,
const G4String value 
)
protected

Definition at line 155 of file G4GDMLWrite.cc.

157{
158 xercesc::XMLString::transcode(name, tempStr, 9999);
159 xercesc::DOMAttr* att = doc->createAttribute(tempStr);
160 xercesc::XMLString::transcode(value, tempStr, 9999);
161 att->setValue(tempStr);
162 return att;
163}

Referenced by AddAuxInfo(), G4GDMLWriteStructure::AssemblyWrite(), G4GDMLWriteMaterials::AtomWrite(), G4GDMLWriteSolids::BooleanWrite(), G4GDMLWriteStructure::BorderSurfaceCache(), G4GDMLWriteParamvol::Box_dimensionsWrite(), G4GDMLWriteSolids::BoxWrite(), G4GDMLWriteParamvol::Cone_dimensionsWrite(), G4GDMLWriteSolids::ConeWrite(), G4GDMLWriteSolids::CutTubeWrite(), G4GDMLWriteStructure::DivisionvolWrite(), G4GDMLWriteMaterials::DWrite(), G4GDMLWriteSolids::ElconeWrite(), G4GDMLWriteMaterials::ElementWrite(), G4GDMLWriteParamvol::Ellipsoid_dimensionsWrite(), G4GDMLWriteSolids::EllipsoidWrite(), G4GDMLWriteSolids::EltubeWrite(), G4GDMLWriteSolids::GenericPolyconeWrite(), G4GDMLWriteSolids::GenTrapWrite(), G4GDMLWriteParamvol::Hype_dimensionsWrite(), G4GDMLWriteSolids::HypeWrite(), G4GDMLWriteMaterials::IsotopeWrite(), G4GDMLWriteMaterials::MaterialWrite(), G4GDMLWriteMaterials::MEEWrite(), G4GDMLWriteSolids::MultiUnionWrite(), G4GDMLWriteSolids::OpticalSurfaceWrite(), G4GDMLWriteParamvol::Orb_dimensionsWrite(), G4GDMLWriteSolids::OrbWrite(), G4GDMLWriteParamvol::Para_dimensionsWrite(), G4GDMLWriteSolids::ParaboloidWrite(), G4GDMLWriteParamvol::ParametersWrite(), G4GDMLWriteParamvol::ParamvolWrite(), G4GDMLWriteSolids::ParaWrite(), G4GDMLWriteStructure::PhysvolWrite(), G4GDMLWriteParamvol::Polycone_dimensionsWrite(), G4GDMLWriteSolids::PolyconeWrite(), G4GDMLWriteParamvol::Polyhedra_dimensionsWrite(), G4GDMLWriteSolids::PolyhedraWrite(), G4GDMLWriteDefine::Position_vectorWrite(), G4GDMLWriteMaterials::PropertyConstWrite(), G4GDMLWriteMaterials::PropertyVectorWrite(), G4GDMLWriteMaterials::PropertyWrite(), G4GDMLWriteSolids::PropertyWrite(), G4GDMLWriteMaterials::PWrite(), G4GDMLWriteStructure::ReplicavolWrite(), G4GDMLWriteDefine::Rotation_vectorWrite(), G4GDMLWriteSolids::RZPointWrite(), G4GDMLWriteDefine::Scale_vectorWrite(), G4GDMLWriteSolids::ScaledWrite(), G4GDMLWriteSetup::SetupWrite(), G4GDMLWriteStructure::SkinSurfaceCache(), G4GDMLWriteParamvol::Sphere_dimensionsWrite(), G4GDMLWriteSolids::SphereWrite(), G4GDMLWriteSolids::TessellatedWrite(), G4GDMLWriteSolids::TetWrite(), G4GDMLWriteParamvol::Torus_dimensionsWrite(), G4GDMLWriteSolids::TorusWrite(), G4GDMLWriteParamvol::Trap_dimensionsWrite(), G4GDMLWriteSolids::TrapWrite(), G4GDMLWriteStructure::TraverseVolumeTree(), G4GDMLWriteParamvol::Trd_dimensionsWrite(), G4GDMLWriteSolids::TrdWrite(), G4GDMLWriteParamvol::Tube_dimensionsWrite(), G4GDMLWriteSolids::TubeWrite(), G4GDMLWriteSolids::TwistedboxWrite(), G4GDMLWriteSolids::TwistedtrapWrite(), G4GDMLWriteSolids::TwistedtrdWrite(), G4GDMLWriteSolids::TwistedtubsWrite(), G4GDMLWriteMaterials::TWrite(), Write(), G4GDMLWriteSolids::XtruWrite(), and G4GDMLWriteSolids::ZplaneWrite().

◆ NewElement()

xercesc::DOMElement * G4GDMLWrite::NewElement ( const G4String name)
protected

Definition at line 181 of file G4GDMLWrite.cc.

182{
183 xercesc::XMLString::transcode(name, tempStr, 9999);
184 return doc->createElement(tempStr);
185}

Referenced by AddAuxInfo(), G4GDMLWriteStructure::AssemblyWrite(), G4GDMLWriteMaterials::AtomWrite(), G4GDMLWriteSolids::BooleanWrite(), G4GDMLWriteStructure::BorderSurfaceCache(), G4GDMLWriteParamvol::Box_dimensionsWrite(), G4GDMLWriteSolids::BoxWrite(), G4GDMLWriteParamvol::Cone_dimensionsWrite(), G4GDMLWriteSolids::ConeWrite(), G4GDMLWriteSolids::CutTubeWrite(), G4GDMLWriteDefine::DefineWrite(), G4GDMLWriteStructure::DivisionvolWrite(), G4GDMLWriteMaterials::DWrite(), G4GDMLWriteSolids::ElconeWrite(), G4GDMLWriteMaterials::ElementWrite(), G4GDMLWriteParamvol::Ellipsoid_dimensionsWrite(), G4GDMLWriteSolids::EllipsoidWrite(), G4GDMLWriteSolids::EltubeWrite(), G4GDMLWriteSolids::GenericPolyconeWrite(), G4GDMLWriteSolids::GenTrapWrite(), G4GDMLWriteParamvol::Hype_dimensionsWrite(), G4GDMLWriteSolids::HypeWrite(), G4GDMLWriteMaterials::IsotopeWrite(), G4GDMLWriteMaterials::MaterialsWrite(), G4GDMLWriteMaterials::MaterialWrite(), G4GDMLWriteMaterials::MEEWrite(), G4GDMLWriteSolids::MultiUnionWrite(), G4GDMLWriteSolids::OpticalSurfaceWrite(), G4GDMLWriteParamvol::Orb_dimensionsWrite(), G4GDMLWriteSolids::OrbWrite(), G4GDMLWriteParamvol::Para_dimensionsWrite(), G4GDMLWriteSolids::ParaboloidWrite(), G4GDMLWriteParamvol::ParametersWrite(), G4GDMLWriteParamvol::ParamvolWrite(), G4GDMLWriteSolids::ParaWrite(), G4GDMLWriteStructure::PhysvolWrite(), G4GDMLWriteParamvol::Polycone_dimensionsWrite(), G4GDMLWriteSolids::PolyconeWrite(), G4GDMLWriteParamvol::Polyhedra_dimensionsWrite(), G4GDMLWriteSolids::PolyhedraWrite(), G4GDMLWriteDefine::Position_vectorWrite(), G4GDMLWriteMaterials::PropertyConstWrite(), G4GDMLWriteMaterials::PropertyVectorWrite(), G4GDMLWriteMaterials::PropertyWrite(), G4GDMLWriteSolids::PropertyWrite(), G4GDMLWriteMaterials::PWrite(), G4GDMLWriteStructure::ReplicavolWrite(), G4GDMLWriteDefine::Rotation_vectorWrite(), G4GDMLWriteSolids::RZPointWrite(), G4GDMLWriteDefine::Scale_vectorWrite(), G4GDMLWriteSolids::ScaledWrite(), G4GDMLWriteSetup::SetupWrite(), G4GDMLWriteStructure::SkinSurfaceCache(), G4GDMLWriteSolids::SolidsWrite(), G4GDMLWriteParamvol::Sphere_dimensionsWrite(), G4GDMLWriteSolids::SphereWrite(), G4GDMLWriteStructure::StructureWrite(), G4GDMLWriteSolids::TessellatedWrite(), G4GDMLWriteSolids::TetWrite(), G4GDMLWriteParamvol::Torus_dimensionsWrite(), G4GDMLWriteSolids::TorusWrite(), G4GDMLWriteParamvol::Trap_dimensionsWrite(), G4GDMLWriteSolids::TrapWrite(), G4GDMLWriteStructure::TraverseVolumeTree(), G4GDMLWriteParamvol::Trd_dimensionsWrite(), G4GDMLWriteSolids::TrdWrite(), G4GDMLWriteParamvol::Tube_dimensionsWrite(), G4GDMLWriteSolids::TubeWrite(), G4GDMLWriteSolids::TwistedboxWrite(), G4GDMLWriteSolids::TwistedtrapWrite(), G4GDMLWriteSolids::TwistedtrdWrite(), G4GDMLWriteSolids::TwistedtubsWrite(), G4GDMLWriteMaterials::TWrite(), UserinfoWrite(), G4GDMLWriteSolids::XtruWrite(), and G4GDMLWriteSolids::ZplaneWrite().

◆ PvolumeMap()

G4GDMLWrite::PhysVolumeMapType & G4GDMLWrite::PvolumeMap ( )
protected

Definition at line 66 of file G4GDMLWrite.cc.

67{
68 static PhysVolumeMapType instance;
69 return instance;
70}

Referenced by AddModule(), and Modularize().

◆ SetAddPointerToName()

void G4GDMLWrite::SetAddPointerToName ( G4bool  set)
static

Definition at line 391 of file G4GDMLWrite.cc.

392{
393 addPointerToName = set;
394}

◆ SetOutputFileOverwrite()

void G4GDMLWrite::SetOutputFileOverwrite ( G4bool  flag)

Definition at line 385 of file G4GDMLWrite.cc.

386{
387 overwriteOutputFile = flag;
388}
G4bool overwriteOutputFile
Definition: G4GDMLWrite.hh:137

◆ SetupWrite()

virtual void G4GDMLWrite::SetupWrite ( xercesc::DOMElement *  ,
const G4LogicalVolume * const   
)
pure virtual

Implemented in G4GDMLWriteSetup.

Referenced by Write().

◆ SolidsWrite()

virtual void G4GDMLWrite::SolidsWrite ( xercesc::DOMElement *  )
pure virtual

Implemented in G4GDMLWriteSolids.

Referenced by Write().

◆ StructureWrite()

virtual void G4GDMLWrite::StructureWrite ( xercesc::DOMElement *  )
pure virtual

Implemented in G4GDMLWriteStructure.

Referenced by Write().

◆ SurfacesWrite()

virtual void G4GDMLWrite::SurfacesWrite ( )
pure virtual

Implemented in G4GDMLWriteStructure.

Referenced by Write().

◆ TraverseVolumeTree()

virtual G4Transform3D G4GDMLWrite::TraverseVolumeTree ( const G4LogicalVolume * const  ,
const  G4int 
)
pure virtual

Implemented in G4GDMLWriteStructure.

Referenced by Write().

◆ UserinfoWrite()

void G4GDMLWrite::UserinfoWrite ( xercesc::DOMElement *  gdmlElement)
virtual

Definition at line 118 of file G4GDMLWrite.cc.

119{
120 if(auxList.size() > 0)
121 {
122#ifdef G4VERBOSE
123 G4cout << "G4GDML: Writing userinfo..." << G4endl;
124#endif
125 userinfoElement = NewElement("userinfo");
126 gdmlElement->appendChild(userinfoElement);
128 }
129}
xercesc::DOMElement * userinfoElement
Definition: G4GDMLWrite.hh:134

Referenced by Write().

◆ VolumeMap()

G4GDMLWrite::VolumeMapType & G4GDMLWrite::VolumeMap ( )
protected

Definition at line 60 of file G4GDMLWrite.cc.

61{
62 static VolumeMapType instance;
63 return instance;
64}

Referenced by G4GDMLWriteStructure::TraverseVolumeTree(), and Write().

◆ Write()

G4Transform3D G4GDMLWrite::Write ( const G4String filename,
const G4LogicalVolume *const  topLog,
const G4String schemaPath,
const G4int  depth,
G4bool  storeReferences = true 
)

Definition at line 188 of file G4GDMLWrite.cc.

192{
193 SchemaLocation = setSchemaLocation;
194 addPointerToName = refs;
195#ifdef G4VERBOSE
196 if(depth == 0)
197 {
198 G4cout << "G4GDML: Writing '" << fname << "'..." << G4endl;
199 }
200 else
201 {
202 G4cout << "G4GDML: Writing module '" << fname << "'..." << G4endl;
203 }
204#endif
205 if(!overwriteOutputFile && FileExists(fname))
206 {
207 G4String ErrorMessage = "File '" + fname + "' already exists!";
208 G4Exception("G4GDMLWrite::Write()", "InvalidSetup", FatalException,
209 ErrorMessage);
210 }
211
212 VolumeMap().clear(); // The module map is global for all modules,
213 // so clear it only at once!
214
215 xercesc::XMLString::transcode("LS", tempStr, 9999);
216 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
217 xercesc::XMLString::transcode("Range", tempStr, 9999);
218 xercesc::DOMImplementation* impl =
219 xercesc::DOMImplementationRegistry::getDOMImplementation(tempStr);
220 xercesc::XMLString::transcode("gdml", tempStr, 9999);
221 doc = impl->createDocument(0, tempStr, 0);
222 xercesc::DOMElement* gdml = doc->getDocumentElement();
223
224#if XERCES_VERSION_MAJOR >= 3
225 // DOM L3 as per Xerces 3.0 API
226 xercesc::DOMLSSerializer* writer =
227 ((xercesc::DOMImplementationLS*) impl)->createLSSerializer();
228
229 xercesc::DOMConfiguration* dc = writer->getDomConfig();
230 dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
231
232#else
233
234 xercesc::DOMWriter* writer =
235 ((xercesc::DOMImplementationLS*) impl)->createDOMWriter();
236
237 if(writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true))
238 writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
239
240#endif
241
242 gdml->setAttributeNode(
243 NewAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"));
244 gdml->setAttributeNode(
245 NewAttribute("xsi:noNamespaceSchemaLocation", SchemaLocation));
246
247 ExtensionWrite(gdml);
248 DefineWrite(gdml);
249 MaterialsWrite(gdml);
250 SolidsWrite(gdml);
251 StructureWrite(gdml);
252 UserinfoWrite(gdml);
253 SetupWrite(gdml, logvol);
254
255 G4Transform3D R = TraverseVolumeTree(logvol, depth);
256
258 xercesc::XMLFormatTarget* myFormTarget =
259 new xercesc::LocalFileFormatTarget(fname.c_str());
260
261 try
262 {
263#if XERCES_VERSION_MAJOR >= 3
264 // DOM L3 as per Xerces 3.0 API
265 xercesc::DOMLSOutput* theOutput =
266 ((xercesc::DOMImplementationLS*) impl)->createLSOutput();
267 theOutput->setByteStream(myFormTarget);
268 writer->write(doc, theOutput);
269#else
270 writer->writeNode(myFormTarget, *doc);
271#endif
272 } catch(const xercesc::XMLException& toCatch)
273 {
274 char* message = xercesc::XMLString::transcode(toCatch.getMessage());
275 G4cout << "G4GDML: Exception message is: " << message << G4endl;
276 xercesc::XMLString::release(&message);
278 } catch(const xercesc::DOMException& toCatch)
279 {
280 char* message = xercesc::XMLString::transcode(toCatch.msg);
281 G4cout << "G4GDML: Exception message is: " << message << G4endl;
282 xercesc::XMLString::release(&message);
284 } catch(...)
285 {
286 G4cout << "G4GDML: Unexpected Exception!" << G4endl;
288 }
289
290 delete myFormTarget;
291 writer->release();
292
293 if(depth == 0)
294 {
295 G4cout << "G4GDML: Writing '" << fname << "' done !" << G4endl;
296 }
297 else
298 {
299#ifdef G4VERBOSE
300 G4cout << "G4GDML: Writing module '" << fname << "' done !" << G4endl;
301#endif
302 }
303
304 return R;
305}
virtual void SurfacesWrite()=0
virtual void MaterialsWrite(xercesc::DOMElement *)=0
G4bool FileExists(const G4String &) const
Definition: G4GDMLWrite.cc:53
G4String SchemaLocation
Definition: G4GDMLWrite.hh:130
virtual void SetupWrite(xercesc::DOMElement *, const G4LogicalVolume *const)=0
virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const, const G4int)=0
virtual void DefineWrite(xercesc::DOMElement *)=0
virtual void UserinfoWrite(xercesc::DOMElement *)
Definition: G4GDMLWrite.cc:118
virtual void ExtensionWrite(xercesc::DOMElement *)
Definition: G4GDMLWrite.cc:88
virtual void SolidsWrite(xercesc::DOMElement *)=0
VolumeMapType & VolumeMap()
Definition: G4GDMLWrite.cc:60
virtual void StructureWrite(xercesc::DOMElement *)=0
static DLL_API const Transform3D Identity
Definition: Transform3D.h:196

Referenced by G4GDMLWriteStructure::TraverseVolumeTree().

Member Data Documentation

◆ addPointerToName

G4bool G4GDMLWrite::addPointerToName = true
staticprotected

Definition at line 131 of file G4GDMLWrite.hh.

Referenced by GenerateName(), SetAddPointerToName(), and Write().

◆ auxList

G4GDMLAuxListType G4GDMLWrite::auxList
protected

Definition at line 136 of file G4GDMLWrite.hh.

Referenced by AddAuxiliary(), and UserinfoWrite().

◆ doc

xercesc::DOMDocument* G4GDMLWrite::doc = nullptr
protected

Definition at line 132 of file G4GDMLWrite.hh.

Referenced by NewAttribute(), NewElement(), and Write().

◆ extElement

xercesc::DOMElement* G4GDMLWrite::extElement = nullptr
protected

Definition at line 133 of file G4GDMLWrite.hh.

◆ overwriteOutputFile

G4bool G4GDMLWrite::overwriteOutputFile = false
protected

Definition at line 137 of file G4GDMLWrite.hh.

Referenced by SetOutputFileOverwrite(), and Write().

◆ SchemaLocation

G4String G4GDMLWrite::SchemaLocation
protected

Definition at line 130 of file G4GDMLWrite.hh.

Referenced by G4GDMLWriteStructure::TraverseVolumeTree(), and Write().

◆ tempStr

XMLCh G4GDMLWrite::tempStr[10000]
protected

Definition at line 135 of file G4GDMLWrite.hh.

Referenced by NewAttribute(), NewElement(), and Write().

◆ userinfoElement

xercesc::DOMElement* G4GDMLWrite::userinfoElement = nullptr
protected

Definition at line 134 of file G4GDMLWrite.hh.

Referenced by UserinfoWrite().


The documentation for this class was generated from the following files: