Geant4 Cross Reference |
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 // G4GDMLReadStructure implementation << 26 // $Id: G4GDMLReadStructure.cc,v 1.52.2.2 2009/08/11 08:27:49 gcosmo Exp $ >> 27 // GEANT4 tag $Name: geant4-09-02-patch-02 $ >> 28 // >> 29 // class G4GDMLReadStructure Implementation >> 30 // >> 31 // Original author: Zoltan Torzsok, November 2007 27 // 32 // 28 // Author: Zoltan Torzsok, November 2007 << 29 // ------------------------------------------- 33 // -------------------------------------------------------------------- 30 34 31 #include "G4GDMLReadStructure.hh" 35 #include "G4GDMLReadStructure.hh" 32 36 33 #include "G4UnitsTable.hh" << 37 G4GDMLReadStructure::G4GDMLReadStructure() : G4GDMLReadParamvol() 34 #include "G4LogicalVolume.hh" << 35 #include "G4VPhysicalVolume.hh" << 36 #include "G4PVPlacement.hh" << 37 #include "G4LogicalVolumeStore.hh" << 38 #include "G4PhysicalVolumeStore.hh" << 39 #include "G4AssemblyVolume.hh" << 40 #include "G4ReflectionFactory.hh" << 41 #include "G4PVDivisionFactory.hh" << 42 #include "G4LogicalBorderSurface.hh" << 43 #include "G4LogicalSkinSurface.hh" << 44 #include "G4VisAttributes.hh" << 45 << 46 // ------------------------------------------- << 47 G4GDMLReadStructure::G4GDMLReadStructure() << 48 : G4GDMLReadParamvol() << 49 { 38 { 50 } 39 } 51 40 52 // ------------------------------------------- << 53 G4GDMLReadStructure::~G4GDMLReadStructure() 41 G4GDMLReadStructure::~G4GDMLReadStructure() 54 { 42 { 55 } 43 } 56 44 57 // ------------------------------------------- << 45 G4GDMLAuxPairType G4GDMLReadStructure:: 58 void G4GDMLReadStructure::BorderSurfaceRead( << 46 AuxiliaryRead(const xercesc::DOMElement* const auxiliaryElement) 59 const xercesc::DOMElement* const bordersurfa << 60 { 47 { 61 G4String name; << 48 G4GDMLAuxPairType auxpair; 62 G4VPhysicalVolume* pv1 = nullptr; << 63 G4VPhysicalVolume* pv2 = nullptr; << 64 G4SurfaceProperty* prop = nullptr; << 65 G4int index = 0; << 66 << 67 const xercesc::DOMNamedNodeMap* const attrib << 68 bordersurfaceElement->getAttributes(); << 69 XMLSize_t attributeCount = attributes->getLe << 70 << 71 for(XMLSize_t attribute_index = 0; attribute << 72 ++attribute_index) << 73 { << 74 xercesc::DOMNode* attribute_node = attribu << 75 << 76 if(attribute_node->getNodeType() != xerces << 77 { << 78 continue; << 79 } << 80 49 81 const xercesc::DOMAttr* const attribute = << 50 const xercesc::DOMNamedNodeMap* const attributes 82 dynamic_cast<xercesc::DOMAttr*>(attribut << 51 = auxiliaryElement->getAttributes(); 83 if(attribute == nullptr) << 52 XMLSize_t attributeCount = attributes->getLength(); 84 { << 53 85 G4Exception("G4GDMLReadStructure::Border << 54 for (XMLSize_t attribute_index=0; 86 FatalException, "No attribut << 55 attribute_index<attributeCount; attribute_index++) 87 return; << 56 { 88 } << 57 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 89 const G4String attName = Transcode(attrib << 58 90 const G4String attValue = Transcode(attrib << 59 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 60 { continue; } >> 61 >> 62 const xercesc::DOMAttr* const attribute >> 63 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 64 const G4String attName = Transcode(attribute->getName()); >> 65 const G4String attValue = Transcode(attribute->getValue()); >> 66 >> 67 if (attName=="auxtype") { auxpair.type = attValue; } else >> 68 if (attName=="auxvalue") { auxpair.value = eval.Evaluate(attValue); } >> 69 } >> 70 >> 71 return auxpair; >> 72 } >> 73 >> 74 void G4GDMLReadStructure:: >> 75 BordersurfaceRead(const xercesc::DOMElement* const bordersurfaceElement) >> 76 { >> 77 G4String name; >> 78 G4VPhysicalVolume* pv1 = 0; >> 79 G4VPhysicalVolume* pv2 = 0; >> 80 G4SurfaceProperty* prop = 0; >> 81 G4int index = 0; >> 82 >> 83 const xercesc::DOMNamedNodeMap* const attributes >> 84 = bordersurfaceElement->getAttributes(); >> 85 XMLSize_t attributeCount = attributes->getLength(); >> 86 >> 87 for (XMLSize_t attribute_index=0; >> 88 attribute_index<attributeCount; attribute_index++) >> 89 { >> 90 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 91 >> 92 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 93 { continue; } >> 94 >> 95 const xercesc::DOMAttr* const attribute >> 96 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 97 const G4String attName = Transcode(attribute->getName()); >> 98 const G4String attValue = Transcode(attribute->getValue()); >> 99 >> 100 if (attName=="name") >> 101 { name = GenerateName(attValue); } else >> 102 if (attName=="surfaceproperty") >> 103 { prop = GetSurfaceProperty(GenerateName(attValue)); } >> 104 } >> 105 >> 106 for (xercesc::DOMNode* iter = bordersurfaceElement->getFirstChild(); >> 107 iter != 0; iter = iter->getNextSibling()) >> 108 { >> 109 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } >> 110 >> 111 const xercesc::DOMElement* const child >> 112 = dynamic_cast<xercesc::DOMElement*>(iter); >> 113 const G4String tag = Transcode(child->getTagName()); >> 114 >> 115 if (tag != "physvolref") { continue; } >> 116 >> 117 if (index==0) >> 118 { pv1 = GetPhysvol(GenerateName(RefRead(child))); index++; } else >> 119 if (index==1) >> 120 { pv2 = GetPhysvol(GenerateName(RefRead(child))); index++; } else >> 121 break; >> 122 } 91 123 92 if(attName == "name") << 124 new G4LogicalBorderSurface(Strip(name),pv1,pv2,prop); 93 { << 125 } 94 name = GenerateName(attValue); << 95 } << 96 else if(attName == "surfaceproperty") << 97 { << 98 prop = GetSurfaceProperty(GenerateName(a << 99 } << 100 } << 101 126 102 for(xercesc::DOMNode* iter = bordersurfaceEl << 127 void G4GDMLReadStructure:: 103 iter != nullptr; iter << 128 DivisionvolRead(const xercesc::DOMElement* const divisionvolElement) >> 129 { >> 130 G4String name; >> 131 G4double unit = 1.0; >> 132 G4double width = 0.0; >> 133 G4double offset = 0.0; >> 134 G4int number = 0; >> 135 EAxis axis = kUndefined; >> 136 G4LogicalVolume* logvol = 0; >> 137 >> 138 const xercesc::DOMNamedNodeMap* const attributes >> 139 = divisionvolElement->getAttributes(); >> 140 XMLSize_t attributeCount = attributes->getLength(); >> 141 >> 142 for (XMLSize_t attribute_index=0; >> 143 attribute_index<attributeCount; attribute_index++) >> 144 { >> 145 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 146 >> 147 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 148 { continue; } >> 149 >> 150 const xercesc::DOMAttr* const attribute >> 151 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 152 const G4String attName = Transcode(attribute->getName()); >> 153 const G4String attValue = Transcode(attribute->getValue()); >> 154 >> 155 if (attName=="name") { name = attValue; } else >> 156 if (attName=="unit") { unit = eval.Evaluate(attValue); } else >> 157 if (attName=="width") { width = eval.Evaluate(attValue); } else >> 158 if (attName=="offset") { offset = eval.Evaluate(attValue); } else >> 159 if (attName=="number") { number = eval.EvaluateInteger(attValue); } else >> 160 if (attName=="axis") >> 161 { >> 162 if (attValue=="kXAxis") { axis = kXAxis; } else >> 163 if (attValue=="kYAxis") { axis = kYAxis; } else >> 164 if (attValue=="kZAxis") { axis = kZAxis; } else >> 165 if (attValue=="kRho") { axis = kRho; } else >> 166 if (attValue=="kPhi") { axis = kPhi; } >> 167 } >> 168 } >> 169 >> 170 width *= unit; >> 171 offset *= unit; >> 172 >> 173 for (xercesc::DOMNode* iter = divisionvolElement->getFirstChild(); >> 174 iter != 0;iter = iter->getNextSibling()) >> 175 { >> 176 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } >> 177 >> 178 const xercesc::DOMElement* const child >> 179 = dynamic_cast<xercesc::DOMElement*>(iter); >> 180 const G4String tag = Transcode(child->getTagName()); >> 181 >> 182 if (tag=="volumeref") { logvol = GetVolume(GenerateName(RefRead(child))); } >> 183 } >> 184 >> 185 G4PVDivisionFactory::GetInstance(); >> 186 G4PhysicalVolumesPair pair; >> 187 >> 188 G4String pv_name = logvol->GetName() + "_div"; >> 189 if ((number != 0) && (width == 0.0)) >> 190 { >> 191 pair = G4ReflectionFactory::Instance() >> 192 ->Divide(pv_name,logvol,pMotherLogical,axis,number,offset); >> 193 } >> 194 else if ((number == 0) && (width != 0.0)) >> 195 { >> 196 pair = G4ReflectionFactory::Instance() >> 197 ->Divide(pv_name,logvol,pMotherLogical,axis,width,offset); >> 198 } >> 199 else >> 200 { >> 201 pair = G4ReflectionFactory::Instance() >> 202 ->Divide(pv_name,logvol,pMotherLogical,axis,number,width,offset); >> 203 } >> 204 >> 205 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); } >> 206 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); } >> 207 } >> 208 >> 209 G4LogicalVolume* G4GDMLReadStructure:: >> 210 FileRead(const xercesc::DOMElement* const fileElement) >> 211 { >> 212 G4String name; >> 213 G4String volname; >> 214 >> 215 const xercesc::DOMNamedNodeMap* const attributes >> 216 = fileElement->getAttributes(); >> 217 XMLSize_t attributeCount = attributes->getLength(); >> 218 >> 219 for (XMLSize_t attribute_index=0; >> 220 attribute_index<attributeCount; attribute_index++) >> 221 { >> 222 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 223 >> 224 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 225 { continue; } >> 226 >> 227 const xercesc::DOMAttr* const attribute >> 228 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 229 const G4String attName = Transcode(attribute->getName()); >> 230 const G4String attValue = Transcode(attribute->getValue()); >> 231 >> 232 if (attName=="name") { name = attValue; } else >> 233 if (attName=="volname") { volname = attValue; } >> 234 } >> 235 >> 236 const G4bool isModule = true; >> 237 G4GDMLReadStructure structure; >> 238 structure.Read(name,validate,isModule); >> 239 >> 240 // Register existing auxiliar information defined in child module >> 241 // >> 242 const G4GDMLAuxMapType* aux = structure.GetAuxMap(); >> 243 if (!aux->empty()) >> 244 { >> 245 G4GDMLAuxMapType::const_iterator pos; >> 246 for (pos = aux->begin(); pos != aux->end(); ++pos) >> 247 { >> 248 auxMap.insert(std::make_pair(pos->first,pos->second)); >> 249 } >> 250 } >> 251 >> 252 // Return volume structure from child module >> 253 // >> 254 if (volname.empty()) >> 255 { >> 256 return structure.GetVolume(structure.GetSetup("Default")); >> 257 } >> 258 else >> 259 { >> 260 return structure.GetVolume(structure.GenerateName(volname)); >> 261 } >> 262 } >> 263 >> 264 void G4GDMLReadStructure:: >> 265 PhysvolRead(const xercesc::DOMElement* const physvolElement) >> 266 { >> 267 G4String name; >> 268 G4LogicalVolume* logvol = 0; >> 269 G4ThreeVector position(0.0,0.0,0.0); >> 270 G4ThreeVector rotation(0.0,0.0,0.0); >> 271 G4ThreeVector scale(1.0,1.0,1.0); >> 272 >> 273 const xercesc::DOMNamedNodeMap* const attributes >> 274 = physvolElement->getAttributes(); >> 275 XMLSize_t attributeCount = attributes->getLength(); >> 276 >> 277 for (XMLSize_t attribute_index=0; >> 278 attribute_index<attributeCount; attribute_index++) >> 279 { >> 280 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 281 >> 282 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 283 { continue; } >> 284 >> 285 const xercesc::DOMAttr* const attribute >> 286 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 287 const G4String attName = Transcode(attribute->getName()); >> 288 const G4String attValue = Transcode(attribute->getValue()); >> 289 >> 290 if (attName=="name") { name = attValue; } >> 291 } >> 292 >> 293 for (xercesc::DOMNode* iter = physvolElement->getFirstChild(); >> 294 iter != 0; iter = iter->getNextSibling()) >> 295 { >> 296 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } >> 297 >> 298 const xercesc::DOMElement* const child >> 299 = dynamic_cast<xercesc::DOMElement*>(iter); >> 300 const G4String tag = Transcode(child->getTagName()); >> 301 >> 302 if (tag=="file") >> 303 { logvol = FileRead(child); } else >> 304 if (tag=="volumeref") >> 305 { logvol = GetVolume(GenerateName(RefRead(child))); } else >> 306 if (tag=="position") >> 307 { VectorRead(child,position); } else >> 308 if (tag=="rotation") >> 309 { VectorRead(child,rotation); } else >> 310 if (tag=="scale") >> 311 { VectorRead(child,scale); } else >> 312 if (tag=="positionref") >> 313 { position = GetPosition(GenerateName(RefRead(child))); } else >> 314 if (tag=="rotationref") >> 315 { rotation = GetRotation(GenerateName(RefRead(child))); } else >> 316 if (tag=="scaleref") >> 317 { scale = GetScale(GenerateName(RefRead(child))); } >> 318 else >> 319 { >> 320 G4String error_msg = "Unknown tag in physvol: " + tag; >> 321 G4Exception("G4GDMLReadStructure::PhysvolRead()", "ReadError", >> 322 FatalException, error_msg); >> 323 } >> 324 } >> 325 >> 326 G4Transform3D transform(GetRotationMatrix(rotation).inverse(),position); >> 327 transform = transform*G4Scale3D(scale.x(),scale.y(),scale.z()); >> 328 >> 329 G4String pv_name = logvol->GetName() + "_PV"; >> 330 G4PhysicalVolumesPair pair = G4ReflectionFactory::Instance() >> 331 ->Place(transform,pv_name,logvol,pMotherLogical,false,0,check); >> 332 >> 333 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); } >> 334 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); } >> 335 } >> 336 >> 337 void G4GDMLReadStructure:: >> 338 ReplicavolRead(const xercesc::DOMElement* const replicavolElement, G4int number) >> 339 { >> 340 G4LogicalVolume* logvol = 0; >> 341 for (xercesc::DOMNode* iter = replicavolElement->getFirstChild(); >> 342 iter != 0; iter = iter->getNextSibling()) 104 { 343 { 105 if(iter->getNodeType() != xercesc::DOMNode << 344 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 106 { << 107 continue; << 108 } << 109 345 110 const xercesc::DOMElement* const child = << 346 const xercesc::DOMElement* const child 111 dynamic_cast<xercesc::DOMElement*>(iter) << 347 = dynamic_cast<xercesc::DOMElement*>(iter); 112 if(child == nullptr) << 113 { << 114 G4Exception("G4GDMLReadStructure::Border << 115 FatalException, "No child fo << 116 return; << 117 } << 118 const G4String tag = Transcode(child->getT 348 const G4String tag = Transcode(child->getTagName()); 119 349 120 if(tag != "physvolref") << 350 if (tag=="volumeref") 121 { 351 { 122 continue; << 352 logvol = GetVolume(GenerateName(RefRead(child))); 123 } 353 } 124 << 354 else if (tag=="replicate_along_axis") 125 if(index == 0) << 126 { 355 { 127 pv1 = GetPhysvol(GenerateName(RefRead(ch << 356 ReplicaRead(child,logvol,number); 128 ++index; << 129 } 357 } 130 else if(index == 1) << 358 else 131 { 359 { 132 pv2 = GetPhysvol(GenerateName(RefRead(ch << 360 G4String error_msg = "Unknown tag in ReplicavolRead: " + tag; 133 ++index; << 361 G4Exception("G4GDMLReadStructure::ReplicavolRead()", >> 362 "ReadError", FatalException, error_msg); 134 } 363 } 135 else << 136 break; << 137 } 364 } 138 << 139 new G4LogicalBorderSurface(Strip(name), pv1, << 140 } 365 } 141 366 142 // ------------------------------------------- << 367 void G4GDMLReadStructure:: 143 void G4GDMLReadStructure::DivisionvolRead( << 368 ReplicaRead(const xercesc::DOMElement* const replicaElement, 144 const xercesc::DOMElement* const divisionvol << 369 G4LogicalVolume* logvol, G4int number) 145 { 370 { 146 G4String name; << 371 G4double width = 0.0; 147 G4double unit = 1.0; << 372 G4double offset = 0.0; 148 G4double width = 0.0; << 373 G4ThreeVector position(0.0,0.0,0.0); 149 G4double offset = 0.0; << 374 G4ThreeVector rotation(0.0,0.0,0.0); 150 G4int number = 0; << 375 EAxis axis = kUndefined; 151 EAxis axis = kUndefined; << 376 G4String name; 152 G4LogicalVolume* logvol = nullptr; << 377 153 << 378 for (xercesc::DOMNode* iter = replicaElement->getFirstChild(); 154 const xercesc::DOMNamedNodeMap* const attrib << 379 iter != 0; iter = iter->getNextSibling()) 155 divisionvolElement->getAttributes(); << 380 { 156 XMLSize_t attributeCount = attributes->getLe << 381 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 157 G4String unitname; << 158 << 159 for(XMLSize_t attribute_index = 0; attribute << 160 ++attribute_index) << 161 { << 162 xercesc::DOMNode* attribute_node = attribu << 163 382 164 if(attribute_node->getNodeType() != xerces << 383 const xercesc::DOMElement* const child 165 { << 384 = dynamic_cast<xercesc::DOMElement*>(iter); 166 continue; << 385 const G4String tag = Transcode(child->getTagName()); 167 } << 168 386 169 const xercesc::DOMAttr* const attribute = << 387 if (tag=="position") 170 dynamic_cast<xercesc::DOMAttr*>(attribut << 388 { VectorRead(child,position); } else 171 if(attribute == nullptr) << 389 if (tag=="rotation") 172 { << 390 { VectorRead(child,rotation); } else 173 G4Exception("G4GDMLReadStructure::Divisi << 391 if (tag=="positionref") 174 FatalException, "No attribut << 392 { position = GetPosition(GenerateName(RefRead(child))); } else 175 return; << 393 if (tag=="rotationref") 176 } << 394 { rotation = GetRotation(GenerateName(RefRead(child))); } else 177 const G4String attName = Transcode(attrib << 395 if (tag=="direction") 178 const G4String attValue = Transcode(attrib << 396 { axis=AxisRead(child); } else 179 << 397 if (tag=="width") 180 if(attName == "name") << 398 { width=QuantityRead(child); } else 181 { << 399 if (tag=="offset") 182 name = attValue; << 400 { offset=QuantityRead(child); } 183 } << 401 else 184 else if(attName == "unit") << 185 { << 186 unit = G4UnitDefinition::GetValueOf( << 187 unitname = G4UnitDefinition::GetCategory << 188 } << 189 else if(attName == "width") << 190 { << 191 width = eval.Evaluate(attValue); << 192 } << 193 else if(attName == "offset") << 194 { << 195 offset = eval.Evaluate(attValue); << 196 } << 197 else if(attName == "number") << 198 { << 199 number = eval.EvaluateInteger(attValue); << 200 } << 201 else if(attName == "axis") << 202 { << 203 if(attValue == "kXAxis") << 204 { << 205 axis = kXAxis; << 206 } << 207 else if(attValue == "kYAxis") << 208 { << 209 axis = kYAxis; << 210 } << 211 else if(attValue == "kZAxis") << 212 { << 213 axis = kZAxis; << 214 } << 215 else if(attValue == "kRho") << 216 { 402 { 217 axis = kRho; << 403 G4String error_msg = "Unknown tag in ReplicaRead: " + tag; >> 404 G4Exception("G4GDMLReadStructure::ReplicaRead()", "ReadError", >> 405 FatalException, error_msg); 218 } 406 } 219 else if(attValue == "kPhi") << 407 } 220 { << 221 axis = kPhi; << 222 } << 223 } << 224 } << 225 408 226 if(((axis == kXAxis || axis == kYAxis || axi << 409 G4String pv_name = logvol->GetName() + "_PV"; 227 unitname != "Length") || << 410 G4PhysicalVolumesPair pair = G4ReflectionFactory::Instance() 228 ((axis == kRho || axis == kPhi) && unitna << 411 ->Replicate(pv_name,logvol,pMotherLogical,axis,number,width,offset); 229 { << 230 G4Exception("G4GDMLReadStructure::Division << 231 FatalException, "Invalid unit! << 232 } << 233 412 234 width *= unit; << 413 if (pair.first != 0) { GeneratePhysvolName(name,pair.first); } 235 offset *= unit; << 414 if (pair.second != 0) { GeneratePhysvolName(name,pair.second); } 236 415 237 for(xercesc::DOMNode* iter = divisionvolElem << 416 } 238 iter != nullptr; iter << 239 { << 240 if(iter->getNodeType() != xercesc::DOMNode << 241 { << 242 continue; << 243 } << 244 417 245 const xercesc::DOMElement* const child = << 418 EAxis G4GDMLReadStructure:: 246 dynamic_cast<xercesc::DOMElement*>(iter) << 419 AxisRead(const xercesc::DOMElement* const axisElement) 247 if(child == nullptr) << 420 { 248 { << 421 249 G4Exception("G4GDMLReadStructure::Divisi << 422 EAxis axis = kUndefined; 250 FatalException, "No child fo << 251 return; << 252 } << 253 const G4String tag = Transcode(child->getT << 254 423 255 if(tag == "volumeref") << 424 const xercesc::DOMNamedNodeMap* const attributes 256 { << 425 = axisElement->getAttributes(); 257 logvol = GetVolume(GenerateName(RefRead( << 426 XMLSize_t attributeCount = attributes->getLength(); 258 } << 259 } << 260 427 261 if(logvol == nullptr) << 428 for (XMLSize_t attribute_index=0; 262 { << 429 attribute_index<attributeCount; attribute_index++) 263 return; << 430 { 264 } << 431 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 265 432 266 G4PVDivisionFactory::GetInstance(); << 433 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 267 G4PhysicalVolumesPair pair; << 434 { continue; } 268 435 269 G4String pv_name = logvol->GetName() + "_div << 436 const xercesc::DOMAttr* const attribute 270 if((number != 0) && (width == 0.0)) << 437 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 271 { << 438 const G4String attName = Transcode(attribute->getName()); 272 pair = G4ReflectionFactory::Instance()->Di << 439 const G4String attValue = Transcode(attribute->getValue()); 273 pv_name, logvol, pMotherLogical, axis, n << 440 if (attName=="x") 274 } << 441 { if( eval.Evaluate(attValue)==1.) {axis=kXAxis;} } 275 else if((number == 0) && (width != 0.0)) << 442 else if (attName=="y") 276 { << 443 { if( eval.Evaluate(attValue)==1.) {axis=kYAxis;} } 277 pair = G4ReflectionFactory::Instance()->Di << 444 else if (attName=="z") 278 pv_name, logvol, pMotherLogical, axis, w << 445 { if( eval.Evaluate(attValue)==1.) {axis=kZAxis;} } 279 } << 446 else if (attName=="rho") 280 else << 447 { if( eval.Evaluate(attValue)==1.) {axis=kRho;} } 281 { << 448 else if (attName=="phi") 282 pair = G4ReflectionFactory::Instance()->Di << 449 { if( eval.Evaluate(attValue)==1.) {axis=kPhi;} } 283 pv_name, logvol, pMotherLogical, axis, n << 450 } 284 } << 285 451 286 if(pair.first != nullptr) << 452 return axis; 287 { << 288 GeneratePhysvolName(name, pair.first); << 289 } << 290 if(pair.second != nullptr) << 291 { << 292 GeneratePhysvolName(name, pair.second); << 293 } << 294 } 453 } 295 454 296 // ------------------------------------------- << 455 G4double G4GDMLReadStructure:: 297 G4LogicalVolume* G4GDMLReadStructure::FileRead << 456 QuantityRead(const xercesc::DOMElement* const readElement) 298 const xercesc::DOMElement* const fileElement << 299 { 457 { 300 G4String name; << 458 G4double value = 0.0; 301 G4String volname; << 459 G4double unit = 0.0; >> 460 const xercesc::DOMNamedNodeMap* const attributes >> 461 = readElement->getAttributes(); >> 462 XMLSize_t attributeCount = attributes->getLength(); 302 463 303 const xercesc::DOMNamedNodeMap* const attrib << 464 for (XMLSize_t attribute_index=0; 304 fileElement->getAttributes(); << 465 attribute_index<attributeCount; attribute_index++) 305 XMLSize_t attributeCount = attributes->getLe << 466 { >> 467 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 306 468 307 for(XMLSize_t attribute_index = 0; attribute << 469 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 308 ++attribute_index) << 470 { continue; } 309 { << 471 const xercesc::DOMAttr* const attribute 310 xercesc::DOMNode* attribute_node = attribu << 472 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 473 const G4String attName = Transcode(attribute->getName()); >> 474 const G4String attValue = Transcode(attribute->getValue()); 311 475 312 if(attribute_node->getNodeType() != xerces << 476 if (attName=="unit") { unit = eval.Evaluate(attValue); } else 313 { << 477 if (attName=="value"){ value= eval.Evaluate(attValue); } 314 continue; << 478 } 315 } << 316 479 317 const xercesc::DOMAttr* const attribute = << 480 return value*unit; 318 dynamic_cast<xercesc::DOMAttr*>(attribut << 319 if(attribute == nullptr) << 320 { << 321 G4Exception("G4GDMLReadStructure::FileRe << 322 FatalException, "No attribut << 323 return nullptr; << 324 } << 325 const G4String attName = Transcode(attrib << 326 const G4String attValue = Transcode(attrib << 327 << 328 if(attName == "name") << 329 { << 330 name = attValue; << 331 } << 332 else if(attName == "volname") << 333 { << 334 volname = attValue; << 335 } << 336 } << 337 << 338 const G4bool isModule = true; << 339 G4GDMLReadStructure structure; << 340 structure.Read(name, validate, isModule); << 341 << 342 // Register existing auxiliar information de << 343 // << 344 const G4GDMLAuxMapType* aux = structure.GetA << 345 if(!aux->empty()) << 346 { << 347 for(auto pos = aux->cbegin(); pos != aux-> << 348 { << 349 auxMap.insert(std::make_pair(pos->first, << 350 } << 351 } << 352 << 353 // Return volume structure from child module << 354 // << 355 if(volname.empty()) << 356 { << 357 return structure.GetVolume(structure.GetSe << 358 } << 359 else << 360 { << 361 return structure.GetVolume(structure.Gener << 362 } << 363 } 481 } 364 482 365 // ------------------------------------------- << 483 void G4GDMLReadStructure:: 366 void G4GDMLReadStructure::PhysvolRead( << 484 VolumeRead(const xercesc::DOMElement* const volumeElement) 367 const xercesc::DOMElement* const physvolElem << 368 { 485 { 369 G4String name; << 486 G4VSolid* solidPtr = 0; 370 G4LogicalVolume* logvol = nullptr; << 487 G4Material* materialPtr = 0; 371 G4AssemblyVolume* assembly = nullptr; << 488 G4GDMLAuxListType auxList; 372 G4ThreeVector position(0.0, 0.0, 0.0); << 489 373 G4ThreeVector rotation(0.0, 0.0, 0.0); << 490 XMLCh *name_attr = xercesc::XMLString::transcode("name"); 374 G4ThreeVector scale(1.0, 1.0, 1.0); << 491 const G4String name = Transcode(volumeElement->getAttribute(name_attr)); 375 G4int copynumber = 0; << 492 xercesc::XMLString::release(&name_attr); 376 << 377 const xercesc::DOMNamedNodeMap* const attrib << 378 physvolElement->getAttributes(); << 379 XMLSize_t attributeCount = attributes->getLe << 380 << 381 for(XMLSize_t attribute_index = 0; attribute << 382 ++attribute_index) << 383 { << 384 xercesc::DOMNode* attribute_node = attribu << 385 << 386 if(attribute_node->getNodeType() != xerces << 387 { << 388 continue; << 389 } << 390 493 391 const xercesc::DOMAttr* const attribute = << 494 for (xercesc::DOMNode* iter = volumeElement->getFirstChild(); 392 dynamic_cast<xercesc::DOMAttr*>(attribut << 495 iter != 0; iter = iter->getNextSibling()) 393 if(attribute == nullptr) << 496 { 394 { << 497 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 395 G4Exception("G4GDMLReadStructure::Physvo << 396 FatalException, "No attribut << 397 return; << 398 } << 399 const G4String attName = Transcode(attrib << 400 const G4String attValue = Transcode(attrib << 401 498 402 if(attName == "name") << 499 const xercesc::DOMElement* const child 403 { << 500 = dynamic_cast<xercesc::DOMElement*>(iter); 404 name = attValue; << 501 const G4String tag = Transcode(child->getTagName()); 405 } << 406 if(attName == "copynumber") << 407 { << 408 copynumber = eval.EvaluateInteger(attVal << 409 } << 410 } << 411 502 412 for(xercesc::DOMNode* iter = physvolElement- << 503 if (tag=="auxiliary") 413 iter = iter->getNextSi << 504 { auxList.push_back(AuxiliaryRead(child)); } else 414 { << 505 if (tag=="materialref") 415 if(iter->getNodeType() != xercesc::DOMNode << 506 { materialPtr = GetMaterial(GenerateName(RefRead(child),true)); } else 416 { << 507 if (tag=="solidref") 417 continue; << 508 { solidPtr = GetSolid(GenerateName(RefRead(child))); } 418 } << 509 } 419 << 420 const xercesc::DOMElement* const child = << 421 dynamic_cast<xercesc::DOMElement*>(iter) << 422 if(child == nullptr) << 423 { << 424 G4Exception("G4GDMLReadStructure::Physvo << 425 FatalException, "No child fo << 426 return; << 427 } << 428 const G4String tag = Transcode(child->getT << 429 << 430 if(tag == "volumeref") << 431 { << 432 const G4String& child_name = GenerateNam << 433 assembly = GetAssembly << 434 if(assembly == nullptr) << 435 { << 436 logvol = GetVolume(child_name); << 437 } << 438 } << 439 else if(tag == "file") << 440 { << 441 logvol = FileRead(child); << 442 } << 443 else if(tag == "position") << 444 { << 445 VectorRead(child, position); << 446 } << 447 else if(tag == "rotation") << 448 { << 449 VectorRead(child, rotation); << 450 } << 451 else if(tag == "scale") << 452 { << 453 VectorRead(child, scale); << 454 } << 455 else if(tag == "positionref") << 456 { << 457 position = GetPosition(GenerateName(RefR << 458 } << 459 else if(tag == "rotationref") << 460 { << 461 rotation = GetRotation(GenerateName(RefR << 462 } << 463 else if(tag == "scaleref") << 464 { << 465 scale = GetScale(GenerateName(RefRead(ch << 466 } << 467 else << 468 { << 469 G4String error_msg = "Unknown tag in phy << 470 G4Exception("G4GDMLReadStructure::Physvo << 471 FatalException, error_msg); << 472 return; << 473 } << 474 } << 475 510 476 G4Transform3D transform(GetRotationMatrix(ro << 511 pMotherLogical = new G4LogicalVolume(solidPtr,materialPtr, 477 transform = transform * G4Scale3D(scale.x(), << 512 GenerateName(name),0,0,0); 478 513 479 if(pAssembly != nullptr) // Fill assembly s << 514 if (!auxList.empty()) { auxMap[pMotherLogical] = auxList; } 480 { << 481 if(assembly != nullptr) // Case of recurs << 482 { << 483 pAssembly->AddPlacedAssembly(assembly, t << 484 } << 485 if(logvol == nullptr) << 486 { << 487 return; << 488 } << 489 pAssembly->AddPlacedVolume(logvol, transfo << 490 } << 491 else // Generate physical volume tree or do << 492 { << 493 if(assembly != nullptr) << 494 { << 495 assembly->MakeImprint(pMotherLogical, tr << 496 } << 497 else << 498 { << 499 if(logvol == nullptr) << 500 { << 501 return; << 502 } << 503 G4String pv_name = logvol->Get << 504 G4PhysicalVolumesPair pair = G4Reflectio << 505 transform, pv_name, logvol, pMotherLog << 506 515 507 if(pair.first != nullptr) << 516 Volume_contentRead(volumeElement); 508 { << 509 GeneratePhysvolName(name, pair.first); << 510 } << 511 if(pair.second != nullptr) << 512 { << 513 GeneratePhysvolName(name, pair.second) << 514 } << 515 } << 516 } << 517 } 517 } 518 518 519 // ------------------------------------------- << 519 void G4GDMLReadStructure:: 520 void G4GDMLReadStructure::ReplicavolRead( << 520 SkinsurfaceRead(const xercesc::DOMElement* const skinsurfaceElement) 521 const xercesc::DOMElement* const replicavolE << 522 { 521 { 523 G4LogicalVolume* logvol = nullptr; << 522 G4String name; 524 for(xercesc::DOMNode* iter = replicavolEleme << 523 G4LogicalVolume* logvol = 0; 525 iter != nullptr; iter << 524 G4SurfaceProperty* prop = 0; 526 { << 527 if(iter->getNodeType() != xercesc::DOMNode << 528 { << 529 continue; << 530 } << 531 525 532 const xercesc::DOMElement* const child = << 526 const xercesc::DOMNamedNodeMap* const attributes 533 dynamic_cast<xercesc::DOMElement*>(iter) << 527 = skinsurfaceElement->getAttributes(); 534 if(child == nullptr) << 528 XMLSize_t attributeCount = attributes->getLength(); 535 { << 536 G4Exception("G4GDMLReadStructure::Replic << 537 FatalException, "No child fo << 538 return; << 539 } << 540 const G4String tag = Transcode(child->getT << 541 529 542 if(tag == "volumeref") << 530 for (XMLSize_t attribute_index=0; 543 { << 531 attribute_index<attributeCount; attribute_index++) 544 logvol = GetVolume(GenerateName(RefRead( << 532 { 545 } << 533 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 546 else if(tag == "replicate_along_axis") << 547 { << 548 if(logvol) << 549 { << 550 ReplicaRead(child, logvol, number); << 551 } << 552 } << 553 else << 554 { << 555 G4String error_msg = "Unknown tag in Rep << 556 G4Exception("G4GDMLReadStructure::Replic << 557 FatalException, error_msg); << 558 } << 559 } << 560 } << 561 534 562 // ------------------------------------------- << 535 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 563 void G4GDMLReadStructure::ReplicaRead( << 536 { continue; } 564 const xercesc::DOMElement* const replicaElem << 565 G4int number) << 566 { << 567 G4double width = 0.0; << 568 G4double offset = 0.0; << 569 G4ThreeVector position(0.0, 0.0, 0.0); << 570 G4ThreeVector rotation(0.0, 0.0, 0.0); << 571 EAxis axis = kUndefined; << 572 G4String name; << 573 537 574 for(xercesc::DOMNode* iter = replicaElement- << 538 const xercesc::DOMAttr* const attribute 575 iter = iter->getNextSi << 539 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 576 { << 540 const G4String attName = Transcode(attribute->getName()); 577 if(iter->getNodeType() != xercesc::DOMNode << 541 const G4String attValue = Transcode(attribute->getValue()); 578 { << 579 continue; << 580 } << 581 542 582 const xercesc::DOMElement* const child = << 543 if (attName=="name") 583 dynamic_cast<xercesc::DOMElement*>(iter) << 544 { name = GenerateName(attValue); } else 584 if(child == nullptr) << 545 if (attName=="surfaceproperty") 585 { << 546 { prop = GetSurfaceProperty(GenerateName(attValue)); } 586 G4Exception("G4GDMLReadStructure::Replic << 547 } 587 FatalException, "No child fo << 588 return; << 589 } << 590 const G4String tag = Transcode(child->getT << 591 548 592 if(tag == "position") << 549 for (xercesc::DOMNode* iter = skinsurfaceElement->getFirstChild(); 593 { << 550 iter != 0; iter = iter->getNextSibling()) 594 VectorRead(child, position); << 551 { 595 } << 552 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 596 else if(tag == "rotation") << 597 { << 598 VectorRead(child, rotation); << 599 } << 600 else if(tag == "positionref") << 601 { << 602 position = GetPosition(GenerateName(RefR << 603 } << 604 else if(tag == "rotationref") << 605 { << 606 rotation = GetRotation(GenerateName(RefR << 607 } << 608 else if(tag == "direction") << 609 { << 610 axis = AxisRead(child); << 611 } << 612 else if(tag == "width") << 613 { << 614 width = QuantityRead(child); << 615 } << 616 else if(tag == "offset") << 617 { << 618 offset = QuantityRead(child); << 619 } << 620 else << 621 { << 622 G4String error_msg = "Unknown tag in Rep << 623 G4Exception("G4GDMLReadStructure::Replic << 624 FatalException, error_msg); << 625 } << 626 } << 627 553 628 G4String pv_name = logvol->GetName << 554 const xercesc::DOMElement* const child 629 G4PhysicalVolumesPair pair = G4ReflectionFac << 555 = dynamic_cast<xercesc::DOMElement*>(iter); 630 pv_name, logvol, pMotherLogical, axis, num << 556 const G4String tag = Transcode(child->getTagName()); 631 557 632 if(pair.first != nullptr) << 558 if (tag=="volumeref") 633 { << 559 { 634 GeneratePhysvolName(name, pair.first); << 560 logvol = GetVolume(GenerateName(RefRead(child))); 635 } << 561 } 636 if(pair.second != nullptr) << 562 else 637 { << 563 { 638 GeneratePhysvolName(name, pair.second); << 564 G4String error_msg = "Unknown tag in skinsurface: " + tag; 639 } << 565 G4Exception("G4GDMLReadStructure::SkinsurfaceRead()", "ReadError", >> 566 FatalException, error_msg); >> 567 } >> 568 } >> 569 >> 570 new G4LogicalSkinSurface(Strip(name),logvol,prop); 640 } 571 } 641 572 642 // ------------------------------------------- << 573 void G4GDMLReadStructure:: 643 EAxis G4GDMLReadStructure::AxisRead( << 574 Volume_contentRead(const xercesc::DOMElement* const volumeElement) 644 const xercesc::DOMElement* const axisElement << 645 { 575 { 646 EAxis axis = kUndefined; << 576 for (xercesc::DOMNode* iter = volumeElement->getFirstChild(); >> 577 iter != 0; iter = iter->getNextSibling()) >> 578 { >> 579 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 647 580 648 const xercesc::DOMNamedNodeMap* const attrib << 581 const xercesc::DOMElement* const child 649 axisElement->getAttributes(); << 582 = dynamic_cast<xercesc::DOMElement*>(iter); 650 XMLSize_t attributeCount = attributes->getLe << 583 const G4String tag = Transcode(child->getTagName()); 651 584 652 for(XMLSize_t attribute_index = 0; attribute << 585 if ((tag=="auxiliary") || (tag=="materialref") || (tag=="solidref")) 653 ++attribute_index) << 654 { << 655 xercesc::DOMNode* attribute_node = attribu << 656 << 657 if(attribute_node->getNodeType() != xerces << 658 { << 659 continue; << 660 } << 661 << 662 const xercesc::DOMAttr* const attribute = << 663 dynamic_cast<xercesc::DOMAttr*>(attribut << 664 if(attribute == nullptr) << 665 { << 666 G4Exception("G4GDMLReadStructure::AxisRe << 667 FatalException, "No attribut << 668 return axis; << 669 } << 670 const G4String attName = Transcode(attrib << 671 const G4String attValue = Transcode(attrib << 672 if(attName == "x") << 673 { << 674 if(eval.Evaluate(attValue) == 1.) << 675 { 586 { 676 axis = kXAxis; << 587 // These are already processed in VolumeRead() 677 } 588 } 678 } << 589 else if (tag=="paramvol") 679 else if(attName == "y") << 680 { << 681 if(eval.Evaluate(attValue) == 1.) << 682 { 590 { 683 axis = kYAxis; << 591 ParamvolRead(child,pMotherLogical); 684 } 592 } 685 } << 593 else if (tag=="physvol") 686 else if(attName == "z") << 687 { << 688 if(eval.Evaluate(attValue) == 1.) << 689 { 594 { 690 axis = kZAxis; << 595 PhysvolRead(child); 691 } 596 } 692 } << 597 else if (tag=="replicavol") 693 else if(attName == "rho") << 694 { << 695 if(eval.Evaluate(attValue) == 1.) << 696 { 598 { 697 axis = kRho; << 599 G4int number = 1; >> 600 const xercesc::DOMNamedNodeMap* const attributes >> 601 = child->getAttributes(); >> 602 XMLSize_t attributeCount = attributes->getLength(); >> 603 for (XMLSize_t attribute_index=0; >> 604 attribute_index<attributeCount; attribute_index++) >> 605 { >> 606 xercesc::DOMNode* attribute_node >> 607 = attributes->item(attribute_index); >> 608 if (attribute_node->getNodeType()!=xercesc::DOMNode::ATTRIBUTE_NODE) >> 609 { >> 610 continue; >> 611 } >> 612 const xercesc::DOMAttr* const attribute >> 613 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 614 const G4String attName = Transcode(attribute->getName()); >> 615 const G4String attValue = Transcode(attribute->getValue()); >> 616 if (attName=="number") >> 617 { >> 618 number = eval.EvaluateInteger(attValue); >> 619 } >> 620 } >> 621 ReplicavolRead(child,number); 698 } 622 } 699 } << 623 else if (tag=="divisionvol") 700 else if(attName == "phi") << 701 { << 702 if(eval.Evaluate(attValue) == 1.) << 703 { 624 { 704 axis = kPhi; << 625 DivisionvolRead(child); 705 } 626 } 706 } << 627 else if (tag=="loop") 707 } << 708 << 709 return axis; << 710 } << 711 << 712 // ------------------------------------------- << 713 G4double G4GDMLReadStructure::QuantityRead( << 714 const xercesc::DOMElement* const readElement << 715 { << 716 G4double value = 0.0; << 717 G4double unit = 0.0; << 718 const xercesc::DOMNamedNodeMap* const attrib << 719 readElement->getAttributes(); << 720 XMLSize_t attributeCount = attributes->getLe << 721 << 722 for(XMLSize_t attribute_index = 0; attribute << 723 ++attribute_index) << 724 { << 725 xercesc::DOMNode* attribute_node = attribu << 726 << 727 if(attribute_node->getNodeType() != xerces << 728 { << 729 continue; << 730 } << 731 const xercesc::DOMAttr* const attribute = << 732 dynamic_cast<xercesc::DOMAttr*>(attribut << 733 if(attribute == nullptr) << 734 { << 735 G4Exception("G4GDMLReadStructure::Quanti << 736 FatalException, "No attribut << 737 return value; << 738 } << 739 const G4String attName = Transcode(attrib << 740 const G4String attValue = Transcode(attrib << 741 << 742 if(attName == "unit") << 743 { << 744 unit = G4UnitDefinition::GetValueOf(attV << 745 if(G4UnitDefinition::GetCategory(attValu << 746 G4UnitDefinition::GetCategory(attValu << 747 { 628 { 748 G4Exception("G4GDMLReadStructure::Quan << 629 LoopRead(child,&G4GDMLRead::Volume_contentRead); 749 FatalException, << 750 "Invalid unit for length o << 751 } 630 } 752 } << 631 else 753 else if(attName == "value") << 632 { 754 { << 633 G4cout << "Treating unknown GDML tag in volume '" << tag 755 value = eval.Evaluate(attValue); << 634 << "' as GDML extension..." << G4endl; 756 } << 635 } 757 } << 636 } 758 << 759 return value * unit; << 760 } << 761 << 762 // ------------------------------------------- << 763 void G4GDMLReadStructure::VolumeRead( << 764 const xercesc::DOMElement* const volumeEleme << 765 { << 766 G4VSolid* solidPtr = nullptr; << 767 G4Material* materialPtr = nullptr; << 768 G4GDMLAuxListType auxList; << 769 << 770 XMLCh* name_attr = xercesc::XMLString::tr << 771 const G4String name = Transcode(volumeElemen << 772 xercesc::XMLString::release(&name_attr); << 773 << 774 for(xercesc::DOMNode* iter = volumeElement-> << 775 iter = iter->getNextSi << 776 { << 777 if(iter->getNodeType() != xercesc::DOMNode << 778 { << 779 continue; << 780 } << 781 << 782 const xercesc::DOMElement* const child = << 783 dynamic_cast<xercesc::DOMElement*>(iter) << 784 if(child == nullptr) << 785 { << 786 G4Exception("G4GDMLReadStructure::Volume << 787 FatalException, "No child fo << 788 return; << 789 } << 790 const G4String tag = Transcode(child->getT << 791 << 792 if(tag == "auxiliary") << 793 { << 794 auxList.push_back(AuxiliaryRead(child)); << 795 } << 796 else if(tag == "materialref") << 797 { << 798 materialPtr = GetMaterial(GenerateName(R << 799 } << 800 else if(tag == "solidref") << 801 { << 802 solidPtr = GetSolid(GenerateName(RefRead << 803 } << 804 } << 805 << 806 pMotherLogical = << 807 new G4LogicalVolume(solidPtr, materialPtr, << 808 << 809 if(!auxList.empty()) << 810 { << 811 auxMap[pMotherLogical] = auxList; << 812 } << 813 << 814 Volume_contentRead(volumeElement); << 815 } << 816 << 817 // ------------------------------------------- << 818 void G4GDMLReadStructure::AssemblyRead( << 819 const xercesc::DOMElement* const assemblyEle << 820 { << 821 XMLCh* name_attr = xercesc::XMLString::tr << 822 const G4String name = Transcode(assemblyElem << 823 xercesc::XMLString::release(&name_attr); << 824 << 825 G4AssemblyVolume* pAssembly = new G4Assembly << 826 auto aName = GenerateName(name); << 827 if(reverseSearch) << 828 { << 829 assemblyMap.insert_or_assign(aName, pAssem << 830 } << 831 else << 832 { << 833 assemblyMap.insert(std::make_pair(aName, p << 834 } << 835 << 836 for(xercesc::DOMNode* iter = assemblyElement << 837 iter != nullptr; iter << 838 { << 839 if(iter->getNodeType() != xercesc::DOMNode << 840 { << 841 continue; << 842 } << 843 const xercesc::DOMElement* const child = << 844 dynamic_cast<xercesc::DOMElement*>(iter) << 845 if(child == nullptr) << 846 { << 847 G4Exception("G4GDMLReadStructure::Assemb << 848 FatalException, "No child fo << 849 return; << 850 } << 851 const G4String tag = Transcode(child->getT << 852 << 853 if(tag == "physvol") << 854 { << 855 PhysvolRead(child, pAssembly); << 856 } << 857 else << 858 { << 859 G4cout << "Unsupported GDML tag '" << ta << 860 << "' for Geant4 assembly structu << 861 } << 862 } << 863 } 637 } 864 638 865 // ------------------------------------------- << 639 void G4GDMLReadStructure:: 866 void G4GDMLReadStructure::SkinSurfaceRead( << 640 StructureRead(const xercesc::DOMElement* const structureElement) 867 const xercesc::DOMElement* const skinsurface << 868 { 641 { 869 G4String name; << 642 G4cout << "G4GDML: Reading structure..." << G4endl; 870 G4LogicalVolume* logvol = nullptr; << 871 G4SurfaceProperty* prop = nullptr; << 872 << 873 const xercesc::DOMNamedNodeMap* const attrib << 874 skinsurfaceElement->getAttributes(); << 875 XMLSize_t attributeCount = attributes->getLe << 876 << 877 for(XMLSize_t attribute_index = 0; attribute << 878 ++attribute_index) << 879 { << 880 xercesc::DOMNode* attribute_node = attribu << 881 << 882 if(attribute_node->getNodeType() != xerces << 883 { << 884 continue; << 885 } << 886 << 887 const xercesc::DOMAttr* const attribute = << 888 dynamic_cast<xercesc::DOMAttr*>(attribut << 889 if(attribute == nullptr) << 890 { << 891 G4Exception("G4GDMLReadStructure::Skinsu << 892 FatalException, "No attribut << 893 return; << 894 } << 895 const G4String attName = Transcode(attrib << 896 const G4String attValue = Transcode(attrib << 897 << 898 if(attName == "name") << 899 { << 900 name = GenerateName(attValue); << 901 } << 902 else if(attName == "surfaceproperty") << 903 { << 904 prop = GetSurfaceProperty(GenerateName(a << 905 } << 906 } << 907 << 908 for(xercesc::DOMNode* iter = skinsurfaceElem << 909 iter != nullptr; iter << 910 { << 911 if(iter->getNodeType() != xercesc::DOMNode << 912 { << 913 continue; << 914 } << 915 643 916 const xercesc::DOMElement* const child = << 644 for (xercesc::DOMNode* iter = structureElement->getFirstChild(); 917 dynamic_cast<xercesc::DOMElement*>(iter) << 645 iter != 0; iter = iter->getNextSibling()) 918 if(child == nullptr) << 646 { 919 { << 647 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 920 G4Exception("G4GDMLReadStructure::Skinsu << 921 FatalException, "No child fo << 922 return; << 923 } << 924 const G4String tag = Transcode(child->getT << 925 << 926 if(tag == "volumeref") << 927 { << 928 logvol = GetVolume(GenerateName(RefRead( << 929 } << 930 else << 931 { << 932 G4String error_msg = "Unknown tag in ski << 933 G4Exception("G4GDMLReadStructure::Skinsu << 934 FatalException, error_msg); << 935 } << 936 } << 937 << 938 new G4LogicalSkinSurface(Strip(name), logvol << 939 } << 940 << 941 // ------------------------------------------- << 942 void G4GDMLReadStructure::Volume_contentRead( << 943 const xercesc::DOMElement* const volumeEleme << 944 { << 945 for(xercesc::DOMNode* iter = volumeElement-> << 946 iter = iter->getNextSi << 947 { << 948 if(iter->getNodeType() != xercesc::DOMNode << 949 { << 950 continue; << 951 } << 952 648 953 const xercesc::DOMElement* const child = << 649 const xercesc::DOMElement* const child 954 dynamic_cast<xercesc::DOMElement*>(iter) << 650 = dynamic_cast<xercesc::DOMElement*>(iter); 955 if(child == nullptr) << 651 const G4String tag = Transcode(child->getTagName()); 956 { << 957 G4Exception("G4GDMLReadStructure::Volume << 958 FatalException, "No child fo << 959 return; << 960 } << 961 const G4String tag = Transcode(child->getT << 962 652 963 if((tag == "auxiliary") || (tag == "materi << 653 if (tag=="bordersurface") { BordersurfaceRead(child); } else 964 { << 654 if (tag=="skinsurface") { SkinsurfaceRead(child); } else 965 // These are already processed in Volume << 655 if (tag=="volume") { VolumeRead(child); } else 966 } << 656 if (tag=="loop") { LoopRead(child,&G4GDMLRead::StructureRead); } 967 else if(tag == "paramvol") << 657 else 968 { << 969 ParamvolRead(child, pMotherLogical); << 970 } << 971 else if(tag == "physvol") << 972 { << 973 PhysvolRead(child); << 974 } << 975 else if(tag == "replicavol") << 976 { << 977 G4int number = 1; << 978 const xercesc::DOMNamedNodeMap* const at << 979 XMLSize_t attributeCount = attributes->g << 980 for(XMLSize_t attribute_index = 0; attri << 981 ++attribute_index) << 982 { 658 { 983 xercesc::DOMNode* attribute_node = att << 659 G4String error_msg = "Unknown tag in structure: " + tag; 984 if(attribute_node->getNodeType() != xe << 660 G4Exception("G4GDMLReadStructure::StructureRead()", 985 { << 661 "ReadError", FatalException, error_msg); 986 continue; << 987 } << 988 const xercesc::DOMAttr* const attribut << 989 dynamic_cast<xercesc::DOMAttr*>(attr << 990 if(attribute == nullptr) << 991 { << 992 G4Exception("G4GDMLReadStructure::Vo << 993 "InvalidRead", FatalExce << 994 return; << 995 } << 996 const G4String attName = Transcode(at << 997 const G4String attValue = Transcode(at << 998 if(attName == "number") << 999 { << 1000 number = eval.EvaluateInteger(attVa << 1001 } << 1002 } 662 } 1003 ReplicavolRead(child, number); << 663 } 1004 } << 1005 else if(tag == "divisionvol") << 1006 { << 1007 DivisionvolRead(child); << 1008 } << 1009 else if(tag == "loop") << 1010 { << 1011 LoopRead(child, &G4GDMLRead::Volume_con << 1012 } << 1013 else << 1014 { << 1015 G4cout << "Treating unknown GDML tag in << 1016 << "' as GDML extension..." << G << 1017 } << 1018 } << 1019 } << 1020 << 1021 // ------------------------------------------ << 1022 void G4GDMLReadStructure::StructureRead( << 1023 const xercesc::DOMElement* const structureE << 1024 { << 1025 #ifdef G4VERBOSE << 1026 G4cout << "G4GDML: Reading structure..." << << 1027 #endif << 1028 for(xercesc::DOMNode* iter = structureEleme << 1029 iter != nullptr; iter << 1030 { << 1031 if(iter->getNodeType() != xercesc::DOMNod << 1032 { << 1033 continue; << 1034 } << 1035 << 1036 const xercesc::DOMElement* const child = << 1037 dynamic_cast<xercesc::DOMElement*>(iter << 1038 if(child == nullptr) << 1039 { << 1040 G4Exception("G4GDMLReadStructure::Struc << 1041 FatalException, "No child f << 1042 return; << 1043 } << 1044 const G4String tag = Transcode(child->get << 1045 << 1046 if(tag == "bordersurface") << 1047 { << 1048 BorderSurfaceRead(child); << 1049 } << 1050 else if(tag == "skinsurface") << 1051 { << 1052 SkinSurfaceRead(child); << 1053 } << 1054 else if(tag == "volume") << 1055 { << 1056 VolumeRead(child); << 1057 } << 1058 else if(tag == "assembly") << 1059 { << 1060 AssemblyRead(child); << 1061 } << 1062 else if(tag == "loop") << 1063 { << 1064 LoopRead(child, &G4GDMLRead::StructureR << 1065 } << 1066 else << 1067 { << 1068 G4String error_msg = "Unknown tag in st << 1069 G4Exception("G4GDMLReadStructure::Struc << 1070 FatalException, error_msg); << 1071 } << 1072 } << 1073 } 664 } 1074 665 1075 // ------------------------------------------ << 666 G4VPhysicalVolume* G4GDMLReadStructure:: 1076 G4VPhysicalVolume* G4GDMLReadStructure::GetPh << 667 GetPhysvol(const G4String& ref) const 1077 { 668 { 1078 G4VPhysicalVolume* physvolPtr << 669 G4VPhysicalVolume* physvolPtr = 1079 = G4PhysicalVolumeStore::GetInstance()->G << 670 G4PhysicalVolumeStore::GetInstance()->GetVolume(ref,false); 1080 671 1081 if(physvolPtr == nullptr) << 672 if (!physvolPtr) 1082 { << 673 { 1083 G4String error_msg = "Referenced physvol << 674 G4String error_msg = "Referenced physvol '" + ref + "' was not found!"; 1084 G4Exception("G4GDMLReadStructure::GetPhys << 675 G4Exception("G4GDMLReadStructure::GetPhysvol()", "ReadError", 1085 FatalException, error_msg); << 676 FatalException, error_msg); 1086 } << 677 } 1087 678 1088 return physvolPtr; << 679 return physvolPtr; 1089 } 680 } 1090 681 1091 // ------------------------------------------ << 682 G4LogicalVolume* G4GDMLReadStructure:: 1092 G4LogicalVolume* G4GDMLReadStructure::GetVolu << 683 GetVolume(const G4String& ref) const 1093 { 684 { 1094 G4LogicalVolume* volumePtr << 685 G4LogicalVolume *volumePtr 1095 = G4LogicalVolumeStore::GetInstance()->Ge << 686 = G4LogicalVolumeStore::GetInstance()->GetVolume(ref,false); 1096 687 1097 if(volumePtr == nullptr) << 688 if (!volumePtr) 1098 { << 689 { 1099 G4String error_msg = "Referenced volume ' << 690 G4String error_msg = "Referenced volume '" + ref + "' was not found!"; 1100 G4Exception("G4GDMLReadStructure::GetVolu << 691 G4Exception("G4GDMLReadStructure::GetVolume()", "ReadError", 1101 error_msg); << 692 FatalException, error_msg); 1102 } << 693 } 1103 694 1104 return volumePtr; << 695 return volumePtr; 1105 } 696 } 1106 697 1107 // ------------------------------------------ << 698 G4GDMLAuxListType G4GDMLReadStructure:: 1108 G4AssemblyVolume* G4GDMLReadStructure::GetAss << 699 GetVolumeAuxiliaryInformation(const G4LogicalVolume* const logvol) 1109 { 700 { 1110 auto pos = assemblyMap.find(ref); << 701 if (auxMap.find(logvol) != auxMap.end()) { return auxMap[logvol]; } 1111 if(pos != assemblyMap.cend()) << 702 else { return G4GDMLAuxListType(); } 1112 { << 1113 return pos->second; << 1114 } << 1115 return nullptr; << 1116 } 703 } 1117 704 1118 // ------------------------------------------ << 705 const G4GDMLAuxMapType* G4GDMLReadStructure:: 1119 G4GDMLAuxListType G4GDMLReadStructure::GetVol << 706 GetAuxMap() const 1120 G4LogicalVolume* logvol) const << 1121 { 707 { 1122 auto pos = auxMap.find(logvol); << 708 return &auxMap; 1123 if(pos != auxMap.cend()) << 1124 { << 1125 return pos->second; << 1126 } << 1127 else << 1128 { << 1129 return G4GDMLAuxListType(); << 1130 } << 1131 } 709 } 1132 710 1133 // ------------------------------------------ << 711 G4VPhysicalVolume* G4GDMLReadStructure:: 1134 G4VPhysicalVolume* G4GDMLReadStructure::GetWo << 712 GetWorldVolume(const G4String& setupName) 1135 const G4String& setupName) << 713 { 1136 { << 714 G4LogicalVolume* volume = GetVolume(Strip(GetSetup(setupName))); 1137 G4String sname = GetSetup(setupName); << 715 volume->SetVisAttributes(G4VisAttributes::Invisible); 1138 if(sname == "") << 716 G4VPhysicalVolume* pvWorld = 1139 { << 717 new G4PVPlacement(0,G4ThreeVector(0,0,0),volume,setupName,0,0,0); 1140 return nullptr; << 718 return pvWorld; 1141 } << 1142 << 1143 G4LogicalVolume* volume = GetVolume(Generat << 1144 volume->SetVisAttributes(G4VisAttributes::G << 1145 << 1146 G4VPhysicalVolume* pvWorld = nullptr; << 1147 << 1148 if(setuptoPV[setupName]) << 1149 { << 1150 pvWorld = setuptoPV[setupName]; << 1151 } << 1152 else << 1153 { << 1154 pvWorld = new G4PVPlacement(nullptr, G4Th << 1155 volume->GetNa << 1156 setuptoPV[setupName] = pvWorld; << 1157 } << 1158 return pvWorld; << 1159 } << 1160 << 1161 // ------------------------------------------ << 1162 void G4GDMLReadStructure::Clear() << 1163 { << 1164 eval.Clear(); << 1165 setuptoPV.clear(); << 1166 auxMap.clear(); << 1167 } 719 } 1168 720