380 lines
13 KiB
Plaintext
380 lines
13 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * 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. *
|
|
// ********************************************************************
|
|
//
|
|
|
|
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
|
|
|
|
#include "G4AccArray.hh"
|
|
#include "G4AccMap.hh"
|
|
#include "G4AccUnorderedMap.hh"
|
|
#include "G4AccVector.hh"
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if (accumulable == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
// check type
|
|
if (! CheckType(accumulable, G4AccType::kValue, warn)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return static_cast<G4AccValue<T>*>(accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T, std::size_t N>
|
|
G4AccArray<T, N>*
|
|
G4AccumulableManager::GetAccArray(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if (accumulable == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
// check type
|
|
if (! CheckType(accumulable, G4AccType::kArray, warn)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return static_cast<G4AccArray<T, N>*>(accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class Key, class T, class Compare, class Allocator>
|
|
G4AccMap<Key, T, Compare, Allocator>*
|
|
G4AccumulableManager::GetAccMap(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if (accumulable == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
// check type
|
|
if (! CheckType(accumulable, G4AccType::kMap, warn)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return static_cast<G4AccMap<Key, T, Compare, Allocator>*>(accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
|
|
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
|
G4AccumulableManager::GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if (accumulable == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
// check type
|
|
if (! CheckType(accumulable, G4AccType::kUnorderedMap, warn)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return static_cast<G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*>(accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, class Allocator>
|
|
G4AccVector<T, Allocator>*
|
|
G4AccumulableManager::GetAccVector(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if (accumulable == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
// check type
|
|
if (! CheckType(accumulable, G4AccType::kVector, warn)) {
|
|
return nullptr;
|
|
}
|
|
|
|
return static_cast<G4AccVector<T, Allocator>*>(accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::CreateAccValue(
|
|
const G4String& name, T value, G4MergeMode mergeMode)
|
|
{
|
|
// do not accept name if it is already used
|
|
if (!CheckName(name, "CreateAccumulable")) {
|
|
return 0;
|
|
}
|
|
|
|
// create accumulable
|
|
auto accumulable = new G4AccValue<T>(name, value, mergeMode);
|
|
|
|
// register accumulable in the map and vector
|
|
Register(accumulable);
|
|
fAccumulablesToDelete.push_back(accumulable);
|
|
|
|
return accumulable;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::CreateAccValue(
|
|
T value, G4MergeMode mergeMode)
|
|
{
|
|
return CreateAccValue<T>(G4String(), value, mergeMode);
|
|
}
|
|
|
|
// Deprecated function using the old accumulable value name
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::CreateAccumulable(
|
|
const G4String& name, T value, G4MergeMode mergeMode)
|
|
{
|
|
return CreateAccValue<T>(name, value, mergeMode);
|
|
}
|
|
|
|
// Deprecated function using the old accumulable value name
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::CreateAccumulable(
|
|
T value, G4MergeMode mergeMode)
|
|
{
|
|
return CreateAccValue<T>(value, mergeMode);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4bool G4AccumulableManager::Register(G4AccValue<T>& accumulable)
|
|
{
|
|
return Register(&accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, std::size_t N>
|
|
G4bool G4AccumulableManager::Register(G4AccArray<T, N>& accumulableArray)
|
|
{
|
|
return Register(&accumulableArray);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class Key, class T, class Compare, class Allocator>
|
|
G4bool G4AccumulableManager::Register(
|
|
G4AccMap<Key, T, Compare, Allocator>& accumulableMap)
|
|
{
|
|
return Register(&accumulableMap);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
|
G4bool G4AccumulableManager::Register(
|
|
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap)
|
|
{
|
|
return Register(&accumulableUnorderedMap);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, class Allocator>
|
|
G4bool G4AccumulableManager::Register(G4AccVector<T, Allocator>& accumulableVector)
|
|
{
|
|
return Register(&accumulableVector);
|
|
}
|
|
|
|
// Deprecated functions with long name
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4bool G4AccumulableManager::RegisterAccumulable(G4AccValue<T>& accumulable)
|
|
{
|
|
return Register(&accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::GetAccValue(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccumulable<T>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, std::size_t N>
|
|
G4AccArray<T, N>*
|
|
G4AccumulableManager::GetAccArray(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccArray<T,N>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class Key, class T, class Compare, class Allocator>
|
|
G4AccMap<Key, T, Compare, Allocator>*
|
|
G4AccumulableManager::GetAccMap(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
|
|
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
|
G4AccumulableManager::GetAccUnorderedMap(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, class Allocator>
|
|
G4AccVector<T, Allocator>*
|
|
G4AccumulableManager::GetAccVector(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccVector<T,Allocator>(accumulable, warn);
|
|
}
|
|
|
|
// Deprecated function using the old accumulable value name
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
|
{
|
|
return GetAccValue<T>(name, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::GetAccValue(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccumulable<T>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, std::size_t N>
|
|
G4AccArray<T, N>*
|
|
G4AccumulableManager::GetAccArray(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccArray<T,N>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class Key, class T, class Compare, class Allocator>
|
|
G4AccMap<Key, T, Compare, Allocator>*
|
|
G4AccumulableManager::GetAccMap(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccMap<Key, T, Compare, Allocator>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename Key, typename T, typename Hash, typename KeyEqual, typename Allocator>
|
|
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
|
G4AccumulableManager::GetAccUnorderedMap(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <class T, class Allocator>
|
|
G4AccVector<T, Allocator>*
|
|
G4AccumulableManager::GetAccVector(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VAccummulable from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccVector<T,Allocator>(accumulable, warn);
|
|
}
|
|
|
|
// Deprecated function using the old accumulable value name
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4AccValue<T>*
|
|
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
|
{
|
|
return GetAccValue<T>(id, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline G4int G4AccumulableManager::GetNofAccumulables() const
|
|
{
|
|
return G4int(fVector.size());
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::Begin()
|
|
{
|
|
return fVector.begin();
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline std::vector<G4VAccumulable*>::iterator G4AccumulableManager::End()
|
|
{
|
|
return fVector.end();
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline std::vector<G4VAccumulable*>::const_iterator
|
|
G4AccumulableManager::BeginConst() const
|
|
{
|
|
return fVector.begin();
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline std::vector<G4VAccumulable*>::const_iterator
|
|
G4AccumulableManager::EndConst() const
|
|
{
|
|
return fVector.end();
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline void G4AccumulableManager::SetVerboseLevel(G4int value)
|
|
{
|
|
G4Accumulables::VerboseLevel = value;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
inline G4int G4AccumulableManager::GetVerboseLevel() const
|
|
{
|
|
return G4Accumulables::VerboseLevel;
|
|
}
|