Import Geant4 11.3.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2024-06-28 13:08:51 +02:00
parent f7b23877ed
commit e58e650b32
5232 changed files with 239416 additions and 244360 deletions
@@ -45,12 +45,12 @@
#ifndef G4TAtomicHitsCollection_h
#define G4TAtomicHitsCollection_h 1
#include "G4VHitsCollection.hh"
#include "G4Allocator.hh"
#include "globals.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "G4Threading.hh"
#include "G4VHitsCollection.hh"
#include "G4atomic.hh"
#include "globals.hh"
#include <deque>
#include <type_traits>
@@ -77,114 +77,110 @@
void* theCollection;
};*/
template <class T>
template<class T>
class G4TAtomicHitsCollection : public G4VHitsCollection
{
protected:
static_assert(std::is_fundamental<T>::value,
"G4TAtomicHitsCollection must use fundamental type");
protected:
static_assert(std::is_fundamental<T>::value,
"G4TAtomicHitsCollection must use fundamental type");
public:
typedef T base_type;
typedef G4atomic<T> value_type;
typedef typename std::deque<value_type*> container_type;
public:
typedef T base_type;
typedef G4atomic<T> value_type;
typedef typename std::deque<value_type*> container_type;
public:
G4TAtomicHitsCollection();
public:
G4TAtomicHitsCollection();
public:
// with description
G4TAtomicHitsCollection(G4String detName, G4String colNam);
public:
// with description
G4TAtomicHitsCollection(G4String detName, G4String colNam);
// constructor.
public:
virtual ~G4TAtomicHitsCollection();
G4bool operator==(const G4TAtomicHitsCollection<T>& right) const;
// constructor.
public:
virtual ~G4TAtomicHitsCollection();
G4bool operator==(const G4TAtomicHitsCollection<T>& right) const;
// inline void *operator new(size_t);
// inline void operator delete(void* anHC);
// inline void *operator new(size_t);
// inline void operator delete(void* anHC);
public: // with description
virtual void DrawAllHits();
virtual void PrintAllHits();
// These two methods invokes Draw() and Print() methods of all of
// hit objects stored in this collection, respectively.
public: // with description
virtual void DrawAllHits();
virtual void PrintAllHits();
// These two methods invokes Draw() and Print() methods of all of
// hit objects stored in this collection, respectively.
public: // with description
inline value_type* operator[](size_t i) const { return (*theCollection)[i]; }
// Returns a pointer to a concrete hit object.
inline container_type* GetVector() const { return theCollection; }
// Returns a collection vector.
inline G4int insert(T* aHit)
{
G4AutoLock l(&fMutex);
theCollection->push_back(aHit);
return theCollection->size();
}
// Insert a hit object. Total number of hit objects stored in this
// collection is returned.
inline G4int entries() const
{
G4AutoLock l(&fMutex);
return theCollection->size();
}
// Returns the number of hit objects stored in this collection
public: // with description
inline value_type* operator[](size_t i) const { return (*theCollection)[i]; }
// Returns a pointer to a concrete hit object.
inline container_type* GetVector() const { return theCollection; }
// Returns a collection vector.
inline G4int insert(T* aHit)
{
G4AutoLock l(&fMutex);
theCollection->push_back(aHit);
return theCollection->size();
}
// Insert a hit object. Total number of hit objects stored in this
// collection is returned.
inline G4int entries() const
{
G4AutoLock l(&fMutex);
return theCollection->size();
}
// Returns the number of hit objects stored in this collection
public:
virtual G4VHit* GetHit(size_t i) const { return (*theCollection)[i]; }
virtual size_t GetSize() const
{
G4AutoLock l(&fMutex);
return theCollection->size();
}
public:
virtual G4VHit* GetHit(size_t i) const { return (*theCollection)[i]; }
virtual size_t GetSize() const
{
G4AutoLock l(&fMutex);
return theCollection->size();
}
protected:
container_type* theCollection;
G4Mutex fMutex;
protected:
container_type* theCollection;
G4Mutex fMutex;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection()
: theCollection(new container_type)
template<class T>
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection() : theCollection(new container_type)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection(G4String detName,
G4String colNam)
: G4VHitsCollection(detName, colNam)
, theCollection(new container_type)
template<class T>
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection(G4String detName, G4String colNam)
: G4VHitsCollection(detName, colNam), theCollection(new container_type)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
template<class T>
G4TAtomicHitsCollection<T>::~G4TAtomicHitsCollection()
{
for(size_t i = 0; i < theCollection->size(); i++)
delete(*theCollection)[i];
for (size_t i = 0; i < theCollection->size(); i++)
delete (*theCollection)[i];
theCollection->clear();
delete theCollection;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
G4bool G4TAtomicHitsCollection<T>::operator==(
const G4TAtomicHitsCollection<T>& right) const
template<class T>
G4bool G4TAtomicHitsCollection<T>::operator==(const G4TAtomicHitsCollection<T>& right) const
{
return (collectionName == right.collectionName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
template<class T>
void G4TAtomicHitsCollection<T>::DrawAllHits()
{
G4AutoLock l(&fMutex);
for(size_t i = 0; i < theCollection->size(); i++)
for (size_t i = 0; i < theCollection->size(); i++)
(*theCollection)[i]->Draw();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <class T>
template<class T>
void G4TAtomicHitsCollection<T>::PrintAllHits()
{
G4AutoLock l(&fMutex);
for(size_t i = 0; i < theCollection->size(); i++)
for (size_t i = 0; i < theCollection->size(); i++)
(*theCollection)[i]->Print();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
@@ -45,12 +45,12 @@
#ifndef G4TAtomicHitsMap_h
#define G4TAtomicHitsMap_h 1
#include "G4AutoLock.hh"
#include "G4THitsCollection.hh"
#include "G4THitsMap.hh"
#include "globals.hh"
#include "G4atomic.hh"
#include "G4Threading.hh"
#include "G4AutoLock.hh"
#include "G4atomic.hh"
#include "globals.hh"
#include <map>
#include <type_traits>
@@ -65,141 +65,132 @@
// cannot be instansiated with a template class. Thus G4HitsMap
// class MUST NOT be directly used by the user.
template <typename T>
template<typename T>
class G4TAtomicHitsMap : public G4VHitsCollection
{
protected:
static_assert(std::is_fundamental<T>::value,
"G4TAtomicHitsMap must use fundamental type");
protected:
static_assert(std::is_fundamental<T>::value, "G4TAtomicHitsMap must use fundamental type");
public:
typedef G4atomic<T> value_type;
typedef value_type* mapped_type;
typedef typename std::map<G4int, mapped_type> container_type;
typedef typename container_type::iterator iterator;
typedef typename container_type::const_iterator const_iterator;
public:
typedef G4atomic<T> value_type;
typedef value_type* mapped_type;
typedef typename std::map<G4int, mapped_type> container_type;
typedef typename container_type::iterator iterator;
typedef typename container_type::const_iterator const_iterator;
public:
G4TAtomicHitsMap();
public:
G4TAtomicHitsMap();
public: // with description
G4TAtomicHitsMap(G4String detName, G4String colNam);
// constructor.
public: // with description
G4TAtomicHitsMap(G4String detName, G4String colNam);
// constructor.
public:
virtual ~G4TAtomicHitsMap();
G4bool operator==(const G4TAtomicHitsMap<T>& right) const;
G4TAtomicHitsMap<T>& operator+=(const G4TAtomicHitsMap<T>& right) const;
G4TAtomicHitsMap<T>& operator+=(const G4THitsMap<T>& right) const;
public:
virtual ~G4TAtomicHitsMap();
G4bool operator==(const G4TAtomicHitsMap<T>& right) const;
G4TAtomicHitsMap<T>& operator+=(const G4TAtomicHitsMap<T>& right) const;
G4TAtomicHitsMap<T>& operator+=(const G4THitsMap<T>& right) const;
public: // with description
virtual void DrawAllHits();
virtual void PrintAllHits();
// These two methods invokes Draw() and Print() methods of all of
// hit objects stored in this map, respectively.
public: // with description
virtual void DrawAllHits();
virtual void PrintAllHits();
// These two methods invokes Draw() and Print() methods of all of
// hit objects stored in this map, respectively.
public: // with description
inline value_type* operator[](G4int key) const;
public: // with description
inline value_type* operator[](G4int key) const;
// Returns a pointer to a concrete hit object.
inline container_type* GetMap() const { return theCollection; }
// Returns a collection map.
inline G4int add(const G4int& key, value_type*& aHit) const;
inline G4int add(const G4int& key, T& aHit) const;
// Insert a hit object. Total number of hit objects stored in this
// map is returned.
inline G4int set(const G4int& key, value_type*& aHit) const;
inline G4int set(const G4int& key, T& aHit) const;
// Overwrite a hit object. Total number of hit objects stored in this
// map is returned.
inline G4int entries() const { return theCollection->size(); }
// Returns the number of hit objects stored in this map
inline void clear();
// Returns a pointer to a concrete hit object.
inline container_type* GetMap() const { return theCollection; }
// Returns a collection map.
inline G4int add(const G4int& key, value_type*& aHit) const;
inline G4int add(const G4int& key, T& aHit) const;
// Insert a hit object. Total number of hit objects stored in this
// map is returned.
inline G4int set(const G4int& key, value_type*& aHit) const;
inline G4int set(const G4int& key, T& aHit) const;
// Overwrite a hit object. Total number of hit objects stored in this
// map is returned.
inline G4int entries() const { return theCollection->size(); }
// Returns the number of hit objects stored in this map
inline void clear();
public:
virtual G4VHit* GetHit(size_t) const { return 0; }
virtual size_t GetSize() const { return theCollection->size(); }
public:
virtual G4VHit* GetHit(size_t) const { return 0; }
virtual size_t GetSize() const { return theCollection->size(); }
virtual size_t size() const { return theCollection->size(); }
virtual size_t size() const { return theCollection->size(); }
public:
iterator begin() { return theCollection->begin(); }
iterator end() { return theCollection->end(); }
public:
iterator begin() { return theCollection->begin(); }
iterator end() { return theCollection->end(); }
const_iterator begin() const { return theCollection->begin(); }
const_iterator end() const { return theCollection->end(); }
const_iterator begin() const { return theCollection->begin(); }
const_iterator end() const { return theCollection->end(); }
const_iterator cbegin() const { return theCollection->cbegin(); }
const_iterator cend() const { return theCollection->cend(); }
const_iterator cbegin() const { return theCollection->cbegin(); }
const_iterator cend() const { return theCollection->cend(); }
iterator find(G4int p) { return theCollection->find(p); }
const_iterator find(G4int p) const { return theCollection->find(p); }
iterator find(G4int p) { return theCollection->find(p); }
const_iterator find(G4int p) const { return theCollection->find(p); }
private:
container_type* theCollection;
mutable G4Mutex fMutex;
private:
container_type* theCollection;
mutable G4Mutex fMutex;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
G4TAtomicHitsMap<T>::G4TAtomicHitsMap()
: theCollection(new container_type)
template<typename T>
G4TAtomicHitsMap<T>::G4TAtomicHitsMap() : theCollection(new container_type)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
G4TAtomicHitsMap<T>::G4TAtomicHitsMap(G4String detName, G4String colNam)
: G4VHitsCollection(detName, colNam)
, theCollection(new container_type)
: G4VHitsCollection(detName, colNam), theCollection(new container_type)
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
G4TAtomicHitsMap<T>::~G4TAtomicHitsMap()
{
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
for (auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
delete itr->second;
delete theCollection;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
G4bool G4TAtomicHitsMap<T>::operator==(const G4TAtomicHitsMap<T>& right) const
{
return (collectionName == right.collectionName);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
const G4TAtomicHitsMap<T>& rhs) const
template<typename T>
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(const G4TAtomicHitsMap<T>& rhs) const
{
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
for (auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
add(itr->first, *(itr->second));
return (G4TAtomicHitsMap<T>&) (*this);
return (G4TAtomicHitsMap<T>&)(*this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(
const G4THitsMap<T>& rhs) const
template<typename T>
G4TAtomicHitsMap<T>& G4TAtomicHitsMap<T>::operator+=(const G4THitsMap<T>& rhs) const
{
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
for (auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
add(itr->first, *(itr->second));
return (G4TAtomicHitsMap<T>&) (*this);
return (G4TAtomicHitsMap<T>&)(*this);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
inline
typename G4TAtomicHitsMap<T>::value_type* G4TAtomicHitsMap<T>::operator[](
G4int key) const
template<typename T>
inline typename G4TAtomicHitsMap<T>::value_type* G4TAtomicHitsMap<T>::operator[](G4int key) const
{
if(theCollection->find(key) != theCollection->end())
if (theCollection->find(key) != theCollection->end())
return theCollection->find(key)->second;
else
{
else {
G4AutoLock l(&fMutex);
if(theCollection->find(key) == theCollection->end())
{
value_type* ptr = new value_type;
if (theCollection->find(key) == theCollection->end()) {
value_type* ptr = new value_type;
(*theCollection)[key] = ptr;
return ptr;
}
@@ -208,13 +199,12 @@ inline
}
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
{
if(theCollection->find(key) != theCollection->end())
if (theCollection->find(key) != theCollection->end())
*(*theCollection)[key] += *aHit;
else
{
else {
G4AutoLock l(&fMutex);
(*theCollection)[key] = aHit;
}
@@ -222,15 +212,14 @@ inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
return theCollection->size();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
{
if(theCollection->find(key) != theCollection->end())
if (theCollection->find(key) != theCollection->end())
*(*theCollection)[key] += aHit;
else
{
else {
value_type* hit = new value_type;
*hit = aHit;
*hit = aHit;
G4AutoLock l(&fMutex);
(*theCollection)[key] = hit;
}
@@ -238,49 +227,47 @@ inline G4int G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
return theCollection->size();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, value_type*& aHit) const
{
if(theCollection->find(key) != theCollection->end())
delete(*theCollection)[key]->second;
if (theCollection->find(key) != theCollection->end()) delete (*theCollection)[key]->second;
(*theCollection)[key] = aHit;
G4AutoLock l(&fMutex);
return theCollection->size();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
inline G4int G4TAtomicHitsMap<T>::set(const G4int& key, T& aHit) const
{
if(theCollection->find(key) != theCollection->end())
if (theCollection->find(key) != theCollection->end())
*(*theCollection)[key] = aHit;
else
{
value_type* hit = new value_type;
*hit = aHit;
else {
value_type* hit = new value_type;
*hit = aHit;
(*theCollection)[key] = hit;
}
G4AutoLock l(&fMutex);
return theCollection->size();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
void G4TAtomicHitsMap<T>::DrawAllHits()
{}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
void G4TAtomicHitsMap<T>::PrintAllHits()
{
G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- "
<< entries() << " entries" << G4endl;
G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- " << entries()
<< " entries" << G4endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename T>
template<typename T>
void G4TAtomicHitsMap<T>::clear()
{
G4AutoLock l(&fMutex);
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
for (auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
delete itr->second;
theCollection->clear();
@@ -75,293 +75,276 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
template <typename _Tp>
template<typename _Tp>
class G4atomic
{
public:
typedef typename std::atomic<_Tp> base_type;
typedef _Tp value_type;
public:
typedef typename std::atomic<_Tp> base_type;
typedef _Tp value_type;
private:
using mem_ord = std::memory_order;
private:
using mem_ord = std::memory_order;
public:
// constructors
explicit G4atomic(mem_ord mo = std::memory_order_acq_rel)
: fMemOrder(mo)
{
atomics::set(&fvalue, value_type());
}
public:
// constructors
explicit G4atomic(mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
{
atomics::set(&fvalue, value_type());
}
explicit G4atomic(const value_type& _init,
mem_ord mo = std::memory_order_acq_rel)
: fMemOrder(mo)
{
atomics::set(&fvalue, _init);
}
explicit G4atomic(const value_type& _init, mem_ord mo = std::memory_order_acq_rel)
: fMemOrder(mo)
{
atomics::set(&fvalue, _init);
}
// copy-constructor from pure C++11 atomic
explicit G4atomic(const base_type& rhs,
mem_ord mo = std::memory_order_acq_rel)
: fMemOrder(mo)
{
atomics::set(&fvalue, rhs);
}
// copy-constructor from pure C++11 atomic
explicit G4atomic(const base_type& rhs, mem_ord mo = std::memory_order_acq_rel) : fMemOrder(mo)
{
atomics::set(&fvalue, rhs);
}
// copy-constructor
explicit G4atomic(const G4atomic& rhs)
: fMemOrder(rhs.fMemOrder)
{
atomics::set(&fvalue, rhs.base());
}
// copy-constructor
explicit G4atomic(const G4atomic& rhs) : fMemOrder(rhs.fMemOrder)
{
atomics::set(&fvalue, rhs.base());
}
// assignment operators
G4atomic& operator=(const G4atomic& rhs)
{
if(this != &rhs)
atomics::set(&fvalue, rhs.fvalue);
return *this;
}
// assignment operators
G4atomic& operator=(const G4atomic& rhs)
{
if (this != &rhs) atomics::set(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator=(const value_type& rhs)
{
atomics::set(&fvalue, rhs);
return *this;
}
G4atomic& operator=(const value_type& rhs)
{
atomics::set(&fvalue, rhs);
return *this;
}
G4atomic& operator=(const base_type& rhs)
{
atomics::set(&fvalue, rhs);
return *this;
}
G4atomic& operator=(const base_type& rhs)
{
atomics::set(&fvalue, rhs);
return *this;
}
// destructor
~G4atomic() { fvalue.~base_type(); }
// destructor
~G4atomic() { fvalue.~base_type(); }
// base version
base_type& base() { return fvalue; }
const base_type& base() const { return fvalue; }
base_type& base() volatile { return fvalue; }
const base_type& base() const volatile { return fvalue; }
// base version
base_type& base() { return fvalue; }
const base_type& base() const { return fvalue; }
base_type& base() volatile { return fvalue; }
const base_type& base() const volatile { return fvalue; }
// check if atomic is lock-free
bool is_lock_free() const { return fvalue.is_lock_free(); }
bool is_lock_free() const volatile { return fvalue.is_lock_free(); }
// check if atomic is lock-free
bool is_lock_free() const { return fvalue.is_lock_free(); }
bool is_lock_free() const volatile { return fvalue.is_lock_free(); }
// store functions
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
{
atomics::set(fvalue, _desired, mo);
}
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst) volatile
{
atomics::set(fvalue, _desired, mo);
}
// store functions
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst)
{
atomics::set(fvalue, _desired, mo);
}
void store(_Tp _desired, mem_ord mo = std::memory_order_seq_cst) volatile
{
atomics::set(fvalue, _desired, mo);
}
// load functions
_Tp load(mem_ord mo = std::memory_order_seq_cst) const
{
return atomics::get(fvalue, mo);
}
_Tp load(mem_ord mo = std::memory_order_seq_cst) const volatile
{
return atomics::get(fvalue, mo);
}
// load functions
_Tp load(mem_ord mo = std::memory_order_seq_cst) const { return atomics::get(fvalue, mo); }
_Tp load(mem_ord mo = std::memory_order_seq_cst) const volatile
{
return atomics::get(fvalue, mo);
}
// implicit conversion functions
operator _Tp() const { return this->load(); }
operator _Tp() const volatile { return this->load(); }
// implicit conversion functions
operator _Tp() const { return this->load(); }
operator _Tp() const volatile { return this->load(); }
operator base_type&() const { return fvalue; }
operator base_type&() const { return fvalue; }
// compare-and-swap functions
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success,
mem_ord _failure)
{
return fvalue.compare_exchange_weak(_expected, _desired, _success,
_failure);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success,
mem_ord _failure) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _success,
_failure);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
mem_ord _order) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success,
mem_ord _failure)
{
return fvalue.compare_exchange_weak(_expected, _desired, _success,
_failure);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success,
// compare-and-swap functions
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success, mem_ord _failure)
{
return fvalue.compare_exchange_weak(_expected, _desired, _success, _failure);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _success,
mem_ord _failure) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _success,
_failure);
}
{
return fvalue.compare_exchange_weak(_expected, _desired, _success, _failure);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
mem_ord _order) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order)
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_weak(_Tp& _expected, _Tp _desired, mem_ord _order) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
// value_type operators
G4atomic& operator+=(const value_type& rhs)
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const value_type& rhs)
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const value_type& rhs)
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const value_type& rhs)
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success, mem_ord _failure)
{
return fvalue.compare_exchange_weak(_expected, _desired, _success, _failure);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _success,
mem_ord _failure) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _success, _failure);
}
// atomic operators
G4atomic& operator+=(const G4atomic& rhs)
{
atomics::increment(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator-=(const G4atomic& rhs)
{
atomics::decrement(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator*=(const G4atomic& rhs)
{
atomics::multiply(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator/=(const G4atomic& rhs)
{
atomics::divide(&fvalue, rhs.fvalue);
return *this;
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order)
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
bool compare_exchange_strong(_Tp& _expected, _Tp _desired, mem_ord _order) volatile
{
return fvalue.compare_exchange_weak(_expected, _desired, _order);
}
G4atomic& operator+=(const G4atomic& rhs) volatile
{
atomics::increment(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator-=(const G4atomic& rhs) volatile
{
atomics::decrement(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator*=(const G4atomic& rhs) volatile
{
atomics::multiply(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator/=(const G4atomic& rhs) volatile
{
atomics::divide(&fvalue, rhs.fvalue);
return *this;
}
// value_type operators
G4atomic& operator+=(const value_type& rhs)
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const value_type& rhs)
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const value_type& rhs)
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const value_type& rhs)
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
// STL atomic operators
G4atomic& operator+=(const std::atomic<_Tp>& rhs)
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const std::atomic<_Tp>& rhs)
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const std::atomic<_Tp>& rhs)
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const std::atomic<_Tp>& rhs)
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
// atomic operators
G4atomic& operator+=(const G4atomic& rhs)
{
atomics::increment(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator-=(const G4atomic& rhs)
{
atomics::decrement(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator*=(const G4atomic& rhs)
{
atomics::multiply(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator/=(const G4atomic& rhs)
{
atomics::divide(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator+=(const std::atomic<_Tp>& rhs) volatile
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const std::atomic<_Tp>& rhs) volatile
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const std::atomic<_Tp>& rhs) volatile
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const std::atomic<_Tp>& rhs) volatile
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator+=(const G4atomic& rhs) volatile
{
atomics::increment(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator-=(const G4atomic& rhs) volatile
{
atomics::decrement(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator*=(const G4atomic& rhs) volatile
{
atomics::multiply(&fvalue, rhs.fvalue);
return *this;
}
G4atomic& operator/=(const G4atomic& rhs) volatile
{
atomics::divide(&fvalue, rhs.fvalue);
return *this;
}
// increment operators
value_type operator++()
{
value_type _tmp = ++fvalue;
return _tmp;
}
value_type operator++(int)
{
value_type _tmp = fvalue++;
return _tmp;
}
// STL atomic operators
G4atomic& operator+=(const std::atomic<_Tp>& rhs)
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const std::atomic<_Tp>& rhs)
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const std::atomic<_Tp>& rhs)
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const std::atomic<_Tp>& rhs)
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
value_type operator--()
{
value_type _tmp = --fvalue;
return _tmp;
}
value_type operator--(int)
{
value_type _tmp = fvalue--;
return _tmp;
}
G4atomic& operator+=(const std::atomic<_Tp>& rhs) volatile
{
atomics::increment(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator-=(const std::atomic<_Tp>& rhs) volatile
{
atomics::decrement(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator*=(const std::atomic<_Tp>& rhs) volatile
{
atomics::multiply(&fvalue, rhs, fMemOrder);
return *this;
}
G4atomic& operator/=(const std::atomic<_Tp>& rhs) volatile
{
atomics::divide(&fvalue, rhs, fMemOrder);
return *this;
}
protected:
base_type fvalue;
mem_ord fMemOrder;
// increment operators
value_type operator++()
{
value_type _tmp = ++fvalue;
return _tmp;
}
value_type operator++(int)
{
value_type _tmp = fvalue++;
return _tmp;
}
value_type operator--()
{
value_type _tmp = --fvalue;
return _tmp;
}
value_type operator--(int)
{
value_type _tmp = fvalue--;
return _tmp;
}
protected:
base_type fvalue;
mem_ord fMemOrder;
};
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
#else // ! G4MULTITHREADED
template <typename _Tp>
template<typename _Tp>
using G4atomic = _Tp;
#endif // G4MULTITHREADED
@@ -46,358 +46,324 @@
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
# include <functional>
# include <atomic>
# include <functional>
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
namespace atomics
{
//------------------------------------------------------------------------//
namespace details
{
//--------------------------------------------------------------------//
template <typename _Tp>
using OpFunction = std::function<_Tp(const _Tp&, const _Tp&)>;
//--------------------------------------------------------------------//
template <typename _Tp>
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic, const _Tp& _value,
std::memory_order mem_odr)
{
_atomic->store(_value, mem_odr);
}
//--------------------------------------------------------------------//
template <typename _Tp>
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic,
const std::atomic<_Tp>& _value,
std::memory_order mem_odr)
{
_atomic->store(_value.load(), mem_odr);
}
//--------------------------------------------------------------------//
template <typename _Tp>
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
const _Tp& _value,
const OpFunction<_Tp>& _operator,
std::memory_order mem_odr)
{
_Tp _expected = _Tp();
do
{
_expected = _atomic->load();
} while(!(_atomic->compare_exchange_weak(
_expected, _operator(_expected, _value), mem_odr)));
}
//--------------------------------------------------------------------//
template <typename _Tp>
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic,
const std::atomic<_Tp>& _atomic_value,
const OpFunction<_Tp>& _operator,
std::memory_order mem_odr)
{
_Tp _expected = _Tp();
do
{
_expected = _atomic->load();
} while(!(_atomic->compare_exchange_weak(
_expected, _operator(_expected, _atomic_value.load()), mem_odr)));
}
//--------------------------------------------------------------------//
} // namespace details
//------------------------------------------------------------------------//
// WITH ATOMIC TEMPLATE BASE TYPE AS SECOND PARAMETER
//------------------------------------------------------------------------//
template <typename T>
inline void set(std::atomic<T>* _atomic, const T& _desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
details::do_compare_and_swap(
_atomic, _desired,
details::OpFunction<T>([](const T&, const T& y) { return y; }), mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void set(std::atomic<T>& _atomic, const T& _desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
set(&_atomic, _desired, mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void increment(std::atomic<T>* _atomic, const T& _increment,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _increment,
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void decrement(std::atomic<T>* _atomic, const T& _decrement,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _decrement,
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void multiply(std::atomic<T>* _atomic, const T& _factor,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _factor,
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void divide(std::atomic<T>* _atomic, const T& _factor,
//------------------------------------------------------------------------//
namespace details
{
//--------------------------------------------------------------------//
template<typename _Tp>
using OpFunction = std::function<_Tp(const _Tp&, const _Tp&)>;
//--------------------------------------------------------------------//
template<typename _Tp>
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic, const _Tp& _value,
std::memory_order mem_odr)
{
_atomic->store(_value, mem_odr);
}
//--------------------------------------------------------------------//
template<typename _Tp>
inline void do_fetch_and_store(std::atomic<_Tp>* _atomic, const std::atomic<_Tp>& _value,
std::memory_order mem_odr)
{
_atomic->store(_value.load(), mem_odr);
}
//--------------------------------------------------------------------//
template<typename _Tp>
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic, const _Tp& _value,
const OpFunction<_Tp>& _operator, std::memory_order mem_odr)
{
_Tp _expected = _Tp();
do {
_expected = _atomic->load();
} while (!(_atomic->compare_exchange_weak(_expected, _operator(_expected, _value), mem_odr)));
}
//--------------------------------------------------------------------//
template<typename _Tp>
inline void do_compare_and_swap(std::atomic<_Tp>* _atomic, const std::atomic<_Tp>& _atomic_value,
const OpFunction<_Tp>& _operator, std::memory_order mem_odr)
{
_Tp _expected = _Tp();
do {
_expected = _atomic->load();
} while (!(_atomic->compare_exchange_weak(_expected, _operator(_expected, _atomic_value.load()),
mem_odr)));
}
//--------------------------------------------------------------------//
} // namespace details
//------------------------------------------------------------------------//
// WITH ATOMIC TEMPLATE BASE TYPE AS SECOND PARAMETER
//------------------------------------------------------------------------//
template<typename T>
inline void set(std::atomic<T>* _atomic, const T& _desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
details::do_compare_and_swap(
_atomic, _desired, details::OpFunction<T>([](const T&, const T& y) { return y; }), mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void set(std::atomic<T>& _atomic, const T& _desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
set(&_atomic, _desired, mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void increment(std::atomic<T>* _atomic, const T& _increment, std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _increment,
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void decrement(std::atomic<T>* _atomic, const T& _decrement, std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _decrement,
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void multiply(std::atomic<T>* _atomic, const T& _factor, std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _factor,
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void divide(std::atomic<T>* _atomic, const T& _factor, std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _factor,
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
mem_odr);
}
//------------------------------------------------------------------------//
// WITH ATOMICS AS SECOND PARAMETER
//------------------------------------------------------------------------//
template<typename T>
inline void set(std::atomic<T>* _atomic, const std::atomic<T>& _atomic_desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
// details::do_fetch_and_store(_atomic, _desired);
details::do_compare_and_swap(_atomic, _atomic_desired,
details::OpFunction<T>([](const T&, const T& y) { return y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void set(std::atomic<T>& _atomic, const std::atomic<T>& _atomic_desired,
std::memory_order mem_odr)
{
set(&_atomic, _atomic_desired, mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void increment(std::atomic<T>* _atomic, const std::atomic<T>& _atomic_increment,
std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _atomic_increment,
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void decrement(std::atomic<T>* _atomic, const std::atomic<T>& _atomic_decrement,
std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _atomic_decrement,
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void multiply(std::atomic<T>* _atomic, const std::atomic<T>& _atomic_factor,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _factor,
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
mem_odr);
}
//------------------------------------------------------------------------//
// WITH ATOMICS AS SECOND PARAMETER
//------------------------------------------------------------------------//
template <typename T>
inline void set(std::atomic<T>* _atomic,
const std::atomic<T>& _atomic_desired,
std::memory_order mem_odr = std::memory_order_seq_cst)
{
// details::do_fetch_and_store(_atomic, _desired);
details::do_compare_and_swap(
_atomic, _atomic_desired,
details::OpFunction<T>([](const T&, const T& y) { return y; }), mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void set(std::atomic<T>& _atomic,
const std::atomic<T>& _atomic_desired,
std::memory_order mem_odr)
{
set(&_atomic, _atomic_desired, mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void increment(std::atomic<T>* _atomic,
const std::atomic<T>& _atomic_increment,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _atomic_increment,
details::OpFunction<T>([](const T& x, const T& y) { return x + y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void decrement(std::atomic<T>* _atomic,
const std::atomic<T>& _atomic_decrement,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _atomic_decrement,
details::OpFunction<T>([](const T& x, const T& y) { return x - y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void multiply(std::atomic<T>* _atomic,
const std::atomic<T>& _atomic_factor,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _atomic_factor,
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template <typename T>
inline void divide(std::atomic<T>* _atomic,
const std::atomic<T>& _atomic_factor,
std::memory_order mem_odr)
{
details::do_compare_and_swap(
_atomic, _atomic_factor,
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
mem_odr);
}
{
details::do_compare_and_swap(_atomic, _atomic_factor,
details::OpFunction<T>([](const T& x, const T& y) { return x * y; }),
mem_odr);
}
//------------------------------------------------------------------------//
template<typename T>
inline void divide(std::atomic<T>* _atomic, const std::atomic<T>& _atomic_factor,
std::memory_order mem_odr)
{
details::do_compare_and_swap(_atomic, _atomic_factor,
details::OpFunction<T>([](const T& x, const T& y) { return x / y; }),
mem_odr);
}
//------------------------------------------------------------------------//
// STANDARD OVERLOAD //
//------------------------------------------------------------------------//
template <typename T>
inline void set(T* _non_atomic, const T& _desired)
{
*_non_atomic = _desired;
}
//------------------------------------------------------------------------//
template <typename T>
inline void set(T& _non_atomic, const T& _desired)
{
set(&_non_atomic, _desired);
}
//------------------------------------------------------------------------//
// STL PAIR OVERLOAD //
//------------------------------------------------------------------------//
//
//------------------------------------------------------------------------//
// WITH ATOMIC TEMPLATE TYPE AS SECOND PARAMETER
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _desired)
{
set(&_atomic->first, _desired.first);
set(&_atomic->second, _desired.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
const std::pair<T, U>& _desired)
{
set(&_atomic, _desired);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void increment(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _increment)
{
increment(&_atomic->first, _increment.first);
increment(&_atomic->second, _increment.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void decrement(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _decrement)
{
decrement(&_atomic->first, _decrement.first);
decrement(&_atomic->second, _decrement.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _factor)
{
multiply(&_atomic->first, _factor.first);
multiply(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
//------------------------------------------------------------------------//
// STANDARD OVERLOAD //
//------------------------------------------------------------------------//
template<typename T>
inline void set(T* _non_atomic, const T& _desired)
{
*_non_atomic = _desired;
}
//------------------------------------------------------------------------//
template<typename T>
inline void set(T& _non_atomic, const T& _desired)
{
set(&_non_atomic, _desired);
}
//------------------------------------------------------------------------//
// STL PAIR OVERLOAD //
//------------------------------------------------------------------------//
//
//------------------------------------------------------------------------//
// WITH ATOMIC TEMPLATE TYPE AS SECOND PARAMETER
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic, const std::pair<T, U>& _desired)
{
set(&_atomic->first, _desired.first);
set(&_atomic->second, _desired.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic, const std::pair<T, U>& _desired)
{
set(&_atomic, _desired);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void increment(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _increment)
{
increment(&_atomic->first, _increment.first);
increment(&_atomic->second, _increment.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void decrement(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _decrement)
{
decrement(&_atomic->first, _decrement.first);
decrement(&_atomic->second, _decrement.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _factor)
{
divide(&_atomic->first, _factor.first);
divide(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
// WITH ATOMICS AS SECOND PARAMETER
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
{
set(&_atomic->first, _desired.first);
set(&_atomic->second, _desired.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
{
set(&_atomic, _desired);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void increment(
std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _increment)
{
increment(&_atomic->first, _increment.first);
increment(&_atomic->second, _increment.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void decrement(
std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _decrement)
{
decrement(&_atomic->first, _decrement.first);
decrement(&_atomic->second, _decrement.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _factor)
{
multiply(&_atomic->first, _factor.first);
multiply(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
{
multiply(&_atomic->first, _factor.first);
multiply(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<T, U>& _factor)
{
divide(&_atomic->first, _factor.first);
divide(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
// WITH ATOMICS AS SECOND PARAMETER
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
{
set(&_atomic->first, _desired.first);
set(&_atomic->second, _desired.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void set(std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _desired)
{
set(&_atomic, _desired);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void increment(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _increment)
{
increment(&_atomic->first, _increment.first);
increment(&_atomic->second, _increment.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void decrement(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _decrement)
{
decrement(&_atomic->first, _decrement.first);
decrement(&_atomic->second, _decrement.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void multiply(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _factor)
{
divide(&_atomic->first, _factor.first);
divide(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
{
multiply(&_atomic->first, _factor.first);
multiply(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline void divide(std::pair<std::atomic<T>, std::atomic<U>>* _atomic,
const std::pair<std::atomic<T>, std::atomic<U>>& _factor)
{
divide(&_atomic->first, _factor.first);
divide(&_atomic->second, _factor.second);
}
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
template <typename T>
inline T get(const T& _non_atomic)
{
return _non_atomic;
}
//------------------------------------------------------------------------//
template <typename T>
inline T get(const T& _non_atomic, std::memory_order)
{
return _non_atomic;
}
//------------------------------------------------------------------------//
template <typename T>
inline T get(const std::atomic<T>& _atomic)
{
return _atomic.load();
}
//------------------------------------------------------------------------//
template <typename T>
inline T get(const std::atomic<T>& _atomic, std::memory_order mem_odr)
{
return _atomic.load(mem_odr);
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline std::pair<T, U> get(
const std::pair<std::atomic<T>, std::atomic<U>>& _atomic)
{
return std::pair<T, U>(get(_atomic.first), get(_atomic.second));
}
//------------------------------------------------------------------------//
template <typename T, typename U>
inline std::pair<T, U> get(
const std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
std::memory_order mem_odr)
{
return std::pair<T, U>(get(_atomic.first, mem_odr),
get(_atomic.second, mem_odr));
}
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
template<typename T>
inline T get(const T& _non_atomic)
{
return _non_atomic;
}
//------------------------------------------------------------------------//
template<typename T>
inline T get(const T& _non_atomic, std::memory_order)
{
return _non_atomic;
}
//------------------------------------------------------------------------//
template<typename T>
inline T get(const std::atomic<T>& _atomic)
{
return _atomic.load();
}
//------------------------------------------------------------------------//
template<typename T>
inline T get(const std::atomic<T>& _atomic, std::memory_order mem_odr)
{
return _atomic.load(mem_odr);
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline std::pair<T, U> get(const std::pair<std::atomic<T>, std::atomic<U>>& _atomic)
{
return std::pair<T, U>(get(_atomic.first), get(_atomic.second));
}
//------------------------------------------------------------------------//
template<typename T, typename U>
inline std::pair<T, U> get(const std::pair<std::atomic<T>, std::atomic<U>>& _atomic,
std::memory_order mem_odr)
{
return std::pair<T, U>(get(_atomic.first, mem_odr), get(_atomic.second, mem_odr));
}
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
// for plain old data (POD) and pairs (e.g. std::pair<atomic<T>, atomic<U>>)
template <typename _Tp_base, typename _Tp_atom>
inline _Tp_base base(const _Tp_atom& _atomic)
{
return get(_atomic);
}
//------------------------------------------------------------------------//
//------------------------------------------------------------------------//
// for plain old data (POD) and pairs (e.g. std::pair<atomic<T>, atomic<U>>)
template<typename _Tp_base, typename _Tp_atom>
inline _Tp_base base(const _Tp_atom& _atomic)
{
return get(_atomic);
}
//------------------------------------------------------------------------//
} // namespace atomics
@@ -40,28 +40,27 @@
#ifndef tsactioninitialization_hh_
#define tsactioninitialization_hh_
#include "globals.hh"
#include "G4VUserActionInitialization.hh"
#include "G4AutoLock.hh"
#include "G4Threading.hh"
#include "G4VUserActionInitialization.hh"
#include "globals.hh"
class TSActionInitialization : public G4VUserActionInitialization
{
public:
// Constructor and Destructors
TSActionInitialization();
virtual ~TSActionInitialization();
public:
// Constructor and Destructors
TSActionInitialization();
virtual ~TSActionInitialization();
static TSActionInitialization* Instance();
static TSActionInitialization* Instance();
public:
virtual void BuildForMaster() const;
virtual void Build() const;
public:
virtual void BuildForMaster() const;
virtual void Build() const;
private:
// Private functions
static TSActionInitialization* fgInstance;
private:
// Private functions
static TSActionInitialization* fgInstance;
};
#endif
@@ -54,9 +54,9 @@
#ifndef tsdetectorconstruction_hh
#define tsdetectorconstruction_hh 1
#include "globals.hh"
#include "G4VUserDetectorConstruction.hh"
#include "G4ThreeVector.hh"
#include "G4VUserDetectorConstruction.hh"
#include "globals.hh"
#include <map>
#include <set>
@@ -70,45 +70,42 @@ class G4Material;
class TSDetectorConstruction : public G4VUserDetectorConstruction
{
public:
typedef std::map<G4String, G4Material*> MaterialCollection_t;
typedef std::set<G4LogicalVolume*> ScoringVolumes_t;
public:
typedef std::map<G4String, G4Material*> MaterialCollection_t;
typedef std::set<G4LogicalVolume*> ScoringVolumes_t;
public:
TSDetectorConstruction();
virtual ~TSDetectorConstruction();
public:
TSDetectorConstruction();
virtual ~TSDetectorConstruction();
static TSDetectorConstruction* Instance();
static TSDetectorConstruction* Instance();
public:
G4VPhysicalVolume* Construct();
inline const G4ThreeVector& GetWorldDimensions() const { return fWorldDim; }
inline const ScoringVolumes_t& GetScoringVolumes() const
{
return fScoringVolumes;
}
inline const G4String& GetMFDName() const { return fMfdName; }
inline G4int GetTotalTargets() const
{
return fTargetSections.x() * fTargetSections.y() * fTargetSections.z();
}
public:
G4VPhysicalVolume* Construct();
inline const G4ThreeVector& GetWorldDimensions() const { return fWorldDim; }
inline const ScoringVolumes_t& GetScoringVolumes() const { return fScoringVolumes; }
inline const G4String& GetMFDName() const { return fMfdName; }
inline G4int GetTotalTargets() const
{
return fTargetSections.x() * fTargetSections.y() * fTargetSections.z();
}
protected:
virtual MaterialCollection_t ConstructMaterials();
virtual G4VPhysicalVolume* ConstructWorld(const MaterialCollection_t&);
virtual void ConstructSDandField();
protected:
virtual MaterialCollection_t ConstructMaterials();
virtual G4VPhysicalVolume* ConstructWorld(const MaterialCollection_t&);
virtual void ConstructSDandField();
private:
static TSDetectorConstruction* fgInstance;
G4VPhysicalVolume* fWorldPhys;
ScoringVolumes_t fScoringVolumes;
G4String fWorldMaterialName;
G4String fTargetMaterialName;
G4String fCasingMaterialName;
G4ThreeVector fWorldDim;
G4ThreeVector fTargetDim;
G4ThreeVector fTargetSections;
G4String fMfdName;
private:
static TSDetectorConstruction* fgInstance;
G4VPhysicalVolume* fWorldPhys;
ScoringVolumes_t fScoringVolumes;
G4String fWorldMaterialName;
G4String fTargetMaterialName;
G4String fCasingMaterialName;
G4ThreeVector fWorldDim;
G4ThreeVector fTargetDim;
G4ThreeVector fTargetSections;
G4String fMfdName;
};
#endif
@@ -42,26 +42,26 @@
#ifndef tsphysicslist_hh
#define tsphysicslist_hh 1
#include "globals.hh"
#include "G4VUserPhysicsList.hh"
#include "G4VPhysicsConstructor.hh"
#include "G4VUserPhysicsList.hh"
#include "globals.hh"
#include <deque>
class TSPhysicsList : public G4VUserPhysicsList
{
public:
typedef std::deque<G4VPhysicsConstructor*> PhysicsSet_t;
public:
typedef std::deque<G4VPhysicsConstructor*> PhysicsSet_t;
public:
TSPhysicsList();
virtual ~TSPhysicsList();
public:
TSPhysicsList();
virtual ~TSPhysicsList();
public:
void ConstructParticle() override;
void ConstructProcess() override;
public:
void ConstructParticle() override;
void ConstructProcess() override;
private:
PhysicsSet_t fConstructors;
private:
PhysicsSet_t fConstructors;
};
#endif
@@ -39,23 +39,23 @@
#ifndef tsprimarygeneratoraction_hh
#define tsprimarygeneratoraction_hh 1
#include "globals.hh"
#include "G4VUserPrimaryGeneratorAction.hh"
#include "globals.hh"
class G4Event;
class G4ParticleGun;
class TSPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
{
public:
TSPrimaryGeneratorAction();
virtual ~TSPrimaryGeneratorAction();
public:
TSPrimaryGeneratorAction();
virtual ~TSPrimaryGeneratorAction();
public:
void GeneratePrimaries(G4Event*);
public:
void GeneratePrimaries(G4Event*);
private:
G4ParticleGun* fGun;
private:
G4ParticleGun* fGun;
};
#endif
@@ -54,15 +54,14 @@
#ifndef tsrun_h
#define tsrun_h 1
#include "globals.hh"
#include "G4Run.hh"
#include "G4Event.hh"
#include "G4THitsMap.hh"
#include "G4TAtomicHitsMap.hh"
#include "G4THitsVector.hh"
#include "G4StatAnalysis.hh"
#include "G4ConvergenceTester.hh"
#include "G4Event.hh"
#include "G4Run.hh"
#include "G4StatAnalysis.hh"
#include "G4TAtomicHitsMap.hh"
#include "G4THitsMap.hh"
#include "G4THitsVector.hh"
#include "globals.hh"
#include <vector>
@@ -70,42 +69,42 @@ class G4Event;
// template <typename _Tp> using G4StatContainer = G4THitsMap<_Tp>;
// template <typename _Tp> using G4StatContainer = G4THitsVector<_Tp>;
template <typename _Tp>
template<typename _Tp>
using G4StatContainer = G4THitsDeque<_Tp>;
class TSRun : public G4Run
{
public:
typedef std::map<G4int, G4double> MutexHitsMap_t;
public:
typedef std::map<G4int, G4double> MutexHitsMap_t;
public:
TSRun(const G4String&);
virtual ~TSRun();
public:
TSRun(const G4String&);
virtual ~TSRun();
// virtual method from G4Run.
// The method is overriden in this class for scoring.
virtual void RecordEvent(const G4Event*);
// virtual method from G4Run.
// The method is overriden in this class for scoring.
virtual void RecordEvent(const G4Event*);
// Access methods for scoring information.
// - Get HitsMap of this RUN.
G4THitsMap<G4double>* GetHitsMap(const G4String& collname) const;
G4TAtomicHitsMap<G4double>* GetAtomicHitsMap(const G4String&) const;
MutexHitsMap_t* GetMutexHitsMap(const G4String&) const;
G4StatContainer<G4StatAnalysis>* GetStatMap(const G4String& collname) const;
G4StatContainer<G4ConvergenceTester>* GetConvMap(const G4String&) const;
// Access methods for scoring information.
// - Get HitsMap of this RUN.
G4THitsMap<G4double>* GetHitsMap(const G4String& collname) const;
G4TAtomicHitsMap<G4double>* GetAtomicHitsMap(const G4String&) const;
MutexHitsMap_t* GetMutexHitsMap(const G4String&) const;
G4StatContainer<G4StatAnalysis>* GetStatMap(const G4String& collname) const;
G4StatContainer<G4ConvergenceTester>* GetConvMap(const G4String&) const;
void ConstructMFD(const G4String&);
void ConstructMFD(const G4String&);
virtual void Merge(const G4Run*);
virtual void Merge(const G4Run*);
private:
std::vector<G4String> fCollNames;
std::vector<G4int> fCollIDs;
std::vector<G4THitsMap<G4double>*> fRunMaps;
std::vector<G4StatContainer<G4StatAnalysis>*> fStatMaps;
static std::vector<G4TAtomicHitsMap<G4double>*> fAtomicRunMaps;
static std::map<G4String, MutexHitsMap_t> fMutexRunMaps;
static std::vector<G4StatContainer<G4ConvergenceTester>*> fConvMaps;
private:
std::vector<G4String> fCollNames;
std::vector<G4int> fCollIDs;
std::vector<G4THitsMap<G4double>*> fRunMaps;
std::vector<G4StatContainer<G4StatAnalysis>*> fStatMaps;
static std::vector<G4TAtomicHitsMap<G4double>*> fAtomicRunMaps;
static std::map<G4String, MutexHitsMap_t> fMutexRunMaps;
static std::vector<G4StatContainer<G4ConvergenceTester>*> fConvMaps;
};
#endif
@@ -37,11 +37,12 @@
#ifndef tsrunaction_hh
#define tsrunaction_hh 1
#include "globals.hh"
#include "G4UserRunAction.hh"
#include <vector>
#include "globals.hh"
#include <map>
#include <tuple>
#include <vector>
class G4Run;
class G4Timer;
@@ -49,24 +50,24 @@ class TSDetectorConstruction;
class TSRunAction : public G4UserRunAction
{
public:
typedef std::tuple<G4double, G4double, G4double> Compare_t;
typedef std::map<G4int, Compare_t> IDcompare_t;
typedef std::map<G4String, IDcompare_t> TypeCompare_t;
public:
typedef std::tuple<G4double, G4double, G4double> Compare_t;
typedef std::map<G4int, Compare_t> IDcompare_t;
typedef std::map<G4String, IDcompare_t> TypeCompare_t;
public:
TSRunAction();
virtual ~TSRunAction();
public:
TSRunAction();
virtual ~TSRunAction();
public:
virtual void BeginOfRunAction(const G4Run*);
virtual void EndOfRunAction(const G4Run*);
virtual G4Run* GenerateRun();
public:
virtual void BeginOfRunAction(const G4Run*);
virtual void EndOfRunAction(const G4Run*);
virtual G4Run* GenerateRun();
private:
TSDetectorConstruction* fDetector;
G4String fName;
TypeCompare_t fTypeCompare;
private:
TSDetectorConstruction* fDetector;
G4String fName;
TypeCompare_t fTypeCompare;
};
#endif