Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
g4nu::G4PhysListFactorySingleton Class Reference

#include <G4PhysListFactorySingleton.hh>

Classes

struct  Cleaner
 

Public Member Functions

G4VModularPhysicsList * GetReferencePhysList (const G4String &)
 
G4VModularPhysicsList * ReferencePhysList ()
 
G4bool IsReferencePhysList (const G4String &)
 
const std::vector< G4String > & AvailablePhysLists () const
 
void PrintAvailablePhysLists () const
 
G4bool RegisterCreator (G4String name, PhysListCtorFuncPtr_t ctorptr, G4bool *ptr)
 
G4bool RegisterPhysicsReplacement (G4String key, G4String physics)
 
void SetDefaultName (const G4String &defname)
 
const G4String & GetDefaultName () const
 

Static Public Member Functions

static G4PhysListFactorySingletonInstance ()
 

Private Member Functions

 G4PhysListFactorySingleton ()
 
G4String GetBaseName (G4String name, std::vector< G4String > &physicsReplacements, G4bool &allKnown)
 
virtual ~G4PhysListFactorySingleton ()
 
 G4PhysListFactorySingleton (const G4PhysListFactorySingleton &)
 
void operator= (const G4PhysListFactorySingleton &)
 

Private Attributes

std::map< G4String, PhysListCtorFuncPtr_tfFunctionMap
 
std::map< G4String, G4bool * > fBoolPtrMap
 
std::map< G4String, G4String > fPhysicsReplaceList
 
G4String defName
 
std::vector< G4String > listnames
 

Static Private Attributes

static G4PhysListFactorySingletonfgTheInstance
 

Friends

struct Cleaner
 

Detailed Description

Definition at line 67 of file G4PhysListFactorySingleton.hh.

Constructor & Destructor Documentation

G4PhysListFactorySingleton::G4PhysListFactorySingleton ( )
private

Definition at line 50 of file G4PhysListFactorySingleton.cc.

51 {
52  defName = "QGSP_BERT"; // default list to use if no PHYSLIST defined
53  fgTheInstance = this; // record created self in static pointer
54 }
static G4PhysListFactorySingleton * fgTheInstance
G4PhysListFactorySingleton::~G4PhysListFactorySingleton ( )
privatevirtual

Definition at line 56 of file G4PhysListFactorySingleton.cc.

57 {
58  fgTheInstance = 0;
59 }
static G4PhysListFactorySingleton * fgTheInstance
g4nu::G4PhysListFactorySingleton::G4PhysListFactorySingleton ( const G4PhysListFactorySingleton )
private

Member Function Documentation

const std::vector< G4String > & G4PhysListFactorySingleton::AvailablePhysLists ( ) const

Definition at line 194 of file G4PhysListFactorySingleton.cc.

195 {
196  // list of names might be out of date due to new registrations
197  // rescan the std::map on each call (which won't be frequent)
198  listnames.clear();
199 
200  // scan map for registered names
202  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
203  listnames.push_back(itr->first);
204 
205  return listnames;
206 }
std::map< G4String, PhysListCtorFuncPtr_t > fFunctionMap
intermediate_table::const_iterator const_iterator
G4String G4PhysListFactorySingleton::GetBaseName ( G4String  name,
std::vector< G4String > &  physicsReplacements,
G4bool &  allKnown 
)
private

Definition at line 262 of file G4PhysListFactorySingleton.cc.

