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