Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4GDMLWrite Class Referenceabstract

#include <G4GDMLWrite.hh>

Inheritance diagram for G4GDMLWrite:
Collaboration 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)
 
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
 
xercesc::DOMElement * extElement
 
xercesc::DOMElement * userinfoElement
 
XMLCh tempStr [10000]
 
G4GDMLAuxListType auxList
 

Static Protected Attributes

static G4bool addPointerToName = true
 

Detailed Description

Definition at line 57 of file G4GDMLWrite.hh.

Constructor & Destructor Documentation

G4GDMLWrite::G4GDMLWrite ( )
protected

Definition at line 46 of file G4GDMLWrite.cc.

46  : doc(0), extElement(0)
47 {
48 }
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:133
xercesc::DOMElement * extElement
Definition: G4GDMLWrite.hh:134
G4GDMLWrite::~G4GDMLWrite ( )
protectedvirtual

Definition at line 50 of file G4GDMLWrite.cc.

51 {
52 }

Member Function Documentation

void G4GDMLWrite::AddAuxiliary ( G4GDMLAuxStructType  myaux)

Definition at line 349 of file G4GDMLWrite.cc.

350 {
351  auxList.push_back(myaux);
352 }
G4GDMLAuxListType auxList
Definition: G4GDMLWrite.hh:137
void G4GDMLWrite::AddAuxInfo ( G4GDMLAuxListType auxInfoList,
xercesc::DOMElement *  element 
)
protected

Definition at line 90 of file G4GDMLWrite.cc.

92 {
93  for(std::vector<G4GDMLAuxStructType>::const_iterator
94  iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ )
95  {
96  xercesc::DOMElement* auxiliaryElement = NewElement("auxiliary");
97  element->appendChild(auxiliaryElement);
98 
99  auxiliaryElement->setAttributeNode(NewAttribute("auxtype", (*iaux).type));
100  auxiliaryElement->setAttributeNode(NewAttribute("auxvalue", (*iaux).value));
101  if (((*iaux).unit)!="")
102  {
103  auxiliaryElement->setAttributeNode(NewAttribute("auxunit", (*iaux).unit));
104  }
105 
106  if (iaux->auxList) { AddAuxInfo(iaux->auxList, auxiliaryElement); }
107  }
108  return;
109 }
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
Definition: G4GDMLWrite.cc:90
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:160
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:136

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 78 of file G4GDMLWrite.cc.

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

Here is the caller graph for this function:

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

Definition at line 281 of file G4GDMLWrite.cc.

282 {
283  G4String fname = GenerateName(physvol->GetName(),physvol);
284  G4cout << "G4GDML: Adding module '" << fname << "'..." << G4endl;
285 
286  if (physvol == 0)
287  {
288  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
289  "Invalid NULL pointer is specified for modularization!");
290  return;
291  }
292  if (dynamic_cast<const G4PVDivision*>(physvol))
293  {
294  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
295  "It is not possible to modularize by divisionvol!");
296  return;
297  }
298  if (physvol->IsParameterised())
299  {
300  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
301  "It is not possible to modularize by parameterised volume!");
302  return;
303  }
304  if (physvol->IsReplicated())
305  {
306  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
307  "It is not possible to modularize by replicated volume!");
308  return;
309  }
310 
311  PvolumeMap()[physvol] = fname;
312 }
PhysVolumeMapType & PvolumeMap()
Definition: G4GDMLWrite.cc:66
G4GLOB_DLL std::ostream G4cout
G4String GenerateName(const G4String &, const void *const)
Definition: G4GDMLWrite.cc:123
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

void G4GDMLWrite::AddModule ( const G4int  depth)

Definition at line 314 of file G4GDMLWrite.cc.

315 {
316  if (depth<0)
317  {
318  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
319  "Depth must be a positive number!");
320  }
321  if (DepthMap().find(depth) != DepthMap().end())
322  {
323  G4Exception("G4GDMLWrite::AddModule()", "InvalidSetup", FatalException,
324  "Adding module(s) at this depth is already requested!");
325  }
326  DepthMap()[depth] = 0;
327 }
DepthMapType & DepthMap()
Definition: G4GDMLWrite.cc:72
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41

