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

#include <G4GDMLRead.hh>

Inheritance diagram for G4GDMLRead:
Collaboration diagram for G4GDMLRead:

Public Member Functions

virtual void DefineRead (const xercesc::DOMElement *const)=0
 
virtual void MaterialsRead (const xercesc::DOMElement *const)=0
 
virtual void SetupRead (const xercesc::DOMElement *const)=0
 
virtual void SolidsRead (const xercesc::DOMElement *const)=0
 
virtual void Paramvol_contentRead (const xercesc::DOMElement *const)=0
 
virtual void Volume_contentRead (const xercesc::DOMElement *const)=0
 
virtual void StructureRead (const xercesc::DOMElement *const)=0
 
virtual void ExtensionRead (const xercesc::DOMElement *const)
 
virtual void UserinfoRead (const xercesc::DOMElement *const)
 
virtual G4LogicalVolumeGetVolume (const G4String &) const =0
 
virtual G4String GetSetup (const G4String &)=0
 
void Read (const G4String &, G4bool validation, G4bool isModule, G4bool strip=true)
 
void StripNames () const
 
void StripName (G4String &) const
 
void OverlapCheck (G4bool)
 
const G4GDMLAuxListTypeGetAuxList () const
 

Protected Member Functions

 G4GDMLRead ()
 
virtual ~G4GDMLRead ()
 
G4String Transcode (const XMLCh *const)
 
G4String GenerateName (const G4String &name, G4bool strip=false)
 
G4String Strip (const G4String &) const
 
void GeneratePhysvolName (const G4String &, G4VPhysicalVolume *)
 
void LoopRead (const xercesc::DOMElement *const, void(G4GDMLRead::*)(const xercesc::DOMElement *const))
 
G4GDMLAuxStructType AuxiliaryRead (const xercesc::DOMElement *const auxElem)
 

Protected Attributes

G4GDMLEvaluator eval
 
G4bool validate
 
G4bool check
 
G4bool dostrip
 

Detailed Description

Definition at line 89 of file G4GDMLRead.hh.

Constructor & Destructor Documentation

G4GDMLRead::G4GDMLRead ( )
protected

Definition at line 45 of file G4GDMLRead.cc.

46  : validate(true), check(false), dostrip(true), inLoop(0), loopCount(0)
47 {
49 }
static void BuildUnitsTable()
G4bool dostrip
Definition: G4GDMLRead.hh:158
G4bool validate
Definition: G4GDMLRead.hh:156
G4bool check
Definition: G4GDMLRead.hh:157

Here is the call graph for this function:

G4GDMLRead::~G4GDMLRead ( )
protectedvirtual

Definition at line 51 of file G4GDMLRead.cc.

52 {
53 }

Member Function Documentation

G4GDMLAuxStructType G4GDMLRead::AuxiliaryRead ( const xercesc::DOMElement *const  auxElem)
protected

Definition at line 262 of file G4GDMLRead.cc.

263 {
264  G4GDMLAuxStructType auxstruct = {"","","",0};
265  G4GDMLAuxListType* auxList=0;
266 
267  const xercesc::DOMNamedNodeMap* const attributes
268  = auxiliaryElement->getAttributes();
269  XMLSize_t attributeCount = attributes->getLength();
270 
271  for (XMLSize_t attribute_index=0;
272  attribute_index<attributeCount; attribute_index++)
273  {
274  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
275 
276  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
277  { continue; }
278 
279  const xercesc::DOMAttr* const attribute
280  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
281  if (!attribute)
282  {
283  G4Exception("G4GDMLRead::AuxiliaryRead()",
284  "InvalidRead", FatalException, "No attribute found!");
285  return auxstruct;
286  }
287  const G4String attName = Transcode(attribute->getName());
288  const G4String attValue = Transcode(attribute->getValue());
289 
290  if (attName=="auxtype") { auxstruct.type = attValue; } else
291  if (attName=="auxvalue") { auxstruct.value = attValue; } else
292  if (attName=="auxunit") { auxstruct.unit = attValue; }
293  }
294 
295  for (xercesc::DOMNode* iter = auxiliaryElement->getFirstChild();
296  iter != 0; iter = iter->getNextSibling())
297  {
298  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
299 
300  const xercesc::DOMElement* const child
301  = dynamic_cast<xercesc::DOMElement*>(iter);
302  if (!child)
303  {
304  G4Exception("G4GDMLRead::AuxiliaryRead()",
305  "InvalidRead", FatalException, "No child found!");
306  break;
307  }
308  const G4String tag = Transcode(child->getTagName());
309 
310  if (tag=="auxiliary")
311  {
312  if(!auxList) { auxList = new G4GDMLAuxListType; }
313  auxList->push_back(AuxiliaryRead(child));
314  }
315  }
316 
317  if (auxList) { auxstruct.auxList = auxList; }
318 
319  return auxstruct;
320 }
std::vector< G4GDMLAuxStructType > * auxList
Definition: xmlparse.cc:187
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::vector< G4GDMLAuxStructType > G4GDMLAuxListType
G4GDMLAuxStructType AuxiliaryRead(const xercesc::DOMElement *const auxElem)
Definition: G4GDMLRead.cc:262

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4GDMLRead::DefineRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadDefine.