265 {
266  allKnown = true;
267  G4String nameNoReplace = name;
268  physicsReplace.clear();
269  G4PhysicsProcessFactorySingleton& procFactory =
271 
273  for ( ; repitr != fPhysicsReplaceList.end(); ++repitr ) {
274  G4String key = repitr->first;
275  size_t i = nameNoReplace.find(key);
276  if ( i != std::string::npos ) {
277  // remove key from base physics list name
278  nameNoReplace.erase(i,key.size());
279 
280  // add to list of things needing replacement
281  G4String procName = repitr->second;
282  physicsReplace.push_back(procName);
283  if ( ! procFactory.IsKnownPhysicsProcess(procName) ) {
284  G4cout << "G4PhysListFactorySingleton::GetBaseName "
285  << "\"" << key << "\" ==> \"" << procName << "\" not found"
286  << G4endl;
287  //procFactory.PrintAvailablePhysicsProcesses();
288  allKnown = false;
289  }
290  }
291  }
292 
294  = fFunctionMap.find(nameNoReplace);
295  if ( fFunctionMap.end() == itr ) allKnown = false;
296 
297  return nameNoReplace;
298 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
std::map< G4String, PhysListCtorFuncPtr_t > fFunctionMap
def key(type, name=None)
Definition: graph.py:13
static G4PhysicsProcessFactorySingleton & Instance()
std::map< G4String, G4String > fPhysicsReplaceList
const G4String& g4nu::G4PhysListFactorySingleton::GetDefaultName ( ) const
inline

Definition at line 97 of file G4PhysListFactorySingleton.hh.

G4VModularPhysicsList * G4PhysListFactorySingleton::GetReferencePhysList ( const G4String &  name)

Definition at line 104 of file G4PhysListFactorySingleton.cc.

105 {
106  G4VModularPhysicsList* p = 0;
107 
108  // Replacing the very fixed list of if/else with a std::map lookup
109  /*
110  if(name == "CHIPS") {p = new CHIPS();}
111  else if(name == "FTFP_BERT") {p = new FTFP_BERT();}
112  else if(name == "FTFP_BERT_EMV") {p = new FTFP_BERT_EMV();}
113  else if(name == "FTFP_BERT_EMX") {p = new FTFP_BERT_EMX();}
114  else if(name == "FTFP_BERT_TRV") {p = new FTFP_BERT_TRV();}
115  else if(name == "FTF_BIC") {p = new FTF_BIC();}
116  else if(name == "LBE") {p = new LBE();}
117  else if(name == "LHEP") {p = new LHEP();}
118  else if(name == "LHEP_EMV") {p = new LHEP_EMV();}
119  else if(name == "QBBC") {p = new QBBC();}
120  else if(name == "QGSC_BERT") {p = new QGSC_BERT();}
121  else if(name == "QGSP") {p = new QGSP();}
122  else if(name == "QGSP_BERT") {p = new QGSP_BERT();}
123  else if(name == "QGSP_BERT_EMV") {p = new QGSP_BERT_EMV();}
124  else if(name == "QGSP_BERT_EMX") {p = new QGSP_BERT_EMX();}
125  else if(name == "QGSP_BERT_HP") {p = new QGSP_BERT_HP();}
126  else if(name == "QGSP_BERT_NOLEP") {p = new QGSP_BERT_NOLEP();}
127  else if(name == "QGSP_BERT_TRV") {p = new QGSP_BERT_TRV();}
128  else if(name == "QGSP_BERT_CHIPS") {p = new QGSP_BERT_CHIPS();}
129  else if(name == "QGSP_BIC") {p = new QGSP_BIC();}
130  else if(name == "QGSP_BIC_EMY") {p = new QGSP_BIC_EMY();}
131  else if(name == "QGSP_BIC_HP") {p = new QGSP_BIC_HP();}
132  else if(name == "QGSP_FTFP_BERT"){p = new QGSP_FTFP_BERT();}
133  else if(name == "QGS_BIC") {p = new QGS_BIC();}
134  else if(name == "QGSP_INCL_ABLA"){p = new QGSP_INCL_ABLA();}
135  else if(name == "Shielding") {p = new Shielding();}
136  */
137 
138  // look for key bits that indicate physics to be replaced in a
139  // base physics list; remove those keys from the physics list name
140  std::vector<G4String> physicsReplacements;
141  G4bool allKnown;
142  G4String nameNoReplace = GetBaseName(name,physicsReplacements,allKnown);
143 
144  // we don't want map creating an entry if it doesn't exist
145  // so use map::find() not map::operator[]
147  = fFunctionMap.find(nameNoReplace);
148  if ( fFunctionMap.end() != itr ) {
149  // found an appropriate entry in the list
150  PhysListCtorFuncPtr_t foo = itr->second; // this is the function
151  p = (*foo)(); // use function to create the physics list
152  }
153  if ( ! p ) {
154  G4cout << "### G4PhysListFactorySingleton WARNING: "
155  << "PhysicsList " << nameNoReplace
156  << "(originally=\"" << name << "\")"
157  << " is not known"
158  << G4endl;
159  } else if ( physicsReplacements.size() != 0 ) {
160  //
161  // if there is physics to be replaced, do so now
162  //
163  G4PhysicsProcessFactorySingleton& procFactory =
165  for (size_t k=0; k<physicsReplacements.size(); ++k) {
166  G4String procName = physicsReplacements[k];
167  if ( ! procFactory.IsKnownPhysicsProcess(procName) ) {
168  G4cout << "### G4PhysListFactorySingleton WARNING: "
169  << "G4PhysicsProcesFactorySingleton had no process \""
170  << procName << "\" registered" << G4endl;
171  } else {
172  G4cout << "### G4PhysListFactorySingleton: ReplacePhysics("
173  << procName << ")" << G4endl;
174  G4VPhysicsConstructor* pctor = procFactory.GetPhysicsProcess(procName);
175  p->ReplacePhysics(pctor);
176  }
177  }
178  }
179 
180  return p;
181 }
static QCString name
Definition: declinfo.cpp:673
intermediate_table::iterator iterator
std::map< G4String, PhysListCtorFuncPtr_t > fFunctionMap
G4String GetBaseName(G4String name, std::vector< G4String > &physicsReplacements, G4bool &allKnown)
p
Definition: test.py:223
static G4PhysicsProcessFactorySingleton & Instance()
G4VModularPhysicsList *(* PhysListCtorFuncPtr_t)()
G4VPhysicsConstructor * GetPhysicsProcess(const G4String &)
G4PhysListFactorySingleton & G4PhysListFactorySingleton::Instance ( void  )
static

Definition at line 61 of file G4PhysListFactorySingleton.cc.

62 {
63  // Cleaner dtor calls G4PhysListFactorySingleton dtor at job end
64  static Cleaner cleaner;
65 
66  if ( ! fgTheInstance ) {
67  // need to create one
68  cleaner.UseMe(); // dummy call to quiet compiler warnings
70 
71  // special pre-register some physics overrides (common EM overrides)
72  fgTheInstance->RegisterPhysicsReplacement("_EMV","G4EmStandardPhysics_option1");
73  fgTheInstance->RegisterPhysicsReplacement("_EMX","G4EmStandardPhysics_option2");
74  fgTheInstance->RegisterPhysicsReplacement("_EMY","G4EmStandardPhysics_option3");
75  fgTheInstance->RegisterPhysicsReplacement("_LIV","G4EmLivermorePhysics");
76  fgTheInstance->RegisterPhysicsReplacement("_PEN","G4EmPenelopePhysics");
77 
78 
79  }
80 
81  return *fgTheInstance;
82 }
static G4PhysListFactorySingleton * fgTheInstance
G4bool RegisterPhysicsReplacement(G4String key, G4String physics)
G4bool G4PhysListFactorySingleton::IsReferencePhysList ( const G4String &  name)

Definition at line 183 of file G4PhysListFactorySingleton.cc.

184 {
185  // check if we know the name (after stripping off replacement keys)
186  std::vector<G4String> physicsReplacements;
187  G4bool allKnown;
188  G4String nameNoReplace = GetBaseName(name,physicsReplacements,allKnown);
189 
190  return allKnown;
191 }
static QCString name
Definition: declinfo.cpp:673
G4String GetBaseName(G4String name, std::vector< G4String > &physicsReplacements, G4bool &allKnown)
void g4nu::G4PhysListFactorySingleton::operator= ( const G4PhysListFactorySingleton )
private
void G4PhysListFactorySingleton::PrintAvailablePhysLists ( ) const

Definition at line 208 of file G4PhysListFactorySingleton.cc.

209 {
210  const std::vector<G4String>& list = AvailablePhysLists();
211  G4cout << "G4VModularPhysicsLists in "
212  << "G4PhysicsProcessFactorySingleton are: "
213  << G4endl;
214  if ( list.empty() ) G4cout << " ... no registered lists" << G4endl;
215  else {
216  for (size_t indx=0; indx < list.size(); ++indx ) {
217  G4cout << " [" << std::setw(2) << indx << "] "
218  << "\"" << list[indx] << "\"" << G4endl;
219  }
220  }
221  G4cout << "G4PhysicsProcessFactorySingleton supports variants of the above"
222  << G4endl << "with physics process replacements:" << G4endl;
223  if ( fPhysicsReplaceList.empty() ) {
224  G4cout << " ... no registered replacements" << G4endl;
225  } else {
226  G4bool printPhysicsProcesses = false;
227  G4PhysicsProcessFactorySingleton& procFactory =
230  fPhysicsReplaceList.begin();
231  for ( ; repitr != fPhysicsReplaceList.end(); ++repitr ) {
232  G4String key = repitr->first;
233  G4String procName = repitr->second;
234  G4bool known = procFactory.IsKnownPhysicsProcess(procName);
235  if ( ! known ) printPhysicsProcesses = true;
236  G4cout << " " << std::setw(10) << key << " ==> "
237  << std::setw(30) << procName << " "
238  << ( (known)?"known":"*** unknown ***" ) << G4endl;
239  }
240  if ( printPhysicsProcesses ) procFactory.PrintAvailablePhysicsProcesses();
241  }
242 }
const std::vector< G4String > & AvailablePhysLists() const
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
static G4PhysicsProcessFactorySingleton & Instance()
std::map< G4String, G4String > fPhysicsReplaceList
G4VModularPhysicsList * G4PhysListFactorySingleton::ReferencePhysList ( )

Definition at line 84 of file G4PhysListFactorySingleton.cc.

85 {
86  // instantiate PhysList by environment variable "PHYSLIST"
87  G4String name = "";
88  char* path = getenv("PHYSLIST");
89  if (path) {
90  name = G4String(path);
91  } else {
92  name = defName;
93  G4cout << "### G4PhysListFactorySingleton WARNING: "
94  << " environment variable PHYSLIST is not defined"
95  << G4endl
96  << " Default Physics Lists " << name
97  << " is instantiated"
98  << G4endl;
99  }
100  return GetReferencePhysList(name);
101 }
static QCString name
Definition: declinfo.cpp:673
G4VModularPhysicsList * GetReferencePhysList(const G4String &)
std::string getenv(std::string const &name)
Definition: getenv.cc:15
G4bool G4PhysListFactorySingleton::RegisterCreator ( G4String  name,
PhysListCtorFuncPtr_t  ctorptr,
G4bool *  ptr 
)

Definition at line 244 of file G4PhysListFactorySingleton.cc.

247 {
248  // record new functions for creating lists
249  fFunctionMap[name] = foo;
250  fBoolPtrMap[name] = boolptr;
251  return true;
252 }
static QCString name
Definition: declinfo.cpp:673
std::map< G4String, PhysListCtorFuncPtr_t > fFunctionMap
std::map< G4String, G4bool * > fBoolPtrMap
G4bool G4PhysListFactorySingleton::RegisterPhysicsReplacement ( G4String  key,
G4String  physics 
)

Definition at line 254 of file G4PhysListFactorySingleton.cc.

256 {
257  fPhysicsReplaceList[key] = physics;
258  return true;
259 }
def key(type, name=None)
Definition: graph.py:13
std::map< G4String, G4String > fPhysicsReplaceList
void g4nu::G4PhysListFactorySingleton::SetDefaultName ( const G4String &  defname)
inline

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 146 of file G4PhysListFactorySingleton.hh.

Member Data Documentation

G4String g4nu::G4PhysListFactorySingleton::defName
private

Definition at line 113 of file G4PhysListFactorySingleton.hh.

std::map<G4String, G4bool*> g4nu::G4PhysListFactorySingleton::fBoolPtrMap
private

Definition at line 106 of file G4PhysListFactorySingleton.hh.

std::map<G4String, PhysListCtorFuncPtr_t> g4nu::G4PhysListFactorySingleton::fFunctionMap
private

Definition at line 103 of file G4PhysListFactorySingleton.hh.

G4PhysListFactorySingleton * G4PhysListFactorySingleton::fgTheInstance
staticprivate

Definition at line 100 of file G4PhysListFactorySingleton.hh.

std::map<G4String, G4String> g4nu::G4PhysListFactorySingleton::fPhysicsReplaceList
private

Definition at line 108 of file G4PhysListFactorySingleton.hh.

std::vector<G4String> g4nu::G4PhysListFactorySingleton::listnames
mutableprivate

Definition at line 116 of file G4PhysListFactorySingleton.hh.


The documentation for this class was generated from the following files: