Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 // ------------------------------------------------------------------- 28 // 29 // GEANT4 Class file 30 // 31 // 32 // File name: G4CrossSectionDataSetRegistry 33 // 34 // Author V.Ivanchenko 24.01.2009 35 // 36 // Modifications: 37 // 38 39 #include "G4ios.hh" 40 41 #include "G4CrossSectionDataSetRegistry.hh" 42 #include "G4VCrossSectionDataSet.hh" 43 #include "G4VComponentCrossSection.hh" 44 #include "G4CrossSectionFactory.hh" 45 #include "G4CrossSectionFactoryRegistry.hh" 46 47 // Needed for running with 'static' libraries to pull the references of the 48 // declared factories 49 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelasticXS); 50 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusElasticXS); 51 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusInelasticXS); 52 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusElasticXS); 53 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroInelasticXS); 54 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroElasticXS); 55 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonInelasticXS); 56 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonElasticXS); 57 G4_REFERENCE_XS_FACTORY(G4ChipsProtonInelasticXS); 58 G4_REFERENCE_XS_FACTORY(G4ChipsProtonElasticXS); 59 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronInelasticXS); 60 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronElasticXS); 61 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusInelasticXS); 62 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusElasticXS); 63 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusInelasticXS); 64 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusElasticXS); 65 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonInelasticXS); 66 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonElasticXS); 67 G4_REFERENCE_XS_FACTORY(G4ElectroNuclearCrossSection); 68 69 G4ThreadLocal G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::instance = nullptr; 70 71 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::Instance() 72 { 73 if(nullptr == instance) { 74 static G4ThreadLocalSingleton<G4CrossSectionDataSetRegistry> inst; 75 instance = inst.Instance(); 76 } 77 return instance; 78 } 79 80 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry() 81 {} 82 83 G4CrossSectionDataSetRegistry::~G4CrossSectionDataSetRegistry() 84 { 85 Clean(); 86 } 87 88 void G4CrossSectionDataSetRegistry::Clean() 89 { 90 std::size_t n = xSections.size(); 91 for (std::size_t i=0; i<n; ++i) { 92 G4VCrossSectionDataSet* p = xSections[i]; 93 if(nullptr != p) { 94 delete p; 95 xSections[i] = nullptr; 96 } 97 } 98 n = xComponents.size(); 99 for (std::size_t i=0; i<n; ++i) { 100 auto p = xComponents[i]; 101 if(nullptr != p) { 102 delete p; 103 xComponents[i] = nullptr; 104 } 105 } 106 } 107 108 void G4CrossSectionDataSetRegistry::Register(G4VCrossSectionDataSet* p) 109 { 110 if(nullptr == p) { return; } 111 for (auto & xsec : xSections) { 112 if(xsec == p) { return; } 113 } 114 xSections.push_back(p); 115 } 116 117 void G4CrossSectionDataSetRegistry::DeRegister(G4VCrossSectionDataSet* p) 118 { 119 if(nullptr == p) { return; } 120 std::size_t n = xSections.size(); 121 for (std::size_t i=0; i<n; ++i) { 122 if(xSections[i] == p) { 123 xSections[i] = nullptr; 124 return; 125 } 126 } 127 } 128 129 void G4CrossSectionDataSetRegistry::Register(G4VComponentCrossSection* p) 130 { 131 if(nullptr == p) { return; } 132 for (auto & xsec : xComponents) { 133 if(xsec == p) { return; } 134 } 135 xComponents.push_back(p); 136 } 137 138 void G4CrossSectionDataSetRegistry::DeRegister(G4VComponentCrossSection* p) 139 { 140 if(nullptr == p) { return; } 141 std::size_t n = xComponents.size(); 142 for (std::size_t i=0; i<n; ++i) { 143 if(xComponents[i] == p) { 144 xComponents[i] = nullptr; 145 return; 146 } 147 } 148 } 149 150 void 151 G4CrossSectionDataSetRegistry::DeleteComponent(G4VComponentCrossSection* p) 152 { 153 if(nullptr == p) { return; } 154 std::size_t n = xComponents.size(); 155 for (std::size_t i=0; i<n; ++i) { 156 if(xComponents[i] == p) { 157 delete p; 158 return; 159 } 160 } 161 } 162 163 G4VCrossSectionDataSet* 164 G4CrossSectionDataSetRegistry::GetCrossSectionDataSet(const G4String& name, 165 G4bool warning) 166 { 167 for (auto & xsec : xSections) { 168 if(nullptr != xsec && xsec->GetName() == name) { return xsec; } 169 } 170 // check if factory exists... 171 // 172 G4CrossSectionFactoryRegistry* factories = 173 G4CrossSectionFactoryRegistry::Instance(); 174 // This throws if factory is not found, add second parameter 175 // to false to avoid this 176 G4VBaseXSFactory* factory = factories->GetFactory(name, warning ); 177 if ( factory ) { 178 return factory->Instantiate(); 179 } else { 180 G4VCrossSectionDataSet* ptr = nullptr; 181 return ptr; 182 } 183 } 184 185 G4VComponentCrossSection* 186 G4CrossSectionDataSetRegistry::GetComponentCrossSection(const G4String& name) 187 { 188 for (auto & xsec : xComponents) { 189 if(nullptr != xsec && xsec->GetName() == name) { return xsec; } 190 } 191 G4VComponentCrossSection* ptr = nullptr; 192 return ptr; 193 } 194