Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CrossSectionFactoryRegistry.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// G4CrossSectionFactoryRegistry class
27//
28// History:
29// 1-Apr-2013: A. Dotti, first implementation
32#include "G4AutoLock.hh"
33#include "globals.hh"
34
35namespace
36{
38}
39
45
47{}
48
50{
51 if ( factories.find(name) == factories.end() ) {
52 G4AutoLock l(regMutex);
53 if ( factories.find(name) == factories.end() ) {
54 factories[name] = factory;
55 }
56 l.unlock();
57 }
58}
59
61{
62 if ( nullptr == factory || factories.empty() ) { return; }
63 G4AutoLock l(regMutex);
64 for ( auto const & f : factories ) {
65 if ( factory == f.second ) {
66 factories[f.first] = nullptr;
67 }
68 }
69 l.unlock();
70}
71
73G4CrossSectionFactoryRegistry::GetFactory( const G4String& name, G4bool abortIfNotFound ) const
74{
75 G4VBaseXSFactory* ptr = nullptr;
76 auto it = factories.find(name);
77 if ( it != factories.end() ) {
78 ptr = it->second;
79 } else if ( abortIfNotFound ) {
81 msg << "Cross section factory with name: " << name << " not found.";
82 G4Exception("G4CrossSectionFactoryRegistry::GetFactory(...)",
83 "CrossSection003", FatalException, msg);
84 }
85 return ptr;
86}
87
88std::ostream& operator<<(std::ostream& msg, const G4CrossSectionFactoryRegistry& rhs) {
89 msg<<"Factory Registry "<<&rhs<<" has factories: [";
90 for ( std::map<G4String,G4VBaseXSFactory*>::const_iterator it =rhs.factories.begin();
91 it != rhs.factories.end() ; ++it )
92 {
93 msg<<(*it).first<<":"<<(*it).second<<",";
94 }
95 msg<<"]";
96 return msg;
97}
G4TemplateAutoLock< G4Mutex > G4AutoLock
std::ostream & operator<<(std::ostream &msg, const G4CrossSectionFactoryRegistry &rhs)
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
#define G4MUTEX_INITIALIZER
std::mutex G4Mutex
bool G4bool
Definition G4Types.hh:86
static G4CrossSectionFactoryRegistry * Instance()
void DeRegister(G4VBaseXSFactory *factory)
G4VBaseXSFactory * GetFactory(const G4String &name, G4bool abortIfNotFound=true) const
G4CrossSectionFactoryRegistry(const G4CrossSectionFactoryRegistry &)=delete
void Register(const G4String &name, G4VBaseXSFactory *factory)