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 // G4GDMLParser implementation << 27 // 26 // 28 // Author: Zoltan Torzsok, November 2007 << 27 // $Id: G4GDMLParser.cc 90041 2015-05-11 09:46:06Z gcosmo $ 29 // ------------------------------------------- << 28 // >> 29 // >> 30 // class G4GDMLParser Implementation >> 31 // >> 32 // ------------------------------------------------------------------------- 30 33 31 #include "G4GDMLParser.hh" 34 #include "G4GDMLParser.hh" 32 35 33 #include "G4UnitsTable.hh" 36 #include "G4UnitsTable.hh" 34 #include "G4LogicalVolumeStore.hh" 37 #include "G4LogicalVolumeStore.hh" 35 #include "G4RegionStore.hh" 38 #include "G4RegionStore.hh" 36 #include "G4UserLimits.hh" 39 #include "G4UserLimits.hh" 37 #include "G4ProductionCuts.hh" 40 #include "G4ProductionCuts.hh" 38 #include "G4ReflectionFactory.hh" 41 #include "G4ReflectionFactory.hh" 39 #include "G4Track.hh" 42 #include "G4Track.hh" 40 43 41 // ------------------------------------------- << 42 G4GDMLParser::G4GDMLParser() 44 G4GDMLParser::G4GDMLParser() 43 : strip(true) << 45 : rlist(0), ullist(0), urcode(false), uwcode(false), strip(true), rexp(false) 44 { 46 { 45 reader = new G4GDMLReadStructure; << 47 reader = new G4GDMLReadStructure; 46 writer = new G4GDMLWriteStructure; << 48 writer = new G4GDMLWriteStructure; 47 messenger = new G4GDMLMessenger(this); 49 messenger = new G4GDMLMessenger(this); 48 50 49 xercesc::XMLPlatformUtils::Initialize(); 51 xercesc::XMLPlatformUtils::Initialize(); 50 } 52 } 51 53 52 // ------------------------------------------- << 53 G4GDMLParser::G4GDMLParser(G4GDMLReadStructure 54 G4GDMLParser::G4GDMLParser(G4GDMLReadStructure* extr) 54 : urcode(true), strip(true) << 55 : rlist(0), ullist(0), urcode(true), uwcode(false), strip(true), rexp(false) 55 { 56 { 56 reader = extr; << 57 reader = extr; 57 writer = new G4GDMLWriteStructure; << 58 writer = new G4GDMLWriteStructure; 58 messenger = new G4GDMLMessenger(this); 59 messenger = new G4GDMLMessenger(this); 59 60 60 xercesc::XMLPlatformUtils::Initialize(); 61 xercesc::XMLPlatformUtils::Initialize(); 61 } 62 } 62 63 63 // ------------------------------------------- << 64 G4GDMLParser::G4GDMLParser(G4GDMLReadStructure 64 G4GDMLParser::G4GDMLParser(G4GDMLReadStructure* extr, 65 G4GDMLWriteStructur 65 G4GDMLWriteStructure* extw) 66 : urcode(true), uwcode(true), strip(true) << 66 : rlist(0), ullist(0), urcode(true), uwcode(true), strip(true), rexp(false) 67 { 67 { 68 reader = extr; << 68 reader = extr; 69 writer = extw; << 69 writer = extw; 70 messenger = new G4GDMLMessenger(this); 70 messenger = new G4GDMLMessenger(this); 71 71 72 xercesc::XMLPlatformUtils::Initialize(); 72 xercesc::XMLPlatformUtils::Initialize(); 73 } 73 } 74 74 75 // ------------------------------------------- << 76 G4GDMLParser::~G4GDMLParser() 75 G4GDMLParser::~G4GDMLParser() 77 { 76 { 78 xercesc::XMLPlatformUtils::Terminate(); 77 xercesc::XMLPlatformUtils::Terminate(); 79 if(!urcode) << 78 if (!urcode) { delete reader; } 80 { << 79 if (!uwcode) { delete writer; delete ullist; delete rlist; } 81 delete reader; << 82 } << 83 if(!uwcode) << 84 { << 85 delete writer; << 86 } << 87 delete ullist; << 88 delete rlist; << 89 80 90 delete messenger; 81 delete messenger; 91 } 82 } 92 83 93 // ------------------------------------------- << 94 void G4GDMLParser::ImportRegions() 84 void G4GDMLParser::ImportRegions() 95 { 85 { 96 G4ReflectionFactory* reflFactory = G4Ref << 86 G4ReflectionFactory* reflFactory = G4ReflectionFactory::Instance(); 97 const G4GDMLAuxListType* auxInfoList = GetAu 87 const G4GDMLAuxListType* auxInfoList = GetAuxList(); 98 for(auto iaux = auxInfoList->cbegin(); iaux << 88 for(std::vector<G4GDMLAuxStructType>::const_iterator >> 89 iaux = auxInfoList->begin(); iaux != auxInfoList->end(); iaux++ ) 99 { 90 { 100 if(iaux->type != "Region") << 91 if (iaux->type != "Region") return; 101 continue; << 102 92 103 G4String name = iaux->value; 93 G4String name = iaux->value; 104 if(strip) << 94 if (strip) { reader->StripName(name); } 105 { << 95 if (name.contains("DefaultRegionForTheWorld")) continue; 106 reader->StripName(name); << 107 } << 108 if(G4StrUtil::contains(name, "DefaultRegio << 109 continue; << 110 96 111 if(!iaux->auxList) << 97 if (!iaux->auxList) 112 { 98 { 113 G4Exception("G4GDMLParser::ImportRegions << 99 G4Exception("G4GDMLParser::ImportRegions()", >> 100 "ReadError", FatalException, 114 "Invalid definition of geome 101 "Invalid definition of geometrical region!"); 115 } 102 } 116 else // Create region and loop over all r 103 else // Create region and loop over all region attributes 117 { 104 { 118 G4Region* aRegion = new G4Region(n << 105 G4Region* aRegion = new G4Region(name); 119 G4ProductionCuts* pcuts = new G4Producti 106 G4ProductionCuts* pcuts = new G4ProductionCuts(); 120 aRegion->SetProductionCuts(pcuts); 107 aRegion->SetProductionCuts(pcuts); 121 for(auto raux = iaux->auxList->cbegin(); << 108 for(std::vector<G4GDMLAuxStructType>::const_iterator 122 raux != iaux->auxList->cend(); << 109 raux = iaux->auxList->begin(); raux != iaux->auxList->end(); raux++ ) 123 { 110 { 124 const G4String& tag = raux->type; 111 const G4String& tag = raux->type; 125 if(tag == "volume") << 112 if (tag=="volume") 126 { 113 { 127 G4String volname = raux->value; 114 G4String volname = raux->value; 128 if(strip) << 115 if (strip) { reader->StripName(volname); } 129 { << 116 G4LogicalVolume* lvol = G4LogicalVolumeStore::GetInstance()->GetVolume(volname); 130 reader->StripName(volname); << 117 aRegion->AddRootLogicalVolume(lvol); 131 } << 118 if(reflFactory->IsConstituent(lvol)) aRegion->AddRootLogicalVolume(reflFactory->GetReflectedLV(lvol)); 132 G4LogicalVolumeStore* store = G4Logi << 119 } else 133 auto pos = store->GetMap().find(voln << 120 if (tag=="pcut") 134 if(pos != store->GetMap().cend()) << 135 { << 136 // Scan for all possible volumes w << 137 // and set them as root logical vo << 138 // Issue a notification in case mo << 139 // with same name exist and get se << 140 // << 141 if (pos->second.size()>1) << 142 { << 143 std::ostringstream message; << 144 message << "There exists more th << 145 << "in store named: " << << 146 << "NOTE: assigning all << 147 << "volumes for region: << 148 G4Exception("G4GDMLParser::Impor << 149 "Notification", Just << 150 } << 151 for (auto vpos = pos->second.cbegi << 152 vpos != pos->second.cend << 153 { << 154 aRegion->AddRootLogicalVolume(*v << 155 if(reflFactory->IsConstituent(*v << 156 aRegion->AddRootLogicalVolume( << 157 } << 158 } << 159 else << 160 { << 161 std::ostringstream message; << 162 message << "Volume NOT found in st << 163 << " Volume " << vo << 164 << G4endl << 165 << " No region is b << 166 G4Exception("G4GDMLParser::ImportR << 167 "InvalidSetup", JustWa << 168 } << 169 } << 170 else if(tag == "pcut") << 171 { 121 { 172 const G4String& cvalue = raux->value 122 const G4String& cvalue = raux->value; 173 const G4String& cunit = raux->unit; << 123 const G4String& cunit = raux->unit; 174 if(G4UnitDefinition::GetCategory(cun << 124 G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit); 175 { << 125 pcuts->SetProductionCut(cut,"proton"); 176 G4Exception("G4GDMLParser::ImportR << 126 } else 177 FatalException, "Inval << 127 if (tag=="ecut") 178 } << 179 G4double cut = << 180 eval.Evaluate(cvalue) * G4UnitDefi << 181 pcuts->SetProductionCut(cut, "proton << 182 } << 183 else if(tag == "ecut") << 184 { 128 { 185 const G4String& cvalue = raux->value 129 const G4String& cvalue = raux->value; 186 const G4String& cunit = raux->unit; << 130 const G4String& cunit = raux->unit; 187 if(G4UnitDefinition::GetCategory(cun << 131 G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit); 188 { << 132 pcuts->SetProductionCut(cut,"e-"); 189 G4Exception("G4GDMLParser::ImportR << 133 } else 190 FatalException, "Inval << 134 if (tag=="poscut") 191 } << 192 G4double cut = << 193 eval.Evaluate(cvalue) * G4UnitDefi << 194 pcuts->SetProductionCut(cut, "e-"); << 195 } << 196 else if(tag == "poscut") << 197 { 135 { 198 const G4String& cvalue = raux->value 136 const G4String& cvalue = raux->value; 199 const G4String& cunit = raux->unit; << 137 const G4String& cunit = raux->unit; 200 if(G4UnitDefinition::GetCategory(cun << 138 G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit); 201 { << 139 pcuts->SetProductionCut(cut,"e+"); 202 G4Exception("G4GDMLParser::ImportR << 140 } else 203 FatalException, "Inval << 141 if (tag=="gamcut") 204 } << 205 G4double cut = << 206 eval.Evaluate(cvalue) * G4UnitDefi << 207 pcuts->SetProductionCut(cut, "e+"); << 208 } << 209 else if(tag == "gamcut") << 210 { 142 { 211 const G4String& cvalue = raux->value 143 const G4String& cvalue = raux->value; 212 const G4String& cunit = raux->unit; << 144 const G4String& cunit = raux->unit; 213 if(G4UnitDefinition::GetCategory(cun << 145 G4double cut = eval.Evaluate(cvalue) * G4UnitDefinition::GetValueOf(cunit); 214 { << 146 pcuts->SetProductionCut(cut,"gamma"); 215 G4Exception("G4GDMLParser::ImportR << 147 } else 216 FatalException, "Inval << 148 if (tag=="ulimits") 217 } << 218 G4double cut = << 219 eval.Evaluate(cvalue) * G4UnitDefi << 220 pcuts->SetProductionCut(cut, "gamma" << 221 } << 222 else if(tag == "ulimits") << 223 { 149 { 224 G4double ustepMax = DBL_MAX, utrakMa << 150 G4double ustepMax=DBL_MAX, utrakMax=DBL_MAX, utimeMax=DBL_MAX; 225 G4double uekinMin = 0., urangMin = 0 << 151 G4double uekinMin=0., urangMin=0.; 226 const G4String& ulname = raux->value 152 const G4String& ulname = raux->value; 227 for(auto uaux = raux->auxList->cbegi << 153 for(std::vector<G4GDMLAuxStructType>::const_iterator 228 uaux != raux->auxList->cend << 154 uaux=raux->auxList->begin(); uaux!=raux->auxList->end(); uaux++ ) 229 { 155 { 230 const G4String& ultag = uaux->typ << 156 const G4String& ultag = uaux->type; 231 const G4String& uvalue = uaux->val 157 const G4String& uvalue = uaux->value; 232 const G4String& uunit = uaux->uni << 158 const G4String& uunit = uaux->unit; 233 G4double ulvalue = eval.Evaluate(u 159 G4double ulvalue = eval.Evaluate(uvalue) * eval.Evaluate(uunit); 234 if(ultag == "ustepMax") << 160 if (ultag=="ustepMax") { ustepMax = ulvalue; } else 235 { << 161 if (ultag=="utrakMax") { utrakMax = ulvalue; } else 236 ustepMax = ulvalue; << 162 if (ultag=="utimeMax") { utimeMax = ulvalue; } else 237 } << 163 if (ultag=="uekinMin") { uekinMin = ulvalue; } else 238 else if(ultag == "utrakMax") << 164 if (ultag=="urangMin") { urangMin = ulvalue; } 239 { << 240 utrakMax = ulvalue; << 241 } << 242 else if(ultag == "utimeMax") << 243 { << 244 utimeMax = ulvalue; << 245 } << 246 else if(ultag == "uekinMin") << 247 { << 248 uekinMin = ulvalue; << 249 } << 250 else if(ultag == "urangMin") << 251 { << 252 urangMin = ulvalue; << 253 } << 254 else 165 else 255 { 166 { 256 G4Exception("G4GDMLParser::Impor << 167 G4Exception("G4GDMLParser::ImportRegions()", 257 FatalException, "Inv << 168 "ReadError", FatalException, >> 169 "Invalid definition of user-limits!"); 258 } 170 } 259 } 171 } 260 G4UserLimits* ulimits = new G4UserLi << 172 G4UserLimits* ulimits = new G4UserLimits(ulname, ustepMax, utrakMax, 261 ulname, ustepMax, utrakMax, utimeM << 173 utimeMax, uekinMin, urangMin); 262 aRegion->SetUserLimits(ulimits); 174 aRegion->SetUserLimits(ulimits); 263 } 175 } 264 else << 176 else continue; // Ignore unknown tags 265 continue; // Ignore unknown tags << 266 } 177 } 267 } 178 } 268 } 179 } 269 } 180 } 270 181 271 // ------------------------------------------- << 272 void G4GDMLParser::ExportRegions(G4bool storeR 182 void G4GDMLParser::ExportRegions(G4bool storeReferences) 273 { 183 { 274 G4RegionStore* rstore = G4RegionS << 184 G4RegionStore* rstore = G4RegionStore::GetInstance(); 275 G4ReflectionFactory* reflFactory = G4Reflect 185 G4ReflectionFactory* reflFactory = G4ReflectionFactory::Instance(); 276 for(std::size_t i = 0; i < rstore->size(); + << 186 for (size_t i=0; i<rstore->size(); ++i) // Skip default regions associated to worlds 277 // Skip default regions associated to wor << 278 { 187 { 279 const G4String& tname = (*rstore)[i]->GetN 188 const G4String& tname = (*rstore)[i]->GetName(); 280 if(G4StrUtil::contains(tname, "DefaultRegi << 189 if (tname.contains("DefaultRegionForParallelWorld")) continue; 281 continue; << 190 const G4String& rname = writer->GenerateName(tname,(*rstore)[i]); 282 const G4String& rname = writer->Generat << 191 rlist = new G4GDMLAuxListType(); 283 rlist = new G4GDMLAuxLi << 192 G4GDMLAuxStructType raux = {"Region", rname, "", rlist}; 284 G4GDMLAuxStructType raux = { "Region", rna << 193 std::vector<G4LogicalVolume*>::iterator rlvol_iter 285 auto rlvol_iter = (*rstore)[i]->GetRootLog << 194 = (*rstore)[i]->GetRootLogicalVolumeIterator(); 286 for(std::size_t j = 0; j < (*rstore)[i]->G << 195 for (size_t j=0; j<(*rstore)[i]->GetNumberOfRootVolumes(); ++j) 287 { 196 { 288 G4LogicalVolume* rlvol = *rlvol_iter; 197 G4LogicalVolume* rlvol = *rlvol_iter; 289 if(reflFactory->IsReflected(rlvol)) << 198 if(reflFactory->IsReflected(rlvol)) continue; 290 continue; << 291 G4String vname = writer->GenerateName(rl 199 G4String vname = writer->GenerateName(rlvol->GetName(), rlvol); 292 if(!storeReferences) << 200 if (!storeReferences) { reader->StripName(vname); } 293 { << 201 G4GDMLAuxStructType rsubaux = {"volume", vname, "", 0}; 294 reader->StripName(vname); << 295 } << 296 G4GDMLAuxStructType rsubaux = { "volume" << 297 rlist->push_back(rsubaux); 202 rlist->push_back(rsubaux); 298 ++rlvol_iter; << 203 rlvol_iter++; 299 } 204 } 300 G4double gam_cut << 205 G4double gam_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("gamma"); 301 = (*rstore)[i]->GetProductionCuts()->Get << 206 G4GDMLAuxStructType caux1 = {"gamcut", eval.ConvertToString(gam_cut), "mm", 0}; 302 G4GDMLAuxStructType caux1 << 303 = { "gamcut", eval.ConvertToString(gam_c << 304 rlist->push_back(caux1); 207 rlist->push_back(caux1); 305 G4double e_cut = (*rstore)[i]->GetProducti 208 G4double e_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("e-"); 306 G4GDMLAuxStructType caux2 << 209 G4GDMLAuxStructType caux2 = {"ecut", eval.ConvertToString(e_cut), "mm", 0}; 307 = { "ecut", eval.ConvertToString(e_cut), << 308 rlist->push_back(caux2); 210 rlist->push_back(caux2); 309 G4double pos_cut << 211 G4double pos_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("e+"); 310 = (*rstore)[i]->GetProductionCuts()->Get << 212 G4GDMLAuxStructType caux3 = {"poscut", eval.ConvertToString(pos_cut), "mm", 0}; 311 G4GDMLAuxStructType caux3 << 312 = { "poscut", eval.ConvertToString(pos_c << 313 rlist->push_back(caux3); 213 rlist->push_back(caux3); 314 G4double p_cut << 214 G4double p_cut = (*rstore)[i]->GetProductionCuts()->GetProductionCut("proton"); 315 = (*rstore)[i]->GetProductionCuts()->Get << 215 G4GDMLAuxStructType caux4 = {"pcut", eval.ConvertToString(p_cut), "mm", 0}; 316 G4GDMLAuxStructType caux4 << 317 = { "pcut", eval.ConvertToString(p_cut), << 318 rlist->push_back(caux4); 216 rlist->push_back(caux4); 319 if((*rstore)[i]->GetUserLimits()) << 217 if ((*rstore)[i]->GetUserLimits()) 320 { 218 { 321 const G4Track fake_trk; 219 const G4Track fake_trk; 322 ullist = new G4GDMLAux << 220 ullist = new G4GDMLAuxListType(); 323 const G4String& utype = (*rstore)[i]- << 221 const G4String& utype = (*rstore)[i]->GetUserLimits()->GetType(); 324 G4GDMLAuxStructType uaux = { "ulimits", << 222 G4GDMLAuxStructType uaux = {"ulimits", utype, "mm", ullist}; 325 G4double max_step << 223 G4double max_step = (*rstore)[i]->GetUserLimits()->GetMaxAllowedStep(fake_trk); 326 = (*rstore)[i]->GetUserLimits()->GetMa << 224 G4GDMLAuxStructType ulaux1 = {"ustepMax", eval.ConvertToString(max_step), "mm", 0}; 327 G4GDMLAuxStructType ulaux1 << 328 = { "ustepMax", eval.ConvertToString(m << 329 ullist->push_back(ulaux1); 225 ullist->push_back(ulaux1); 330 G4double max_trk << 226 G4double max_trk = (*rstore)[i]->GetUserLimits()->GetUserMaxTrackLength(fake_trk); 331 = (*rstore)[i]->GetUserLimits()->GetUs << 227 G4GDMLAuxStructType ulaux2 = {"utrakMax", eval.ConvertToString(max_trk), "mm", 0}; 332 G4GDMLAuxStructType ulaux2 << 333 = { "utrakMax", eval.ConvertToString(m << 334 ullist->push_back(ulaux2); 228 ullist->push_back(ulaux2); 335 G4double max_time << 229 G4double max_time = (*rstore)[i]->GetUserLimits()->GetUserMaxTime(fake_trk); 336 = (*rstore)[i]->GetUserLimits()->GetUs << 230 G4GDMLAuxStructType ulaux3 = {"utimeMax", eval.ConvertToString(max_time), "mm", 0}; 337 G4GDMLAuxStructType ulaux3 << 338 = { "utimeMax", eval.ConvertToString(m << 339 ullist->push_back(ulaux3); 231 ullist->push_back(ulaux3); 340 G4double min_ekin << 232 G4double min_ekin = (*rstore)[i]->GetUserLimits()->GetUserMinEkine(fake_trk); 341 = (*rstore)[i]->GetUserLimits()->GetUs << 233 G4GDMLAuxStructType ulaux4 = {"uekinMin", eval.ConvertToString(min_ekin), "mm", 0}; 342 G4GDMLAuxStructType ulaux4 << 343 = { "uekinMin", eval.ConvertToString(m << 344 ullist->push_back(ulaux4); 234 ullist->push_back(ulaux4); 345 G4double min_rng << 235 G4double min_rng = (*rstore)[i]->GetUserLimits()->GetUserMinRange(fake_trk); 346 = (*rstore)[i]->GetUserLimits()->GetUs << 236 G4GDMLAuxStructType ulaux5 = {"urangMin", eval.ConvertToString(min_rng), "mm", 0}; 347 G4GDMLAuxStructType ulaux5 << 348 = { "urangMin", eval.ConvertToString(m << 349 ullist->push_back(ulaux5); 237 ullist->push_back(ulaux5); 350 rlist->push_back(uaux); 238 rlist->push_back(uaux); 351 } 239 } 352 AddAuxiliary(raux); 240 AddAuxiliary(raux); 353 } 241 } 354 } 242 } 355 243