Here is the call graph for this function:

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

Implemented in G4GDMLWriteDefine.

Here is the caller graph for this function:

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

Definition at line 72 of file G4GDMLWrite.cc.

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

Here is the caller graph for this function:

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

Definition at line 85 of file G4GDMLWrite.cc.

86 {
87  // Empty implementation. To be overwritten by user for specific extensions
88 }

Here is the caller graph for this function:

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

Definition at line 54 of file G4GDMLWrite.cc.

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

Here is the caller graph for this function:

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

Definition at line 123 of file G4GDMLWrite.cc.

124 {
125  G4String nameOut;
126  std::stringstream stream; stream << name;
127  if (addPointerToName) { stream << ptr; };
128 
129  nameOut=G4String(stream.str());
130  if(nameOut.contains(' '))
131  nameOut.erase(std::remove(nameOut.begin(),nameOut.end(),' '),nameOut.end());
132 
133  return nameOut;
134 }
const XML_Char * name
Definition: expat.h:151
static G4bool addPointerToName
Definition: G4GDMLWrite.hh:132
G4bool contains(const std::string &) const

Here is the call graph for this function:

Here is the caller graph for this function:

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

Implemented in G4GDMLWriteMaterials.

Here is the caller graph for this function:

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

Definition at line 329 of file G4GDMLWrite.cc.

331 {
332  if (PvolumeMap().find(physvol) != PvolumeMap().end())
333  {
334  return PvolumeMap()[physvol]; // Modularize via physvol
335  }
336 
337  if (DepthMap().find(depth) != DepthMap().end()) // Modularize via depth
338  {
339  std::stringstream stream;
340  stream << "depth" << depth << "_module" << DepthMap()[depth] << ".gdml";
341  DepthMap()[depth]++; // There can be more modules at this depth!
342  return G4String(stream.str());
343  }
344 
345  return G4String(""); // Empty string for module name = no modularization
346  // was requested at that level/physvol!
347 }
PhysVolumeMapType & PvolumeMap()
Definition: G4GDMLWrite.cc:66
DepthMapType & DepthMap()
Definition: G4GDMLWrite.cc:72

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 136 of file G4GDMLWrite.cc.

138 {
139  xercesc::XMLString::transcode(name,tempStr,9999);
140  xercesc::DOMAttr* att = doc->createAttribute(tempStr);
141  xercesc::XMLString::transcode(value,tempStr,9999);
142  att->setValue(tempStr);
143  return att;
144 }
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:133
XMLCh tempStr[10000]
Definition: G4GDMLWrite.hh:136
xercesc::DOMAttr * G4GDMLWrite::NewAttribute ( const G4String name,
const G4double value 
)
protected

Definition at line 146 of file G4GDMLWrite.cc.

148 {
149  xercesc::XMLString::transcode(name,tempStr,9999);
150  xercesc::DOMAttr* att = doc->createAttribute(tempStr);
151  std::ostringstream ostream;
152  ostream.precision(15);
153  ostream << value;
154  G4String str = ostream.str();
155  xercesc::XMLString::transcode(str,tempStr,9999);
156  att->setValue(tempStr);
157  return att;
158 }
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:133
const XML_Char int const XML_Char * value
Definition: expat.h:331
XMLCh tempStr[10000]
Definition: G4GDMLWrite.hh:136
xercesc::DOMElement * G4GDMLWrite::NewElement ( const G4String name)
protected

Definition at line 160 of file G4GDMLWrite.cc.

161 {
162  xercesc::XMLString::transcode(name,tempStr,9999);
163  return doc->createElement(tempStr);
164 }
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:133
XMLCh tempStr[10000]
Definition: G4GDMLWrite.hh:136
G4GDMLWrite::PhysVolumeMapType & G4GDMLWrite::PvolumeMap ( )
protected

Definition at line 66 of file G4GDMLWrite.cc.

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

Here is the caller graph for this function:

