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 // G4GDMLReadDefine implementation << 26 // $Id: G4GDMLReadDefine.cc 68053 2013-03-13 14:39:51Z gcosmo $ >> 27 // >> 28 // class G4GDMLReadDefine Implementation >> 29 // >> 30 // Original author: Zoltan Torzsok, November 2007 27 // 31 // 28 // Author: Zoltan Torzsok, November 2007 << 29 // ------------------------------------------- 32 // -------------------------------------------------------------------- 30 33 31 #include "G4GDMLReadDefine.hh" 34 #include "G4GDMLReadDefine.hh" 32 #include "G4UnitsTable.hh" << 33 35 34 // G4GDMLMatrix ------------------------------ << 35 << 36 // ------------------------------------------- << 37 G4GDMLMatrix::G4GDMLMatrix() 36 G4GDMLMatrix::G4GDMLMatrix() >> 37 : m(0), rows(0), cols(0) 38 { 38 { 39 } 39 } 40 40 41 // ------------------------------------------- << 41 G4GDMLMatrix::G4GDMLMatrix(size_t rows0, size_t cols0) 42 G4GDMLMatrix::G4GDMLMatrix(std::size_t rows0, << 42 { 43 { << 43 if ((rows0==0) || (cols0==0)) 44 if((rows0 == 0) || (cols0 == 0)) << 44 { 45 { << 45 G4Exception("G4GDMLMatrix::G4GDMLMatrix(r,c)", "InvalidSetup", 46 G4Exception("G4GDMLMatrix::G4GDMLMatrix(r, << 46 FatalException, "Zero indeces as arguments!?"); 47 FatalException, "Zero indices << 47 } 48 } << 48 rows = rows0; 49 rows = rows0; << 49 cols = cols0; 50 cols = cols0; << 50 m = new G4double[rows*cols]; 51 m = new G4double[rows * cols]; << 52 } 51 } 53 52 54 // ------------------------------------------- << 55 G4GDMLMatrix::G4GDMLMatrix(const G4GDMLMatrix& 53 G4GDMLMatrix::G4GDMLMatrix(const G4GDMLMatrix& rhs) >> 54 : m(0), rows(0), cols(0) 56 { 55 { 57 if(rhs.m) << 56 if (rhs.m) 58 { << 57 { 59 rows = rhs.rows; << 58 rows = rhs.rows; 60 cols = rhs.cols; << 59 cols = rhs.cols; 61 m = new G4double[rows * cols]; << 60 m = new G4double[rows*cols]; 62 for(std::size_t i = 0; i < rows * cols; ++ << 61 for (size_t i=0; i<rows*cols; i++) { m[i] = rhs.m[i]; } 63 { << 62 } 64 m[i] = rhs.m[i]; << 65 } << 66 } << 67 } 63 } 68 64 69 // ------------------------------------------- << 70 G4GDMLMatrix& G4GDMLMatrix::operator=(const G4 65 G4GDMLMatrix& G4GDMLMatrix::operator=(const G4GDMLMatrix& rhs) 71 { 66 { 72 // Check assignment to self << 67 // Check assignment to self 73 // << 68 // 74 if(this == &rhs) << 69 if (this == &rhs) { return *this; } 75 { << 70 76 return *this; << 71 // Copy data 77 } << 72 // 78 << 73 rows = rhs.rows; 79 // Copy data << 74 cols = rhs.cols; 80 // << 75 if (rhs.m) 81 rows = rhs.rows; << 76 { 82 cols = rhs.cols; << 77 m = new G4double[rows*cols]; 83 if(rhs.m) << 78 for (size_t i=0; i<rows*cols; i++) { m[i] = rhs.m[i]; } 84 { << 79 } 85 m = new G4double[rows * cols]; << 80 else 86 for(std::size_t i = 0; i < rows * cols; ++ << 81 { 87 { << 82 m = 0; 88 m[i] = rhs.m[i]; << 83 } 89 } << 90 } << 91 else << 92 { << 93 m = nullptr; << 94 } << 95 84 96 return *this; << 85 return *this; 97 } 86 } 98 87 99 // ------------------------------------------- << 100 G4GDMLMatrix::~G4GDMLMatrix() 88 G4GDMLMatrix::~G4GDMLMatrix() 101 { 89 { 102 delete[] m; << 90 delete [] m; 103 } 91 } 104 92 105 // ------------------------------------------- << 93 void G4GDMLMatrix::Set(size_t r,size_t c,G4double a) 106 void G4GDMLMatrix::Set(std::size_t r, std::siz << 94 { 107 { << 95 if (r>=rows || c>=cols) 108 if(r >= rows || c >= cols) << 96 { 109 { << 97 G4Exception("G4GDMLMatrix::set()", "InvalidSetup", 110 G4Exception("G4GDMLMatrix::set()", "Invali << 98 FatalException, "Index out of range!"); 111 "Index out of range!"); << 99 } 112 } << 100 m[cols*r+c] = a; 113 m[cols * r + c] = a; << 114 } 101 } 115 102 116 // ------------------------------------------- << 103 G4double G4GDMLMatrix::Get(size_t r,size_t c) const 117 G4double G4GDMLMatrix::Get(std::size_t r, std: << 104 { 118 { << 105 if (r>=rows || c>=cols) 119 if(r >= rows || c >= cols) << 106 { 120 { << 107 G4Exception("G4GDMLMatrix::get()", "InvalidSetup", 121 G4Exception("G4GDMLMatrix::get()", "Invali << 108 FatalException, "Index out of range!"); 122 "Index out of range!"); << 109 } 123 } << 110 return m[cols*r+c]; 124 return m[cols * r + c]; << 125 } 111 } 126 112 127 // ------------------------------------------- << 113 size_t G4GDMLMatrix::GetRows() const 128 std::size_t G4GDMLMatrix::GetRows() const << 129 { 114 { 130 return rows; << 115 return rows; 131 } 116 } 132 117 133 // ------------------------------------------- << 118 size_t G4GDMLMatrix::GetCols() const 134 std::size_t G4GDMLMatrix::GetCols() const << 135 { 119 { 136 return cols; << 120 return cols; 137 } 121 } 138 122 139 // G4GDMLReadDefine -------------------------- << 123 G4GDMLReadDefine::G4GDMLReadDefine() : G4GDMLRead() 140 << 141 // ------------------------------------------- << 142 G4GDMLReadDefine::G4GDMLReadDefine() << 143 : G4GDMLRead() << 144 { 124 { 145 } 125 } 146 126 147 // ------------------------------------------- << 148 G4GDMLReadDefine::~G4GDMLReadDefine() 127 G4GDMLReadDefine::~G4GDMLReadDefine() 149 { 128 { 150 } 129 } 151 130 152 // ------------------------------------------- << 131 G4RotationMatrix 153 G4RotationMatrix G4GDMLReadDefine::GetRotation << 132 G4GDMLReadDefine::GetRotationMatrix(const G4ThreeVector& angles) 154 const G4ThreeVector& angles) << 155 { 133 { 156 G4RotationMatrix rot; << 134 G4RotationMatrix rot; 157 135 158 rot.rotateX(angles.x()); << 136 rot.rotateX(angles.x()); 159 rot.rotateY(angles.y()); << 137 rot.rotateY(angles.y()); 160 rot.rotateZ(angles.z()); << 138 rot.rotateZ(angles.z()); 161 rot.rectify(); // Rectify matrix from possi << 162 139 163 return rot; << 140 return rot; 164 } 141 } 165 142 166 // ------------------------------------------- << 143 void 167 void G4GDMLReadDefine::ConstantRead( << 144 G4GDMLReadDefine::ConstantRead(const xercesc::DOMElement* const constantElement) 168 const xercesc::DOMElement* const constantEle << 169 { 145 { 170 G4String name = ""; << 146 G4String name = ""; 171 G4double value = 0.0; << 147 G4double value = 0.0; >> 148 >> 149 const xercesc::DOMNamedNodeMap* const attributes >> 150 = constantElement->getAttributes(); >> 151 XMLSize_t attributeCount = attributes->getLength(); 172 152 173 const xercesc::DOMNamedNodeMap* const attrib << 153 for (XMLSize_t attribute_index=0; 174 constantElement->getAttributes(); << 154 attribute_index<attributeCount; attribute_index++) 175 XMLSize_t attributeCount = attributes->getLe << 155 { 176 << 156 xercesc::DOMNode* node = attributes->item(attribute_index); 177 for(XMLSize_t attribute_index = 0; attribute << 178 ++attribute_index) << 179 { << 180 xercesc::DOMNode* node = attributes->item( << 181 << 182 if(node->getNodeType() != xercesc::DOMNode << 183 { << 184 continue; << 185 } << 186 << 187 const xercesc::DOMAttr* const attribute = << 188 dynamic_cast<xercesc::DOMAttr*>(node); << 189 if(attribute == nullptr) << 190 { << 191 G4Exception("G4GDMLRead::ConstantRead()" << 192 "No attribute found!"); << 193 return; << 194 } << 195 const G4String attName = Transcode(attrib << 196 const G4String attValue = Transcode(attrib << 197 << 198 if(attName == "name") << 199 { << 200 name = attValue; << 201 } << 202 else if(attName == "value") << 203 { << 204 value = eval.Evaluate(attValue); << 205 } << 206 } << 207 157 208 eval.DefineConstant(name, value); << 158 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } >> 159 >> 160 const xercesc::DOMAttr* const attribute >> 161 = dynamic_cast<xercesc::DOMAttr*>(node); >> 162 if (!attribute) >> 163 { >> 164 G4Exception("G4GDMLRead::ConstantRead()", "InvalidRead", >> 165 FatalException, "No attribute found!"); >> 166 return; >> 167 } >> 168 const G4String attName = Transcode(attribute->getName()); >> 169 const G4String attValue = Transcode(attribute->getValue()); >> 170 >> 171 if (attName=="name") { name = attValue; } else >> 172 if (attName=="value") { value = eval.Evaluate(attValue); } >> 173 } >> 174 >> 175 eval.DefineConstant(name,value); 209 } 176 } 210 177 211 // ------------------------------------------- << 178 void 212 void G4GDMLReadDefine::ExpressionRead( << 179 G4GDMLReadDefine::ExpressionRead(const xercesc::DOMElement* const expElement) 213 const xercesc::DOMElement* const expElement) << 214 { 180 { 215 G4String name = ""; << 181 G4String name = ""; 216 G4double value = 0.0; << 182 G4double value = 0.0; 217 183 218 const xercesc::DOMNamedNodeMap* const attrib << 184 const xercesc::DOMNamedNodeMap* const attributes 219 expElement->getAttributes(); << 185 = expElement->getAttributes(); 220 XMLSize_t attributeCount = attributes->getLe << 186 XMLSize_t attributeCount = attributes->getLength(); 221 << 187 222 for(XMLSize_t attribute_index = 0; attribute << 188 for (XMLSize_t attribute_index=0; 223 ++attribute_index) << 189 attribute_index<attributeCount; attribute_index++) 224 { << 190 { 225 xercesc::DOMNode* node = attributes->item( << 191 xercesc::DOMNode* node = attributes->item(attribute_index); 226 << 192 227 if(node->getNodeType() != xercesc::DOMNode << 193 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } 228 { << 194 229 continue; << 195 const xercesc::DOMAttr* const attribute 230 } << 196 = dynamic_cast<xercesc::DOMAttr*>(node); 231 << 197 if (!attribute) 232 const xercesc::DOMAttr* const attribute = << 198 { 233 dynamic_cast<xercesc::DOMAttr*>(node); << 199 G4Exception("G4GDMLRead::ExpressionRead()", "InvalidRead", 234 if(attribute == nullptr) << 200 FatalException, "No attribute found!"); 235 { << 201 return; 236 G4Exception("G4GDMLRead::ExpressionRead( << 202 } 237 "No attribute found!"); << 203 const G4String attName = Transcode(attribute->getName()); 238 return; << 204 const G4String attValue = Transcode(attribute->getValue()); 239 } << 205 240 const G4String attName = Transcode(attrib << 206 if (attName=="name") { name = attValue; } 241 const G4String attValue = Transcode(attrib << 207 } 242 << 208 243 if(attName == "name") << 209 const G4String expValue = Transcode(expElement->getTextContent()); 244 { << 210 value = eval.Evaluate(expValue); 245 name = attValue; << 211 eval.DefineConstant(name,value); 246 } << 247 } << 248 << 249 const G4String expValue = Transcode(expEleme << 250 value = eval.Evaluate(expV << 251 eval.DefineConstant(name, value); << 252 } 212 } 253 213 254 // ------------------------------------------- << 214 void 255 void G4GDMLReadDefine::MatrixRead( << 215 G4GDMLReadDefine::MatrixRead(const xercesc::DOMElement* const matrixElement) 256 const xercesc::DOMElement* const matrixEleme << 257 { 216 { 258 G4String name = ""; << 217 G4String name = ""; 259 G4int coldim = 0; << 218 G4int coldim = 0; 260 G4String values = ""; << 219 G4String values = ""; 261 << 220 262 const xercesc::DOMNamedNodeMap* const attrib << 221 const xercesc::DOMNamedNodeMap* const attributes 263 matrixElement->getAttributes(); << 222 = matrixElement->getAttributes(); 264 XMLSize_t attributeCount = attributes->getLe << 223 XMLSize_t attributeCount = attributes->getLength(); 265 << 224 266 for(XMLSize_t attribute_index = 0; attribute << 225 for (XMLSize_t attribute_index=0; 267 ++attribute_index) << 226 attribute_index<attributeCount; attribute_index++) 268 { << 227 { 269 xercesc::DOMNode* node = attributes->item( << 228 xercesc::DOMNode* node = attributes->item(attribute_index); 270 << 229 271 if(node->getNodeType() != xercesc::DOMNode << 230 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } 272 { << 231 273 continue; << 232 const xercesc::DOMAttr* const attribute 274 } << 233 = dynamic_cast<xercesc::DOMAttr*>(node); 275 << 234 if (!attribute) 276 const xercesc::DOMAttr* const attribute = << 235 { 277 dynamic_cast<xercesc::DOMAttr*>(node); << 236 G4Exception("G4GDMLRead::MatrixRead()", "InvalidRead", 278 if(attribute == nullptr) << 237 FatalException, "No attribute found!"); 279 { << 238 return; 280 G4Exception("G4GDMLRead::MatrixRead()", << 239 } 281 "No attribute found!"); << 240 const G4String attName = Transcode(attribute->getName()); 282 return; << 241 const G4String attValue = Transcode(attribute->getValue()); 283 } << 242 284 const G4String attName = Transcode(attrib << 243 if (attName=="name") { name = GenerateName(attValue); } else 285 const G4String attValue = Transcode(attrib << 244 if (attName=="coldim") { coldim = eval.EvaluateInteger(attValue); } else 286 << 245 if (attName=="values") { values = attValue; } 287 if(attName == "name") << 246 } 288 { << 247 289 name = GenerateName(attValue); << 248 std::stringstream MatrixValueStream(values); 290 } << 249 std::vector<G4double> valueList; 291 else if(attName == "coldim") << 250 292 { << 251 while (!MatrixValueStream.eof()) 293 coldim = eval.EvaluateInteger(attValue); << 252 { 294 } << 253 G4String MatrixValue; 295 else if(attName == "values") << 254 MatrixValueStream >> MatrixValue; 296 { << 255 valueList.push_back(eval.Evaluate(MatrixValue)); 297 values = attValue; << 256 } 298 } << 257 299 } << 258 eval.DefineMatrix(name,coldim,valueList); 300 << 259 301 std::stringstream MatrixValueStream(values); << 260 G4GDMLMatrix matrix(valueList.size()/coldim,coldim); 302 std::vector<G4double> valueList; << 261 303 << 262 for (size_t i=0;i<valueList.size();i++) 304 while(!MatrixValueStream.eof()) << 263 { 305 { << 264 matrix.Set(i/coldim,i%coldim,valueList[i]); 306 G4String MatrixValue; << 265 } 307 MatrixValueStream >> MatrixValue; << 308 valueList.push_back(eval.Evaluate(MatrixVa << 309 } << 310 << 311 eval.DefineMatrix(name, coldim, valueList); << 312 << 313 G4GDMLMatrix matrix(valueList.size() / coldi << 314 << 315 for(std::size_t i = 0; i < valueList.size(); << 316 { << 317 matrix.Set(i / coldim, i % coldim, valueLi << 318 } << 319 266 320 matrixMap[name] = matrix; << 267 matrixMap[name] = matrix; 321 } 268 } 322 269 323 // ------------------------------------------- << 270 void 324 void G4GDMLReadDefine::PositionRead( << 271 G4GDMLReadDefine::PositionRead(const xercesc::DOMElement* const positionElement) 325 const xercesc::DOMElement* const positionEle << 326 { 272 { 327 G4String name = ""; << 273 G4String name = ""; 328 G4double unit = 1.0; << 274 G4double unit = 1.0; 329 G4ThreeVector position(0., 0., 0.); << 275 G4ThreeVector position(0.,0.,0.); 330 << 276 331 const xercesc::DOMNamedNodeMap* const attrib << 277 const xercesc::DOMNamedNodeMap* const attributes 332 positionElement->getAttributes(); << 278 = positionElement->getAttributes(); 333 XMLSize_t attributeCount = attributes->getLe << 279 XMLSize_t attributeCount = attributes->getLength(); 334 << 280 335 for(XMLSize_t attribute_index = 0; attribute << 281 for (XMLSize_t attribute_index=0; 336 ++attribute_index) << 282 attribute_index<attributeCount; attribute_index++) 337 { << 283 { 338 xercesc::DOMNode* node = attributes->item( << 284 xercesc::DOMNode* node = attributes->item(attribute_index); 339 << 340 if(node->getNodeType() != xercesc::DOMNode << 341 { << 342 continue; << 343 } << 344 << 345 const xercesc::DOMAttr* const attribute = << 346 dynamic_cast<xercesc::DOMAttr*>(node); << 347 if(attribute == nullptr) << 348 { << 349 G4Exception("G4GDMLRead::PositionRead()" << 350 "No attribute found!"); << 351 return; << 352 } << 353 const G4String attName = Transcode(attrib << 354 const G4String attValue = Transcode(attrib << 355 << 356 if(attName == "name") << 357 { << 358 name = GenerateName(attValue); << 359 } << 360 else if(attName == "unit") << 361 { << 362 unit = G4UnitDefinition::GetValueOf(attV << 363 if(G4UnitDefinition::GetCategory(attValu << 364 { << 365 G4Exception("G4GDMLReadDefine::Positio << 366 FatalException, "Invalid u << 367 } << 368 } << 369 else if(attName == "x") << 370 { << 371 position.setX(eval.Evaluate(attValue)); << 372 } << 373 else if(attName == "y") << 374 { << 375 position.setY(eval.Evaluate(attValue)); << 376 } << 377 else if(attName == "z") << 378 { << 379 position.setZ(eval.Evaluate(attValue)); << 380 } << 381 } << 382 285 383 positionMap[name] = position * unit; << 286 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } >> 287 >> 288 const xercesc::DOMAttr* const attribute >> 289 = dynamic_cast<xercesc::DOMAttr*>(node); >> 290 if (!attribute) >> 291 { >> 292 G4Exception("G4GDMLRead::PositionRead()", "InvalidRead", >> 293 FatalException, "No attribute found!"); >> 294 return; >> 295 } >> 296 const G4String attName = Transcode(attribute->getName()); >> 297 const G4String attValue = Transcode(attribute->getValue()); >> 298 >> 299 if (attName=="name") { name = GenerateName(attValue); } else >> 300 if (attName=="unit") { unit = eval.Evaluate(attValue); } else >> 301 if (attName=="x") { position.setX(eval.Evaluate(attValue)); } else >> 302 if (attName=="y") { position.setY(eval.Evaluate(attValue)); } else >> 303 if (attName=="z") { position.setZ(eval.Evaluate(attValue)); } >> 304 } >> 305 >> 306 positionMap[name] = position*unit; 384 } 307 } 385 308 386 // ------------------------------------------- << 309 void 387 void G4GDMLReadDefine::RotationRead( << 310 G4GDMLReadDefine::RotationRead(const xercesc::DOMElement* const rotationElement) 388 const xercesc::DOMElement* const rotationEle << 389 { 311 { 390 G4String name = ""; << 312 G4String name = ""; 391 G4double unit = 1.0; << 313 G4double unit = 1.0; 392 G4ThreeVector rotation(0., 0., 0.); << 314 G4ThreeVector rotation(0.,0.,0.); 393 << 315 394 const xercesc::DOMNamedNodeMap* const attrib << 316 const xercesc::DOMNamedNodeMap* const attributes 395 rotationElement->getAttributes(); << 317 = rotationElement->getAttributes(); 396 XMLSize_t attributeCount = attributes->getLe << 318 XMLSize_t attributeCount = attributes->getLength(); 397 << 398 for(XMLSize_t attribute_index = 0; attribute << 399 ++attribute_index) << 400 { << 401 xercesc::DOMNode* node = attributes->item( << 402 << 403 if(node->getNodeType() != xercesc::DOMNode << 404 { << 405 continue; << 406 } << 407 << 408 const xercesc::DOMAttr* const attribute = << 409 dynamic_cast<xercesc::DOMAttr*>(node); << 410 if(attribute == nullptr) << 411 { << 412 G4Exception("G4GDMLRead::RotationRead()" << 413 "No attribute found!"); << 414 return; << 415 } << 416 const G4String attName = Transcode(attrib << 417 const G4String attValue = Transcode(attrib << 418 << 419 if(attName == "name") << 420 { << 421 name = GenerateName(attValue); << 422 } << 423 else if(attName == "unit") << 424 { << 425 unit = G4UnitDefinition::GetValueOf(attV << 426 if(G4UnitDefinition::GetCategory(attValu << 427 { << 428 G4Exception("G4GDMLReadDefine::Rotatio << 429 FatalException, "Invalid u << 430 } << 431 } << 432 else if(attName == "x") << 433 { << 434 rotation.setX(eval.Evaluate(attValue)); << 435 } << 436 else if(attName == "y") << 437 { << 438 rotation.setY(eval.Evaluate(attValue)); << 439 } << 440 else if(attName == "z") << 441 { << 442 rotation.setZ(eval.Evaluate(attValue)); << 443 } << 444 } << 445 319 446 rotationMap[name] = rotation * unit; << 320 for (XMLSize_t attribute_index=0; >> 321 attribute_index<attributeCount; attribute_index++) >> 322 { >> 323 xercesc::DOMNode* node = attributes->item(attribute_index); >> 324 >> 325 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } >> 326 >> 327 const xercesc::DOMAttr* const attribute >> 328 = dynamic_cast<xercesc::DOMAttr*>(node); >> 329 if (!attribute) >> 330 { >> 331 G4Exception("G4GDMLRead::RotationRead()", "InvalidRead", >> 332 FatalException, "No attribute found!"); >> 333 return; >> 334 } >> 335 const G4String attName = Transcode(attribute->getName()); >> 336 const G4String attValue = Transcode(attribute->getValue()); >> 337 >> 338 if (attName=="name") { name = GenerateName(attValue); } else >> 339 if (attName=="unit") { unit = eval.Evaluate(attValue); } else >> 340 if (attName=="x") { rotation.setX(eval.Evaluate(attValue)); } else >> 341 if (attName=="y") { rotation.setY(eval.Evaluate(attValue)); } else >> 342 if (attName=="z") { rotation.setZ(eval.Evaluate(attValue)); } >> 343 } >> 344 >> 345 rotationMap[name] = rotation*unit; 447 } 346 } 448 347 449 // ------------------------------------------- << 450 void G4GDMLReadDefine::ScaleRead(const xercesc 348 void G4GDMLReadDefine::ScaleRead(const xercesc::DOMElement* const scaleElement) 451 { 349 { 452 G4String name = ""; << 350 G4String name = ""; 453 G4ThreeVector scale(1.0, 1.0, 1.0); << 351 G4ThreeVector scale(1.0,1.0,1.0); >> 352 >> 353 const xercesc::DOMNamedNodeMap* const attributes >> 354 = scaleElement->getAttributes(); >> 355 XMLSize_t attributeCount = attributes->getLength(); >> 356 >> 357 for (XMLSize_t attribute_index=0; >> 358 attribute_index<attributeCount; attribute_index++) >> 359 { >> 360 xercesc::DOMNode* node = attributes->item(attribute_index); >> 361 >> 362 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } >> 363 >> 364 const xercesc::DOMAttr* const attribute >> 365 = dynamic_cast<xercesc::DOMAttr*>(node); >> 366 if (!attribute) >> 367 { >> 368 G4Exception("G4GDMLRead::ScaleRead()", "InvalidRead", >> 369 FatalException, "No attribute found!"); >> 370 return; >> 371 } >> 372 const G4String attName = Transcode(attribute->getName()); >> 373 const G4String attValue = Transcode(attribute->getValue()); 454 374 455 const xercesc::DOMNamedNodeMap* const attrib << 375 if (attName=="name") { name = GenerateName(attValue); } else 456 scaleElement->getAttributes(); << 376 if (attName=="x") { scale.setX(eval.Evaluate(attValue)); } else 457 XMLSize_t attributeCount = attributes->getLe << 377 if (attName=="y") { scale.setY(eval.Evaluate(attValue)); } else 458 << 378 if (attName=="z") { scale.setZ(eval.Evaluate(attValue)); } 459 for(XMLSize_t attribute_index = 0; attribute << 379 } 460 ++attribute_index) << 461 { << 462 xercesc::DOMNode* node = attributes->item( << 463 << 464 if(node->getNodeType() != xercesc::DOMNode << 465 { << 466 continue; << 467 } << 468 << 469 const xercesc::DOMAttr* const attribute = << 470 dynamic_cast<xercesc::DOMAttr*>(node); << 471 if(attribute == nullptr) << 472 { << 473 G4Exception("G4GDMLRead::ScaleRead()", " << 474 "No attribute found!"); << 475 return; << 476 } << 477 const G4String attName = Transcode(attrib << 478 const G4String attValue = Transcode(attrib << 479 << 480 if(attName == "name") << 481 { << 482 name = GenerateName(attValue); << 483 } << 484 else if(attName == "x") << 485 { << 486 scale.setX(eval.Evaluate(attValue)); << 487 } << 488 else if(attName == "y") << 489 { << 490 scale.setY(eval.Evaluate(attValue)); << 491 } << 492 else if(attName == "z") << 493 { << 494 scale.setZ(eval.Evaluate(attValue)); << 495 } << 496 } << 497 380 498 scaleMap[name] = scale; << 381 scaleMap[name] = scale; 499 } 382 } 500 383 501 // ------------------------------------------- << 384 void 502 void G4GDMLReadDefine::VariableRead( << 385 G4GDMLReadDefine::VariableRead(const xercesc::DOMElement* const variableElement) 503 const xercesc::DOMElement* const variableEle << 504 { 386 { 505 G4String name = ""; << 387 G4String name = ""; 506 G4double value = 0.0; << 388 G4double value = 0.0; >> 389 >> 390 const xercesc::DOMNamedNodeMap* const attributes >> 391 = variableElement->getAttributes(); >> 392 XMLSize_t attributeCount = attributes->getLength(); >> 393 >> 394 for (XMLSize_t attribute_index=0; >> 395 attribute_index<attributeCount; attribute_index++) >> 396 { >> 397 xercesc::DOMNode* node = attributes->item(attribute_index); 507 398 508 const xercesc::DOMNamedNodeMap* const attrib << 399 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } 509 variableElement->getAttributes(); << 400 510 XMLSize_t attributeCount = attributes->getLe << 401 const xercesc::DOMAttr* const attribute 511 << 402 = dynamic_cast<xercesc::DOMAttr*>(node); 512 for(XMLSize_t attribute_index = 0; attribute << 403 if (!attribute) 513 ++attribute_index) << 404 { 514 { << 405 G4Exception("G4GDMLRead::VariableRead()", "InvalidRead", 515 xercesc::DOMNode* node = attributes->item( << 406 FatalException, "No attribute found!"); 516 << 407 return; 517 if(node->getNodeType() != xercesc::DOMNode << 408 } 518 { << 409 const G4String attName = Transcode(attribute->getName()); 519 continue; << 410 const G4String attValue = Transcode(attribute->getValue()); 520 } << 521 << 522 const xercesc::DOMAttr* const attribute = << 523 dynamic_cast<xercesc::DOMAttr*>(node); << 524 if(attribute == nullptr) << 525 { << 526 G4Exception("G4GDMLRead::VariableRead()" << 527 "No attribute found!"); << 528 return; << 529 } << 530 const G4String attName = Transcode(attrib << 531 const G4String attValue = Transcode(attrib << 532 << 533 if(attName == "name") << 534 { << 535 name = attValue; << 536 } << 537 else if(attName == "value") << 538 { << 539 value = eval.Evaluate(attValue); << 540 } << 541 } << 542 411 543 eval.DefineVariable(name, value); << 412 if (attName=="name") { name = attValue; } else >> 413 if (attName=="value") { value = eval.Evaluate(attValue); } >> 414 } >> 415 >> 416 eval.DefineVariable(name,value); 544 } 417 } 545 418 546 // ------------------------------------------- << 547 void G4GDMLReadDefine::QuantityRead(const xerc 419 void G4GDMLReadDefine::QuantityRead(const xercesc::DOMElement* const element) 548 { 420 { 549 G4String name = ""; << 421 G4String name = ""; 550 G4double unit = 1.0; << 422 G4double unit = 1.0; 551 G4double value = 0.0; << 423 G4double value = 0.0; 552 << 424 553 const xercesc::DOMNamedNodeMap* const attrib << 425 const xercesc::DOMNamedNodeMap* const attributes 554 XMLSize_t attributeCount << 426 = element->getAttributes(); 555 << 427 XMLSize_t attributeCount = attributes->getLength(); 556 for(XMLSize_t attribute_index = 0; attribute << 428 557 ++attribute_index) << 429 for (XMLSize_t attribute_index=0; 558 { << 430 attribute_index<attributeCount; attribute_index++) 559 xercesc::DOMNode* node = attributes->item( << 431 { 560 << 432 xercesc::DOMNode* node = attributes->item(attribute_index); 561 if(node->getNodeType() != xercesc::DOMNode << 433 562 { << 434 if (node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) { continue; } 563 continue; << 435 564 } << 436 const xercesc::DOMAttr* const attribute 565 << 437 = dynamic_cast<xercesc::DOMAttr*>(node); 566 const xercesc::DOMAttr* const attribute = << 438 if (!attribute) 567 dynamic_cast<xercesc::DOMAttr*>(node); << 439 { 568 if(attribute == nullptr) << 440 G4Exception("G4GDMLRead::QuantityRead()", "InvalidRead", 569 { << 441 FatalException, "No attribute found!"); 570 G4Exception("G4GDMLRead::QuantityRead()" << 442 return; 571 "No attribute found!"); << 443 } 572 return; << 444 const G4String attName = Transcode(attribute->getName()); 573 } << 445 const G4String attValue = Transcode(attribute->getValue()); 574 const G4String attName = Transcode(attrib << 446 575 const G4String attValue = Transcode(attrib << 447 if (attName=="name") { name = attValue; } else 576 << 448 if (attName=="value") { value = eval.Evaluate(attValue); } else 577 if(attName == "name") << 449 if (attName=="unit") { unit = eval.Evaluate(attValue); } 578 { << 450 } 579 name = attValue; << 580 } << 581 else if(attName == "value") << 582 { << 583 value = eval.Evaluate(attValue); << 584 } << 585 else if(attName == "unit") << 586 { << 587 unit = G4UnitDefinition::GetValueOf(attV << 588 } << 589 } << 590 451 591 quantityMap[name] = value * unit; << 452 quantityMap[name] = value*unit; 592 eval.DefineConstant(name, value * unit); << 453 eval.DefineConstant(name,value*unit); 593 } 454 } 594 455 595 // ------------------------------------------- << 456 void 596 void G4GDMLReadDefine::DefineRead( << 457 G4GDMLReadDefine::DefineRead(const xercesc::DOMElement* const defineElement) 597 const xercesc::DOMElement* const defineEleme << 598 { 458 { 599 #ifdef G4VERBOSE << 459 G4cout << "G4GDML: Reading definitions..." << G4endl; 600 G4cout << "G4GDML: Reading definitions..." < << 460 601 #endif << 461 for (xercesc::DOMNode* iter = defineElement->getFirstChild(); 602 for(xercesc::DOMNode* iter = defineElement-> << 462 iter != 0;iter = iter->getNextSibling()) 603 iter = iter->getNextSi << 463 { 604 { << 464 if (iter->getNodeType() != xercesc::DOMNode::ELEMENT_NODE) { continue; } 605 if(iter->getNodeType() != xercesc::DOMNode << 465 606 { << 466 const xercesc::DOMElement* const child 607 continue; << 467 = dynamic_cast<xercesc::DOMElement*>(iter); 608 } << 468 if (!child) 609 << 469 { 610 const xercesc::DOMElement* const child = << 470 G4Exception("G4GDMLRead::DefineRead()", "InvalidRead", 611 dynamic_cast<xercesc::DOMElement*>(iter) << 471 FatalException, "No child found!"); 612 if(child == nullptr) << 472 return; 613 { << 473 } 614 G4Exception("G4GDMLRead::DefineRead()", << 474 const G4String tag = Transcode(child->getTagName()); 615 "No child found!"); << 475 616 return; << 476 if (tag=="constant") { ConstantRead(child); } else 617 } << 477 if (tag=="matrix") { MatrixRead(child); } else 618 const G4String tag = Transcode(child->getT << 478 if (tag=="position") { PositionRead(child); } else 619 << 479 if (tag=="rotation") { RotationRead(child); } else 620 if(tag == "constant") << 480 if (tag=="scale") { ScaleRead(child); } else 621 { << 481 if (tag=="variable") { VariableRead(child); } else 622 ConstantRead(child); << 482 if (tag=="quantity") { QuantityRead(child); } else 623 } << 483 if (tag=="expression") { ExpressionRead(child); } 624 else if(tag == "matrix") << 484 else 625 { << 485 { 626 MatrixRead(child); << 486 G4String error_msg = "Unknown tag in define: "+tag; 627 } << 487 G4Exception("G4GDMLReadDefine::defineRead()", "ReadError", 628 else if(tag == "position") << 488 FatalException, error_msg); 629 { << 489 } 630 PositionRead(child); << 490 } 631 } << 632 else if(tag == "rotation") << 633 { << 634 RotationRead(child); << 635 } << 636 else if(tag == "scale") << 637 { << 638 ScaleRead(child); << 639 } << 640 else if(tag == "variable") << 641 { << 642 VariableRead(child); << 643 } << 644 else if(tag == "quantity") << 645 { << 646 QuantityRead(child); << 647 } << 648 else if(tag == "expression") << 649 { << 650 ExpressionRead(child); << 651 } << 652 else << 653 { << 654 G4String error_msg = "Unknown tag in def << 655 G4Exception("G4GDMLReadDefine::defineRea << 656 error_msg); << 657 } << 658 } << 659 } 491 } 660 492 661 // ------------------------------------------- << 493 void 662 void G4GDMLReadDefine::VectorRead( << 494 G4GDMLReadDefine::VectorRead(const xercesc::DOMElement* const vectorElement, 663 const xercesc::DOMElement* const vectorEleme << 495 G4ThreeVector& vec) 664 { 496 { 665 G4double unit = 1.0; << 497 G4double unit = 1.0; >> 498 >> 499 const xercesc::DOMNamedNodeMap* const attributes >> 500 = vectorElement->getAttributes(); >> 501 XMLSize_t attributeCount = attributes->getLength(); >> 502 >> 503 for (XMLSize_t attribute_index=0; >> 504 attribute_index<attributeCount; attribute_index++) >> 505 { >> 506 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); >> 507 >> 508 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) >> 509 { continue; } >> 510 >> 511 const xercesc::DOMAttr* const attribute >> 512 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); >> 513 if (!attribute) >> 514 { >> 515 G4Exception("G4GDMLRead::VectorRead()", "InvalidRead", >> 516 FatalException, "No attribute found!"); >> 517 return; >> 518 } >> 519 const G4String attName = Transcode(attribute->getName()); >> 520 const G4String attValue = Transcode(attribute->getValue()); 666 521 667 const xercesc::DOMNamedNodeMap* const attrib << 522 if (attName=="unit") { unit = eval.Evaluate(attValue); } else 668 vectorElement->getAttributes(); << 523 if (attName=="x") { vec.setX(eval.Evaluate(attValue)); } else 669 XMLSize_t attributeCount = attributes->getLe << 524 if (attName=="y") { vec.setY(eval.Evaluate(attValue)); } else 670 << 525 if (attName=="z") { vec.setZ(eval.Evaluate(attValue)); } 671 for(XMLSize_t attribute_index = 0; attribute << 526 } 672 ++attribute_index) << 673 { << 674 xercesc::DOMNode* attribute_node = attribu << 675 << 676 if(attribute_node->getNodeType() != xerces << 677 { << 678 continue; << 679 } << 680 << 681 const xercesc::DOMAttr* const attribute = << 682 dynamic_cast<xercesc::DOMAttr*>(attribut << 683 if(attribute == nullptr) << 684 { << 685 G4Exception("G4GDMLRead::VectorRead()", << 686 "No attribute found!"); << 687 return; << 688 } << 689 const G4String attName = Transcode(attrib << 690 const G4String attValue = Transcode(attrib << 691 << 692 if(attName == "unit") << 693 { << 694 unit = G4UnitDefinition::GetValueOf(attV << 695 } << 696 else if(attName == "x") << 697 { << 698 vec.setX(eval.Evaluate(attValue)); << 699 } << 700 else if(attName == "y") << 701 { << 702 vec.setY(eval.Evaluate(attValue)); << 703 } << 704 else if(attName == "z") << 705 { << 706 vec.setZ(eval.Evaluate(attValue)); << 707 } << 708 } << 709 527 710 vec *= unit; << 528 vec *= unit; 711 } 529 } 712 530 713 // ------------------------------------------- << 714 G4String G4GDMLReadDefine::RefRead(const xerce 531 G4String G4GDMLReadDefine::RefRead(const xercesc::DOMElement* const element) 715 { 532 { 716 G4String ref; << 533 G4String ref; 717 534 718 const xercesc::DOMNamedNodeMap* const attrib << 535 const xercesc::DOMNamedNodeMap* const attributes = element->getAttributes(); 719 XMLSize_t attributeCount << 536 XMLSize_t attributeCount = attributes->getLength(); 720 537 721 for(XMLSize_t attribute_index = 0; attribute << 538 for (XMLSize_t attribute_index=0; 722 ++attribute_index) << 539 attribute_index<attributeCount; attribute_index++) 723 { << 540 { 724 xercesc::DOMNode* attribute_node = attribu << 541 xercesc::DOMNode* attribute_node = attributes->item(attribute_index); 725 << 542 726 if(attribute_node->getNodeType() != xerces << 543 if (attribute_node->getNodeType() != xercesc::DOMNode::ATTRIBUTE_NODE) 727 { << 544 { continue; } 728 continue; << 545 729 } << 546 const xercesc::DOMAttr* const attribute 730 << 547 = dynamic_cast<xercesc::DOMAttr*>(attribute_node); 731 const xercesc::DOMAttr* const attribute = << 548 if (!attribute) 732 dynamic_cast<xercesc::DOMAttr*>(attribut << 549 { 733 if(attribute == nullptr) << 550 G4Exception("G4GDMLRead::Read()", "InvalidRead", 734 { << 551 FatalException, "No attribute found!"); 735 G4Exception("G4GDMLRead::Read()", "Inval << 552 return ref; 736 "No attribute found!"); << 553 } 737 return ref; << 554 const G4String attName = Transcode(attribute->getName()); 738 } << 555 const G4String attValue = Transcode(attribute->getValue()); 739 const G4String attName = Transcode(attrib << 740 const G4String attValue = Transcode(attrib << 741 << 742 if(attName == "ref") << 743 { << 744 ref = attValue; << 745 } << 746 } << 747 556 748 return ref; << 557 if (attName=="ref") { ref = attValue; } >> 558 } >> 559 >> 560 return ref; 749 } 561 } 750 562 751 // ------------------------------------------- << 752 G4bool G4GDMLReadDefine::IsValidID(const G4Str 563 G4bool G4GDMLReadDefine::IsValidID(const G4String& ref) const 753 { 564 { 754 return eval.IsVariable(ref); << 565 return eval.IsVariable(ref); 755 } 566 } 756 567 757 // ------------------------------------------- << 758 G4double G4GDMLReadDefine::GetConstant(const G 568 G4double G4GDMLReadDefine::GetConstant(const G4String& ref) 759 { 569 { 760 return eval.GetConstant(ref); << 570 return eval.GetConstant(ref); 761 } 571 } 762 572 763 // ------------------------------------------- << 764 G4double G4GDMLReadDefine::GetVariable(const G 573 G4double G4GDMLReadDefine::GetVariable(const G4String& ref) 765 { 574 { 766 return eval.GetVariable(ref); << 575 return eval.GetVariable(ref); 767 } 576 } 768 577 769 // ------------------------------------------- << 770 G4double G4GDMLReadDefine::GetQuantity(const G 578 G4double G4GDMLReadDefine::GetQuantity(const G4String& ref) 771 { 579 { 772 if(quantityMap.find(ref) == quantityMap.cend << 580 if (quantityMap.find(ref) == quantityMap.end()) 773 { << 581 { 774 G4String error_msg = "Quantity '" + ref + << 582 G4String error_msg = "Quantity '"+ref+"' was not found!"; 775 G4Exception("G4GDMLReadDefine::getQuantity << 583 G4Exception("G4GDMLReadDefine::getQuantity()", "ReadError", 776 error_msg); << 584 FatalException, error_msg); 777 } << 585 } 778 return quantityMap[ref]; << 586 return quantityMap[ref]; 779 } 587 } 780 588 781 // ------------------------------------------- << 782 G4ThreeVector G4GDMLReadDefine::GetPosition(co 589 G4ThreeVector G4GDMLReadDefine::GetPosition(const G4String& ref) 783 { 590 { 784 if(positionMap.find(ref) == positionMap.cend << 591 if (positionMap.find(ref) == positionMap.end()) 785 { << 592 { 786 G4String error_msg = "Position '" + ref + << 593 G4String error_msg = "Position '"+ref+"' was not found!"; 787 G4Exception("G4GDMLReadDefine::getPosition << 594 G4Exception("G4GDMLReadDefine::getPosition()", "ReadError", 788 error_msg); << 595 FatalException, error_msg); 789 } << 596 } 790 return positionMap[ref]; << 597 return positionMap[ref]; 791 } 598 } 792 599 793 // ------------------------------------------- << 794 G4ThreeVector G4GDMLReadDefine::GetRotation(co 600 G4ThreeVector G4GDMLReadDefine::GetRotation(const G4String& ref) 795 { 601 { 796 if(rotationMap.find(ref) == rotationMap.cend << 602 if (rotationMap.find(ref) == rotationMap.end()) 797 { << 603 { 798 G4String error_msg = "Rotation '" + ref + << 604 G4String error_msg = "Rotation '"+ref+"' was not found!"; 799 G4Exception("G4GDMLReadDefine::getRotation << 605 G4Exception("G4GDMLReadDefine::getRotation()", "ReadError", 800 error_msg); << 606 FatalException, error_msg); 801 } << 607 } 802 return rotationMap[ref]; << 608 return rotationMap[ref]; 803 } 609 } 804 610 805 // ------------------------------------------- << 806 G4ThreeVector G4GDMLReadDefine::GetScale(const 611 G4ThreeVector G4GDMLReadDefine::GetScale(const G4String& ref) 807 { 612 { 808 if(scaleMap.find(ref) == scaleMap.end()) << 613 if (scaleMap.find(ref) == scaleMap.end()) 809 { << 614 { 810 G4String error_msg = "Scale '" + ref + "' << 615 G4String error_msg = "Scale '"+ref+"' was not found!"; 811 G4Exception("G4GDMLReadDefine::getScale()" << 616 G4Exception("G4GDMLReadDefine::getScale()", "ReadError", 812 error_msg); << 617 FatalException, error_msg); 813 } << 618 } 814 return scaleMap[ref]; << 619 return scaleMap[ref]; 815 } 620 } 816 621 817 // ------------------------------------------- << 818 G4GDMLMatrix G4GDMLReadDefine::GetMatrix(const 622 G4GDMLMatrix G4GDMLReadDefine::GetMatrix(const G4String& ref) 819 { 623 { 820 if(matrixMap.find(ref) == matrixMap.end()) << 624 if (matrixMap.find(ref) == matrixMap.end()) 821 { << 625 { 822 G4String error_msg = "Matrix '" + ref + "' << 626 G4String error_msg = "Matrix '"+ref+"' was not found!"; 823 G4Exception("G4GDMLReadDefine::getMatrix() << 627 G4Exception("G4GDMLReadDefine::getMatrix()", "ReadError", 824 error_msg); << 628 FatalException, error_msg); 825 } << 629 } 826 return matrixMap[ref]; << 630 return matrixMap[ref]; 827 } 631 } 828 632