135 lines
4.9 KiB
Plaintext
135 lines
4.9 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. *
|
|
// ********************************************************************
|
|
//
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4Accumulable<T>*
|
|
G4AccumulableManager::GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const
|
|
{
|
|
// Do not check type if nullptr
|
|
if ( ! accumulable ) return nullptr;
|
|
|
|
// check type
|
|
auto taccumulable = dynamic_cast<G4Accumulable<T>*>(accumulable);
|
|
if ( ! taccumulable && warn ) {
|
|
G4ExceptionDescription description;
|
|
description << " " << "Accumulable " << accumulable->GetName()
|
|
<< " has different type";
|
|
G4Exception("G4AccumulableManager::GetAccumulable<T>",
|
|
"Analysis_W001", JustWarning, description);
|
|
return nullptr;
|
|
}
|
|
|
|
return taccumulable;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
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;
|
|
|
|
// create accumulable
|
|
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
|
|
|
|
// register accumulable in the map and vector
|
|
RegisterAccumulable(accumulable);
|
|
fAccumulablesToDelete.push_back(accumulable);
|
|
|
|
return accumulable;
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4Accumulable<T>*
|
|
G4AccumulableManager::CreateAccumulable(
|
|
T value, G4MergeMode mergeMode)
|
|
{
|
|
return CreateAccumulable(G4String(), value, mergeMode);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
|
|
{
|
|
return RegisterAccumulable(&accumulable);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4Accumulable<T>*
|
|
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
|
{
|
|
// get G4VParammeter from the map
|
|
auto accumulable = GetAccumulable(name, warn);
|
|
return GetAccumulable<T>(accumulable, warn);
|
|
}
|
|
|
|
//_____________________________________________________________________________
|
|
template <typename T>
|
|
G4Accumulable<T>*
|
|
G4AccumulableManager::GetAccumulable(G4int id, G4bool warn) const
|
|
{
|
|
// get G4VParammeter from the map
|
|
auto accumulable = GetAccumulable(id, warn);
|
|
return GetAccumulable<T>(accumulable, 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();
|
|
}
|