void G4GDMLWrite::SetAddPointerToName ( G4bool  set)
static

Definition at line 354 of file G4GDMLWrite.cc.

355 {
356  addPointerToName = set;
357 }
static G4bool addPointerToName
Definition: G4GDMLWrite.hh:132
virtual void G4GDMLWrite::SetupWrite ( xercesc::DOMElement *  ,
const G4LogicalVolume const 
)
pure virtual

Implemented in G4GDMLWriteSetup.

Here is the caller graph for this function:

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

Implemented in G4GDMLWriteSolids.

Here is the caller graph for this function:

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

Implemented in G4GDMLWriteStructure.

Here is the caller graph for this function:

virtual void G4GDMLWrite::SurfacesWrite ( )
pure virtual

Implemented in G4GDMLWriteStructure.

Here is the caller graph for this function:

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

Implemented in G4GDMLWriteStructure.

Here is the caller graph for this function:

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

Definition at line 111 of file G4GDMLWrite.cc.

112 {
113  if(auxList.size()>0)
114  {
115  G4cout << "G4GDML: Writing userinfo..." << G4endl;
116 
117  userinfoElement = NewElement("userinfo");
118  gdmlElement->appendChild(userinfoElement);
120  }
121 }
void AddAuxInfo(G4GDMLAuxListType *auxInfoList, xercesc::DOMElement *element)
Definition: G4GDMLWrite.cc:90
xercesc::DOMElement * NewElement(const G4String &)
Definition: G4GDMLWrite.cc:160
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
G4GDMLAuxListType auxList
Definition: G4GDMLWrite.hh:137
xercesc::DOMElement * userinfoElement
Definition: G4GDMLWrite.hh:135

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 60 of file G4GDMLWrite.cc.

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

Here is the caller graph for this function:

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

Definition at line 166 of file G4GDMLWrite.cc.

