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