Geant4-11
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
G4Cache< VALTYPE > Class Template Reference

#include <G4Cache.hh>

Public Types

typedef VALTYPE value_type
 

Public Member Functions

 G4Cache ()
 
 G4Cache (const G4Cache &rhs)
 
 G4Cache (const value_type &v)
 
value_typeGet () const
 
G4Cacheoperator= (const G4Cache &rhs)
 
value_type Pop ()
 
void Put (const value_type &val) const
 
virtual ~G4Cache ()
 

Protected Member Functions

const G4intGetId () const
 

Private Member Functions

value_typeGetCache () const
 

Private Attributes

G4int id
 
G4CacheReference< value_typetheCache
 

Static Private Attributes

static std::atomic< unsigned int > dstrctr
 
static std::atomic< unsigned int > instancesctr
 

Detailed Description

template<class VALTYPE>
class G4Cache< VALTYPE >

Definition at line 88 of file G4Cache.hh.

Member Typedef Documentation

◆ value_type

template<class VALTYPE >
typedef VALTYPE G4Cache< VALTYPE >::value_type

Definition at line 91 of file G4Cache.hh.

Constructor & Destructor Documentation

◆ G4Cache() [1/3]

template<class V >
G4Cache< V >::G4Cache

Definition at line 210 of file G4Cache.hh.

211{
213 id = instancesctr++;
214#ifdef g4cdebug
215 std::cout << "G4Cache id: " << id << std::endl;
216#endif
217}
G4Mutex & G4TypeMutex(const unsigned int &_n=0)
Definition: G4Threading.hh:124
static std::atomic< unsigned int > instancesctr
Definition: G4Cache.hh:121

References G4TypeMutex().

◆ G4Cache() [2/3]

template<class VALTYPE >
G4Cache< VALTYPE >::G4Cache ( const value_type v)

◆ ~G4Cache()

template<class V >
G4Cache< V >::~G4Cache
virtual

Definition at line 270 of file G4Cache.hh.

271{
272#ifdef g4cdebug
273 std::cout << "~G4Cache id: " << id << std::endl;
274#endif
275 // don't automatically lock --> wait until we can catch an error
276 // without scoping the G4AutoLock
277 //
278 G4AutoLock l(G4TypeMutex<G4Cache<V>>(), std::defer_lock);
279
280 // sometimes the mutex is unavailable in destructors so
281 // try to lock the associated mutex, but catch if it fails
282 try
283 {
284 // a system_error in lock means that the mutex is unavailable
285 // we want to throw the error that comes from locking an unavailable
286 // mutex so that we know there is a memory leak
287 // if the mutex is valid, this will hold until the other thread finishes
288 //
289 l.lock();
290 } catch(std::system_error& e)
291 {
292 // the error that comes from locking an unavailable mutex
293#ifdef G4VERBOSE
294 G4cout << "Non-critical error: mutex lock failure in ~G4Cache<"
295 << typeid(V).name() << ">. " << G4endl
296 << "If the RunManagerKernel has been deleted, it failed to "
297 << "delete an allocated resource" << G4endl
298 << "and this destructor is being called after the statics "
299 << "were destroyed." << G4endl;
300 G4cout << "Exception: [code: " << e.code() << "] caught: " << e.what()
301 << G4endl;
302#endif
303 }
304 ++dstrctr;
305 G4bool last = (dstrctr == instancesctr);
306 theCache.Destroy(id, last);
307 if(last)
308 {
309 instancesctr.store(0);
310 dstrctr.store(0);
311 }
312}
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void Destroy(unsigned int id, G4bool last)
G4CacheReference< value_type > theCache
Definition: G4Cache.hh:120
static std::atomic< unsigned int > dstrctr
Definition: G4Cache.hh:122
const char * name(G4int ptype)

References G4cout, G4endl, G4TypeMutex(), G4TemplateAutoLock< _Mutex_t >::lock(), and G4InuclParticleNames::name().

◆ G4Cache() [3/3]

template<class VALTYPE >
G4Cache< VALTYPE >::G4Cache ( const G4Cache< VALTYPE > &  rhs)

