Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/persistency/gdml/src/G4GDMLRead.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /persistency/gdml/src/G4GDMLRead.cc (Version 11.3.0) and /persistency/gdml/src/G4GDMLRead.cc (Version 9.6.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4GDMLRead implementation                   <<  26 // $Id$
 27 //                                                 27 //
 28 // Author: Zoltan Torzsok, November 2007       <<  28 // class G4GDMLRead Implementation
 29 // ------------------------------------------- <<  29 //
                                                   >>  30 // History:
                                                   >>  31 // - Created.                                  Zoltan Torzsok, November 2007
                                                   >>  32 // -------------------------------------------------------------------------
 30                                                    33 
 31 #include "globals.hh"                              34 #include "globals.hh"
 32                                                    35 
 33 #include "G4GDMLRead.hh"                           36 #include "G4GDMLRead.hh"
 34                                                    37 
 35 #include "G4UnitsTable.hh"                         38 #include "G4UnitsTable.hh"
 36 #include "G4Element.hh"                            39 #include "G4Element.hh"
 37 #include "G4Material.hh"                           40 #include "G4Material.hh"
 38 #include "G4SolidStore.hh"                         41 #include "G4SolidStore.hh"
 39 #include "G4LogicalVolumeStore.hh"                 42 #include "G4LogicalVolumeStore.hh"
 40 #include "G4PhysicalVolumeStore.hh"                43 #include "G4PhysicalVolumeStore.hh"
 41 #include "G4EnvironmentUtils.hh"               << 
 42 #include "G4Exception.hh"                      << 
 43                                                    44 
 44 // ------------------------------------------- << 
 45 G4GDMLRead::G4GDMLRead()                           45 G4GDMLRead::G4GDMLRead()
                                                   >>  46   : validate(true), check(false), inLoop(0), loopCount(0)
 46 {                                                  47 {
 47   // Make sure units are defined.              <<  48    G4UnitDefinition::BuildUnitsTable();
 48   G4UnitDefinition::GetUnitsTable();           << 
 49 }                                                  49 }
 50                                                    50 
 51 // ------------------------------------------- << 
 52 G4GDMLRead::~G4GDMLRead()                          51 G4GDMLRead::~G4GDMLRead()
 53 {                                                  52 {
 54 }                                                  53 }
 55                                                    54 
 56 // ------------------------------------------- << 
 57 G4String G4GDMLRead::Transcode(const XMLCh* co     55 G4String G4GDMLRead::Transcode(const XMLCh* const toTranscode)
 58 {                                                  56 {
 59   char* char_str = xercesc::XMLString::transco <<  57    char* char_str = xercesc::XMLString::transcode(toTranscode);
 60   G4String my_str(char_str);                   <<  58    G4String my_str(char_str);
 61   xercesc::XMLString::release(&char_str);      <<  59    xercesc::XMLString::release(&char_str);
 62   return my_str;                               <<  60    return my_str;
 63 }                                                  61 }
 64                                                    62 
 65 // ------------------------------------------- << 
 66 void G4GDMLRead::OverlapCheck(G4bool flag)         63 void G4GDMLRead::OverlapCheck(G4bool flag)
 67 {                                                  64 {
 68   check = flag;                                <<  65    check = flag;
 69 }                                                  66 }
 70                                                    67 
 71 // ------------------------------------------- << 
 72 G4String G4GDMLRead::GenerateName(const G4Stri     68 G4String G4GDMLRead::GenerateName(const G4String& nameIn, G4bool strip)
 73 {                                                  69 {
 74   G4String nameOut(nameIn);                    <<  70    G4String nameOut(nameIn);
 75                                                    71 
 76   if(inLoop > 0)                               <<  72    if (inLoop>0)
 77   {                                            <<  73    {
 78     nameOut = eval.SolveBrackets(nameOut);     <<  74      nameOut = eval.SolveBrackets(nameOut);
 79   }                                            <<  75 //     std::stringstream stream;
 80   if(strip)                                    <<  76 //     stream << "0x" << loopCount;
 81   {                                            <<  77 //     nameOut = nameOut + stream.str();
 82     StripName(nameOut);                        <<  78    }
 83   }                                            <<  79    if (strip) { StripName(nameOut); }
 84                                                    80 
 85   return nameOut;                              <<  81    return nameOut;
 86 }                                                  82 }
 87                                                    83 
 88 // ------------------------------------------- << 
 89 void G4GDMLRead::GeneratePhysvolName(const G4S     84 void G4GDMLRead::GeneratePhysvolName(const G4String& nameIn,
 90                                      G4VPhysic     85                                      G4VPhysicalVolume* physvol)
 91 {                                                  86 {
 92   G4String nameOut(nameIn);                    <<  87    G4String nameOut(nameIn);
 93                                                    88 
 94   if(nameIn.empty())                           <<  89    if (nameIn.empty())
 95   {                                            <<  90    {
 96     std::stringstream stream;                  <<  91      std::stringstream stream;
 97     stream << physvol->GetLogicalVolume()->Get <<  92      stream << physvol->GetLogicalVolume()->GetName() << "_PV";
 98     nameOut = stream.str();                    <<  93      nameOut = stream.str();
 99   }                                            <<  94    }
100   nameOut = eval.SolveBrackets(nameOut);       <<  95    nameOut = eval.SolveBrackets(nameOut);
101                                                    96 
102   physvol->SetName(nameOut);                   <<  97    physvol->SetName(nameOut);
103 }                                                  98 }
104                                                    99 
105 // ------------------------------------------- << 
106 G4String G4GDMLRead::Strip(const G4String& nam    100 G4String G4GDMLRead::Strip(const G4String& name) const
107 {                                                 101 {
108   G4String sname(name);                           102   G4String sname(name);
109   StripName(sname);                            << 103   return sname.remove(sname.find("0x"));
110   return sname;                                << 
111 }                                                 104 }
112                                                   105 
113 // ------------------------------------------- << 
114 void G4GDMLRead::StripName(G4String& name) con    106 void G4GDMLRead::StripName(G4String& name) const
115 {                                                 107 {
116   auto idx = name.find("0x");                  << 108   name.remove(name.find("0x"));
117   if(idx != G4String::npos)                    << 
118   {                                            << 
119     name.erase(idx);                           << 
120   }                                            << 
121 }                                                 109 }
122                                                   110 
123 // ------------------------------------------- << 
124 void G4GDMLRead::StripNames() const               111 void G4GDMLRead::StripNames() const
125 {                                                 112 {
126   // Strips off names of volumes, solids eleme    113   // Strips off names of volumes, solids elements and materials from possible
127   // reference pointers or IDs attached to the    114   // reference pointers or IDs attached to their original identifiers.
128                                                   115 
129   G4PhysicalVolumeStore* pvols     = G4Physica << 116   G4PhysicalVolumeStore* pvols = G4PhysicalVolumeStore::GetInstance();
130   G4LogicalVolumeStore* lvols      = G4Logical << 117   G4LogicalVolumeStore* lvols = G4LogicalVolumeStore::GetInstance();
131   G4SolidStore* solids             = G4SolidSt << 118   G4SolidStore* solids = G4SolidStore::GetInstance();
132   const G4ElementTable* elements   = G4Element << 119   const G4ElementTable* elements = G4Element::GetElementTable();
133   const G4MaterialTable* materials = G4Materia    120   const G4MaterialTable* materials = G4Material::GetMaterialTable();
134                                                   121 
135   G4cout << "Stripping off GDML names of mater    122   G4cout << "Stripping off GDML names of materials, solids and volumes ..."
136          << G4endl;                               123          << G4endl;
137                                                   124 
138   G4String sname;                                 125   G4String sname;
139   std::size_t i;                               << 126   register size_t i;
140                                                   127 
141   // Solids...                                    128   // Solids...
142   //                                              129   //
143   for(i = 0; i < solids->size(); ++i)          << 130   for (i=0; i<solids->size(); i++)
144   {                                               131   {
145     G4VSolid* psol = (*solids)[i];                132     G4VSolid* psol = (*solids)[i];
146     sname          = psol->GetName();          << 133     sname = psol->GetName();
147     StripName(sname);                             134     StripName(sname);
148     psol->SetName(sname);                         135     psol->SetName(sname);
149   }                                               136   }
150   solids->UpdateMap();                         << 
151                                                   137 
152   // Logical volumes...                           138   // Logical volumes...
153   //                                              139   //
154   for(i = 0; i < lvols->size(); ++i)           << 140   for (i=0; i<lvols->size(); i++)
155   {                                               141   {
156     G4LogicalVolume* lvol = (*lvols)[i];          142     G4LogicalVolume* lvol = (*lvols)[i];
157     sname                 = lvol->GetName();   << 143     sname = lvol->GetName();
158     StripName(sname);                             144     StripName(sname);
159     lvol->SetName(sname);                         145     lvol->SetName(sname);
160   }                                               146   }
161   lvols->UpdateMap();                          << 
162                                                   147 
163   // Physical volumes...                          148   // Physical volumes...
164   //                                              149   //
165   for(i = 0; i < pvols->size(); ++i)           << 150   for (i=0; i<pvols->size(); i++)
166   {                                               151   {
167     G4VPhysicalVolume* pvol = (*pvols)[i];        152     G4VPhysicalVolume* pvol = (*pvols)[i];
168     sname                   = pvol->GetName(); << 153     sname = pvol->GetName();
169     StripName(sname);                             154     StripName(sname);
170     pvol->SetName(sname);                         155     pvol->SetName(sname);
171   }                                               156   }
172   pvols->UpdateMap();                          << 
173                                                   157 
174   // Materials...                                 158   // Materials...
175   //                                              159   //
176   for(i = 0; i < materials->size(); ++i)       << 160   for (i=0; i<materials->size(); i++)
177   {                                               161   {
178     G4Material* pmat = (*materials)[i];           162     G4Material* pmat = (*materials)[i];
179     sname            = pmat->GetName();        << 163     sname = pmat->GetName();
180     StripName(sname);                             164     StripName(sname);
181     pmat->SetName(sname);                         165     pmat->SetName(sname);
182   }                                               166   }
183                                                   167 
184   // Elements...                                  168   // Elements...
185   //                                              169   //
186   for(i = 0; i < elements->size(); ++i)        << 170   for (i=0; i<elements->size(); i++)
187   {                                               171   {
188     G4Element* pelm = (*elements)[i];             172     G4Element* pelm = (*elements)[i];
189     sname           = pelm->GetName();         << 173     sname = pelm->GetName();
190     StripName(sname);                             174     StripName(sname);
191     pelm->SetName(sname);                         175     pelm->SetName(sname);
192   }                                               176   }
193 }                                                 177 }
194                                                   178 
195 // ------------------------------------------- << 179 void G4GDMLRead::LoopRead(const xercesc::DOMElement* const element,
196 void G4GDMLRead::LoopRead( const xercesc::DOME << 180      void(G4GDMLRead::*func)(const xercesc::DOMElement* const))
197   void (G4GDMLRead::*func)(const xercesc::DOME << 181 {
198 {                                              << 182    G4String var;
199   G4String var;                                << 183    G4String from;
200   G4String from;                               << 184    G4String to;
201   G4String to;                                 << 185    G4String step;
202   G4String step;                               << 186 
203                                                << 187    const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes();
204   const xercesc::DOMNamedNodeMap* const attrib << 188    XMLSize_t attributeCount = attributes->getLength();
205   XMLSize_t attributeCount                     << 189 
206                                                << 190    for (XMLSize_t attribute_index=0;
207   for(XMLSize_t attribute_index = 0; attribute << 191         attribute_index<attributeCount;attribute_index++)
208       ++attribute_index)                       << 192    {
209   {                                            << 193       xercesc::DOMNode* attribute_node = attributes->item(attribute_index);
210     xercesc::DOMNode* attribute_node = attribu << 194 
211                                                << 195       if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE)
212     if(attribute_node->getNodeType() != xerces << 196       { continue; }
213     {                                          << 197 
214       continue;                                << 198       const xercesc::DOMAttr* const attribute
215     }                                          << 199             = dynamic_cast<xercesc::DOMAttr*>(attribute_node);   
216                                                << 200       if (!attribute)
217     const xercesc::DOMAttr* const attribute =  << 
218       dynamic_cast<xercesc::DOMAttr*>(attribut << 
219     if(!attribute)                             << 
220     {                                          << 
221       G4Exception("G4GDMLRead::LoopRead()", "I << 
222                   "No attribute found!");      << 
223       return;                                  << 
224     }                                          << 
225     const G4String attribute_name  = Transcode << 
226     const G4String attribute_value = Transcode << 
227                                                << 
228     if(attribute_name == "for")                << 
229     {                                          << 
230       var = attribute_value;                   << 
231     }                                          << 
232     else if(attribute_name == "from")          << 
233     {                                          << 
234       from = attribute_value;                  << 
235     }                                          << 
236     else if(attribute_name == "to")            << 
237     {                                          << 
238       to = attribute_value;                    << 
239     }                                          << 
240     else if(attribute_name == "step")          << 
241     {                                          << 
242       step = attribute_value;                  << 
243     }                                          << 
244   }                                            << 
245                                                << 
246   if(var.empty())                              << 
247   {                                            << 
248     G4Exception("G4GDMLRead::loopRead()", "Inv << 
249                 "No variable is determined for << 
250   }                                            << 
251                                                << 
252   if(!eval.IsVariable(var))                    << 
253   {                                            << 
254     G4Exception("G4GDMLRead::loopRead()", "Inv << 
255                 "Variable is not defined in lo << 
256   }                                            << 
257                                                << 
258   G4int _var  = eval.EvaluateInteger(var);     << 
259   G4int _from = eval.EvaluateInteger(from);    << 
260   G4int _to   = eval.EvaluateInteger(to);      << 
261   G4int _step = eval.EvaluateInteger(step);    << 
262                                                << 
263   if(!from.empty())                            << 
264   {                                            << 
265     _var = _from;                              << 
266   }                                            << 
267                                                << 
268   if((_from < _to) && (_step <= 0))            << 
269   {                                            << 
270     G4Exception("G4GDMLRead::loopRead()", "Inv << 
271                 "Infinite loop!");             << 
272   }                                            << 
273   if((_from > _to) && (_step >= 0))            << 
274   {                                            << 
275     G4Exception("G4GDMLRead::loopRead()", "Inv << 
276                 "Infinite loop!");             << 
277   }                                            << 
278                                                << 
279   ++inLoop;                                    << 
280                                                << 
281   while(_var <= _to)                           << 
282   {                                            << 
283     eval.SetVariable(var, _var);               << 
284     (this->*func)(element);                    << 
285     _var += _step;                             << 
286     ++loopCount;                               << 
287   }                                            << 
288                                                << 
289   --inLoop;                                    << 
290   if(!inLoop)                                  << 
291   {                                            << 
292     loopCount = 0;                             << 
293   }                                            << 
294 }                                              << 
295                                                << 
296 // ------------------------------------------- << 
297 G4GDMLAuxStructType G4GDMLRead::AuxiliaryRead( << 
298   const xercesc::DOMElement* const auxiliaryEl << 
299 {                                              << 
300   G4GDMLAuxStructType auxstruct = { "", "", "" << 
301   G4GDMLAuxListType* auxList    = nullptr;     << 
302                                                << 
303   const xercesc::DOMNamedNodeMap* const attrib << 
304     auxiliaryElement->getAttributes();         << 
305   XMLSize_t attributeCount = attributes->getLe << 
306                                                << 
307   for(XMLSize_t attribute_index = 0; attribute << 
308       ++attribute_index)                       << 
309   {                                            << 
310     xercesc::DOMNode* attribute_node = attribu << 
311                                                << 
312     if(attribute_node->getNodeType() != xerces << 
313     {                                          << 
314       continue;                                << 
315     }                                          << 
316                                                << 
317     const xercesc::DOMAttr* const attribute =  << 
318       dynamic_cast<xercesc::DOMAttr*>(attribut << 
319     if(!attribute)                             << 
320     {                                          << 
321       G4Exception("G4GDMLRead::AuxiliaryRead() << 
322                   "No attribute found!");      << 
323       return auxstruct;                        << 
324     }                                          << 
325     const G4String attName  = Transcode(attrib << 
326     const G4String attValue = Transcode(attrib << 
327                                                << 
328     if(attName == "auxtype")                   << 
329     {                                          << 
330       auxstruct.type = attValue;               << 
331     }                                          << 
332     else if(attName == "auxvalue")             << 
333     {                                          << 
334       auxstruct.value = attValue;              << 
335     }                                          << 
336     else if(attName == "auxunit")              << 
337     {                                          << 
338       auxstruct.unit = attValue;               << 
339     }                                          << 
340   }                                            << 
341                                                << 
342   for(xercesc::DOMNode* iter = auxiliaryElemen << 
343                         iter != nullptr; iter  << 
344   {                                            << 
345     if(iter->getNodeType() != xercesc::DOMNode << 
346     {                                          << 
347       continue;                                << 
348     }                                          << 
349                                                << 
350     const xercesc::DOMElement* const child =   << 
351       dynamic_cast<xercesc::DOMElement*>(iter) << 
352     if(!child)                                 << 
353     {                                          << 
354       G4Exception("G4GDMLRead::AuxiliaryRead() << 
355                   "No child found!");          << 
356       break;                                   << 
357     }                                          << 
358     const G4String tag = Transcode(child->getT << 
359                                                << 
360     if(tag == "auxiliary")                     << 
361     {                                          << 
362       if(!auxList)                             << 
363       {                                           201       {
364         auxList = new G4GDMLAuxListType;       << 202         G4Exception("G4GDMLRead::LoopRead()", "InvalidRead",
                                                   >> 203                     FatalException, "No attribute found!");
                                                   >> 204         return;
365       }                                           205       }
366       auxList->push_back(AuxiliaryRead(child)) << 206       const G4String attribute_name = Transcode(attribute->getName());
367     }                                          << 207       const G4String attribute_value = Transcode(attribute->getValue());
368   }                                            << 
369                                                   208 
370   if(auxList)                                  << 209       if (attribute_name=="for")  { var = attribute_value; }  else
371   {                                            << 210       if (attribute_name=="from") { from = attribute_value; } else
372     auxstruct.auxList = auxList;               << 211       if (attribute_name=="to")   { to = attribute_value; }   else
373   }                                            << 212       if (attribute_name=="step") { step = attribute_value; }
                                                   >> 213    }
                                                   >> 214 
                                                   >> 215    if (var.empty())
                                                   >> 216    {
                                                   >> 217      G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                                                   >> 218                  FatalException, "No variable is determined for loop!");
                                                   >> 219    }
                                                   >> 220 
                                                   >> 221    if (!eval.IsVariable(var))
                                                   >> 222    {
                                                   >> 223      G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                                                   >> 224                  FatalException, "Variable is not defined in loop!");
                                                   >> 225    }
                                                   >> 226 
                                                   >> 227    G4int _var = eval.EvaluateInteger(var);
                                                   >> 228    G4int _from = eval.EvaluateInteger(from);
                                                   >> 229    G4int _to = eval.EvaluateInteger(to);
                                                   >> 230    G4int _step = eval.EvaluateInteger(step);
                                                   >> 231    
                                                   >> 232    if (!from.empty()) { _var = _from; }
374                                                   233 
375   return auxstruct;                            << 234    if (_from == _to)
376 }                                              << 235    {
                                                   >> 236      G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                                                   >> 237                  FatalException, "Empty loop!");
                                                   >> 238    }
                                                   >> 239    if ((_from < _to) && (_step <= 0))
                                                   >> 240    {
                                                   >> 241      G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                                                   >> 242                  FatalException, "Infinite loop!");
                                                   >> 243    }
                                                   >> 244    if ((_from > _to) && (_step >= 0))
                                                   >> 245    {
                                                   >> 246      G4Exception("G4GDMLRead::loopRead()", "InvalidRead",
                                                   >> 247                  FatalException, "Infinite loop!");
                                                   >> 248    }
                                                   >> 249 
                                                   >> 250    inLoop++;
                                                   >> 251 
                                                   >> 252    while (_var <= _to)
                                                   >> 253    {
                                                   >> 254       eval.SetVariable(var,_var);
                                                   >> 255       (this->*func)(element);
                                                   >> 256       _var += _step;
                                                   >> 257       loopCount++;
                                                   >> 258    }
377                                                   259 
378 // ------------------------------------------- << 260    inLoop--;
379 void G4GDMLRead::UserinfoRead(const xercesc::D << 261    if (!inLoop) { loopCount = 0; }
380 {                                              << 
381 #ifdef G4VERBOSE                               << 
382   G4cout << "G4GDML: Reading userinfo..." << G << 
383 #endif                                         << 
384   for(xercesc::DOMNode* iter = userinfoElement << 
385                         iter != nullptr; iter  << 
386   {                                            << 
387     if(iter->getNodeType() != xercesc::DOMNode << 
388     {                                          << 
389       continue;                                << 
390     }                                          << 
391                                                << 
392     const xercesc::DOMElement* const child =   << 
393       dynamic_cast<xercesc::DOMElement*>(iter) << 
394     if(!child)                                 << 
395     {                                          << 
396       G4Exception("G4GDMLRead::UserinfoRead()" << 
397                   "No child found!");          << 
398       return;                                  << 
399     }                                          << 
400     const G4String tag = Transcode(child->getT << 
401                                                << 
402     if(tag == "auxiliary")                     << 
403     {                                          << 
404       auxGlobalList.push_back(AuxiliaryRead(ch << 
405     }                                          << 
406     else                                       << 
407     {                                          << 
408       G4String error_msg = "Unknown tag in str << 
409       G4Exception("G4GDMLRead::UserinfoRead()" << 
410                   error_msg);                  << 
411     }                                          << 
412   }                                            << 
413 }                                                 262 }
414                                                   263 
415 // ------------------------------------------- << 
416 void G4GDMLRead::ExtensionRead(const xercesc::    264 void G4GDMLRead::ExtensionRead(const xercesc::DOMElement* const)
417 {                                                 265 {
418   G4String error_msg = "No handle to user-code << 266    G4String error_msg = "No handle to user-code for parsing extensions!";
419   G4Exception("G4GDMLRead::ExtensionRead()", " << 267    G4Exception("G4GDMLRead::ExtensionRead()",
420               error_msg);                      << 268                "NotImplemented", JustWarning, error_msg);
421 }                                              << 269 }
422                                                << 270 
423 // ------------------------------------------- << 271 void G4GDMLRead::Read(const G4String& fileName,
424 const G4String& G4GDMLRead::GetSchemaFile() co << 272                             G4bool validation,
425 {                                              << 273                             G4bool isModule,
426   return schema;                               << 274                             G4bool strip)
427 }                                              << 275 {
428                                                << 276    if (isModule)
429 // ------------------------------------------- << 277    {
430 void G4GDMLRead::SetSchemaFile(const G4String& << 278       G4cout << "G4GDML: Reading module '" << fileName << "'..." << G4endl;
431 {                                              << 279    }
432   schema = schemaFile;                         << 280    else
433 }                                              << 281    {
434                                                << 282       G4cout << "G4GDML: Reading '" << fileName << "'..." << G4endl;
435 // ------------------------------------------- << 283    }
436 void G4GDMLRead::Read(const G4String& fileName << 284 
437                       G4bool isModule, G4bool  << 285    inLoop = 0;
438 {                                              << 286    validate = validation;
439   dostrip = strip;                             << 287 
440 #ifdef G4VERBOSE                               << 288    xercesc::ErrorHandler* handler = new G4GDMLErrorHandler(!validate);
441   if(isModule)                                 << 289    xercesc::XercesDOMParser* parser = new xercesc::XercesDOMParser;
442   {                                            << 290 
443     G4cout << "G4GDML: Reading module '" << fi << 291    parser->setValidationScheme(xercesc::XercesDOMParser::Val_Always);
444   }                                            << 292    parser->setValidationSchemaFullChecking(true);
445   else                                         << 293    parser->setCreateEntityReferenceNodes(false); 
446   {                                            << 294      // Entities will be automatically resolved by Xerces
447     G4cout << "G4GDML: Reading '" << fileName  << 295 
448   }                                            << 296    parser->setDoNamespaces(true);
449 #endif                                         << 297    parser->setDoSchema(true);
450   inLoop   = 0;                                << 298    parser->setErrorHandler(handler);
451   validate = validation;                       << 299 
452                                                << 300    try { parser->parse(fileName.c_str()); }
453   xercesc::ErrorHandler* handler   = new G4GDM << 301    catch (const xercesc::XMLException &e)
454   xercesc::XercesDOMParser* parser = new xerce << 302      { G4cout << "G4GDML: " << Transcode(e.getMessage()) << G4endl; }
455                                                << 303    catch (const xercesc::DOMException &e)
456   if(validate)                                 << 304      { G4cout << "G4GDML: " << Transcode(e.getMessage()) << G4endl; }
457   {                                            << 305 
458     parser->setValidationScheme(xercesc::Xerce << 306    xercesc::DOMDocument* doc = parser->getDocument();
459                                                << 307 
460     // Load alternative schema path if specifi << 308    if (!doc)
461     // 1. environment variable, or             << 309    {
462     // 2. `schema` data member, or             << 310      G4String error_msg = "Unable to open document: " + fileName;
463     // Will fall back to default validation ot << 311      G4Exception("G4GDMLRead::Read()", "InvalidRead",
464     if(auto schemaPath = G4GetEnv<G4String>("G << 312                  FatalException, error_msg);
465     {                                          << 313      return;
466       // Pre-parse grammar to check it's prese << 314    }
467       if(parser->loadGrammar(schemaPath.c_str( << 315    xercesc::DOMElement* element = doc->getDocumentElement();
                                                   >> 316 
                                                   >> 317    if (!element)
                                                   >> 318    {
                                                   >> 319      G4Exception("G4GDMLRead::Read()", "InvalidRead",
                                                   >> 320                  FatalException, "Empty document!");
                                                   >> 321      return;
                                                   >> 322    }
                                                   >> 323 
                                                   >> 324    for (xercesc::DOMNode* iter = element->getFirstChild();
                                                   >> 325         iter != 0; iter = iter->getNextSibling())
                                                   >> 326    {
                                                   >> 327       if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE)  { continue; }
                                                   >> 328 
                                                   >> 329       const xercesc::DOMElement* const child
                                                   >> 330             = dynamic_cast<xercesc::DOMElement*>(iter);
                                                   >> 331       if (!child)
468       {                                           332       {
469         G4cout << "G4GDML: Loaded alternative  << 333         G4Exception("G4GDMLRead::Read()", "InvalidRead",
                                                   >> 334                     FatalException, "No child found!");
                                                   >> 335         return;
470       }                                           336       }
471       else                                     << 337       const G4String tag = Transcode(child->getTagName());
                                                   >> 338 
                                                   >> 339       if (tag=="define")    { DefineRead(child);    } else
                                                   >> 340       if (tag=="materials") { MaterialsRead(child); } else
                                                   >> 341       if (tag=="solids")    { SolidsRead(child);    } else
                                                   >> 342       if (tag=="setup")     { SetupRead(child);     } else
                                                   >> 343       if (tag=="structure") { StructureRead(child); } else
                                                   >> 344       if (tag=="extension") { ExtensionRead(child); }
                                                   >> 345       else
472       {                                           346       {
473         G4Exception("G4GDMLRead::Read()",      << 347         G4String error_msg = "Unknown tag in gdml: " + tag;
474                     "InvalidGDMLSchemaFile",   << 348         G4Exception("G4GDMLRead::Read()", "InvalidRead",
475                     FatalException,            << 349                     FatalException, error_msg);
476                     G4String("Failed to load/p << 
477       }                                           350       }
478       parser->useCachedGrammarInParse(true);   << 351    }
479       // If the schema has been set manually t << 
480       parser->setExternalNoNamespaceSchemaLoca << 
481     }                                          << 
482   }                                            << 
483   parser->setValidationSchemaFullChecking(vali << 
484   parser->setCreateEntityReferenceNodes(false) << 
485   // Entities will be automatically resolved b << 
486                                                << 
487   parser->setDoNamespaces(true);               << 
488   parser->setDoSchema(validate);               << 
489   parser->setErrorHandler(handler);            << 
490                                                << 
491   try                                          << 
492   {                                            << 
493     parser->parse(fileName.c_str());           << 
494   } catch(const xercesc::XMLException& e)      << 
495   {                                            << 
496     G4cout << "G4GDML: " << Transcode(e.getMes << 
497   } catch(const xercesc::DOMException& e)      << 
498   {                                            << 
499     G4cout << "G4GDML: " << Transcode(e.getMes << 
500   }                                            << 
501                                                   352 
502   xercesc::DOMDocument* doc = parser->getDocum << 353    delete parser;
503                                                << 354    delete handler;
504   if(doc == nullptr)                           << 
505   {                                            << 
506     G4String error_msg = "Unable to open docum << 
507     G4Exception("G4GDMLRead::Read()", "Invalid << 
508     return;                                    << 
509   }                                            << 
510   xercesc::DOMElement* element = doc->getDocum << 
511                                                << 
512   if(element == nullptr )                      << 
513   {                                            << 
514     std::ostringstream message;                << 
515     message << "ERROR - Empty document or unab << 
516             << "        Check Internet connect << 
517             << G4endl                          << 
518             << "        validation enabled and << 
519             << G4endl << "        the GDML fil << 
520             << " - being imported!" << G4endl  << 
521             << "        Otherwise, verify GDML << 
522     G4Exception("G4GDMLRead::Read()", "Invalid << 
523     return;                                    << 
524   }                                            << 
525                                                   355 
526   for(xercesc::DOMNode* iter = element->getFir << 356    if (isModule)
527       iter                   = iter->getNextSi << 357    {
528   {                                            << 358       G4cout << "G4GDML: Reading module '" << fileName << "' done!" << G4endl;
529     if(iter->getNodeType() != xercesc::DOMNode << 359    }
530     {                                          << 360    else
531       continue;                                << 361    {
532     }                                          << 362       G4cout << "G4GDML: Reading '" << fileName << "' done!" << G4endl;
533                                                << 363       if (strip)  { StripNames(); }
534     const xercesc::DOMElement* const child =   << 364    }
535       dynamic_cast<xercesc::DOMElement*>(iter) << 
536     if(child == nullptr)                       << 
537     {                                          << 
538       G4Exception("G4GDMLRead::Read()", "Inval << 
539                   "No child found!");          << 
540       return;                                  << 
541     }                                          << 
542     const G4String tag = Transcode(child->getT << 
543                                                << 
544     if(tag == "define")                        << 
545     {                                          << 
546       DefineRead(child);                       << 
547     }                                          << 
548     else if(tag == "materials")                << 
549     {                                          << 
550       MaterialsRead(child);                    << 
551     }                                          << 
552     else if(tag == "solids")                   << 
553     {                                          << 
554       SolidsRead(child);                       << 
555     }                                          << 
556     else if(tag == "setup")                    << 
557     {                                          << 
558       SetupRead(child);                        << 
559     }                                          << 
560     else if(tag == "structure")                << 
561     {                                          << 
562       StructureRead(child);                    << 
563     }                                          << 
564     else if(tag == "userinfo")                 << 
565     {                                          << 
566       UserinfoRead(child);                     << 
567     }                                          << 
568     else if(tag == "extension")                << 
569     {                                          << 
570       ExtensionRead(child);                    << 
571     }                                          << 
572     else                                       << 
573     {                                          << 
574       G4String error_msg = "Unknown tag in gdm << 
575       G4Exception("G4GDMLRead::Read()", "Inval << 
576                   error_msg);                  << 
577     }                                          << 
578   }                                            << 
579                                                << 
580   delete parser;                               << 
581   delete handler;                              << 
582                                                << 
583   if(isModule)                                 << 
584   {                                            << 
585 #ifdef G4VERBOSE                               << 
586     G4cout << "G4GDML: Reading module '" << fi << 
587 #endif                                         << 
588   }                                            << 
589   else                                         << 
590   {                                            << 
591     G4cout << "G4GDML: Reading '" << fileName  << 
592     if(strip)                                  << 
593     {                                          << 
594       StripNames();                            << 
595     }                                          << 
596   }                                            << 
597 }                                              << 
598                                                << 
599 // ------------------------------------------- << 
600 const G4GDMLAuxListType* G4GDMLRead::GetAuxLis << 
601 {                                              << 
602   return &auxGlobalList;                       << 
603 }                                                 365 }
604                                                   366