File indexing completed on 2026-09-23 09:10:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef G4CrossSectionFactory_h
0027 #define G4CrossSectionFactory_h 1
0028
0029
0030 #include "globals.hh"
0031 #include "G4VCrossSectionDataSet.hh"
0032 #include "G4CrossSectionFactoryRegistry.hh"
0033 #include "G4Threading.hh"
0034
0035 class G4VBaseXSFactory
0036 {
0037 public:
0038
0039 G4VBaseXSFactory()
0040 {
0041 fRegistry = G4CrossSectionFactoryRegistry::Instance();
0042 }
0043
0044 virtual ~G4VBaseXSFactory() = default;
0045
0046 virtual G4VCrossSectionDataSet* Instantiate() = 0;
0047
0048 protected:
0049 G4CrossSectionFactoryRegistry* fRegistry;
0050 };
0051
0052
0053 template <typename T, int mode> class G4CrossSectionFactory : public G4VBaseXSFactory
0054 {
0055 public:
0056 G4CrossSectionFactory(const G4String& name)
0057 {
0058 fRegistry->Register(name, this);
0059 }
0060
0061 G4VCrossSectionDataSet* Instantiate() override
0062 {
0063 G4ExceptionDescription msg;
0064 msg<<"Factory mode: "<<mode<<" not supported!";
0065 G4Exception("G4CrossSectionFactory::Instantiate","CrossSectionFactory001",FatalException,msg);
0066 return static_cast<T*>(0);
0067 }
0068 };
0069
0070
0071
0072 template <typename T> class G4CrossSectionFactory<T,0> : public G4VBaseXSFactory
0073 {
0074 public:
0075
0076 G4CrossSectionFactory(const G4String& name)
0077 {
0078 fRegistry->Register(name, this);
0079 }
0080
0081 G4VCrossSectionDataSet* Instantiate() override
0082 {
0083 return new T();
0084 }
0085 };
0086
0087
0088
0089 template <typename T> class G4CrossSectionFactory<T,1> : public G4VBaseXSFactory
0090 {
0091 public:
0092 G4CrossSectionFactory(const G4String& name)
0093 {
0094 fRegistry->Register(name,this);
0095 }
0096
0097 G4VCrossSectionDataSet* Instantiate() override
0098 {
0099 static T* shared = new T();
0100 return shared;
0101 }
0102 };
0103
0104
0105
0106 template <typename T> class G4CrossSectionFactory<T,2> : public G4VBaseXSFactory
0107 {
0108 G4CrossSectionFactory(const G4String& name)
0109 {
0110 fRegistry->Register(name,this);
0111 }
0112
0113 G4VCrossSectionDataSet* Instantiate() override
0114 {
0115 static G4ThreadLocal T* shared = new T();
0116 return shared;
0117 }
0118 };
0119
0120
0121 #define G4_BASE_DECLARE_XS_FACTORY(cross_section, flag) \
0122 const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory = G4CrossSectionFactory<cross_section,flag>(cross_section::Default_Name())
0123
0124 #define G4_BASE_REFERENCE_XS_FACTORY(cross_section,flag) \
0125 class cross_section; \
0126 extern const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory; \
0127 const G4CrossSectionFactory<cross_section,flag>& cross_section##FactoryRef = cross_section##Factory
0128
0129
0130 #define G4_DECLARE_XS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,0)
0131 #define G4_DECLARE_SHAREDXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,1)
0132 #define G4_DECLARE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,2)
0133
0134
0135 #define G4_REFERENCE_XS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,0)
0136 #define G4_REFERENCE_SHAREDXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,1)
0137 #define G4_REFERENCE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,2)
0138
0139 #endif