Here is the caller graph for this function:

void G4GDMLRead::ExtensionRead ( const xercesc::DOMElement * const  )
virtual

Definition at line 354 of file G4GDMLRead.cc.

355 {
356  G4String error_msg = "No handle to user-code for parsing extensions!";
357  G4Exception("G4GDMLRead::ExtensionRead()",
358  "NotImplemented", JustWarning, error_msg);
359 }
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:

Here is the caller graph for this function:

G4String G4GDMLRead::GenerateName ( const G4String name,
G4bool  strip = false 
)
protected

Definition at line 68 of file G4GDMLRead.cc.

69 {
70  G4String nameOut(nameIn);
71 
72  if (inLoop>0)
73  {
74  nameOut = eval.SolveBrackets(nameOut);
75  }
76  if (strip) { StripName(nameOut); }
77 
78  return nameOut;
79 }
G4GDMLEvaluator eval
Definition: G4GDMLRead.hh:155
void StripName(G4String &) const
Definition: G4GDMLRead.cc:103
G4String SolveBrackets(const G4String &)

Here is the call graph for this function:

void G4GDMLRead::GeneratePhysvolName ( const G4String nameIn,
G4VPhysicalVolume physvol 
)
protected

Definition at line 81 of file G4GDMLRead.cc.

83 {
84  G4String nameOut(nameIn);
85 
86  if (nameIn.empty())
87  {
88  std::stringstream stream;
89  stream << physvol->GetLogicalVolume()->GetName() << "_PV";
90  nameOut = stream.str();
91  }
92  nameOut = eval.SolveBrackets(nameOut);
93 
94  physvol->SetName(nameOut);
95 }
G4GDMLEvaluator eval
Definition: G4GDMLRead.hh:155
void SetName(const G4String &pName)
G4String SolveBrackets(const G4String &)
G4LogicalVolume * GetLogicalVolume() const
const G4String & GetName() const

Here is the call graph for this function:

Here is the caller graph for this function:

const G4GDMLAuxListType * G4GDMLRead::GetAuxList ( ) const

Definition at line 470 of file G4GDMLRead.cc.

471 {
472  return &auxGlobalList;
473 }
virtual G4String G4GDMLRead::GetSetup ( const G4String )
pure virtual

Implemented in G4GDMLReadSetup.

virtual G4LogicalVolume* G4GDMLRead::GetVolume ( const G4String ) const
pure virtual

Implemented in G4GDMLReadStructure.

Here is the caller graph for this function:

void G4GDMLRead::LoopRead ( const xercesc::DOMElement * const  element,
void(G4GDMLRead::*)(const xercesc::DOMElement *const)  func 
)
protected

Definition at line 176 of file G4GDMLRead.cc.

