Back to home page

EIC code displayed by LXR

 
 

    


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

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 G4PhysListStamper_h
0027 #define G4PhysListStamper_h 1
0028 
0029 
0030 #include "globals.hh"
0031 #include "G4PhysListRegistry.hh"
0032 #include "G4VModularPhysicsList.hh"
0033 
0034 class G4VBasePhysListStamper
0035 {
0036 
0037 public:
0038 
0039   virtual G4VModularPhysicsList* Instantiate(G4int /* verbose */) = 0;
0040 
0041 };
0042 
0043 
0044 template <typename T> class G4PhysListStamper : public G4VBasePhysListStamper
0045 {
0046 public:
0047   
0048   G4PhysListStamper(const G4String& name)
0049   {
0050     G4PhysListRegistry::Instance()->AddFactory(name, this);
0051   }
0052   
0053   virtual G4VModularPhysicsList* Instantiate(G4int verbose) 
0054   {
0055     return new T(verbose);
0056   }
0057 };
0058 
0059 #define G4_DECLARE_PHYSLIST_FACTORY(physics_list) \
0060   const G4PhysListStamper<physics_list>& physics_list##Factory = G4PhysListStamper<physics_list>(#physics_list)
0061 
0062 // support for physics list defined within a namespace
0063 // a bit tricky because cpp macro expansion doesn't like "::"
0064 // ala  G4_DECLARE_PHYSLIST_FACTORY_NS(myns::MyPL,myns,MyPL);
0065 #define G4_DECLARE_PHYSLIST_FACTORY_NS( physics_list , nsname , plbase )    \
0066   namespace nsname {                                                    \
0067     const G4PhysListStamper<physics_list>& plbase##Factory = G4PhysListStamper<physics_list>(#physics_list); \
0068   } \
0069   typedef int xyzzy__LINE__
0070   // eat trailing semicolon using silly typedef
0071 
0072 // REFERENCE (rather than DECLARE) when the physics list if it is part
0073 // of a static library.  No need to include the header (DECLARE needs this
0074 // to build the code), we just need to make a reference in order to pull
0075 // the compilation unit static variable from the library and cause it
0076 // to be initialized (and thus self-register)
0077 
0078 // this is _very_ much complicated because of the templating of these lists
0079 
0080 #define G4_REFERENCE_PHYSLIST_FACTORY(physics_list) \
0081   class G4VModularPhysicsList;                  \
0082   template <class T> class T##physics_list; \
0083   typedef T##physics_list<G4VModularPhysicsList> physics_list;         \
0084   extern const G4PhysListStamper<physics_list>& physics_list##Factory; \
0085   const G4PhysListStamper<physics_list>& physics_list##FactoryRef = physics_list##Factory
0086 
0087 #define G4_REFERENCE_PHYSLIST_FACTORY_NS(physics_list, nsname, plbase ) \
0088   class G4VModularPhysicsList;    \
0089   namespace nsname { \
0090     template <class T> class T##plbase; \
0091     typedef T##plbase<G4VModularPhysicsList> plbase; \
0092     extern const G4PhysListStamper<plbase>& plbase##Factory; \
0093     const G4PhysListStamper<plbase>& plbase##FactoryRef = plbase##Factory; \
0094   } \
0095   typedef int xyzzy__LINE__
0096   // eat trailing semicolon using silly typedef
0097 
0098 #endif
0099