Member Function Documentation

◆ Get()

template<class V >
V & G4Cache< V >::Get
inline

Definition at line 315 of file G4Cache.hh.

316{
317 return GetCache();
318}
value_type & GetCache() const
Definition: G4Cache.hh:124

Referenced by G4ParticleHPFinalState::adjust_final_state(), G4FissionLibrary::ApplyYourself(), G4ParticleHP2AInelasticFS::ApplyYourself(), G4ParticleHP2N2AInelasticFS::ApplyYourself(), G4ParticleHP2NAInelasticFS::ApplyYourself(), G4ParticleHP2NDInelasticFS::ApplyYourself(), G4ParticleHP2NInelasticFS::ApplyYourself(), G4ParticleHP2NPInelasticFS::ApplyYourself(), G4ParticleHP2PInelasticFS::ApplyYourself(), G4ParticleHP3AInelasticFS::ApplyYourself(), G4ParticleHP3NAInelasticFS::ApplyYourself(), G4ParticleHP3NInelasticFS::ApplyYourself(), G4ParticleHP3NPInelasticFS::ApplyYourself(), G4ParticleHP4NInelasticFS::ApplyYourself(), G4ParticleHPAInelasticFS::ApplyYourself(), G4ParticleHPCaptureFS::ApplyYourself(), G4ParticleHPD2AInelasticFS::ApplyYourself(), G4ParticleHPDAInelasticFS::ApplyYourself(), G4ParticleHPDInelasticFS::ApplyYourself(), G4ParticleHPElasticFS::ApplyYourself(), G4ParticleHPFissionFS::ApplyYourself(), G4ParticleHPHe3InelasticFS::ApplyYourself(), G4ParticleHPN2AInelasticFS::ApplyYourself(), G4ParticleHPN2PInelasticFS::ApplyYourself(), G4ParticleHPN3AInelasticFS::ApplyYourself(), G4ParticleHPNAInelasticFS::ApplyYourself(), G4ParticleHPND2AInelasticFS::ApplyYourself(), G4ParticleHPNDInelasticFS::ApplyYourself(), G4ParticleHPNHe3InelasticFS::ApplyYourself(), G4ParticleHPNInelasticFS::ApplyYourself(), G4ParticleHPNPAInelasticFS::ApplyYourself(), G4ParticleHPNPInelasticFS::ApplyYourself(), G4ParticleHPNT2AInelasticFS::ApplyYourself(), G4ParticleHPNTInelasticFS::ApplyYourself(), G4ParticleHPNXInelasticFS::ApplyYourself(), G4ParticleHPPAInelasticFS::ApplyYourself(), G4ParticleHPPDInelasticFS::ApplyYourself(), G4ParticleHPPInelasticFS::ApplyYourself(), G4ParticleHPPTInelasticFS::ApplyYourself(), G4ParticleHPT2AInelasticFS::ApplyYourself(), G4ParticleHPTInelasticFS::ApplyYourself(), G4ParticleHPInelasticBaseFS::BaseApply(), G4VectorCache< VALTYPE >::Begin(), G4MapCache< KEYTYPE, VALTYPE >::Begin(), G4BiasingProcessInterface::BuildPhysicsTable(), G4BiasingProcessInterface::BuildWorkerPhysicsTable(), G4VectorCache< VALTYPE >::Clear(), G4ParticleHPContEnergyAngular::ClearHistories(), G4ParticleHPInelasticCompFS::CompositeApply(), G4VectorCache< VALTYPE >::End(), G4MapCache< KEYTYPE, VALTYPE >::End(), G4BiasingProcessInterface::EndTracking(), G4MapCache< KEYTYPE, VALTYPE >::Erase(), G4MapCache< KEYTYPE, VALTYPE >::Find(), G4VBiasingOperator::G4VBiasingOperator(), G4VectorCache< VALTYPE >::G4VectorCache(), G4BiasingOperationManager::GetBiasingOperations(), G4VBiasingOperator::GetBiasingOperators(), G4ParticleHPPhotonDist::GetPhotons(), G4MapCache< KEYTYPE, VALTYPE >::Insert(), G4ThreadLocalSingleton< T >::Instance(), G4PhaseSpaceDecayChannel::ManyBodyDecayIt(), G4ParticleHPContEnergyAngular::MeanEnergyOfThisInteraction(), G4PhaseSpaceDecayChannel::OneBodyDecayIt(), G4VectorCache< VALTYPE >::operator[](), G4VectorCache< VALTYPE >::Pop_back(), G4VectorCache< VALTYPE >::Push_back(), G4ParticleHPContEnergyAngular::Sample(), G4PenelopeBremsstrahlungFS::SampleGammaEnergy(), G4VectorCache< VALTYPE >::Size(), G4MapCache< KEYTYPE, VALTYPE >::Size(), G4BiasingProcessInterface::StartTracking(), G4PhaseSpaceDecayChannel::ThreeBodyDecayIt(), G4PhaseSpaceDecayChannel::TwoBodyDecayIt(), G4ParticleHPInelasticCompFS::use_nresp71_model(), G4ParticleHPContEnergyAngular::~G4ParticleHPContEnergyAngular(), G4ParticleHPFinalState::~G4ParticleHPFinalState(), and G4ParticleHPPhotonDist::~G4ParticleHPPhotonDist().