178 {
179  G4String var;
180  G4String from;
181  G4String to;
182  G4String step;
183 
184  const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
185  XMLSize_t attributeCount = attributes->getLength();
186 
187  for (XMLSize_t attribute_index=0;
188  attribute_index<attributeCount;attribute_index++)
189  {
190  xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
191 
192  if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
193  { continue; }
194 
195  const xercesc::DOMAttr* const attribute
196  = dynamic_cast<xercesc::DOMAttr*>(attribute_node);
197  if (!attribute)
198  {
199  G4Exception("G4GDMLRead::LoopRead()", "InvalidRead",
200  FatalException, "No attribute found!");
201  return;
202  }
203  const G4String attribute_name = Transcode(attribute->getName());
204  const G4String attribute_value = Transcode(attribute->getValue());
205 
206  if (attribute_name=="for") { var = attribute_value; } else
207  if (attribute_name=="from") { from = attribute_value; } else
208  if (attribute_name=="to") { to = attribute_value; } else
209  if (attribute_name=="step") { step = attribute_value; }
210  }
211 
212  if (var.empty())
213  {
214  G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
215  FatalException, "No variable is determined for loop!");
216  }
217 
218  if (!eval.IsVariable(var))
219  {
220  G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
221  FatalException, "Variable is not defined in loop!");
222  }
223 
224  G4int _var = eval.EvaluateInteger(var);
225  G4int _from = eval.EvaluateInteger(from);
226  G4int _to = eval.EvaluateInteger(to);
227  G4int _step = eval.EvaluateInteger(step);
228 
229  if (!from.empty()) { _var = _from; }
230 
231  if (_from == _to)
232  {
233  G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
234  FatalException, "Empty loop!");
235  }
236  if ((_from < _to) && (_step <= 0))
237  {
238  G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
239  FatalException, "Infinite loop!");
240  }
241  if ((_from > _to) && (_step >= 0))
242  {
243  G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
244  FatalException, "Infinite loop!");
245  }
246 
247  inLoop++;
248 
249  while (_var <= _to)
250  {
251  eval.SetVariable(var,_var);
252  (this->*func)(element);
253  _var += _step;
254  loopCount++;
255  }
256 
257  inLoop--;
258  if (!inLoop) { loopCount = 0; }
259 }
G4int EvaluateInteger(const G4String &)
G4GDMLEvaluator eval
Definition: G4GDMLRead.hh:155
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
int G4int
Definition: G4Types.hh:78
G4bool IsVariable(const G4String &) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetVariable(const G4String &, G4double)

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4GDMLRead::MaterialsRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadMaterials.

Here is the caller graph for this function:

void G4GDMLRead::OverlapCheck ( G4bool  flag)

Definition at line 63 of file G4GDMLRead.cc.

64 {
65  check = flag;
66 }
G4bool check
Definition: G4GDMLRead.hh:157
virtual void G4GDMLRead::Paramvol_contentRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadParamvol.

Here is the caller graph for this function:

void G4GDMLRead::Read ( const G4String fileName,
G4bool  validation,
G4bool  isModule,
G4bool  strip = true 
)

Definition at line 361 of file G4GDMLRead.cc.

