LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
G4PhysicsProcessFactorySingleton.cc
Go to the documentation of this file.
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 // $Id: G4PhysicsProcessFactorySingleton.cc,v 1.2 2012-09-20 21:43:53 greenc Exp $
27 // GEANT4 tag $Name: not supported by cvs2svn $
28 //
29 //---------------------------------------------------------------------------
30 //
31 // ClassName: G4PhysicsProcessFactorySingleton
32 //
33 // Author: 2012-02-02 R. Hatcher
34 //
35 // Modified:
36 //
37 //----------------------------------------------------------------------------
38 //
39 
41 
42 #include <iomanip>
43 
44 // Define static variable which holds the one-and-only instance
46 
48 {
49  fgTheInstance = this; // record created self in static pointer
50 }
51 
53 {
54  fgTheInstance = 0;
55 }
56 
58 {
59  // Cleaner dtor calls G4PhysicsProcessFactorySingleton dtor at job end
60  static Cleaner cleaner;
61 
62  if ( ! fgTheInstance ) {
63  // need to create one
64  cleaner.UseMe(); // dummy call to quiet compiler warnings
66  }
67 
68  return *fgTheInstance;
69 }
70 
71 G4VPhysicsConstructor*
73 {
74  G4VPhysicsConstructor* p = 0;
75 
76  // we don't want map creating an entry if it doesn't exist
77  // so use map::find() not map::operator[]
79  = fFunctionMap.find(name);
80  if ( fFunctionMap.end() != itr ) {
81  // found an appropriate entry in the list
82  PhysProcCtorFuncPtr_t foo = itr->second; // this is the function
83  p = (*foo)(); // use function to create the physics process
84  }
85  if ( ! p ) {
86  G4cout << "### G4PhysicsProcessFactorySingleton WARNING: "
87  << "PhysicsProcess " << name << " is not known"
88  << G4endl;
89  }
90  return p;
91 }
92 
94 {
95  // check if we know the name
96  G4bool res = false;
98  = fFunctionMap.find(name);
99  if ( fFunctionMap.end() != itr ) res = true;
100  return res;
101 }
102 
103 const std::vector<G4String>&
105 {
106  // list of names might be out of date due to new registrations
107  // rescan the std::map on each call (which won't be frequent)
108  listnames.clear();
109 
110  // scan map for registered names
112  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
113  listnames.push_back(itr->first);
114 
115  return listnames;
116 }
117 
119 {
120  std::vector<G4String> list = AvailablePhysicsProcesses();
121  G4cout << "G4VPhysicsConstructors in "
122  << "G4PhysicsProcessFactorySingleton are: "
123  << G4endl;
124  if ( list.empty() ) G4cout << " ... no registered processes" << G4endl;
125  else {
126  for (size_t indx=0; indx < list.size(); ++indx ) {
127  G4cout << " [" << std::setw(2) << indx << "] "
128  << "\"" << list[indx] << "\"" << G4endl;
129  }
130  }
131 
132 }
133 
136  G4bool* boolptr)
137 {
138  // record new functions for creating processes
139  fFunctionMap[name] = foo;
140  fBoolPtrMap[name] = boolptr;
141  return true;
142 }
143 
145 //#include "G4PhysProcRegisterOld.icc"
G4bool RegisterCreator(G4String name, PhysProcCtorFuncPtr_t ctorptr, G4bool *ptr)
intermediate_table::iterator iterator
const std::vector< G4String > & AvailablePhysicsProcesses() const
intermediate_table::const_iterator const_iterator
static G4PhysicsProcessFactorySingleton & Instance()
G4VPhysicsConstructor *(* PhysProcCtorFuncPtr_t)()
std::map< G4String, PhysProcCtorFuncPtr_t > fFunctionMap
static G4PhysicsProcessFactorySingleton * fgTheInstance
G4VPhysicsConstructor * GetPhysicsProcess(const G4String &)