◆ GetCache()

template<class VALTYPE >
value_type & G4Cache< VALTYPE >::GetCache ( ) const
inlineprivate

Definition at line 124 of file G4Cache.hh.

125 {
127 return theCache.GetCache(id);
128 }
VALTYPE & GetCache(unsigned int id) const
void Initialize(unsigned int id)

References G4CacheReference< VALTYPE >::GetCache(), G4CacheReference< VALTYPE >::Initialize(), and G4Cache< VALTYPE >::theCache.

Referenced by G4Cache< VALTYPE >::operator=().

◆ GetId()

template<class VALTYPE >
const G4int & G4Cache< VALTYPE >::GetId ( ) const
inlineprotected

Definition at line 116 of file G4Cache.hh.

116{ return id; }
G4int id
Definition: G4Cache.hh:119

References G4Cache< VALTYPE >::id.

Referenced by G4MapCache< KEYTYPE, VALTYPE >::~G4MapCache().

◆ operator=()

template<class VALTYPE >
G4Cache< V > & G4Cache< V >::operator= ( const G4Cache< VALTYPE > &  rhs)

Definition at line 241 of file G4Cache.hh.

242{
243 if(this == &rhs)
244 return *this;
245
246 // Force copy of cached data
247 //
248 V aCopy = rhs.GetCache();
249 Put(aCopy);
250
251#ifdef g4cdebug
252 std::cout << "Assignement operator with id: " << id << std::endl;
253#endif
254 return *this;
255}
void Put(const value_type &val) const
Definition: G4Cache.hh:321

References G4Cache< VALTYPE >::GetCache().

◆ Pop()

template<class V >
V G4Cache< V >::Pop
inline

Definition at line 328 of file G4Cache.hh.

329{
330 return GetCache();
331}

◆ Put()

template<class VALTYPE >
void G4Cache< V >::Put ( const value_type val) const
inline

Field Documentation

◆ dstrctr

template<class V >
std::atomic< unsigned int > G4Cache< V >::dstrctr
staticprivate

Definition at line 122 of file G4Cache.hh.

◆ id

template<class VALTYPE >
G4int G4Cache< VALTYPE >::id
private

Definition at line 119 of file G4Cache.hh.

Referenced by G4Cache< VALTYPE >::GetId().

◆ instancesctr

template<class V >
std::atomic< unsigned int > G4Cache< V >::instancesctr
staticprivate

Definition at line 121 of file G4Cache.hh.

◆ theCache

template<class VALTYPE >
G4CacheReference<value_type> G4Cache< VALTYPE >::theCache
mutableprivate

Definition at line 120 of file G4Cache.hh.

Referenced by G4Cache< VALTYPE >::GetCache().


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