Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:04

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
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 
0038 public:
0039 
0040   virtual G4VCrossSectionDataSet* Instantiate() = 0;
0041 
0042 };
0043 
0044 
0045 //Generic template XS-factory
0046 template <typename T, int mode> class G4CrossSectionFactory : public G4VBaseXSFactory
0047 {
0048 public:
0049   G4CrossSectionFactory(const G4String& name)
0050   {
0051       G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0052   }
0053   
0054   virtual G4VCrossSectionDataSet* Instantiate() 
0055   {
0056       G4ExceptionDescription msg;
0057       msg<<"Factory mode: "<<mode<<" not supported!";
0058       G4Exception("G4CrossSectionFactory::Instantiate","CrossSectionFactory001",FatalException,msg);
0059     return static_cast<T*>(0);
0060   }
0061 };
0062 
0063 //Partial specialized template for non-singleton non-shared factory
0064 // each call to Instantiate creates a new XS
0065 template <typename T> class G4CrossSectionFactory<T,0> : public G4VBaseXSFactory
0066 {
0067 public:
0068     
0069     G4CrossSectionFactory(const G4String& name)
0070     {
0071         G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0072     }
0073     
0074     virtual G4VCrossSectionDataSet* Instantiate()
0075     {
0076         return new T();
0077     }
0078 };
0079 
0080 //Partial specialized template for singleton, shared factory
0081 // each call to Instantiate returns pointer to static object
0082 template <typename T> class G4CrossSectionFactory<T,1> : public G4VBaseXSFactory
0083 {
0084 public:
0085     G4CrossSectionFactory(const G4String& name)
0086     {
0087         G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0088     }
0089     
0090     virtual G4VCrossSectionDataSet* Instantiate()
0091     {
0092         static T* shared = new T();
0093         return shared;
0094     }
0095 };
0096 
0097 //Partial specialized template for singleton, shared factory
0098 // each call to Instantiate returns pointer to static thread-local object
0099 template <typename T> class G4CrossSectionFactory<T,2> : public G4VBaseXSFactory
0100 {
0101     G4CrossSectionFactory(const G4String& name)
0102     {
0103         G4CrossSectionFactoryRegistry::Instance()->Register(name,this);
0104     }
0105     
0106     virtual G4VCrossSectionDataSet* Instantiate()
0107     {
0108         static G4ThreadLocal T* shared = new T();
0109         return shared;
0110     }
0111 };
0112 
0113 
0114 #define G4_BASE_DECLARE_XS_FACTORY(cross_section, flag) \
0115   const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory = G4CrossSectionFactory<cross_section,flag>(cross_section::Default_Name())
0116 
0117 #define G4_BASE_REFERENCE_XS_FACTORY(cross_section,flag) \
0118   class cross_section; \
0119   extern const G4CrossSectionFactory<cross_section,flag>& cross_section##Factory; \
0120   const G4CrossSectionFactory<cross_section,flag>& cross_section##FactoryRef = cross_section##Factory
0121 
0122 //Macros to help define and reference factories
0123 #define G4_DECLARE_XS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,0)
0124 #define G4_DECLARE_SHAREDXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,1)
0125 #define G4_DECLARE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_DECLARE_XS_FACTORY(cross_section,2)
0126 
0127 
0128 #define G4_REFERENCE_XS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,0)
0129 #define G4_REFERENCE_SHAREDXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,1)
0130 #define G4_REFERENCE_SHAREDTLSXS_FACTORY(cross_section) G4_BASE_REFERENCE_XS_FACTORY(cross_section,2)
0131 
0132 #endif