Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -40,16 +40,18 @@ template <typename T>
|
||||
class G4Accumulable : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(T initValue,
|
||||
G4Accumulable(T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(const G4Accumulable& rhs);
|
||||
G4Accumulable(G4Accumulable&& rhs);
|
||||
G4Accumulable() = delete;
|
||||
virtual ~G4Accumulable();
|
||||
virtual ~G4Accumulable() = default;
|
||||
|
||||
// operators
|
||||
// Operators
|
||||
G4Accumulable<T>& operator= (const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator= (G4Accumulable<T>&& rhs);
|
||||
G4Accumulable<T>& operator+=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator*=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T> operator++(int); // postfix increment
|
||||
@@ -59,16 +61,16 @@ class G4Accumulable : public G4VAccumulable
|
||||
G4Accumulable<T>& operator+=(const T& rhs);
|
||||
G4Accumulable<T>& operator*=(const T& rhs);
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
virtual void Merge(const G4VAccumulable& other) final;
|
||||
virtual void Reset() final;
|
||||
|
||||
// get methods
|
||||
// Get methods
|
||||
T GetValue() const;
|
||||
G4MergeMode GetMergeMode() const;
|
||||
|
||||
private:
|
||||
// data members
|
||||
// Data members
|
||||
T fValue;
|
||||
T fInitValue;
|
||||
G4MergeMode fMergeMode;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
using namespace G4Accumulables;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name),
|
||||
fValue(initValue),
|
||||
@@ -45,7 +45,7 @@ G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode m
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(),
|
||||
fValue(initValue),
|
||||
@@ -55,7 +55,7 @@ G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(rhs.fValue),
|
||||
@@ -65,12 +65,17 @@ G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::~G4Accumulable()
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(std::move(rhs.fValue)),
|
||||
fInitValue(std::move(rhs.fInitValue)),
|
||||
fMergeMode(rhs.fMergeMode),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -90,7 +95,27 @@ G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs)
|
||||
{
|
||||
// check assignment to self
|
||||
if (this == &rhs) return *this;
|
||||
|
||||
// base class assignment
|
||||
G4VAccumulable::operator=(rhs);
|
||||
|
||||
// this class data assignment
|
||||
fValue = std::move(rhs.fValue);
|
||||
fInitValue = std::move(rhs.fInitValue);
|
||||
fMergeMode = rhs.fMergeMode;
|
||||
fMergeFunction = rhs.fMergeFunction;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -100,7 +125,7 @@ G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
{
|
||||
@@ -110,7 +135,7 @@ G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const T& value)
|
||||
{
|
||||
@@ -120,7 +145,7 @@ G4Accumulable<T>::operator=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const T& value)
|
||||
{
|
||||
@@ -130,7 +155,7 @@ G4Accumulable<T>::operator+=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const T& value)
|
||||
{
|
||||
@@ -140,18 +165,18 @@ G4Accumulable<T>::operator*=(const T& value)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
G4Accumulable<T>::operator++(int)
|
||||
{
|
||||
// postfix increment
|
||||
G4Accumulable<T> temp = *this;
|
||||
fValue++;
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator++()
|
||||
{
|
||||
@@ -161,7 +186,7 @@ G4Accumulable<T>::operator++()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
// G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
|
||||
@@ -171,14 +196,14 @@ void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Reset()
|
||||
{
|
||||
fValue = fInitValue;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
T G4Accumulable<T>::GetValue() const
|
||||
{
|
||||
return fValue;
|
||||
|
||||
@@ -37,51 +37,56 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class G4AccumulableManager;
|
||||
class G4AnalysisManagerState;
|
||||
class G4VAccumulable;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
|
||||
class G4AccumulableManager
|
||||
{
|
||||
friend class G4ThreadLocalSingleton<G4AccumulableManager>;
|
||||
|
||||
public:
|
||||
virtual ~G4AccumulableManager();
|
||||
|
||||
// static methods
|
||||
|
||||
// Static methods
|
||||
static G4AccumulableManager* Instance();
|
||||
|
||||
|
||||
// Methods
|
||||
|
||||
// Create accumulables
|
||||
//
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(T value,
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
CreateAccumulable(T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Register existing accumulables
|
||||
//
|
||||
//
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
|
||||
// user defined accumulable
|
||||
G4bool RegisterAccumulable(G4VAccumulable* accumulable);
|
||||
|
||||
// Access registered accumulables
|
||||
//
|
||||
//
|
||||
// Via name
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
// Via id (in the order of registering)
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
@@ -98,26 +103,25 @@ class G4AccumulableManager
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
// hide ctor requiring master/worker specification
|
||||
G4AccumulableManager(G4bool isMaster);
|
||||
// Hide singleton ctor
|
||||
G4AccumulableManager();
|
||||
|
||||
// metods
|
||||
// Methods
|
||||
// Generate generic accumulable name: accumulableN, where N is the actual number of accumulables
|
||||
G4String GenerateName() const;
|
||||
// Check if a name is already used in a map and print a warning
|
||||
// Check if a name is already used in a map and print a warning
|
||||
G4bool CheckName(const G4String& name, const G4String& where) const;
|
||||
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
// constants
|
||||
// Constants
|
||||
const G4String kBaseName = "accumulable";
|
||||
|
||||
// static data members
|
||||
static G4AccumulableManager* fgMasterInstance;
|
||||
static G4ThreadLocal G4AccumulableManager* fgInstance;
|
||||
// Static data members
|
||||
inline static G4AccumulableManager* fgMasterInstance { nullptr };
|
||||
|
||||
// data members
|
||||
// Data members
|
||||
std::vector<G4VAccumulable*> fVector;
|
||||
std::map<G4String, G4VAccumulable*> fMap;
|
||||
std::vector<G4VAccumulable*> fAccumulablesToDelete;
|
||||
|
||||
@@ -25,21 +25,21 @@
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
|
||||
{
|
||||
// Do not check type if nullptr
|
||||
if ( ! accumulable ) return nullptr;
|
||||
|
||||
// check type
|
||||
G4Accumulable<T>* taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
||||
auto taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
||||
if ( ! taccumulable && warn ) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << "Accumulable " << accumulable->GetName()
|
||||
description << " " << "Accumulable " << accumulable->GetName()
|
||||
<< " has different type";
|
||||
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
||||
"Analysis_W011", JustWarning, description);
|
||||
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -47,13 +47,13 @@ G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) c
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
const G4String& name, T value, G4MergeMode mergeMode)
|
||||
{
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
|
||||
if ( ! CheckName(name, "CreateAccumulable") ) return 0;
|
||||
|
||||
// create accumulable
|
||||
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
|
||||
@@ -66,8 +66,8 @@ G4AccumulableManager::CreateAccumulable(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
T value, G4MergeMode mergeMode)
|
||||
{
|
||||
@@ -75,15 +75,15 @@ G4AccumulableManager::CreateAccumulable(
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
template <typename T>
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
|
||||
{
|
||||
return RegisterAccumulable(&accumulable);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
@@ -92,8 +92,8 @@ G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
@@ -120,14 +120,14 @@ inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::BeginConst() const
|
||||
{
|
||||
return fVector.begin();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
inline std::vector<G4VAccumulable*>::const_iterator
|
||||
G4AccumulableManager::EndConst() const
|
||||
{
|
||||
return fVector.end();
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#define G4MergeMode_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4Exception.hh"
|
||||
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
@@ -41,7 +42,7 @@ enum class G4MergeMode {
|
||||
kMultiplication, // "And" if boolean type
|
||||
kMaximum, // "Or" if boolean type
|
||||
kMinimum // "And" if boolean type
|
||||
};
|
||||
};
|
||||
|
||||
// Generic merge function
|
||||
template <typename T>
|
||||
@@ -62,7 +63,7 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
|
||||
case G4MergeMode::kMultiplication:
|
||||
return [](const T& x, const T& y) { return x * y; };
|
||||
|
||||
|
||||
case G4MergeMode::kMaximum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::max(x,y);});
|
||||
return [](const T& x, const T& y) { return std::max(x,y); };
|
||||
@@ -70,10 +71,13 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
case G4MergeMode::kMinimum:
|
||||
// return std::bind([](const T& x, const T& y) { return std::min(x,y);});
|
||||
return [](const T& x, const T& y) { return std::min(x,y); };
|
||||
|
||||
default:
|
||||
return [](const T&, const T&) { return 0.0; };
|
||||
}
|
||||
|
||||
// Must never get here, but we need a return to satisfy MSVC
|
||||
G4Exception("G4Accumulables::GetMergeFunction<T>",
|
||||
"Analysis_F001", FatalException,
|
||||
"Undefined merge mode");
|
||||
return [](const T&, const T&) { return T(); };
|
||||
}
|
||||
|
||||
template <G4bool>
|
||||
|
||||
@@ -41,17 +41,19 @@ class G4VAccumulable
|
||||
|
||||
public:
|
||||
G4VAccumulable(const G4String& name = "");
|
||||
G4VAccumulable(const G4VAccumulable& rhs);
|
||||
virtual ~G4VAccumulable() {}
|
||||
G4VAccumulable(const G4VAccumulable& rhs) = default;
|
||||
G4VAccumulable(G4VAccumulable&& rhs) = default;
|
||||
virtual ~G4VAccumulable() = default;
|
||||
|
||||
// operators
|
||||
G4VAccumulable& operator=(const G4VAccumulable& rhs);
|
||||
// Operators
|
||||
G4VAccumulable& operator=(const G4VAccumulable& rhs) = default;
|
||||
G4VAccumulable& operator=(G4VAccumulable&& rhs) = default;
|
||||
|
||||
// methods
|
||||
// Methods
|
||||
virtual void Merge(const G4VAccumulable& other) = 0;
|
||||
virtual void Reset() = 0;
|
||||
|
||||
// get methods
|
||||
// Get methods
|
||||
G4String GetName() const;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -29,21 +29,8 @@ inline G4VAccumulable::G4VAccumulable(const G4String& name)
|
||||
: fName(name)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(const G4VAccumulable& rhs)
|
||||
: fName(rhs.fName)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable& G4VAccumulable::operator=(const G4VAccumulable& rhs)
|
||||
{
|
||||
fName = rhs.fName;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4String G4VAccumulable::GetName() const
|
||||
{
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user