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 // $Id: G4CrossSectionDataSetRegistry.cc,v 1.3.2.5 2010/01/26 14:50:08 gcosmo Exp $ >> 28 // GEANT4 tag $Name: geant4-09-02-patch-04 $ >> 29 // 27 // ------------------------------------------- 30 // ------------------------------------------------------------------- 28 // 31 // 29 // GEANT4 Class file 32 // GEANT4 Class file 30 // 33 // 31 // 34 // 32 // File name: G4CrossSectionDataSetRegistry 35 // File name: G4CrossSectionDataSetRegistry 33 // 36 // 34 // Author V.Ivanchenko 24.01.2009 37 // Author V.Ivanchenko 24.01.2009 35 // 38 // 36 // Modifications: 39 // Modifications: 37 // 40 // 38 41 39 #include "G4ios.hh" << 40 << 41 #include "G4CrossSectionDataSetRegistry.hh" 42 #include "G4CrossSectionDataSetRegistry.hh" 42 #include "G4VCrossSectionDataSet.hh" 43 #include "G4VCrossSectionDataSet.hh" 43 #include "G4VComponentCrossSection.hh" << 44 #include "G4CrossSectionFactory.hh" << 45 #include "G4CrossSectionFactoryRegistry.hh" << 46 << 47 // Needed for running with 'static' libraries << 48 // declared factories << 49 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusInelas << 50 G4_REFERENCE_XS_FACTORY(G4ChipsKaonMinusElasti << 51 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusInelast << 52 G4_REFERENCE_XS_FACTORY(G4ChipsKaonPlusElastic << 53 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroInelast << 54 G4_REFERENCE_XS_FACTORY(G4ChipsKaonZeroElastic << 55 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonInelasti << 56 G4_REFERENCE_XS_FACTORY(G4ChipsHyperonElasticX << 57 G4_REFERENCE_XS_FACTORY(G4ChipsProtonInelastic << 58 G4_REFERENCE_XS_FACTORY(G4ChipsProtonElasticXS << 59 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronInelasti << 60 G4_REFERENCE_XS_FACTORY(G4ChipsNeutronElasticX << 61 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusInelast << 62 G4_REFERENCE_XS_FACTORY(G4ChipsPionPlusElastic << 63 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusInelas << 64 G4_REFERENCE_XS_FACTORY(G4ChipsPionMinusElasti << 65 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonInela << 66 G4_REFERENCE_XS_FACTORY(G4ChipsAntiBaryonElast << 67 G4_REFERENCE_XS_FACTORY(G4ElectroNuclearCrossS << 68 44 69 G4ThreadLocal G4CrossSectionDataSetRegistry* G << 45 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::theInstance = 0; 70 46 71 G4CrossSectionDataSetRegistry* G4CrossSectionD 47 G4CrossSectionDataSetRegistry* G4CrossSectionDataSetRegistry::Instance() 72 { 48 { 73 if(nullptr == instance) { << 49 if(0 == theInstance) { 74 static G4ThreadLocalSingleton<G4CrossSecti << 50 static G4CrossSectionDataSetRegistry manager; 75 instance = inst.Instance(); << 51 theInstance = &manager; 76 } 52 } 77 return instance; << 53 return theInstance; 78 } 54 } 79 55 80 G4CrossSectionDataSetRegistry::G4CrossSectionD 56 G4CrossSectionDataSetRegistry::G4CrossSectionDataSetRegistry() 81 {} 57 {} 82 58 83 G4CrossSectionDataSetRegistry::~G4CrossSection 59 G4CrossSectionDataSetRegistry::~G4CrossSectionDataSetRegistry() 84 { 60 { 85 Clean(); 61 Clean(); 86 } 62 } 87 63 88 void G4CrossSectionDataSetRegistry::Clean() 64 void G4CrossSectionDataSetRegistry::Clean() 89 { 65 { 90 std::size_t n = xSections.size(); << 66 size_t n = xSections.size(); 91 for (std::size_t i=0; i<n; ++i) { << 67 if(n > 0) { 92 G4VCrossSectionDataSet* p = xSections[i]; << 68 for (size_t i=0; i<n; ++i) { 93 if(nullptr != p) { << 69 if(xSections[i]) { 94 delete p; << 70 G4VCrossSectionDataSet* p = xSections[i]; 95 xSections[i] = nullptr; << 71 xSections[i] = 0; 96 } << 72 delete p; 97 } << 73 } 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 } 74 } >> 75 xSections.clear(); 105 } 76 } 106 } 77 } 107 78 108 void G4CrossSectionDataSetRegistry::Register(G 79 void G4CrossSectionDataSetRegistry::Register(G4VCrossSectionDataSet* p) 109 { 80 { 110 if(nullptr == p) { return; } << 81 if(!p) return; 111 for (auto & xsec : xSections) { << 82 size_t n = xSections.size(); 112 if(xsec == p) { return; } << 83 if(n > 0) { >> 84 for (size_t i=0; i<n; ++i) { >> 85 if(xSections[i] == p) { return; } >> 86 } 113 } 87 } 114 xSections.push_back(p); 88 xSections.push_back(p); 115 } 89 } 116 90 117 void G4CrossSectionDataSetRegistry::DeRegister 91 void G4CrossSectionDataSetRegistry::DeRegister(G4VCrossSectionDataSet* p) 118 { 92 { 119 if(nullptr == p) { return; } << 93 if(!p) return; 120 std::size_t n = xSections.size(); << 94 size_t n = xSections.size(); 121 for (std::size_t i=0; i<n; ++i) { << 95 if(n > 0) { 122 if(xSections[i] == p) { << 96 for (size_t i=0; i<n; ++i) { 123 xSections[i] = nullptr; << 97 if(xSections[i] == p) { 124 return; << 98 xSections[i] = 0; 125 } << 99 if(i == n-1) { xSections.pop_back(); } 126 } << 100 return; 127 } << 101 } 128 << 129 void G4CrossSectionDataSetRegistry::Register(G << 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 << 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 } 102 } 147 } 103 } 148 } 104 } 149 105 150 void << 151 G4CrossSectionDataSetRegistry::DeleteComponent << 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 106 163 G4VCrossSectionDataSet* << 164 G4CrossSectionDataSetRegistry::GetCrossSection << 165 << 166 { << 167 for (auto & xsec : xSections) { << 168 if(nullptr != xsec && xsec->GetName() == n << 169 } << 170 // check if factory exists... << 171 // << 172 G4CrossSectionFactoryRegistry* factories = << 173 G4CrossSectionFactoryRegistry::Instance(); << 174 // This throws if factory is not found, add << 175 // to false to avoid this << 176 G4VBaseXSFactory* factory = factories->GetFa << 177 if ( factory ) { << 178 return factory->Instantiate(); << 179 } else { << 180 G4VCrossSectionDataSet* ptr = nullptr; << 181 return ptr; << 182 } << 183 } << 184 << 185 G4VComponentCrossSection* << 186 G4CrossSectionDataSetRegistry::GetComponentCro << 187 { << 188 for (auto & xsec : xComponents) { << 189 if(nullptr != xsec && xsec->GetName() == n << 190 } << 191 G4VComponentCrossSection* ptr = nullptr; << 192 return ptr; << 193 } << 194 107