365 {
366  dostrip = strip;
367  if (isModule)
368  {
369  G4cout << "G4GDML: Reading module '" << fileName << "'..." << G4endl;
370  }
371  else
372  {
373  G4cout << "G4GDML: Reading '" << fileName << "'..." << G4endl;
374  }
375 
376  inLoop = 0;
377  validate = validation;
378 
379  xercesc::ErrorHandler* handler = new G4GDMLErrorHandler(!validate);
380  xercesc::XercesDOMParser* parser = new xercesc::XercesDOMParser;
381 
382  if (validate)
383  {
384  parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
385  }
386  parser->setValidationSchemaFullChecking(validate);
387  parser->setCreateEntityReferenceNodes(false);
388  // Entities will be automatically resolved by Xerces
389 
390  parser->setDoNamespaces(true);
391  parser->setDoSchema(validate);
392  parser->setErrorHandler(handler);
393 
394  try { parser->parse(fileName.c_str()); }
395  catch (const xercesc::XMLException &e)
396  { G4cout << "G4GDML: " << Transcode(e.getMessage()) << G4endl; }
397  catch (const xercesc::DOMException &e)
398  { G4cout << "G4GDML: " << Transcode(e.getMessage()) << G4endl; }
399 
400  xercesc::DOMDocument* doc = parser->getDocument();
401 
402  if (!doc)
403  {
404  G4String error_msg = "Unable to open document: " + fileName;
405  G4Exception("G4GDMLRead::Read()", "InvalidRead",
406  FatalException, error_msg);
407  return;
408  }
409  xercesc::DOMElement* element = doc->getDocumentElement();
410 
411  if (!element)
412  {
413  std::ostringstream message;
414  message << "ERROR - Empty document or unable to validate schema!" << G4endl
415  << " Check Internet connection is ON in case of schema"
416  << G4endl
417  << " validation enabled and location defined as URL in"
418  << G4endl
419  << " the GDML file - " << fileName << " - being imported!"
420  << G4endl
421  << " Otherwise, verify GDML schema server is reachable!";
422  G4Exception("G4GDMLRead::Read()", "InvalidRead", FatalException, message);
423  return;
424  }
425 
426  for (xercesc::DOMNode* iter = element->getFirstChild();
427  iter != 0; iter = iter->getNextSibling())
428  {
429  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
430 
431  const xercesc::DOMElement* const child
432  = dynamic_cast<xercesc::DOMElement*>(iter);
433  if (!child)
434  {
435  G4Exception("G4GDMLRead::Read()", "InvalidRead",
436  FatalException, "No child found!");
437  return;
438  }
439  const G4String tag = Transcode(child->getTagName());
440 
441  if (tag=="define") { DefineRead(child); } else
442  if (tag=="materials") { MaterialsRead(child); } else
443  if (tag=="solids") { SolidsRead(child); } else
444  if (tag=="setup") { SetupRead(child); } else
445  if (tag=="structure") { StructureRead(child); } else
446  if (tag=="userinfo") { UserinfoRead(child); } else
447  if (tag=="extension") { ExtensionRead(child); }
448  else
449  {
450  G4String error_msg = "Unknown tag in gdml: " + tag;
451  G4Exception("G4GDMLRead::Read()", "InvalidRead",
452  FatalException, error_msg);
453  }
454  }
455 
456  delete parser;
457  delete handler;
458 
459  if (isModule)
460  {
461  G4cout << "G4GDML: Reading module '" << fileName << "' done!" << G4endl;
462  }
463  else
464  {
465  G4cout << "G4GDML: Reading '" << fileName << "' done!" << G4endl;
466  if (strip) { StripNames(); }
467  }
468 }
Definition: xmlparse.cc:187
G4bool dostrip
Definition: G4GDMLRead.hh:158
virtual void MaterialsRead(const xercesc::DOMElement *const)=0
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
void StripNames() const
Definition: G4GDMLRead.cc:108
virtual void StructureRead(const xercesc::DOMElement *const)=0
G4GLOB_DLL std::ostream G4cout
virtual void UserinfoRead(const xercesc::DOMElement *const)
Definition: G4GDMLRead.cc:322
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void DefineRead(const xercesc::DOMElement *const)=0
virtual void ExtensionRead(const xercesc::DOMElement *const)
Definition: G4GDMLRead.cc:354
G4bool validate
Definition: G4GDMLRead.hh:156
#define G4endl
Definition: G4ios.hh:61
virtual void SetupRead(const xercesc::DOMElement *const)=0
virtual void SolidsRead(const xercesc::DOMElement *const)=0

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4GDMLRead::SetupRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadSetup.

Here is the caller graph for this function:

virtual void G4GDMLRead::SolidsRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadSolids.

Here is the caller graph for this function:

G4String G4GDMLRead::Strip ( const G4String name) const
protected

Definition at line 97 of file G4GDMLRead.cc.

