Import Geant4 10.2.0 source tree
This commit is contained in:
@@ -0,0 +1,208 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/atomics/G4TAtomicHitsCollection.hh
|
||||
/// \brief Definition of the G4TAtomicHitsCollection class
|
||||
//
|
||||
//
|
||||
// $Id: G4TAtomicHitsCollection.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// This is an implementation of G4THitsCollection<T> where the underlying
|
||||
/// type is G4atomic<T>, not just T. A static assert is provided to
|
||||
/// ensure that T is fundamental. This class should be used in lieu
|
||||
/// of G4THitsCollection<T> when memory is a concern. Atomics are
|
||||
/// thread-safe and *generally* faster that mutexes (as long as the
|
||||
/// STL implementation is lock-free) but the synchronization does
|
||||
/// not come without a cost. If performance is the primary concern,
|
||||
/// use G4THitsCollection<T> in thread-local instances.
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef G4TAtomicHitsCollection_h
|
||||
#define G4TAtomicHitsCollection_h 1
|
||||
|
||||
#include "G4VHitsCollection.hh"
|
||||
#include "G4Allocator.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4atomic.hh"
|
||||
|
||||
#include <deque>
|
||||
#include <type_traits>
|
||||
|
||||
// class description:
|
||||
//
|
||||
// This is a template class of hits collection and parametrized by
|
||||
// The concrete class of G4VHit. This is a uniform collection for
|
||||
// a particular concrete hit class objects.
|
||||
// An intermediate layer class G4HitsCollection appeared in this
|
||||
// header file is used just for G4Allocator, because G4Allocator
|
||||
// cannot be instansiated with a template class. Thus G4HitsCollection
|
||||
// class MUST NOT be directly used by the user.
|
||||
|
||||
/*class G4HitsCollection : public G4VHitsCollection
|
||||
{
|
||||
public:
|
||||
G4HitsCollection();
|
||||
G4HitsCollection(G4String detName,G4String colNam);
|
||||
virtual ~G4HitsCollection();
|
||||
G4int operator==(const G4HitsCollection &right) const;
|
||||
|
||||
protected:
|
||||
void* theCollection;
|
||||
};*/
|
||||
|
||||
|
||||
template <class T>
|
||||
class G4TAtomicHitsCollection : public G4VHitsCollection
|
||||
{
|
||||
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:
|
||||
G4TAtomicHitsCollection();
|
||||
|
||||
public:
|
||||
// with description
|
||||
G4TAtomicHitsCollection(G4String detName, G4String colNam);
|
||||
|
||||
// constructor.
|
||||
public:
|
||||
virtual ~G4TAtomicHitsCollection();
|
||||
G4int operator==(const G4TAtomicHitsCollection<T> &right) const;
|
||||
|
||||
//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
|
||||
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();
|
||||
}
|
||||
|
||||
protected:
|
||||
container_type* theCollection;
|
||||
G4Mutex fMutex;
|
||||
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection()
|
||||
: theCollection(new container_type), fMutex(G4MUTEX_INITIALIZER)
|
||||
{ }
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4TAtomicHitsCollection<T>::G4TAtomicHitsCollection(G4String detName,
|
||||
G4String colNam)
|
||||
: G4VHitsCollection(detName,colNam),
|
||||
theCollection(new container_type),
|
||||
fMutex(G4MUTEX_INITIALIZER)
|
||||
{ }
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T> G4TAtomicHitsCollection<T>::~G4TAtomicHitsCollection()
|
||||
{
|
||||
for(size_t i = 0; i < theCollection->size(); i++)
|
||||
delete (*theCollection)[i];
|
||||
theCollection->clear();
|
||||
delete theCollection;
|
||||
G4MUTEXDESTROY(fMutex);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
G4int G4TAtomicHitsCollection<T>
|
||||
::operator==(const G4TAtomicHitsCollection<T> &right) const
|
||||
{
|
||||
return (collectionName == right.collectionName);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
void G4TAtomicHitsCollection<T>::DrawAllHits()
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
for(size_t i = 0; i < theCollection->size(); i++)
|
||||
(*theCollection)[i]->Draw();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <class T>
|
||||
void G4TAtomicHitsCollection<T>::PrintAllHits()
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
for(size_t i = 0; i < theCollection->size(); i++)
|
||||
(*theCollection)[i]->Print();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,308 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/atomics/G4TAtomicHitsMap.hh
|
||||
/// \brief Definition of the G4TAtomicHitsMap class
|
||||
//
|
||||
//
|
||||
// $Id: G4TAtomicHitsMap.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// This is an implementation of G4THitsMap<T> where the underlying
|
||||
/// type is G4atomic<T>, not just T. A static assert is provided to
|
||||
/// ensure that T is fundamental. This class should be used in lieu
|
||||
/// of G4THitsMap<T> when memory is a concern. Atomics are
|
||||
/// thread-safe and *generally* faster that mutexes (as long as the
|
||||
/// STL implementation is lock-free) but the synchronization does
|
||||
/// not come without a cost. If performance is the primary concern,
|
||||
/// use G4THitsMap<T> in thread-local instances.
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef G4TAtomicHitsMap_h
|
||||
#define G4TAtomicHitsMap_h 1
|
||||
|
||||
#include "G4THitsCollection.hh"
|
||||
#include "G4THitsMap.hh"
|
||||
#include "globals.hh"
|
||||
#include "G4atomic.hh"
|
||||
#include "G4Threading.hh"
|
||||
#include "G4AutoLock.hh"
|
||||
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
||||
// class description:
|
||||
//
|
||||
// This is a template class of hits map and parametrized by
|
||||
// The concrete class of G4VHit. This is a uniform collection for
|
||||
// a particular concrete hit class objects.
|
||||
// An intermediate layer class G4HitsMap appeared in this
|
||||
// header file is used just for G4Allocator, because G4Allocator
|
||||
// cannot be instansiated with a template class. Thus G4HitsMap
|
||||
// class MUST NOT be directly used by the user.
|
||||
|
||||
template <typename T>
|
||||
class G4TAtomicHitsMap : public G4VHitsCollection
|
||||
{
|
||||
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:
|
||||
G4TAtomicHitsMap();
|
||||
|
||||
public: // with description
|
||||
G4TAtomicHitsMap(G4String detName, G4String colNam);
|
||||
// constructor.
|
||||
|
||||
public:
|
||||
virtual ~G4TAtomicHitsMap();
|
||||
G4int 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
|
||||
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();
|
||||
|
||||
public:
|
||||
virtual G4VHit* GetHit(size_t) const {return 0;}
|
||||
virtual size_t GetSize() const
|
||||
{
|
||||
return theCollection->size();
|
||||
}
|
||||
|
||||
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 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); }
|
||||
|
||||
private:
|
||||
container_type* theCollection;
|
||||
mutable G4Mutex fMutex;
|
||||
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap()
|
||||
: theCollection(new container_type),
|
||||
fMutex(G4MUTEX_INITIALIZER)
|
||||
{ }
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::G4TAtomicHitsMap(G4String detName,
|
||||
G4String colNam)
|
||||
: G4VHitsCollection(detName,colNam),
|
||||
theCollection(new container_type),
|
||||
fMutex(G4MUTEX_INITIALIZER)
|
||||
{ }
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>::~G4TAtomicHitsMap()
|
||||
{
|
||||
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
delete itr->second;
|
||||
|
||||
delete theCollection;
|
||||
G4MUTEXDESTROY(fMutex);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4int 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
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
G4TAtomicHitsMap<T>&
|
||||
G4TAtomicHitsMap<T>::operator+=(const G4THitsMap<T>& rhs) const
|
||||
{
|
||||
for(auto itr = rhs.GetMap()->begin(); itr != rhs.GetMap()->end(); itr++)
|
||||
add(itr->first, *(itr->second));
|
||||
|
||||
return (G4TAtomicHitsMap<T>&)(*this);
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline typename G4TAtomicHitsMap<T>::value_type*
|
||||
G4TAtomicHitsMap<T>::operator[](G4int key) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
return theCollection->find(key)->second;
|
||||
else
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
if(theCollection->find(key) == theCollection->end())
|
||||
{
|
||||
value_type* ptr = new value_type;
|
||||
(*theCollection)[key] = ptr;
|
||||
return ptr;
|
||||
} else
|
||||
return theCollection->find(key)->second;
|
||||
}
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::add(const G4int& key, value_type*& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += *aHit;
|
||||
else
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
(*theCollection)[key] = aHit;
|
||||
}
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::add(const G4int& key, T& aHit) const
|
||||
{
|
||||
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] += aHit;
|
||||
else
|
||||
{
|
||||
value_type* hit = new value_type;
|
||||
*hit = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
(*theCollection)[key] = hit;
|
||||
}
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
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;
|
||||
|
||||
(*theCollection)[key] = aHit;
|
||||
G4AutoLock l(&fMutex);
|
||||
return theCollection->size();
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
inline G4int
|
||||
G4TAtomicHitsMap<T>::set(const G4int& key, T& aHit) const
|
||||
{
|
||||
if(theCollection->find(key) != theCollection->end())
|
||||
*(*theCollection)[key] = 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>
|
||||
void G4TAtomicHitsMap<T>::DrawAllHits()
|
||||
{ }
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
void G4TAtomicHitsMap<T>::PrintAllHits()
|
||||
{
|
||||
G4cout << "G4TAtomicHitsMap " << SDname << " / " << collectionName << " --- "
|
||||
<< entries() << " entries" << G4endl;
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
template <typename T>
|
||||
void G4TAtomicHitsMap<T>::clear()
|
||||
{
|
||||
G4AutoLock l(&fMutex);
|
||||
|
||||
for(auto itr = theCollection->begin(); itr != theCollection->end(); itr++)
|
||||
delete itr->second;
|
||||
|
||||
theCollection->clear();
|
||||
|
||||
}
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,277 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/atomics/G4atomic.hh
|
||||
/// \brief Definition of the G4atomic class
|
||||
//
|
||||
//
|
||||
// $Id: G4atomic.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// This is an friendly implementation of the STL atomic class.
|
||||
/// This class has the same interface as the STL atomic but can be used
|
||||
/// in an extremely similar fashion to plain old data (POD) types.
|
||||
/// In other words, the copy constructor and assignment operators are
|
||||
/// defined, and a load() does not need to be called to get the POD
|
||||
/// value.
|
||||
///
|
||||
/// IMPORTANT: Care must be taken when using this class as a RHS term.
|
||||
/// The best use case scenario for this class is as a LHS term that is
|
||||
/// only used as a RHS term outside of the multithreaded operations on it.
|
||||
///
|
||||
/// FOR EXAMPLE:
|
||||
/// Proper use:
|
||||
/// Goal: sum energy deposited in run
|
||||
/// Impl: Is a member variable of derived
|
||||
/// G4VUserActionInitialization (of which there will
|
||||
/// always be just one instance). Accumulate
|
||||
/// thread-local energy deposit into EventAction,
|
||||
/// add to ActionInit at end of event, print sum
|
||||
/// on master EndOfRunAction
|
||||
/// Why: the sum is only a LHS term
|
||||
/// Improper use:
|
||||
/// Goal: compute error during event processing
|
||||
/// Impl: sum += x; sum_sq += x*x; counts++;
|
||||
/// error = sqrt(sum_sq/(sum*sum) - 1/counts;
|
||||
/// (where sum, sum_sq, counts are G4atomics)
|
||||
/// Why: This will work but error can/will be wrong when
|
||||
/// sum, sum_sq, and counts are updated by another thread
|
||||
/// while error is being calculated, i.e. they are used as
|
||||
/// RHS terms
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef G4atomic_hh_
|
||||
#define G4atomic_hh_
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
#include "G4atomic_defines.hh"
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
template<typename _Tp>
|
||||
class G4atomic
|
||||
{
|
||||
public:
|
||||
typedef typename std::atomic<_Tp> base_type;
|
||||
typedef _Tp value_type;
|
||||
|
||||
private:
|
||||
using mem_odr = std::memory_order;
|
||||
|
||||
public:
|
||||
// constructors
|
||||
explicit
|
||||
G4atomic(mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
|
||||
{ atomics::set(&fvalue, value_type()); }
|
||||
|
||||
explicit
|
||||
G4atomic(const value_type& _init,
|
||||
mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
|
||||
{ atomics::set(&fvalue, _init); }
|
||||
|
||||
// copy-constructor from pure C++11 atomic
|
||||
explicit
|
||||
G4atomic(const base_type& rhs,
|
||||
mem_odr odr = std::memory_order_acq_rel) : fMemOrder(odr)
|
||||
{ atomics::set(&fvalue, rhs); }
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
G4atomic& operator=(const value_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(); }
|
||||
|
||||
// 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(); }
|
||||
|
||||
// store functions
|
||||
void store(_Tp _desired, std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst)
|
||||
{ atomics::set(fvalue, _desired, mem_odr); }
|
||||
void store(_Tp _desired, std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst) volatile
|
||||
{ atomics::set(fvalue, _desired, mem_odr); }
|
||||
|
||||
// load functions
|
||||
_Tp load(std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst) const
|
||||
{ return atomics::get(fvalue, mem_odr); }
|
||||
_Tp load(std::memory_order mem_odr
|
||||
= std::memory_order_seq_cst) const volatile
|
||||
{ return atomics::get(fvalue, mem_odr); }
|
||||
|
||||
// implicit conversion functions
|
||||
operator _Tp() const { return this->load(); }
|
||||
operator _Tp() const volatile { return this->load(); }
|
||||
|
||||
operator base_type&() const { return fvalue; }
|
||||
|
||||
// compare-and-swap functions
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _success,
|
||||
std::memory_order _failure)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _success,
|
||||
std::memory_order _failure) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _order)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
bool compare_exchange_weak(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _order) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _success,
|
||||
std::memory_order _failure)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _success,
|
||||
std::memory_order _failure) volatile
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired,
|
||||
_success, _failure); }
|
||||
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _order)
|
||||
{ return fvalue.compare_exchange_weak(_expected, _desired, _order); }
|
||||
bool compare_exchange_strong(_Tp& _expected, _Tp _desired,
|
||||
std::memory_order _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; }
|
||||
|
||||
// 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 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; }
|
||||
|
||||
// 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; }
|
||||
|
||||
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; }
|
||||
|
||||
// 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_odr fMemOrder;
|
||||
|
||||
};
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#else // ! G4MULTITHREADED
|
||||
|
||||
template <typename _Tp> using G4atomic = _Tp;
|
||||
|
||||
#endif // G4MULTITHREADED
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif // G4atomic_hh_
|
||||
@@ -0,0 +1,443 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/atomics/G4atomic_defines.hh
|
||||
/// \brief Definition of the G4atomic_defines class
|
||||
//
|
||||
//
|
||||
// $Id: G4atomic_defines.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// This is a functional class for G4atomic. The functions in this
|
||||
/// file are not intended to be used outside of their implementation
|
||||
/// in G4atomic.
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef G4atomic_defines_hh_
|
||||
#define G4atomic_defines_hh_
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#include <functional>
|
||||
#include <atomic>
|
||||
|
||||
//....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)));
|
||||
}
|
||||
//--------------------------------------------------------------------//
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
// 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, _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,
|
||||
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,
|
||||
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));
|
||||
}
|
||||
//------------------------------------------------------------------------//
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------//
|
||||
// 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
|
||||
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
#endif // G4MULTITHREADED
|
||||
|
||||
#endif // atomic_typedefs_hh_
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSActionInitialization.hh
|
||||
/// \brief Definition of the TSActionInitialization class
|
||||
//
|
||||
//
|
||||
// $Id: TSActionInitialization.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// Standard ActionInitialization class creating a RunAction instance for the
|
||||
/// master thread and RunAction and PrimaryGeneratorAction instances for
|
||||
/// the worker threads
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef tsactioninitialization_hh_
|
||||
#define tsactioninitialization_hh_
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserActionInitialization.hh"
|
||||
|
||||
#include "G4AutoLock.hh"
|
||||
#include "G4Threading.hh"
|
||||
|
||||
class TSActionInitialization : public G4VUserActionInitialization
|
||||
{
|
||||
public:
|
||||
// Constructor and Destructors
|
||||
TSActionInitialization();
|
||||
virtual ~TSActionInitialization();
|
||||
|
||||
static TSActionInitialization* Instance();
|
||||
|
||||
public:
|
||||
virtual void BuildForMaster() const;
|
||||
virtual void Build() const;
|
||||
|
||||
private:
|
||||
// Private functions
|
||||
static TSActionInitialization* fgInstance;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSDetectorConstruction.hh
|
||||
/// \brief Definition of the TSDetectorConstruction class
|
||||
//
|
||||
//
|
||||
// $Id: TSDetectorConstruction.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// Construction of a target material (default = boron) surrounded by a
|
||||
/// casing material (default = water) and a vacuum world (default =
|
||||
/// target and casing fill world). The target + casing is brick
|
||||
/// geometry with fTargetSections defining the number of divisions
|
||||
/// in each dimension. The end sections in each dimension
|
||||
/// is set to the casing. So a fTargetSections = G4ThreeVector(3, 3, 3)
|
||||
/// would be one section of boron and 8 sections of water.
|
||||
/// The idea behind this geometry is just to create a simple geometry that
|
||||
/// scatters and produces a lot neutrons with a minimal number of sections
|
||||
/// (i.e. coarse meshing) such that the contention in operating on
|
||||
/// the atomic hits maps is higher and round-off errors in the
|
||||
/// thread-local hits maps are detectable (printed out in TSRunAction)
|
||||
/// from the sheer number of floating point sum operations.
|
||||
/// Two scorers are implemented: EnergyDeposit and Number of steps
|
||||
/// The energy deposit is to (possibly) show the round-off error seen
|
||||
/// with thread-local hits maps. The # of steps scorer is to verify
|
||||
/// the thread-safe and thread-local hits maps provide the same results.
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsdetectorconstruction_hh
|
||||
#define tsdetectorconstruction_hh 1
|
||||
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserDetectorConstruction.hh"
|
||||
#include "G4ThreeVector.hh"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class G4Box;
|
||||
class G4Tubs;
|
||||
class G4Sphere;
|
||||
class G4LogicalVolume;
|
||||
class G4VPhysicalVolume;
|
||||
class G4Material;
|
||||
|
||||
class TSDetectorConstruction : public G4VUserDetectorConstruction
|
||||
{
|
||||
public:
|
||||
typedef std::map<G4String, G4Material*> MaterialCollection_t;
|
||||
typedef std::set<G4LogicalVolume*> ScoringVolumes_t;
|
||||
|
||||
public:
|
||||
TSDetectorConstruction();
|
||||
virtual ~TSDetectorConstruction();
|
||||
|
||||
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; }
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSPhysicsList.hh
|
||||
/// \brief Definition of the TSPhysicsList class
|
||||
//
|
||||
//
|
||||
// $Id: TSPhysicsList.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// This is a very, very extensive physics list and step-limiters are applied
|
||||
/// to many particles. The reasoning behind this is because we wan't to put
|
||||
/// as much pressure on the atomics as possible and produce as much
|
||||
/// round-off error as possible. See descriptions in README and
|
||||
/// TSDetectorConstruction for more details.
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsphysicslist_hh
|
||||
#define tsphysicslist_hh 1
|
||||
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserPhysicsList.hh"
|
||||
|
||||
#include "G4EmStandardPhysics_option4.hh"
|
||||
#include "G4RadioactiveDecayPhysics.hh"
|
||||
#include "G4HadronPhysicsQGSP_BERT_HP.hh"
|
||||
#include "G4HadronElasticPhysicsHP.hh"
|
||||
#include "G4IonElasticPhysics.hh"
|
||||
#include "G4IonBinaryCascadePhysics.hh"
|
||||
#include "G4DecayPhysics.hh"
|
||||
|
||||
class TSPhysicsList : public G4VUserPhysicsList
|
||||
{
|
||||
public:
|
||||
typedef std::deque<G4VPhysicsConstructor*> PhysicsSet_t;
|
||||
|
||||
public:
|
||||
TSPhysicsList();
|
||||
virtual ~TSPhysicsList();
|
||||
|
||||
static TSPhysicsList* Instance();
|
||||
|
||||
public:
|
||||
void ConstructParticle();
|
||||
void ConstructProcess();
|
||||
void SetCuts();
|
||||
|
||||
private:
|
||||
static TSPhysicsList* fgInstance;
|
||||
|
||||
G4EmStandardPhysics_option4* fEmPhysics_opt4;
|
||||
G4DecayPhysics* fDecayPhysics;
|
||||
G4RadioactiveDecayPhysics* fRadDecayPhysics;
|
||||
G4HadronPhysicsQGSP_BERT_HP* fHadronInelasticPhysics;
|
||||
G4HadronElasticPhysicsHP* fHadronElasticPhysics;
|
||||
G4IonElasticPhysics* fIonElasticPhysics;
|
||||
G4IonBinaryCascadePhysics* fIonBinaryCascadePhysics;
|
||||
|
||||
PhysicsSet_t fConstructors;
|
||||
|
||||
G4double fDefaultCutValue;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSPrimaryGeneratorAction.hh
|
||||
/// \brief Definition of the TSPrimaryGeneratorAction class
|
||||
//
|
||||
//
|
||||
// $Id: TSPrimaryGeneratorAction.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// Simple PrimaryGeneratorAction that produces a -Z surface flux of 1 MeV
|
||||
/// neutrons into the world
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsprimarygeneratoraction_hh
|
||||
#define tsprimarygeneratoraction_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4VUserPrimaryGeneratorAction.hh"
|
||||
|
||||
class G4Event;
|
||||
class G4ParticleGun;
|
||||
|
||||
class TSPrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction
|
||||
{
|
||||
public:
|
||||
TSPrimaryGeneratorAction();
|
||||
virtual ~TSPrimaryGeneratorAction();
|
||||
|
||||
public:
|
||||
void GeneratePrimaries(G4Event*);
|
||||
|
||||
private:
|
||||
G4ParticleGun* fGun;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSRun.hh
|
||||
/// \brief Definition of the TSRun class
|
||||
//
|
||||
//
|
||||
// $Id: TSRun.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
/// TSRun contains three collections of hits maps: a thread-local hits map,
|
||||
/// a global atomic hits map (implemented as a static since TSRun is
|
||||
/// implemented as a thread-local instance), and a global "mutex" hits map
|
||||
/// (also implemented as a static). The thread-local hits map is the
|
||||
/// same as you will find in many other examples. The atomics hits map
|
||||
/// is the purpose of this example. Code-wise, the implementation looks
|
||||
/// extremely similar to the thread-local version with the 3 primary
|
||||
/// exceptions: (1) construction - there should only be one instance so
|
||||
/// it should be a static member variable or a pointer/reference to a
|
||||
/// single instance elsewhere in the code (stored in ActionInitialization,
|
||||
/// for instance); (2) It does not need to, nor should be, summed in
|
||||
/// G4Run::Merge(); and (3) destruction -- it should only be cleared by
|
||||
/// the master thread since there is only one instance.
|
||||
/// A "mutex" hits map is also included as reference for checking the results
|
||||
/// accumulated by the thread-local hits maps and atomic hits maps. The
|
||||
/// differences w.r.t. this hits maps are computed in
|
||||
/// TSRunAction::EndOfRunAction
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsrun_h
|
||||
#define tsrun_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include "G4Run.hh"
|
||||
#include "G4Event.hh"
|
||||
#include "G4THitsMap.hh"
|
||||
#include "G4TAtomicHitsMap.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class G4Event;
|
||||
|
||||
class TSRun : public G4Run
|
||||
{
|
||||
public:
|
||||
typedef std::map<G4int, G4double> MutexHitsMap_t;
|
||||
typedef std::vector<G4atomic<G4double>*> AtomicHitsSum_t;
|
||||
|
||||
public:
|
||||
TSRun(const G4String&);
|
||||
virtual ~TSRun();
|
||||
|
||||
// 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;
|
||||
|
||||
void ConstructMFD(const G4String&);
|
||||
|
||||
virtual void Merge(const G4Run*);
|
||||
|
||||
private:
|
||||
std::vector<G4String> fCollNames;
|
||||
std::vector<G4int> fCollIDs;
|
||||
std::vector<G4THitsMap<G4double>*> fRunMaps;
|
||||
static AtomicHitsSum_t fAtomicRunSums;
|
||||
static std::vector<G4TAtomicHitsMap<G4double>*> fAtomicRunMaps;
|
||||
static std::map<G4String, MutexHitsMap_t> fMutexRunMaps;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
/// \file parallel/ThreadsafeScorers/include/TSRunAction.hh
|
||||
/// \brief Definition of the TSRunAction class
|
||||
//
|
||||
//
|
||||
// $Id: TSRunAction.hh 93110 2015-11-05 08:37:42Z jmadsen $
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
|
||||
|
||||
|
||||
#ifndef tsrunaction_hh
|
||||
#define tsrunaction_hh 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4UserRunAction.hh"
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
class G4Run;
|
||||
class G4Timer;
|
||||
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:
|
||||
TSRunAction();
|
||||
virtual ~TSRunAction();
|
||||
|
||||
public:
|
||||
virtual void BeginOfRunAction(const G4Run*);
|
||||
virtual void EndOfRunAction(const G4Run*);
|
||||
virtual G4Run* GenerateRun();
|
||||
|
||||
private:
|
||||
TSDetectorConstruction* fDetector;
|
||||
G4String fName;
|
||||
TypeCompare_t fTypeCompare;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user