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 // 26 // 27 // ------------------------------------------- 27 // ------------------------------------------------------------------- 28 // 28 // 29 // GEANT4 Class file 29 // GEANT4 Class file 30 // 30 // 31 // 31 // 32 // File name: G4CrossSectionDataSetRegistry 32 // File name: G4CrossSectionDataSetRegistry 33 // 33 // 34 // Author V.Ivanchenko 24.01.2009 34 // Author V.Ivanchenko 24.01.2009 35 // 35 // 36 // Modifications: 36 // Modifications: 37 // 37 // 38 38 39 #include "G4ios.hh" 39 #include "G4ios.hh" 40 40 41 #include "G4CrossSectionDataSetRegistry.hh" 41 #include "G4CrossSectionDataSetRegistry.hh" 42 #include "G4VCrossSectionDataSet.hh" 42 #include "G4VCrossSectionDataSet.hh" 43 #include "G4VComponentCrossSection.hh" 43 #include "G4VComponentCrossSection.hh" 44 #include "G4CrossSectionFactory.hh" 44 #include "G4CrossSectionFactory.hh" 45 #include "G4CrossSectionFactoryRegistry.hh" 45 #include "G4CrossSectionFactoryRegistry.hh" 46 46 47 // Needed for running with 'static' libraries << 47 // Neeed for running with 'static' libraries to pull the references of the 48 // declared factories 48 // declared factories 49 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelas 49 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelasticXS); 50 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusElasti 50 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusElasticXS); 51 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusInelast 51 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusInelasticXS); 52 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusElastic 52 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusElasticXS); 53 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroInelast 53 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroInelasticXS); 54 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroElastic 54 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroElasticXS); 55 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonInelasti 55 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonInelasticXS); 56 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonElasticX 56 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonElasticXS); 57 G4_REFERENCE_XS_FACTORY(G4ChipsProtonInelastic 57 G4_REFERENCE_XS_FACTORY(G4ChipsProtonInelasticXS); 58 G4_REFERENCE_XS_FACTORY(G4ChipsProtonElasticXS 58 G4_REFERENCE_XS_FACTORY(G4ChipsProtonElasticXS); 59 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronInelasti 59 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronInelasticXS); 60 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronElasticX 60 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronElasticXS); 61 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusInelast 61 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusInelasticXS); 62 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusElastic 62 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusElasticXS); 63 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusInelas 63 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusInelasticXS); 64 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusElasti 64 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusElasticXS); 65 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonInela 65 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonInelasticXS); 66 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonElast 66 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonElasticXS); >> 67 G4_REFERENCE_XS_FACTORY(G4NucleonNuclearCrossSection); 67 G4_REFERENCE_XS_FACTORY(G4ElectroNuclearCrossS 68 G4_REFERENCE_XS_FACTORY(G4ElectroNuclearCrossSection); >> 69 G4_REFERENCE_XS_FACTORY(G4PhotoNuclearCrossSection); >> 70 G4_REFERENCE_XS_FACTORY(G4PiNuclearCrossSection); >> 71 G4_REFERENCE_XS_FACTORY(G4NeutronInelasticXS); >> 72 G4_REFERENCE_XS_FACTORY(G4NeutronElasticXS); >> 73 G4_REFERENCE_XS_FACTORY(G4NeutronCaptureXS); 68 74 69 G4ThreadLocal G4CrossSectionDataSetRegistry* G 75 G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::instance = nullptr; 70 76 71 G4CrossSectionDataSetRegistry* G4CrossSectionD 77 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::Instance() 72 { 78 { 73 if(nullptr == instance) { << 79 if(!instance) { 74 static G4ThreadLocalSingleton<G4CrossSecti 80 static G4ThreadLocalSingleton<G4CrossSectionDataSetRegistry> inst; 75 instance = inst.Instance(); 81 instance = inst.Instance(); 76 } 82 } 77 return instance; 83 return instance; 78 } 84 } 79 85 80 G4CrossSectionDataSetRegistry::G4CrossSectionD 86 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry() 81 {} 87 {} 82 88 83 G4CrossSectionDataSetRegistry::~G4CrossSection 89 G4CrossSectionDataSetRegistry::~G4CrossSectionDataSetRegistry() 84 { 90 { 85 Clean(); 91 Clean(); 86 } 92 } 87 93 88 void G4CrossSectionDataSetRegistry::Clean() 94 void G4CrossSectionDataSetRegistry::Clean() 89 { 95 { 90 std::size_t n = xSections.size(); << 96 size_t n = xSections.size(); 91 for (std::size_t i=0; i<n; ++i) { << 97 for (size_t i=0; i<n; ++i) { 92 G4VCrossSectionDataSet* p = xSections[i]; 98 G4VCrossSectionDataSet* p = xSections[i]; 93 if(nullptr != p) { << 99 if(p) { >> 100 //std::cout << "Clean x-section #" << i << std::endl; >> 101 //std::cout << " " << p->GetName() << std::endl; 94 delete p; 102 delete p; 95 xSections[i] = nullptr; 103 xSections[i] = nullptr; 96 } 104 } 97 } 105 } 98 n = xComponents.size(); 106 n = xComponents.size(); 99 for (std::size_t i=0; i<n; ++i) { << 107 for (size_t i=0; i<n; ++i) { 100 auto p = xComponents[i]; << 108 G4VComponentCrossSection* p = xComponents[i]; 101 if(nullptr != p) { << 109 if(p) { >> 110 //std::cout << "Clean component #" << i << std::endl; >> 111 //std::cout << " " << p->GetName() << std::endl; 102 delete p; 112 delete p; 103 xComponents[i] = nullptr; 113 xComponents[i] = nullptr; 104 } 114 } 105 } 115 } 106 } 116 } 107 117 108 void G4CrossSectionDataSetRegistry::Register(G 118 void G4CrossSectionDataSetRegistry::Register(G4VCrossSectionDataSet* p) 109 { 119 { 110 if(nullptr == p) { return; } << 120 if(!p) { return; } 111 for (auto & xsec : xSections) { << 121 for (auto xsec : xSections) { 112 if(xsec == p) { return; } 122 if(xsec == p) { return; } 113 } 123 } >> 124 //G4cout << "Register x-section #" << xSections.size() >> 125 //<< " " << p->GetName() << G4endl; 114 xSections.push_back(p); 126 xSections.push_back(p); 115 } 127 } 116 128 117 void G4CrossSectionDataSetRegistry::DeRegister 129 void G4CrossSectionDataSetRegistry::DeRegister(G4VCrossSectionDataSet* p) 118 { 130 { 119 if(nullptr == p) { return; } << 131 if(!p) { return; } 120 std::size_t n = xSections.size(); << 132 size_t n = xSections.size(); 121 for (std::size_t i=0; i<n; ++i) { << 133 for (size_t i=0; i<n; ++i) { 122 if(xSections[i] == p) { 134 if(xSections[i] == p) { >> 135 //std::cout << "DeRegister x-section #" << i << std::endl; >> 136 //std:: cout << " " << p->GetName() << std::endl; 123 xSections[i] = nullptr; 137 xSections[i] = nullptr; 124 return; 138 return; 125 } 139 } 126 } 140 } 127 } 141 } 128 142 129 void G4CrossSectionDataSetRegistry::Register(G 143 void G4CrossSectionDataSetRegistry::Register(G4VComponentCrossSection* p) 130 { 144 { 131 if(nullptr == p) { return; } << 145 if(!p) { return; } 132 for (auto & xsec : xComponents) { << 146 for (auto xsec : xComponents) { 133 if(xsec == p) { return; } 147 if(xsec == p) { return; } 134 } 148 } >> 149 //G4cout << "Register component #" << xComponents.size() >> 150 //<< " " << p->GetName() << G4endl; 135 xComponents.push_back(p); 151 xComponents.push_back(p); 136 } 152 } 137 153 138 void G4CrossSectionDataSetRegistry::DeRegister 154 void G4CrossSectionDataSetRegistry::DeRegister(G4VComponentCrossSection* p) 139 { 155 { 140 if(nullptr == p) { return; } << 156 if(!p) { return; } 141 std::size_t n = xComponents.size(); << 157 size_t n = xComponents.size(); 142 for (std::size_t i=0; i<n; ++i) { << 158 for (size_t i=0; i<n; ++i) { 143 if(xComponents[i] == p) { 159 if(xComponents[i] == p) { >> 160 //std::cout << "DeRegister component #" << i << std::endl; >> 161 //std::cout << " " << p->GetName() << std::endl; 144 xComponents[i] = nullptr; 162 xComponents[i] = nullptr; 145 return; 163 return; 146 } 164 } 147 } 165 } 148 } 166 } 149 167 150 void 168 void 151 G4CrossSectionDataSetRegistry::DeleteComponent 169 G4CrossSectionDataSetRegistry::DeleteComponent(G4VComponentCrossSection* p) 152 { 170 { 153 if(nullptr == p) { return; } << 171 if(!p) { return; } 154 std::size_t n = xComponents.size(); << 172 size_t n = xComponents.size(); 155 for (std::size_t i=0; i<n; ++i) { << 173 for (size_t i=0; i<n; ++i) { 156 if(xComponents[i] == p) { 174 if(xComponents[i] == p) { >> 175 //std::cout << "Delete component #" << i << std::endl; >> 176 //std::cout << " " << p->GetName() << std::endl; 157 delete p; 177 delete p; 158 return; 178 return; 159 } 179 } 160 } 180 } 161 } 181 } 162 182 163 G4VCrossSectionDataSet* 183 G4VCrossSectionDataSet* 164 G4CrossSectionDataSetRegistry::GetCrossSection 184 G4CrossSectionDataSetRegistry::GetCrossSectionDataSet(const G4String& name, 165 185 G4bool warning) 166 { 186 { 167 for (auto & xsec : xSections) { << 187 for (auto xsec : xSections) { 168 if(nullptr != xsec && xsec->GetName() == n << 188 if(xsec && xsec->GetName() == name) { return xsec; } 169 } 189 } 170 // check if factory exists... 190 // check if factory exists... 171 // 191 // 172 G4CrossSectionFactoryRegistry* factories = 192 G4CrossSectionFactoryRegistry* factories = 173 G4CrossSectionFactoryRegistry::Instance(); 193 G4CrossSectionFactoryRegistry::Instance(); 174 // This throws if factory is not found, add 194 // This throws if factory is not found, add second parameter 175 // to false to avoid this 195 // to false to avoid this 176 G4VBaseXSFactory* factory = factories->GetFa 196 G4VBaseXSFactory* factory = factories->GetFactory(name, warning ); 177 if ( factory ) { 197 if ( factory ) { 178 return factory->Instantiate(); 198 return factory->Instantiate(); 179 } else { 199 } else { 180 G4VCrossSectionDataSet* ptr = nullptr; 200 G4VCrossSectionDataSet* ptr = nullptr; 181 return ptr; 201 return ptr; 182 } 202 } 183 } 203 } 184 204 185 G4VComponentCrossSection* 205 G4VComponentCrossSection* 186 G4CrossSectionDataSetRegistry::GetComponentCro 206 G4CrossSectionDataSetRegistry::GetComponentCrossSection(const G4String& name) 187 { 207 { 188 for (auto & xsec : xComponents) { << 208 for (auto xsec : xComponents) { 189 if(nullptr != xsec && xsec->GetName() == n << 209 if(xsec && xsec->GetName() == name) { return xsec; } 190 } 210 } 191 G4VComponentCrossSection* ptr = nullptr; 211 G4VComponentCrossSection* ptr = nullptr; 192 return ptr; 212 return ptr; 193 } 213 } 194 214