98 {
99  G4String sname(name);
100  return sname.remove(sname.find("0x"));
101 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GDMLRead::StripName ( G4String name) const

Definition at line 103 of file G4GDMLRead.cc.

104 {
105  name.remove(name.find("0x"));
106 }
G4String & remove(str_size)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4GDMLRead::StripNames ( ) const

Definition at line 108 of file G4GDMLRead.cc.

109 {
110  // Strips off names of volumes, solids elements and materials from possible
111  // reference pointers or IDs attached to their original identifiers.
112 
116  const G4ElementTable* elements = G4Element::GetElementTable();
117  const G4MaterialTable* materials = G4Material::GetMaterialTable();
118 
119  G4cout << "Stripping off GDML names of materials, solids and volumes ..."
120  << G4endl;
121 
122  G4String sname;
123  size_t i;
124 
125  // Solids...
126  //
127  for (i=0; i<solids->size(); ++i)
128  {
129  G4VSolid* psol = (*solids)[i];
130  sname = psol->GetName();
131  StripName(sname);
132  psol->SetName(sname);
133  }
134 
135  // Logical volumes...
136  //
137  for (i=0; i<lvols->size(); ++i)
138  {
139  G4LogicalVolume* lvol = (*lvols)[i];
140  sname = lvol->GetName();
141  StripName(sname);
142  lvol->SetName(sname);
143  }
144 
145  // Physical volumes...
146  //
147  for (i=0; i<pvols->size(); ++i)
148  {
149  G4VPhysicalVolume* pvol = (*pvols)[i];
150  sname = pvol->GetName();
151  StripName(sname);
152  pvol->SetName(sname);
153  }
154 
155  // Materials...
156  //
157  for (i=0; i<materials->size(); ++i)
158  {
159  G4Material* pmat = (*materials)[i];
160  sname = pmat->GetName();
161  StripName(sname);
162  pmat->SetName(sname);
163  }
164 
165  // Elements...
166  //
167  for (i=0; i<elements->size(); ++i)
168  {
169  G4Element* pelm = (*elements)[i];
170  sname = pelm->GetName();
171  StripName(sname);
172  pelm->SetName(sname);
173  }
174 }
G4String GetName() const
void SetName(const G4String &name)
Definition: G4Material.hh:279
const G4String & GetName() const
Definition: G4Material.hh:178
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
std::vector< G4Material * > G4MaterialTable
void SetName(const G4String &pName)
static G4PhysicalVolumeStore * GetInstance()
void SetName(const G4String &name)
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
static G4LogicalVolumeStore * GetInstance()
static G4SolidStore * GetInstance()
void StripName(G4String &) const
Definition: G4GDMLRead.cc:103
void SetName(const G4String &pName)
#define G4endl
Definition: G4ios.hh:61
std::vector< G4Element * > G4ElementTable
const G4String & GetName() const
const G4String & GetName() const
Definition: G4Element.hh:127
static G4ElementTable * GetElementTable()
Definition: G4Element.cc:398
void SetName(const G4String &name)
Definition: G4Element.hh:214

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4GDMLRead::StructureRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadStructure.

Here is the caller graph for this function:

G4String G4GDMLRead::Transcode ( const XMLCh * const  toTranscode)
protected

Definition at line 55 of file G4GDMLRead.cc.

56 {
57  char* char_str = xercesc::XMLString::transcode(toTranscode);
58  G4String my_str(char_str);
59  xercesc::XMLString::release(&char_str);
60  return my_str;
61 }
void G4GDMLRead::UserinfoRead ( const xercesc::DOMElement * const  userinfoElement)
virtual

Definition at line 322 of file G4GDMLRead.cc.

323 {
324  G4cout << "G4GDML: Reading userinfo..." << G4endl;
325 
326  for (xercesc::DOMNode* iter = userinfoElement->getFirstChild();
327  iter != 0; iter = iter->getNextSibling())
328  {
329  if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; }
330 
331  const xercesc::DOMElement* const child
332  = dynamic_cast<xercesc::DOMElement*>(iter);
333  if (!child)
334  {
335  G4Exception("G4GDMLRead::UserinfoRead()",
336  "InvalidRead", FatalException, "No child found!");
337  return;
338  }
339  const G4String tag = Transcode(child->getTagName());
340 
341  if (tag=="auxiliary")
342  {
343  auxGlobalList.push_back(AuxiliaryRead(child));
344  }
345  else
346  {
347  G4String error_msg = "Unknown tag in structure: " + tag;
348  G4Exception("G4GDMLRead::UserinfoRead()",
349  "ReadError", FatalException, error_msg);
350  }
351  }
352 }
Definition: xmlparse.cc:187
G4String Transcode(const XMLCh *const)
Definition: G4GDMLRead.cc:55
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4GDMLAuxStructType AuxiliaryRead(const xercesc::DOMElement *const auxElem)
Definition: G4GDMLRead.cc:262
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void G4GDMLRead::Volume_contentRead ( const xercesc::DOMElement *  const)
pure virtual

Implemented in G4GDMLReadStructure.

Here is the caller graph for this function:

Member Data Documentation

G4bool G4GDMLRead::check
protected

Definition at line 157 of file G4GDMLRead.hh.

G4bool G4GDMLRead::dostrip
protected

Definition at line 158 of file G4GDMLRead.hh.

G4GDMLEvaluator G4GDMLRead::eval
protected

Definition at line 155 of file G4GDMLRead.hh.

G4bool G4GDMLRead::validate
protected

Definition at line 156 of file G4GDMLRead.hh.


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