LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
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 G4StringGetDefaultName () 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, G4StringfPhysicsReplaceList
 
G4String defName
 
std::vector< G4Stringlistnames
 

Static Private Attributes

static G4PhysListFactorySingletonfgTheInstance
 

Friends

struct Cleaner
 

Detailed Description

Definition at line 65 of file G4PhysListFactorySingleton.hh.

Constructor & Destructor Documentation

G4PhysListFactorySingleton::G4PhysListFactorySingleton ( )
private

Definition at line 48 of file G4PhysListFactorySingleton.cc.

References defName, and fgTheInstance.

Referenced by Instance().

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

Definition at line 54 of file G4PhysListFactorySingleton.cc.

References fgTheInstance.

55 {
56  fgTheInstance = 0;
57 }
static G4PhysListFactorySingleton * fgTheInstance
G4PhysListFactorySingleton::G4PhysListFactorySingleton ( const G4PhysListFactorySingleton )
private

Member Function Documentation

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

Definition at line 192 of file G4PhysListFactorySingleton.cc.

References fFunctionMap, and listnames.

Referenced by alt::G4PhysListFactory::AvailablePhysLists(), and PrintAvailablePhysLists().

193 {
194  // list of names might be out of date due to new registrations
195  // rescan the std::map on each call (which won't be frequent)
196  listnames.clear();
197 
198  // scan map for registered names
200  for ( itr = fFunctionMap.begin(); itr != fFunctionMap.end(); ++itr )
201  listnames.push_back(itr->first);
202 
203  return listnames;
204 }
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 260 of file G4PhysListFactorySingleton.cc.

References fFunctionMap, fPhysicsReplaceList, G4PhysicsProcessFactorySingleton::Instance(), and G4PhysicsProcessFactorySingleton::IsKnownPhysicsProcess().

Referenced by GetReferencePhysList(), and IsReferencePhysList().

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

Definition at line 95 of file G4PhysListFactorySingleton.hh.

References defName.

Referenced by alt::G4PhysListFactory::GetDefaultName().

G4VModularPhysicsList * G4PhysListFactorySingleton::GetReferencePhysList ( const G4String name)

Definition at line 102 of file G4PhysListFactorySingleton.cc.

References fFunctionMap, GetBaseName(), G4PhysicsProcessFactorySingleton::GetPhysicsProcess(), G4PhysicsProcessFactorySingleton::Instance(), and G4PhysicsProcessFactorySingleton::IsKnownPhysicsProcess().

Referenced by alt::G4PhysListFactory::GetReferencePhysList(), and ReferencePhysList().

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

Definition at line 59 of file G4PhysListFactorySingleton.cc.

References fgTheInstance, G4PhysListFactorySingleton(), RegisterPhysicsReplacement(), and G4PhysListFactorySingleton::Cleaner::UseMe().

Referenced by alt::G4PhysListFactory::AvailablePhysLists(), alt::G4PhysListFactory::GetDefaultName(), alt::G4PhysListFactory::GetReferencePhysList(), alt::G4PhysListFactory::IsReferencePhysList(), alt::G4PhysListFactory::PrintAvailablePhysLists(), alt::G4PhysListFactory::ReferencePhysList(), and alt::G4PhysListFactory::SetDefaultName().

60 {
61  // Cleaner dtor calls G4PhysListFactorySingleton 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  // special pre-register some physics overrides (common EM overrides)
70  fgTheInstance->RegisterPhysicsReplacement("_EMV","G4EmStandardPhysics_option1");
71  fgTheInstance->RegisterPhysicsReplacement("_EMX","G4EmStandardPhysics_option2");
72  fgTheInstance->RegisterPhysicsReplacement("_EMY","G4EmStandardPhysics_option3");
73  fgTheInstance->RegisterPhysicsReplacement("_LIV","G4EmLivermorePhysics");
74  fgTheInstance->RegisterPhysicsReplacement("_PEN","G4EmPenelopePhysics");
75 
76 
77  }
78 
79  return *fgTheInstance;
80 }
static G4PhysListFactorySingleton * fgTheInstance
G4bool RegisterPhysicsReplacement(G4String key, G4String physics)
G4bool G4PhysListFactorySingleton::IsReferencePhysList ( const G4String name)

Definition at line 181 of file G4PhysListFactorySingleton.cc.

References GetBaseName().

Referenced by alt::G4PhysListFactory::IsReferencePhysList().

182 {
183  // check if we know the name (after stripping off replacement keys)
184  std::vector<G4String> physicsReplacements;
185  G4bool allKnown;
186  G4String nameNoReplace = GetBaseName(name,physicsReplacements,allKnown);
187 
188  return allKnown;
189 }
G4String GetBaseName(G4String name, std::vector< G4String > &physicsReplacements, G4bool &allKnown)
void G4PhysListFactorySingleton::operator= ( const G4PhysListFactorySingleton )
private
void G4PhysListFactorySingleton::PrintAvailablePhysLists ( ) const

Definition at line 206 of file G4PhysListFactorySingleton.cc.

References AvailablePhysLists(), fPhysicsReplaceList, G4PhysicsProcessFactorySingleton::Instance(), G4PhysicsProcessFactorySingleton::IsKnownPhysicsProcess(), and G4PhysicsProcessFactorySingleton::PrintAvailablePhysicsProcesses().

Referenced by alt::G4PhysListFactory::PrintAvailablePhysLists().

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

Definition at line 82 of file G4PhysListFactorySingleton.cc.

References defName, and GetReferencePhysList().

Referenced by alt::G4PhysListFactory::ReferencePhysList().

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

Definition at line 242 of file G4PhysListFactorySingleton.cc.

References fBoolPtrMap, and fFunctionMap.

245 {
246  // record new functions for creating lists
247  fFunctionMap[name] = foo;
248  fBoolPtrMap[name] = boolptr;
249  return true;
250 }
std::map< G4String, PhysListCtorFuncPtr_t > fFunctionMap
std::map< G4String, G4bool * > fBoolPtrMap
G4bool G4PhysListFactorySingleton::RegisterPhysicsReplacement ( G4String  key,
G4String  physics 
)

Definition at line 252 of file G4PhysListFactorySingleton.cc.

References fPhysicsReplaceList.

Referenced by Instance().

254 {
255  fPhysicsReplaceList[key] = physics;
256  return true;
257 }
std::map< G4String, G4String > fPhysicsReplaceList
void G4PhysListFactorySingleton::SetDefaultName ( const G4String defname)
inline

Definition at line 94 of file G4PhysListFactorySingleton.hh.

References defName.

Referenced by alt::G4PhysListFactory::SetDefaultName().

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 144 of file G4PhysListFactorySingleton.hh.

Member Data Documentation

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

Definition at line 104 of file G4PhysListFactorySingleton.hh.

Referenced by RegisterCreator().

std::map<G4String, PhysListCtorFuncPtr_t> G4PhysListFactorySingleton::fFunctionMap
private
G4PhysListFactorySingleton * G4PhysListFactorySingleton::fgTheInstance
staticprivate
std::map<G4String, G4String> G4PhysListFactorySingleton::fPhysicsReplaceList
private
std::vector<G4String> G4PhysListFactorySingleton::listnames
mutableprivate

Definition at line 114 of file G4PhysListFactorySingleton.hh.

Referenced by AvailablePhysLists().


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