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