171 {
172  SchemaLocation = setSchemaLocation;
173  addPointerToName = refs;
174 
175  if (depth==0) { G4cout << "G4GDML: Writing '" << fname << "'..." << G4endl; }
176  else { G4cout << "G4GDML: Writing module '" << fname << "'..." << G4endl; }
177 
178  if (FileExists(fname))
179  {
180  G4String ErrorMessage = "File '"+fname+"' already exists!";
181  G4Exception("G4GDMLWrite::Write()", "InvalidSetup",
182  FatalException, ErrorMessage);
183  }
184 
185  VolumeMap().clear(); // The module map is global for all modules,
186  // so clear it only at once!
187 
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);
194  doc = impl->createDocument(0,tempStr,0);
195  xercesc::DOMElement* gdml = doc->getDocumentElement();
196 
197 #if XERCES_VERSION_MAJOR >= 3
198  // DOM L3 as per Xerces 3.0 API
199  xercesc::DOMLSSerializer* writer =
200  ((xercesc::DOMImplementationLS*)impl)->createLSSerializer();
201 
202  xercesc::DOMConfiguration *dc = writer->getDomConfig();
203  dc->setParameter(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
204 
205 #else
206 
207  xercesc::DOMWriter* writer =
208  ((xercesc::DOMImplementationLS*)impl)->createDOMWriter();
209 
210  if (writer->canSetFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true))
211  writer->setFeature(xercesc::XMLUni::fgDOMWRTFormatPrettyPrint, true);
212 
213 #endif
214 
215  gdml->setAttributeNode(NewAttribute("xmlns:xsi",
216  "http://www.w3.org/2001/XMLSchema-instance"));
217  gdml->setAttributeNode(NewAttribute("xsi:noNamespaceSchemaLocation",
218  SchemaLocation));
219 
220  ExtensionWrite(gdml);
221  DefineWrite(gdml);
222  MaterialsWrite(gdml);
223  SolidsWrite(gdml);
224  StructureWrite(gdml);
225  UserinfoWrite(gdml);
226  SetupWrite(gdml,logvol);
227 
228  G4Transform3D R = TraverseVolumeTree(logvol,depth);
229 
230  SurfacesWrite();
231  xercesc::XMLFormatTarget *myFormTarget =
232  new xercesc::LocalFileFormatTarget(fname.c_str());
233 
234  try
235  {
236 #if XERCES_VERSION_MAJOR >= 3
237  // DOM L3 as per Xerces 3.0 API
238  xercesc::DOMLSOutput *theOutput =
239  ((xercesc::DOMImplementationLS*)impl)->createLSOutput();
240  theOutput->setByteStream(myFormTarget);
241  writer->write(doc, theOutput);
242 #else
243  writer->writeNode(myFormTarget, *doc);
244 #endif
245  }
246  catch (const xercesc::XMLException& toCatch)
247  {
248  char* message = xercesc::XMLString::transcode(toCatch.getMessage());
249  G4cout << "G4GDML: Exception message is: " << message << G4endl;
250  xercesc::XMLString::release(&message);
252  }
253  catch (const xercesc::DOMException& toCatch)
254  {
255  char* message = xercesc::XMLString::transcode(toCatch.msg);
256  G4cout << "G4GDML: Exception message is: " << message << G4endl;
257  xercesc::XMLString::release(&message);
259  }
260  catch (...)
261  {
262  G4cout << "G4GDML: Unexpected Exception!" << G4endl;
264  }
265 
266  delete myFormTarget;
267  writer->release();
268 
269  if (depth==0)
270  {
271  G4cout << "G4GDML: Writing '" << fname << "' done !" << G4endl;
272  }
273  else
274  {
275  G4cout << "G4GDML: Writing module '" << fname << "' done !" << G4endl;
276  }
277 
278  return R;
279 }
virtual void ExtensionWrite(xercesc::DOMElement *)
Definition: G4GDMLWrite.cc:85
xercesc::DOMDocument * doc
Definition: G4GDMLWrite.hh:133
G4String SchemaLocation
Definition: G4GDMLWrite.hh:131
G4bool FileExists(const G4String &) const
Definition: G4GDMLWrite.cc:54
virtual void SetupWrite(xercesc::DOMElement *, const G4LogicalVolume *const)=0
G4GLOB_DLL std::ostream G4cout
virtual void StructureWrite(xercesc::DOMElement *)=0
virtual void DefineWrite(xercesc::DOMElement *)=0
virtual void MaterialsWrite(xercesc::DOMElement *)=0
static G4bool addPointerToName
Definition: G4GDMLWrite.hh:132
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
xercesc::DOMAttr * NewAttribute(const G4String &, const G4String &)
Definition: G4GDMLWrite.cc:136
virtual G4Transform3D TraverseVolumeTree(const G4LogicalVolume *const, const G4int)=0
virtual void UserinfoWrite(xercesc::DOMElement *)
Definition: G4GDMLWrite.cc:111
virtual void SolidsWrite(xercesc::DOMElement *)=0
#define G4endl
Definition: G4ios.hh:61
virtual void SurfacesWrite()=0
XMLCh tempStr[10000]
Definition: G4GDMLWrite.hh:136
VolumeMapType & VolumeMap()
Definition: G4GDMLWrite.cc:60
static const Transform3D Identity
Definition: Transform3D.h:197

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

G4bool G4GDMLWrite::addPointerToName = true
staticprotected

Definition at line 132 of file G4GDMLWrite.hh.

G4GDMLAuxListType G4GDMLWrite::auxList
protected

Definition at line 137 of file G4GDMLWrite.hh.

xercesc::DOMDocument* G4GDMLWrite::doc
protected

Definition at line 133 of file G4GDMLWrite.hh.

xercesc::DOMElement* G4GDMLWrite::extElement
protected

Definition at line 134 of file G4GDMLWrite.hh.

G4String G4GDMLWrite::SchemaLocation
protected

Definition at line 131 of file G4GDMLWrite.hh.

XMLCh G4GDMLWrite::tempStr[10000]
protected

Definition at line 136 of file G4GDMLWrite.hh.

xercesc::DOMElement* G4GDMLWrite::userinfoElement
protected

Definition at line 135 of file G4GDMLWrite.hh.


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