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 namespace g4nu {
45 
46 // Define static variable which holds the one-and-only instance
48 
50 {
51  fgTheInstance = this; // record created self in static pointer
52 }
53 
55 {
56  fgTheInstance = 0;
57 }
58 
60 {
61  // Cleaner dtor calls G4PhysicsProcessFactorySingleton dtor at job end
62  static Cleaner cleaner;
63 
64  if ( ! fgTheInstance ) {
65  // need to create one
66  cleaner.UseMe(); // dummy call to quiet compiler warnings
68  }
69 
70  return *fgTheInstance;
71 }
72 
73 G4VPhysicsConstructor*
75 {
76  G4VPhysicsConstructor* p = 0;
77 
78  // we don't want map creating an entry if it doesn't exist
79  // so use map::find() not map::operator[]
81  = fFunctionMap.find(name);
82  if ( fFunctionMap.end() != itr ) {
83  // found an appropriate entry in the list
84  PhysProcCtorFuncPtr_t foo = itr->second; // this is the function
85  p = (*foo)(); // use function to create the physics process
86  }
87  if ( ! p ) {
88  G4cout << "### G4PhysicsProcessFactorySingleton WARNING: "
89  << "PhysicsProcess " << name << " is not known"
90  << G4endl;
91  }
92  return p;
93 }
94 
96 {
97  // check if we know the name
98  G4bool res = false;
100  = fFunctionMap.find(name);
101  if ( fFunctionMap.end() != itr ) res = true;
102  return res;
103 }
104 
105 const std::vector<G4String>&
107 {
108  // list of names might be out of date due to new registrations
109  // rescan the std::map on each call (which won't be frequent)
110  listnames.clear();
111 
112  // scan map for registered names
114  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
115  listnames.push_back(itr->first);
116 
117  return listnames;
118 }
119 
121 {
122  std::vector<G4String> list = AvailablePhysicsProcesses();
123  G4cout << "G4VPhysicsConstructors in "
124  << "G4PhysicsProcessFactorySingleton are: "
125  << G4endl;
126  if ( list.empty() ) G4cout << " ... no registered processes" << G4endl;
127  else {
128  for (size_t indx=0; indx < list.size(); ++indx ) {
129  G4cout << " [" << std::setw(2) << indx << "] "
130  << "\"" << list[indx] << "\"" << G4endl;
131  }
132  }
133 
134 }
135 
138  G4bool* boolptr)
139 {
140  // record new functions for creating processes
141  fFunctionMap[name] = foo;
142  fBoolPtrMap[name] = boolptr;
143  return true;
144 }
145 
146 } // end-of-namespace g4nu
147 
148 /// !!!!!! register existing classes without disturbing their .cc files (yet)
149 //#include "G4PhysProcRegisterOld.icc"
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
G4bool RegisterCreator(G4String name, PhysProcCtorFuncPtr_t ctorptr, G4bool *ptr)
intermediate_table::const_iterator const_iterator
const std::vector< G4String > & AvailablePhysicsProcesses() const
static G4PhysicsProcessFactorySingleton * fgTheInstance
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
p
Definition: test.py:223
static G4PhysicsProcessFactorySingleton & Instance()
std::map< G4String, PhysProcCtorFuncPtr_t > fFunctionMap
G4VPhysicsConstructor *(* PhysProcCtorFuncPtr_t)()
G4VPhysicsConstructor * GetPhysicsProcess(const G4String &)