Import Geant4 11.3.0 source tree
This commit is contained in:
@@ -6,6 +6,56 @@ It must **not** be used as a substitute for writing good git commit messages!
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
## 2024-11-04 I. Hrivnacova (analysis-V11-02-08)
|
||||
- Coverity fixes:
|
||||
- Correct usage of std::move
|
||||
|
||||
## 2024-10-16 I. Hrivnacova (analysis-V11-02-07)
|
||||
- G4AccVector, G4Acc[Unordered]Map:
|
||||
Replaced inheritance from standard collections with composition,
|
||||
added most frequent functions:
|
||||
- operator[], at, size, [c]begin, [c]end, clear - all
|
||||
- insert, find - map, unordered_map
|
||||
- push_back, emplace_back, pop_back - vector
|
||||
|
||||
## 2024-09-13 I. Hrivnacova (analysis-V11-02-06)
|
||||
- Fix setting file compression level in G4GenericFileManager:
|
||||
propagate setting to all registered file managers.
|
||||
(Addressing the problem report #2625.)
|
||||
|
||||
## 2024-09-10 I. Hrivnacova (analysis-V11-02-05)
|
||||
- Coverity fixes:
|
||||
- Use std::move, const auto& instead of auto to avoid copying
|
||||
|
||||
## 2024-08-30 G. Cosmo (analysis-V11-02-04)
|
||||
- Fixed compilation warning on macOS/XCode for implicit type conversion in
|
||||
G4AccumulableManager.
|
||||
|
||||
## 2024-07-08 I. Hrivnacova (analysis-V11-02-03)
|
||||
Added support for accumulable collections, and more:
|
||||
- New classes:
|
||||
G4AccArray, G4AccMap, G4AccUnorderedMap, G4AccVector
|
||||
- Renamed class G4Accumulable<T> in G4AccValue<T>,
|
||||
and added a using for the old name for backward compatibility
|
||||
- Replaced G4AccumulableManager::RegisterAccumulable with Register
|
||||
and deprecated the function with the old name
|
||||
- Added G4AccType enumaration for avalable accumulable types
|
||||
- Added functions for printing with G4PrintOption argument
|
||||
to all accumulable types and G4AccumulableManager:
|
||||
- Note this will require to update user classes which implement
|
||||
the Print() function without or with different argument(s)
|
||||
- Added G4Accumulables::VerboseLevel and its setter/getter
|
||||
in G4AccumulableManager
|
||||
- Extended test08 with new accumulable types
|
||||
|
||||
## 2024-07-08 I. Hrivnacova (analysis-V11-02-02)
|
||||
- Clang-tidy checks:
|
||||
- Removed virtual keywords for overriding functions
|
||||
(G4GenericFileManager, G4THnToolsManager)
|
||||
- removed redundant data initialization (G4HnInformation)
|
||||
- use emplace-back in G4RootMainNtupleManager.cc
|
||||
- removed redundant data initialization
|
||||
|
||||
## 2024-06-05 I. Hrivnacova (analysis-V11-02-01)
|
||||
- Do not delete G4Accumulable<T> default constructor,
|
||||
as it prevents from using it in an array without an explicit
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulable arrays handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 18/07/2024
|
||||
|
||||
#ifndef G4AccArray_h
|
||||
#define G4AccArray_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <array>
|
||||
|
||||
template <class T, std::size_t N>
|
||||
class G4AccArray : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
// Default constructor (1)
|
||||
// Constructs the container with the default init value
|
||||
G4AccArray(const G4String& name = "",
|
||||
const T& value = 0,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (2)
|
||||
// Constructs the container with the provided initializer list
|
||||
// and defaults for all other members
|
||||
template <typename... Args>
|
||||
G4AccArray(Args&&... args);
|
||||
|
||||
// // Constructor (3)
|
||||
// // Constructs the container with the provided name and initializer list
|
||||
// // and defaults for the other members
|
||||
template <typename First, typename... Args>
|
||||
G4AccArray(const First& firstArg, Args&&... args);
|
||||
|
||||
// Copy constructor
|
||||
G4AccArray(const G4AccArray& rhs) = default;
|
||||
// Move constructor
|
||||
G4AccArray(G4AccArray&& rhs) = default;
|
||||
|
||||
// Destructor
|
||||
~G4AccArray() override = default;
|
||||
|
||||
// operators
|
||||
inline T& operator[](typename std::array<T,N>::size_type i) { return fArray[i]; }
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const final;
|
||||
void SetMergeMode(G4MergeMode value) final;
|
||||
|
||||
// Get methods
|
||||
G4AccType GetType() const final { return G4AccType::kArray; }
|
||||
std::array<T,N>& GetArray();
|
||||
const std::array<T,N>& GetArray() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::array<T,N> fArray {};
|
||||
T fInitValue = 0;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4AccArray.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 18/07/2024
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
G4AccArray<T, N>::G4AccArray(
|
||||
const G4String& name, const T& value, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fInitValue(value),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccArray ctor1" << G4endl;
|
||||
}
|
||||
|
||||
for (auto& element : fArray ) {
|
||||
element = fInitValue;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
template <typename... Args>
|
||||
G4AccArray<T, N>::G4AccArray(Args&&... args)
|
||||
: G4VAccumulable(),
|
||||
fArray{{std::forward<Args>(args)...}}, fMergeFunction(GetMergeFunction<T>(fMergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccArray ctor2" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
template <typename First, typename... Args>
|
||||
G4AccArray<T, N>::G4AccArray(const First& firstArg, Args&&... args)
|
||||
: G4VAccumulable(firstArg),
|
||||
fArray{{std::forward<Args>(args)...}},
|
||||
fMergeFunction(GetMergeFunction<T>(fMergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccArray ctor3" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
void G4AccArray<T, N>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
const auto& otherArrayAcc = static_cast<const G4AccArray<T,N>&>(other);
|
||||
const auto& otherArray = otherArrayAcc.GetArray();
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << "G4AccArray<T, N>::Merge: " << G4endl;
|
||||
G4cout << "destination: ";
|
||||
for (auto v : this->fArray) {
|
||||
G4cout << v << ", ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << "merged data: ";
|
||||
for (auto v : otherArray) {
|
||||
G4cout << v << ", ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
std::transform(fArray.begin(), fArray.end(), otherArray.begin(),
|
||||
fArray.begin(), fMergeFunction);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccArray<T, N>::Merge: done" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
void G4AccArray<T, N>::Reset()
|
||||
{
|
||||
for (auto& value : fArray) {
|
||||
value = fInitValue;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
void G4AccArray<T, N>::Print(G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kType)) {
|
||||
G4cout << "array<" << typeid(fInitValue).name() << ">: ";
|
||||
}
|
||||
|
||||
PrintBase(options);
|
||||
|
||||
bool first = true;
|
||||
for (auto& value : fArray) {
|
||||
if (! first) { G4cout << ", "; }
|
||||
G4cout << value;
|
||||
first = false;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
void G4AccArray<T, N>::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
G4VAccumulable::SetMergeMode(value);
|
||||
fMergeFunction = GetMergeFunction<T>(value);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
std::array<T,N>& G4AccArray<T, N>::GetArray()
|
||||
{
|
||||
return fArray;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, std::size_t N>
|
||||
const std::array<T,N>& G4AccArray<T, N>::GetArray() const
|
||||
{
|
||||
return fArray;
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulable maps handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 19/07/2024
|
||||
|
||||
#ifndef G4AccMap_h
|
||||
#define G4AccMap_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
|
||||
template <class Key,
|
||||
class T,
|
||||
class Compare = std::less<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
class G4AccMap : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
// ctors to be supported
|
||||
// (https://en.cppreference.com/w/cpp/container/map/map)
|
||||
//
|
||||
// Default constructor (1) - Constructs an empty container.
|
||||
// map();
|
||||
//
|
||||
// Constructor (2) - Constructs an empty container.
|
||||
// explicit map(const Compare& comp,
|
||||
// const Allocator& alloc = Allocator());
|
||||
//
|
||||
// Constructor (3) - Constructs an empty container.
|
||||
// explicit map(const Allocator& alloc);
|
||||
//
|
||||
// 4,5) Constructs the container with the contents of the range [first, last).
|
||||
// - skipped
|
||||
//
|
||||
// Constructor (6) - Copy constructor.
|
||||
// Constructs the container with the copy of the contents of other.
|
||||
// map( const map& other );
|
||||
//
|
||||
// Constructor (7) - Copy constructor with provided allocator
|
||||
// map( const map& other, const Allocator& alloc );
|
||||
//
|
||||
// Constructor (8) - Move constructor.
|
||||
// Constructs the container with the contents of other using move semantics.
|
||||
// map(map&& other);
|
||||
//
|
||||
// Constructor (9) - Move constructor with provided allocator
|
||||
// Constructs the container with the contents of other using move semantics.
|
||||
// map(map&& other, const Allocator& alloc);
|
||||
//
|
||||
// Constructor (10) - Initializer-list constructor.
|
||||
// Constructs the container with the contents of the initializer list init
|
||||
// map(std::initializer_list<value_type> init,
|
||||
// const Compare& comp = Compare(),
|
||||
// const Allocator& alloc = Allocator());
|
||||
//
|
||||
// Constructor (11) - Initializer-list constructor.
|
||||
// Constructs the container with the contents of the initializer list init
|
||||
// map(std::initializer_list<value_type> init,
|
||||
// const Allocator& alloc);
|
||||
// - skipped
|
||||
//
|
||||
// (since C++20)
|
||||
// (12,13) Constructs the container with the contents of rg.
|
||||
// - skipped
|
||||
|
||||
// Default constructor (1)
|
||||
// Constructs an empty container with all defaults.
|
||||
G4AccMap(const G4String& name = "",
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (2)
|
||||
// Constructs an empty container with the given compare.
|
||||
G4AccMap(const Compare& comp,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Constructor (2) with name
|
||||
// Constructs an empty container with the given compare with name
|
||||
G4AccMap(const G4String& name,
|
||||
const Compare& comp,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Constructor (3)
|
||||
// Constructs an empty container with the given allocator alloc.
|
||||
G4AccMap(const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (3) with name
|
||||
// Constructs an empty container with the given allocator alloc and name
|
||||
G4AccMap(const G4String& name,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (10)
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
G4AccMap(std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Compare& comp = Compare(),
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Constructor (10) with name
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
G4AccMap(const G4String& name,
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Compare& comp = Compare(),
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Copy constructor
|
||||
G4AccMap(const G4AccMap& rhs) = default;
|
||||
G4AccMap(const G4AccMap& rhs, const Allocator& allocator);
|
||||
// Move constructor
|
||||
G4AccMap(G4AccMap&& rhs) = default;
|
||||
G4AccMap(G4AccMap&& rhs, const Allocator& allocator);
|
||||
|
||||
// Destructor
|
||||
~G4AccMap() override = default;
|
||||
|
||||
// std::map functions, operators
|
||||
// operator []
|
||||
inline T& operator[](const Key& key) { return fMap[key]; }
|
||||
inline T& operator[](Key&& key) { return fMap[std::move(key)]; }
|
||||
// at
|
||||
inline T& at(const Key& key) { return fMap[key]; }
|
||||
inline const T& at(const Key& key ) const { return fMap[key]; }
|
||||
// size
|
||||
inline typename std::map<Key, T, Compare, Allocator>::size_type size() const { return fMap.size(); }
|
||||
// begin, cbegin
|
||||
inline typename std::map<Key, T, Compare, Allocator>::iterator begin() { return fMap.begin(); }
|
||||
inline typename std::map<Key, T, Compare, Allocator>::const_iterator begin() const { return fMap.begin(); }
|
||||
inline typename std::map<Key, T, Compare, Allocator>::const_iterator cbegin() const { return fMap.cbegin(); }
|
||||
// end, cend
|
||||
inline typename std::map<Key, T, Compare, Allocator>::iterator end() { return fMap.end(); }
|
||||
inline typename std::map<Key, T, Compare, Allocator>::const_iterator end() const { return fMap.end(); }
|
||||
inline typename std::map<Key, T, Compare, Allocator>::const_iterator cend() const { return fMap.cend(); }
|
||||
// clear
|
||||
inline void clear() { fMap.clear(); }
|
||||
// insert
|
||||
inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert(const T& value) { return fMap.insert(value); }
|
||||
template< class P >
|
||||
inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert( P&& value ) { return fMap.insert(std::move(value)); }
|
||||
inline std::pair<typename std::map<Key, T, Compare, Allocator>::iterator, bool> insert( T&& value ) { return fMap.insert(std::move(value)); }
|
||||
// find
|
||||
inline typename std::map<Key, T, Compare, Allocator>::iterator find( const Key& key ) { return fMap.find(key); }
|
||||
inline typename std::map<Key, T, Compare, Allocator>::const_iterator find( const Key& key ) const { return fMap.find(key); }
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const final;
|
||||
void SetMergeMode(G4MergeMode value) final;
|
||||
void SetInitValue(const T& value);
|
||||
|
||||
// Get methods
|
||||
G4AccType GetType() const final { return G4AccType::kMap; }
|
||||
std::map<Key, T, Compare, Allocator>& GetMap() { return fMap; }
|
||||
const std::map<Key, T, Compare, Allocator>& GetMap() const { return fMap; }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::map<Key, T, Compare, Allocator> fMap {};
|
||||
T fInitValue = 0;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4AccMap.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 19/07/2024
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
// Default constructor (1)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const G4String& name,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fMap(),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor1" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const Compare& comp,
|
||||
G4MergeMode mergeMode,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fMap(comp, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor2" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const G4String& name,
|
||||
const Compare& comp,
|
||||
G4MergeMode mergeMode,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fMap(comp, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor2n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fMap(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor3" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const G4String& name,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fMap(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor3n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (10)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode,
|
||||
const Compare& comp,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fMap(init, comp, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor10" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (10) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const G4String& name,
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode,
|
||||
const Compare& comp,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fMap(init, comp, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccMap ctor10n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
const G4AccMap& rhs,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(rhs),
|
||||
fMap(rhs, allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
// Move ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4AccMap<Key, T, Compare, Allocator>::G4AccMap(
|
||||
G4AccMap&& rhs,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(std::move(rhs)),
|
||||
fMap(std::move(rhs), allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
void G4AccMap<Key, T, Compare, Allocator>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
const auto& otherMap = static_cast<const G4AccMap<Key, T, Compare, Allocator>&>(other);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << "G4AccMap<Key, T, Compare, Allocator>::Merge: " << G4endl;
|
||||
G4cout << "destination: ";
|
||||
for (const auto& [key, v] : fMap) {
|
||||
G4cout << "[ " << key << ", " << v << " ], ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << "merged data: ";
|
||||
for (const auto& [key, v] : otherMap.fMap) {
|
||||
G4cout << "[ " << key << ", " << v << " ], ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
for (const auto& [key, value] : otherMap.fMap) {
|
||||
if ( fMap.find(key) == fMap.end()) {
|
||||
fMap[key] = value;
|
||||
}
|
||||
else {
|
||||
fMap[key] = fMergeFunction(fMap[key], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
void G4AccMap<Key, T, Compare, Allocator>::Reset()
|
||||
{
|
||||
for (auto& [key, value] :fMap) {
|
||||
fMap[key] = fInitValue;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
void G4AccMap<Key, T, Compare, Allocator>::Print(
|
||||
G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kType)) {
|
||||
G4cout << "map<" << typeid(Key).name() << ", " << typeid(T).name() << ">: ";
|
||||
}
|
||||
|
||||
PrintBase(options);
|
||||
|
||||
bool first = true;
|
||||
for (const auto& [key, value] : fMap) {
|
||||
if (! first) { G4cout << ", "; }
|
||||
G4cout << "[ " << key << ", " << value << "] ";
|
||||
first = false;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
void G4AccMap<Key, T, Compare, Allocator>::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
G4VAccumulable::SetMergeMode(value);
|
||||
fMergeFunction = GetMergeFunction<T>(fMergeMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
void G4AccMap<Key, T, Compare, Allocator>::SetInitValue(const T& value)
|
||||
{
|
||||
fInitValue = value;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 25/07/2024
|
||||
|
||||
#ifndef G4AccType_h
|
||||
#define G4AccType_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <bitset>
|
||||
|
||||
// Enumeration for definition available accummulables
|
||||
|
||||
enum class G4AccType {
|
||||
kValue, // G4AccValue<T>
|
||||
kArray, // G4AccArray<T>
|
||||
kMap, // G4AccMap<T>
|
||||
kUnorderedMap, // G4AccUnorderedMap<T>
|
||||
kVector, // G4AccumulableVector<T>
|
||||
kUser // User type
|
||||
};
|
||||
|
||||
// TODO: add G4String GetTypeName(G4AccType)
|
||||
|
||||
// Helper class for printing
|
||||
//
|
||||
class G4PrintOptions {
|
||||
public:
|
||||
enum Option : std::size_t {
|
||||
kName = 0,
|
||||
kType = 1,
|
||||
kId = 2
|
||||
};
|
||||
|
||||
G4PrintOptions() {
|
||||
SetDefaults();
|
||||
}
|
||||
G4PrintOptions(std::initializer_list<Option> options) {
|
||||
SetDefaults();
|
||||
for (const Option& option : options) {
|
||||
fValue.set(option);
|
||||
}
|
||||
}
|
||||
~G4PrintOptions() = default;
|
||||
|
||||
void Set(Option option, bool value = true) { fValue.set(option, value); }
|
||||
bool Has(Option option) const { return fValue[option]; }
|
||||
|
||||
private:
|
||||
// methods
|
||||
void SetDefaults() {
|
||||
fValue.set(kName);
|
||||
fValue.set(kType);
|
||||
}
|
||||
|
||||
// data members
|
||||
static constexpr std::size_t kMax = G4PrintOptions::kId + 1;
|
||||
std::bitset<kMax> fValue{0};
|
||||
};
|
||||
|
||||
namespace G4Accumulables
|
||||
{
|
||||
|
||||
// Constant expressions
|
||||
//
|
||||
constexpr G4int kInvalidId { -1 };
|
||||
|
||||
// Verbose level
|
||||
//
|
||||
[[maybe_unused]] static G4int VerboseLevel {1};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,257 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulable unordered_maps handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 19/07/2024
|
||||
|
||||
#ifndef G4AccUnorderedMap_h
|
||||
#define G4AccUnorderedMap_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
template <class Key,
|
||||
class T,
|
||||
class Hash = std::hash<Key>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
class G4AccUnorderedMap : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
// ctors to be supported
|
||||
// (https://en.cppreference.com/w/cpp/container/unordered_map/unordered_map)
|
||||
//
|
||||
// Default constructor (1) - Constructs an empty container.
|
||||
// unordered_map();
|
||||
//
|
||||
// Constructor (2) - Constructs an empty container.
|
||||
// explicit unordered_map( size_type bucket_count,
|
||||
// const Hash& hash = Hash(),
|
||||
// const KeyEqual& equal = KeyEqual(),
|
||||
// const Allocator& alloc = Allocator() );
|
||||
//
|
||||
// Constructor (3) - Constructs an empty container.
|
||||
// unordered_map( size_type bucket_count,
|
||||
// const Allocator& alloc )
|
||||
// : unordered_map(bucket_count, Hash(), KeyEqual(), alloc) {}
|
||||
//
|
||||
// Constructor (4) (since C++14)
|
||||
// Constructs empty container.
|
||||
// unordered_map( size_type bucket_count,
|
||||
// const Hash& hash,
|
||||
// const Allocator& alloc )
|
||||
// : unordered_map(bucket_count, hash, KeyEqual(), alloc) {}
|
||||
//
|
||||
// Constructor (5) (since C++11)
|
||||
// Constructs empty container.
|
||||
// explicit unordered_map( const Allocator& alloc );
|
||||
//
|
||||
// (6,7,8) (since C++11)
|
||||
// Constructs the container with the contents of the range
|
||||
// - skipped
|
||||
//
|
||||
// (9) (since C++11) - Copy constructor.
|
||||
// unordered_map( const unordered_map& other );
|
||||
//
|
||||
// (10) (since C++11) - Copy constructor with provided allocator
|
||||
// unordered_map( const unordered_map& other, const Allocator& alloc );
|
||||
//
|
||||
// (11) (since C++11) - Move constructor.
|
||||
// unordered_map( unordered_map&& other );
|
||||
//
|
||||
// (12) (since C++11) - Move constructor with provided allocator
|
||||
// unordered_map( unordered_map&& other, const Allocator& alloc );
|
||||
//
|
||||
// (13) (since C++11) - Initializer-list constructor.
|
||||
// Constructs the container with the contents of the initializer list init
|
||||
// unordered_map( std::initializer_list<value_type> init,
|
||||
// size_type bucket_count = /* implementation-defined */,
|
||||
// const Hash& hash = Hash(),
|
||||
// const KeyEqual& equal = KeyEqual(),
|
||||
// const Allocator& alloc = Allocator() );
|
||||
//
|
||||
// (14) (since C++11) - Initializer-list constructor.
|
||||
// Constructs the container with the contents of the initializer list init
|
||||
// unordered_map( std::initializer_list<value_type> init,
|
||||
// size_type bucket_count,
|
||||
// const Allocator& alloc )
|
||||
// : unordered_map(init, bucket_count,
|
||||
// Hash(), KeyEqual(), alloc) {}
|
||||
//
|
||||
// (15) (since C++14) - Initializer-list constructor.
|
||||
// unordered_map( std::initializer_list<value_type> init,
|
||||
// size_type bucket_count,
|
||||
// const Hash& hash,
|
||||
// const Allocator& alloc )
|
||||
// : unordered_map(init, bucket_count,
|
||||
// hash, KeyEqual(), alloc) {}
|
||||
//
|
||||
// (16,17) (since C++23)
|
||||
// Constructs the container with the contents of rg.
|
||||
// - skipped
|
||||
|
||||
|
||||
// Default constructor (1)
|
||||
// Constructs an empty container with all defaults.
|
||||
G4AccUnorderedMap(const G4String& name = "",
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (2)
|
||||
// Constructs an empty container with the given bucket_count
|
||||
G4AccUnorderedMap(std::size_t bucket_count,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Constructor (2) with name
|
||||
// Constructs an empty container with the given bucket_count and name
|
||||
G4AccUnorderedMap(const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
// Constructor (3)
|
||||
// Constructs an empty container with the given bucket_count and allocator
|
||||
G4AccUnorderedMap(std::size_t bucket_count,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (3) with name
|
||||
// Constructs an empty container with the given bucket_count, allocator and name
|
||||
G4AccUnorderedMap(const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
// Constructor (4)
|
||||
// Constructs an empty container with the given bucket_count, allocator and hash
|
||||
G4AccUnorderedMap(std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (4) with name
|
||||
// Constructs an empty container with the given bucket_count, allocator, hash and name
|
||||
G4AccUnorderedMap(const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
// Constructor (5)
|
||||
// Constructs an empty container with the given allocator alloc.
|
||||
G4AccUnorderedMap(const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (5) with name
|
||||
// Constructs an empty container with the given allocator alloc and name
|
||||
G4AccUnorderedMap(const G4String& name,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (13)
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
G4AccUnorderedMap(std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
std::size_t bucket_count = 0,
|
||||
const Hash& hash = Hash(),
|
||||
const KeyEqual& equal = KeyEqual(),
|
||||
const Allocator& alloc = Allocator() );
|
||||
|
||||
// Constructor (13) with name
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
G4AccUnorderedMap(const G4String& name,
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
std::size_t bucket_count = 0,
|
||||
const Hash& hash = Hash(),
|
||||
const KeyEqual& equal = KeyEqual(),
|
||||
const Allocator& alloc = Allocator() );
|
||||
|
||||
// Copy constructor
|
||||
G4AccUnorderedMap(const G4AccUnorderedMap& rhs) = default;
|
||||
G4AccUnorderedMap(const G4AccUnorderedMap& rhs, const Allocator& allocator);
|
||||
// Move constructor
|
||||
G4AccUnorderedMap(G4AccUnorderedMap&& rhs) = default;
|
||||
G4AccUnorderedMap(G4AccUnorderedMap&& rhs, const Allocator& allocator);
|
||||
|
||||
// Destructor
|
||||
~G4AccUnorderedMap() override = default;
|
||||
|
||||
// std::unordered_map functions, operators
|
||||
// operator []
|
||||
inline T& operator[](const Key& key) { return fUMap[key]; }
|
||||
inline T& operator[](Key&& key) { return fUMap[std::move(key)]; }
|
||||
// at
|
||||
inline T& at(const Key& key) { return fUMap[key]; }
|
||||
inline const T& at(const Key& key ) const { return fUMap[key]; }
|
||||
// size
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::size_type size() const { return fUMap.size(); }
|
||||
// begin, cbegin
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator begin() { return fUMap.begin(); }
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator begin() const { return fUMap.begin(); }
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator cbegin() const { return fUMap.cbegin(); }
|
||||
// end, cend
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator end() { return fUMap.end(); }
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator end() const { return fUMap.end(); }
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator cend() const { return fUMap.cend(); }
|
||||
// clear
|
||||
inline void clear() { fUMap.clear(); }
|
||||
// insert
|
||||
inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert(const T& value) { return fUMap.insert(value); }
|
||||
template< class P >
|
||||
inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert( P&& value ) { return fUMap.insert(std::move(value)); }
|
||||
inline std::pair<typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator, bool> insert( T&& value ) { return fUMap.insert(std::move(value)); }
|
||||
// find
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::iterator find( const Key& key ) { return fUMap.find(key); }
|
||||
inline typename std::unordered_map<Key, T, Hash, KeyEqual, Allocator>::const_iterator find( const Key& key ) const { return fUMap.find(key); }
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const final;
|
||||
void SetMergeMode(G4MergeMode value) final;
|
||||
void SetInitValue(const T& value);
|
||||
|
||||
// Get methods
|
||||
G4AccType GetType() const final { return G4AccType::kUnorderedMap; }
|
||||
std::unordered_map<Key, T, Hash, KeyEqual, Allocator>& GetUnorderedMap() { return fUMap; }
|
||||
const std::unordered_map<Key, T, Hash, KeyEqual, Allocator>& GetUnorderedMap() const { return fUMap; }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::unordered_map<Key, T, Hash, KeyEqual, Allocator> fUMap;
|
||||
T fInitValue = 0;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4AccUnorderedMap.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,315 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 19/07/2024
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
// Default constructor (1)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor1" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
std::size_t bucket_count,
|
||||
G4MergeMode mergeMode,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fUMap(bucket_count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor2" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
G4MergeMode mergeMode,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(bucket_count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor2n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
std::size_t bucket_count,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fUMap(bucket_count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor3" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(bucket_count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor3n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (4)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fUMap(bucket_count, hash, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor4" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (4) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(bucket_count, hash, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor4n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (5)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fUMap(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor5" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (5) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor5n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (13)
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode,
|
||||
std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const KeyEqual& equal,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fUMap(init, bucket_count, hash, equal, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor13" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (13) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4String& name,
|
||||
std::initializer_list<std::pair<const Key,T>> init,
|
||||
G4MergeMode mergeMode,
|
||||
std::size_t bucket_count,
|
||||
const Hash& hash,
|
||||
const KeyEqual& equal,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fUMap(init, bucket_count, hash, equal, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccUnorderedMap ctor13n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
const G4AccUnorderedMap& rhs,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(rhs),
|
||||
fUMap(rhs, allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
// Move ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::G4AccUnorderedMap(
|
||||
G4AccUnorderedMap&& rhs,
|
||||
const Allocator& allocator)
|
||||
: G4VAccumulable(std::move(rhs)),
|
||||
fUMap(std::move(rhs), allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
const auto& otherMap = static_cast<const G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>&>(other);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << "G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Merge: " << G4endl;
|
||||
G4cout << "destination: ";
|
||||
for (const auto& [key, v] : fUMap) {
|
||||
G4cout << "[ " << key << ", " << v << " ], ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << "merged data: ";
|
||||
for (const auto& [key, v] : otherMap.fUMap) {
|
||||
G4cout << "[ " << key << ", " << v << " ], ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
for (const auto& [key, value] : otherMap.fUMap) {
|
||||
if ( fUMap.find(key) == fUMap.end()) {
|
||||
(fUMap)[key] = value;
|
||||
}
|
||||
else {
|
||||
(fUMap)[key] = fMergeFunction((fUMap)[key], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Reset()
|
||||
{
|
||||
for (auto& [key, value] : fUMap) {
|
||||
fUMap[key] = fInitValue;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::Print(
|
||||
G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kType)) {
|
||||
G4cout << "unordered_map<" << typeid(Key).name() << ", " << typeid(T).name() << ">: ";
|
||||
}
|
||||
|
||||
PrintBase(options);
|
||||
|
||||
bool first = true;
|
||||
for (const auto& [key, value] : fUMap) {
|
||||
if (! first) { G4cout << ", "; }
|
||||
G4cout << "[ " << key << ", " << value << "] ";
|
||||
first = false;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
G4VAccumulable::SetMergeMode(value);
|
||||
fMergeFunction = GetMergeFunction<T>(fMergeMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
void G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>::SetInitValue(const T& value)
|
||||
{
|
||||
fInitValue = value;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulable values handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
|
||||
|
||||
#ifndef G4AccValue_h
|
||||
#define G4AccValue_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
template <typename T>
|
||||
class G4AccValue : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
G4AccValue(const G4String& name, T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4AccValue(T initValue = 0,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4AccValue(const G4AccValue& rhs);
|
||||
G4AccValue(G4AccValue&& rhs) noexcept;
|
||||
~G4AccValue() override = default;
|
||||
|
||||
// Operators
|
||||
G4AccValue<T>& operator= (const G4AccValue<T>& rhs);
|
||||
G4AccValue<T>& operator=(G4AccValue<T>&& rhs) noexcept;
|
||||
G4AccValue<T>& operator+=(const G4AccValue<T>& rhs);
|
||||
G4AccValue<T>& operator*=(const G4AccValue<T>& rhs);
|
||||
G4AccValue<T> operator++(int); // postfix increment
|
||||
G4AccValue<T>& operator++(); // prefix increment
|
||||
|
||||
G4AccValue<T>& operator= (const T& rhs);
|
||||
G4AccValue<T>& operator+=(const T& rhs);
|
||||
G4AccValue<T>& operator*=(const T& rhs);
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
using G4VAccumulable::Print;
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const final;
|
||||
|
||||
// using G4VAccumulable::SetMergeMode;
|
||||
void SetMergeMode(G4MergeMode value) final;
|
||||
|
||||
G4AccType GetType() const final { return G4AccType::kValue; }
|
||||
|
||||
// Get methods
|
||||
T GetValue() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
T fValue = 0;
|
||||
T fInitValue = 0;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4AccValue.icc"
|
||||
|
||||
#endif
|
||||
+67
-42
@@ -24,9 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
//
|
||||
// utilities
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
|
||||
|
||||
//
|
||||
// public functions
|
||||
@@ -36,51 +34,50 @@ using namespace G4Accumulables;
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4String& name, T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name),
|
||||
G4AccValue<T>::G4AccValue(
|
||||
const G4String& name, T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fValue(initValue),
|
||||
fInitValue(initValue),
|
||||
fMergeMode(mergeMode),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(T initValue, G4MergeMode mergeMode)
|
||||
G4AccValue<T>::G4AccValue(T initValue, G4MergeMode mergeMode)
|
||||
: G4VAccumulable(),
|
||||
fValue(initValue),
|
||||
fInitValue(initValue),
|
||||
fMergeMode(mergeMode),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(const G4Accumulable& rhs)
|
||||
G4AccValue<T>::G4AccValue(const G4AccValue& rhs)
|
||||
: G4VAccumulable(rhs),
|
||||
fValue(rhs.fValue),
|
||||
fInitValue(rhs.fInitValue),
|
||||
fMergeMode(rhs.fMergeMode),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>::G4Accumulable(G4Accumulable&& rhs) noexcept
|
||||
: G4VAccumulable(rhs),
|
||||
G4AccValue<T>::G4AccValue(G4AccValue&& rhs) noexcept
|
||||
: G4VAccumulable(std::move(rhs)),
|
||||
fValue(std::move(rhs.fValue)),
|
||||
fInitValue(std::move(rhs.fInitValue)),
|
||||
fMergeMode(rhs.fMergeMode),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator=(const G4AccValue<T>& rhs)
|
||||
{
|
||||
// check assignment to self
|
||||
if (this == &rhs) return *this;
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// base class assignment
|
||||
G4VAccumulable::operator=(rhs);
|
||||
@@ -88,7 +85,6 @@ G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
// this class data assignment
|
||||
fValue = rhs.fValue;
|
||||
fInitValue = rhs.fInitValue;
|
||||
fMergeMode = rhs.fMergeMode;
|
||||
fMergeFunction = rhs.fMergeFunction;
|
||||
|
||||
return *this;
|
||||
@@ -96,10 +92,12 @@ G4Accumulable<T>::operator=(const G4Accumulable<T>& rhs)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>& G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs) noexcept
|
||||
G4AccValue<T>& G4AccValue<T>::operator=(G4AccValue<T>&& rhs) noexcept
|
||||
{
|
||||
// check assignment to self
|
||||
if (this == &rhs) return *this;
|
||||
if (this == &rhs) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// base class assignment
|
||||
G4VAccumulable::operator=(rhs);
|
||||
@@ -107,7 +105,6 @@ G4Accumulable<T>& G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs) noexcept
|
||||
// this class data assignment
|
||||
fValue = std::move(rhs.fValue);
|
||||
fInitValue = std::move(rhs.fInitValue);
|
||||
fMergeMode = rhs.fMergeMode;
|
||||
fMergeFunction = rhs.fMergeFunction;
|
||||
|
||||
return *this;
|
||||
@@ -115,8 +112,8 @@ G4Accumulable<T>& G4Accumulable<T>::operator=(G4Accumulable<T>&& rhs) noexcept
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator+=(const G4AccValue<T>& rhs)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue += rhs.fValue;
|
||||
@@ -125,8 +122,8 @@ G4Accumulable<T>::operator+=(const G4Accumulable<T>& rhs)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator*=(const G4AccValue<T>& rhs)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue *= rhs.fValue;
|
||||
@@ -135,8 +132,8 @@ G4Accumulable<T>::operator*=(const G4Accumulable<T>& rhs)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator=(const T& value)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator=(const T& value)
|
||||
{
|
||||
// only update the value
|
||||
fValue = value;
|
||||
@@ -145,8 +142,8 @@ G4Accumulable<T>::operator=(const T& value)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator+=(const T& value)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator+=(const T& value)
|
||||
{
|
||||
// only update the value
|
||||
fValue += value;
|
||||
@@ -155,8 +152,8 @@ G4Accumulable<T>::operator+=(const T& value)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator*=(const T& value)
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator*=(const T& value)
|
||||
{
|
||||
// only update the value from rhs
|
||||
fValue *= value;
|
||||
@@ -165,19 +162,19 @@ G4Accumulable<T>::operator*=(const T& value)
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>
|
||||
G4Accumulable<T>::operator++(int)
|
||||
G4AccValue<T>
|
||||
G4AccValue<T>::operator++(int)
|
||||
{
|
||||
// postfix increment
|
||||
G4Accumulable<T> temp = *this;
|
||||
G4AccValue<T> temp = *this;
|
||||
fValue++;
|
||||
return temp;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>&
|
||||
G4Accumulable<T>::operator++()
|
||||
G4AccValue<T>&
|
||||
G4AccValue<T>::operator++()
|
||||
{
|
||||
// prefix increment
|
||||
fValue++;
|
||||
@@ -186,24 +183,52 @@ G4Accumulable<T>::operator++()
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Merge(const G4VAccumulable& other)
|
||||
void G4AccValue<T>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
// G4cout << "Merging other: " << other.GetName() << " " << static_cast<const G4Accumulable<T>&>(other).fValue << G4endl;
|
||||
// G4cout << " to master: " << fName << " " << fValue << G4endl;
|
||||
fValue = fMergeFunction(fValue, static_cast<const G4Accumulable<T>&>(other).fValue);
|
||||
// G4cout << " new value: " << fName << " " << fValue << G4endl;
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << "Merging other: " << other.GetName() << " "
|
||||
<< static_cast<const G4AccValue<T>&>(other).fValue << G4endl;
|
||||
G4cout << " to master: " << fName << " " << fValue << G4endl;
|
||||
}
|
||||
|
||||
fValue = fMergeFunction(fValue, static_cast<const G4AccValue<T>&>(other).fValue);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << " new value: " << fName << " " << fValue << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
void G4Accumulable<T>::Reset()
|
||||
void G4AccValue<T>::Reset()
|
||||
{
|
||||
fValue = fInitValue;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T G4Accumulable<T>::GetValue() const
|
||||
void G4AccValue<T>::Print(G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kType)) {
|
||||
G4cout << typeid(T).name() << ": ";
|
||||
}
|
||||
|
||||
PrintBase(options);
|
||||
|
||||
G4cout << fValue << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T>
|
||||
void G4AccValue<T>::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
G4VAccumulable::SetMergeMode(value);
|
||||
fMergeFunction = GetMergeFunction<T>(fMergeMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
T G4AccValue<T>::GetValue() const
|
||||
{
|
||||
return fValue;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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. *
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulable vectors handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 12/07/2024
|
||||
|
||||
#ifndef G4AccVector_h
|
||||
#define G4AccVector_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
// using vector_std::size_t = std::vector::std::size_t;
|
||||
|
||||
template <class T, class Allocator = std::allocator<T>>
|
||||
class G4AccVector : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
// ctors to be supported
|
||||
// (https://en.cppreference.com/w/cpp/container/vector/vector)
|
||||
// 1) Default constructor. Constructs an empty container with a default-constructed allocator.
|
||||
// vector() noexcept(noexcept(Allocator()));
|
||||
// 3) Constructs the container with count copies of elements with value value.
|
||||
// vector( std::size_t count,
|
||||
// const T& value,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
// 4) Constructs the container with count default-inserted instances of T. No copies are made.
|
||||
// vector( std::size_t count,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
// 6) Copy constructor. Constructs the container with the copy of the contents of other.
|
||||
// vector( const vector& other );
|
||||
// 8) Move constructor. Constructs the container with the contents of other using move semantics.
|
||||
// vector( vector&& other );
|
||||
// 10) Constructs the container with the contents of the initializer list init.
|
||||
// vector( std::initializer_list<T> init,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
|
||||
// Default constructor (1)
|
||||
// Constructs an empty container with a default-constructed allocator.
|
||||
G4AccVector(const G4String& name = "",
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (2)
|
||||
// Constructs an empty container with the given allocator alloc.
|
||||
G4AccVector(const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (2) with name
|
||||
// Constructs an empty container with the given allocator alloc.
|
||||
G4AccVector(const G4String& name,
|
||||
const Allocator& alloc,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Constructor (3)
|
||||
// Constructs the container with count copies of elements with value value
|
||||
// with a default-constructed allocator.
|
||||
// G4AccVector(std::size_t count, const T& value,
|
||||
// const Allocator& alloc = Allocator());
|
||||
G4AccVector(std::size_t count, const T& value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
|
||||
// Constructor (3) with name
|
||||
// Constructs the container with count copies of elements with value value
|
||||
// with a default-constructed allocator.
|
||||
// G4AccVector(std::size_t count, const T& value,
|
||||
// const Allocator& alloc = Allocator());
|
||||
G4AccVector(const G4String& name,
|
||||
std::size_t count, const T& value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
// Constructor (4)
|
||||
// Constructs the container with count default-inserted instances of T.
|
||||
// No copies are made.
|
||||
// G4AccVector(std::size_t count,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
G4AccVector(std::size_t count,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
|
||||
// Constructor (4) with name
|
||||
// Constructs the container with count default-inserted instances of T.
|
||||
// No copies are made.
|
||||
// G4AccVector(std::size_t count,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
G4AccVector(const G4String& name,
|
||||
std::size_t count,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
|
||||
// Constructor (10)
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
// G4AccVector(std::initializer_list<T> init,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
G4AccVector(std::initializer_list<T> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
|
||||
// Constructor (10) with name
|
||||
// Constructs the container with the contents of the initializer list init.
|
||||
// G4AccVector(std::initializer_list<T> init,
|
||||
// const Allocator& alloc = Allocator() );
|
||||
G4AccVector(const G4String& name,
|
||||
std::initializer_list<T> init,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition,
|
||||
const Allocator& allocator = Allocator());
|
||||
|
||||
// Copy constructor
|
||||
G4AccVector(const G4AccVector& rhs) = default;
|
||||
G4AccVector(const G4AccVector& rhs, const Allocator& allocator);
|
||||
// Move constructor
|
||||
G4AccVector(G4AccVector&& rhs) = default;
|
||||
G4AccVector(G4AccVector&& rhs, const Allocator& allocator);
|
||||
|
||||
// Destructor
|
||||
~G4AccVector() override = default;
|
||||
|
||||
// std::vector functions, operators
|
||||
// operator []
|
||||
inline T& operator[](typename std::vector<T>::size_type i) { return fVector[i]; }
|
||||
// at
|
||||
inline T& at(typename std::vector<T>::size_type i) { return fVector.at(i); }
|
||||
// size
|
||||
inline typename std::vector<T>::size_type size() const { return fVector.size(); }
|
||||
// begin, cbegin
|
||||
inline typename std::vector<T>::iterator begin() { return fVector.begin(); }
|
||||
inline typename std::vector<T>::const_iterator begin() const { return fVector.begin(); }
|
||||
inline typename std::vector<T>::const_iterator cbegin() const { return fVector.cbegin(); }
|
||||
// end, cend
|
||||
inline typename std::vector<T>::iterator end() { return fVector.end(); }
|
||||
inline typename std::vector<T>::const_iterator end() const { return fVector.end(); }
|
||||
inline typename std::vector<T>::const_iterator cend() const { return fVector.cend(); }
|
||||
// clear
|
||||
inline void clear() { fVector.clear(); }
|
||||
// push_back
|
||||
inline void push_back(const T& value) { fVector.push_back(value); }
|
||||
inline void push_back(T&& value ) { fVector.push_back(std::move(value)); }
|
||||
// emplace_back
|
||||
template< class... Args >
|
||||
inline void emplace_back(Args&&... args ) { fVector.emplace_back(args...); }
|
||||
template< class... Args >
|
||||
inline T& emplace_back(Args&&... args ) { return fVector.emplace_back(args...); }
|
||||
// pop_back
|
||||
inline void pop_back() { fVector.pop_back(); }
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const final;
|
||||
void SetMergeMode(G4MergeMode value) final;
|
||||
|
||||
// Get methods
|
||||
G4AccType GetType() const final { return G4AccType::kVector; }
|
||||
std::vector<T>& GetVector();
|
||||
const std::vector<T>& GetVector() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::vector<T> fVector {};
|
||||
T fInitValue = 0;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4AccVector.icc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,254 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * 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, 12/07/2024
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
// Default constructor (1)
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4String& name,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fVector(),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor1" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2)
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fVector(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor2" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (2) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4String& name,
|
||||
const Allocator& allocator,
|
||||
G4MergeMode mergeMode)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fVector(allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor2n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3)
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
std::size_t count, const T& value,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fVector(count, value, allocator),
|
||||
fInitValue(value),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor3" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (3) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4String& name,
|
||||
std::size_t count, const T& value,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fVector(count, value, allocator),
|
||||
fInitValue(value),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor3n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (4)
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
std::size_t count,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fVector(count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor4" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (4) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4String& name,
|
||||
std::size_t count,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fVector(count, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor4n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (10)
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
std::initializer_list<T> init,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(mergeMode),
|
||||
fVector(init, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor10" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Constructor (10) with name
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4String& name,
|
||||
std::initializer_list<T> init,
|
||||
G4MergeMode mergeMode, const Allocator& allocator)
|
||||
: G4VAccumulable(name, mergeMode),
|
||||
fVector(init, allocator),
|
||||
fMergeFunction(GetMergeFunction<T>(mergeMode))
|
||||
{
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "G4AccVector ctor10n" << G4endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Copy ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
const G4AccVector& rhs, const Allocator& allocator)
|
||||
: G4VAccumulable(rhs),
|
||||
fVector(rhs, allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
// Move ctor
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
G4AccVector<T, Allocator>::G4AccVector(
|
||||
G4AccVector&& rhs, const Allocator& allocator)
|
||||
: G4VAccumulable(std::move(rhs)),
|
||||
fVector(std::move(rhs), allocator),
|
||||
fMergeFunction(rhs.fMergeFunction)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
void G4AccVector<T, Allocator>::Merge(const G4VAccumulable& other)
|
||||
{
|
||||
const auto& otherVector = static_cast<const G4AccVector<T, Allocator>&>(other);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 2 ) {
|
||||
G4cout << "G4AccVector<T, Allocator>::Merge: " << G4endl;
|
||||
G4cout << "destination: ";
|
||||
for (const auto& v : fVector) {
|
||||
G4cout << v << ", ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
G4cout << "merged data: ";
|
||||
for (const auto& v : otherVector.fVector) {
|
||||
G4cout << v << ", ";
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
std::transform(fVector.begin(), fVector.end(), otherVector.fVector.begin(),
|
||||
fVector.begin(), fMergeFunction);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
void G4AccVector<T, Allocator>::Reset()
|
||||
{
|
||||
for (auto& value : fVector) {
|
||||
value = fInitValue;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
void G4AccVector<T, Allocator>::Print(G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kType)) {
|
||||
G4cout << "vector<" << typeid(T).name() << ">: ";
|
||||
}
|
||||
|
||||
PrintBase(options);
|
||||
|
||||
bool first = true;
|
||||
for (const auto& value : fVector) {
|
||||
if (! first) { G4cout << ", "; }
|
||||
G4cout << value;
|
||||
first = false;
|
||||
}
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <class T, class Allocator>
|
||||
void G4AccVector<T, Allocator>::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
G4VAccumulable::SetMergeMode(value);
|
||||
fMergeFunction = GetMergeFunction<T>(fMergeMode);
|
||||
}
|
||||
@@ -24,60 +24,14 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Class template for accumulables handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 06/08/2024
|
||||
|
||||
#ifndef G4Accumulable_h
|
||||
#define G4Accumulable_h 1
|
||||
|
||||
#include "G4VAccumulable.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
#include "G4AccValue.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
template <typename T>
|
||||
class G4Accumulable : public G4VAccumulable
|
||||
{
|
||||
public:
|
||||
G4Accumulable(const G4String& name, T initValue,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(T initValue = 0,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4Accumulable(const G4Accumulable& rhs);
|
||||
G4Accumulable(G4Accumulable&& rhs) noexcept;
|
||||
~G4Accumulable() override = default;
|
||||
|
||||
// Operators
|
||||
G4Accumulable<T>& operator= (const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator=(G4Accumulable<T>&& rhs) noexcept;
|
||||
G4Accumulable<T>& operator+=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T>& operator*=(const G4Accumulable<T>& rhs);
|
||||
G4Accumulable<T> operator++(int); // postfix increment
|
||||
G4Accumulable<T>& operator++(); // prefix increment
|
||||
|
||||
G4Accumulable<T>& operator= (const T& rhs);
|
||||
G4Accumulable<T>& operator+=(const T& rhs);
|
||||
G4Accumulable<T>& operator*=(const T& rhs);
|
||||
|
||||
// Methods
|
||||
void Merge(const G4VAccumulable& other) final;
|
||||
void Reset() final;
|
||||
|
||||
// Get methods
|
||||
T GetValue() const;
|
||||
G4MergeMode GetMergeMode() const;
|
||||
|
||||
private:
|
||||
// Data members
|
||||
T fValue;
|
||||
T fInitValue;
|
||||
G4MergeMode fMergeMode;
|
||||
G4MergeFunction<T> fMergeFunction;
|
||||
};
|
||||
|
||||
// inline functions
|
||||
|
||||
#include "G4Accumulable.icc"
|
||||
template<typename T>
|
||||
using G4Accumulable = G4AccValue<T>;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -26,22 +26,30 @@
|
||||
|
||||
// The common implementation of analysis manager classes.
|
||||
|
||||
// Author: Ivana Hrivnacova, 07/09/2015 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
|
||||
|
||||
#ifndef G4AccumulableManager_h
|
||||
#define G4AccumulableManager_h 1
|
||||
|
||||
#include "G4Accumulable.hh"
|
||||
#include "G4AccValue.hh"
|
||||
#include "G4AccType.hh"
|
||||
#include "globals.hh"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
class G4AccumulableManager;
|
||||
class G4AnalysisManagerState;
|
||||
class G4VAccumulable;
|
||||
template <class T>
|
||||
class G4ThreadLocalSingleton;
|
||||
template <class T, std::size_t N>
|
||||
class G4AccArray;
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
class G4AccMap;
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
class G4AccUnorderedMap;
|
||||
template <class T, class Allocator>
|
||||
class G4AccVector;
|
||||
|
||||
class G4AccumulableManager
|
||||
{
|
||||
@@ -58,38 +66,124 @@ class G4AccumulableManager
|
||||
// Create accumulables
|
||||
//
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccValue<T>*
|
||||
CreateAccValue(const G4String& name, T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
template <typename T>
|
||||
G4AccValue<T>*
|
||||
CreateAccValue(T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Deprecated function using the old accumulable value name
|
||||
//
|
||||
|
||||
template <typename T>
|
||||
[[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
|
||||
G4AccValue<T>*
|
||||
CreateAccumulable(const G4String& name, T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
[[deprecated("Use `G4AccumulableManager::CreateAccValue<T>` instead")]]
|
||||
G4AccValue<T>*
|
||||
CreateAccumulable(T value,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
|
||||
// Register existing accumulables
|
||||
//
|
||||
// templated accumulable
|
||||
template <typename T>
|
||||
G4bool RegisterAccumulable(G4Accumulable<T>& accumulable);
|
||||
G4bool Register(G4AccValue<T>& accumulable);
|
||||
|
||||
template <class T, std::size_t N>
|
||||
G4bool Register(G4AccArray<T, N>& accumulableArray);
|
||||
|
||||
template <class Key, class T, class Compare, class Allocator>
|
||||
G4bool Register(G4AccMap<Key, T, Compare, Allocator>& accumulableMap);
|
||||
|
||||
template <class Key, class T, class Hash, class KeyEqual, class Allocator>
|
||||
G4bool Register(G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>& accumulableUnorderedMap);
|
||||
|
||||
template <class T, class Allocator>
|
||||
G4bool Register(G4AccVector<T, Allocator>& accumulableVector);
|
||||
|
||||
// user defined accumulable
|
||||
G4bool Register(G4VAccumulable* accumulable);
|
||||
|
||||
// Deprecated functions with long name
|
||||
//
|
||||
template <typename T>
|
||||
[[deprecated("Use `G4AccumulableManager::Register` instead")]]
|
||||
G4bool RegisterAccumulable(G4AccValue<T>& accumulable);
|
||||
// user defined accumulable
|
||||
[[deprecated("Use `G4AccumulableManager::Register` instead")]]
|
||||
G4bool RegisterAccumulable(G4VAccumulable* accumulable);
|
||||
|
||||
// Access registered accumulables
|
||||
//
|
||||
// Via name
|
||||
// templated accumulable
|
||||
//
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
G4AccValue<T>* GetAccValue(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
template <class T, std::size_t N>
|
||||
G4AccArray<T, N>*
|
||||
GetAccArray(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
template <class Key, class T, class Compare = std::less<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccMap<Key, T, Compare, Allocator>*
|
||||
GetAccMap(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
||||
GetAccUnorderedMap(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
template <class T, class Allocator = std::allocator<T>>
|
||||
G4AccVector<T, Allocator>*
|
||||
GetAccVector(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
|
||||
// Deprecated function using the old accumulable value name
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
[[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
|
||||
G4AccValue<T>* GetAccumulable(const G4String& name, G4bool warn = true) const;
|
||||
|
||||
// Via id (in the order of registering)
|
||||
// templated accumulable
|
||||
//
|
||||
template <typename T>
|
||||
G4AccValue<T>* GetAccValue(G4int id, G4bool warn = true) const;
|
||||
|
||||
template <class T, std::size_t N>
|
||||
G4AccArray<T, N>* GetAccArray(G4int id, G4bool warn = true) const;
|
||||
|
||||
template <class Key, class T, class Compare = std::less<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccMap<Key, T, Compare, Allocator>*
|
||||
GetAccMap(G4int id, G4bool warn = true) const;
|
||||
|
||||
template <class Key, class T, class Hash = std::hash<Key>, class KeyEqual = std::equal_to<Key>,
|
||||
class Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
||||
GetAccUnorderedMap(G4int id, G4bool warn = true) const;
|
||||
|
||||
template <class T, class Allocator = std::allocator<T>>
|
||||
G4AccVector<T, Allocator>*
|
||||
GetAccVector(G4int id, G4bool warn = true) const;
|
||||
|
||||
// user defined accumulable
|
||||
G4VAccumulable* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
|
||||
// Deprecated function using the old accumulable value name
|
||||
template <typename T>
|
||||
[[deprecated("Use `G4AccumulableManager::GetAccValue<T>` instead")]]
|
||||
G4AccValue<T>* GetAccumulable(G4int id, G4bool warn = true) const;
|
||||
|
||||
G4int GetNofAccumulables() const;
|
||||
|
||||
// Via vector iterators
|
||||
@@ -101,6 +195,20 @@ class G4AccumulableManager
|
||||
// Methods applied to all accumulables
|
||||
void Merge();
|
||||
void Reset();
|
||||
void Print(G4PrintOptions options = G4PrintOptions()) const;
|
||||
|
||||
// Print a selected range
|
||||
void Print(G4int startId, G4int count,
|
||||
G4PrintOptions options = G4PrintOptions()) const;
|
||||
void Print(std::vector<G4VAccumulable*>::iterator startIt, std::size_t count,
|
||||
G4PrintOptions options = G4PrintOptions()) const;
|
||||
void Print(std::vector<G4VAccumulable*>::iterator startIt,
|
||||
std::vector<G4VAccumulable*>::iterator endIt,
|
||||
G4PrintOptions options = G4PrintOptions()) const;
|
||||
|
||||
// Verbose level
|
||||
void SetVerboseLevel(G4int value);
|
||||
G4int GetVerboseLevel() const;
|
||||
|
||||
private:
|
||||
// Hide singleton ctor
|
||||
@@ -111,9 +219,27 @@ class G4AccumulableManager
|
||||
G4String GenerateName() const;
|
||||
// Check if a name is already used in a map and print a warning
|
||||
G4bool CheckName(const G4String& name, const G4String& where) const;
|
||||
G4bool CheckType(G4VAccumulable* accumulable, G4AccType type, G4bool warn) const;
|
||||
|
||||
template <typename T>
|
||||
G4Accumulable<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
G4AccValue<T>* GetAccumulable(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
G4AccArray<T, N>* GetAccArray(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
template <typename Key, typename T, typename Compare = std::less<Key>,
|
||||
typename Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccMap<Key, T, Compare, Allocator>*
|
||||
GetAccMap(G4VAccumulable* accumulable, G4bool warn = true) const;
|
||||
|
||||
template <typename Key, typename T, typename Hash = std::hash<Key>, typename KeyEqual = std::equal_to<Key>,
|
||||
typename Allocator = std::allocator<std::pair<const Key, T>>>
|
||||
G4AccUnorderedMap<Key, T, Hash, KeyEqual, Allocator>*
|
||||
GetAccUnorderedMap(G4VAccumulable* accumulable, G4bool warn = true) const;
|
||||
|
||||
template <typename T, typename Allocator = std::allocator<T>>
|
||||
G4AccVector<T, Allocator>*
|
||||
GetAccVector(G4VAccumulable* accumulable, G4bool warn) const;
|
||||
|
||||
// Constants
|
||||
const G4String kBaseName = "accumulable";
|
||||
|
||||
@@ -24,42 +24,119 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 07/09/2015
|
||||
|
||||
#include "G4AccArray.hh"
|
||||
#include "G4AccMap.hh"
|
||||
#include "G4AccUnorderedMap.hh"
|
||||
#include "G4AccVector.hh"
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<T>*
|
||||
G4AccValue<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);
|
||||
if (accumulable == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return taccumulable;
|
||||
// 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>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::CreateAccumulable(
|
||||
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;
|
||||
if (!CheckName(name, "CreateAccumulable")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// create accumulable
|
||||
auto accumulable = new G4Accumulable<T>(name, value, mergeMode);
|
||||
auto accumulable = new G4AccValue<T>(name, value, mergeMode);
|
||||
|
||||
// register accumulable in the map and vector
|
||||
RegisterAccumulable(accumulable);
|
||||
Register(accumulable);
|
||||
fAccumulablesToDelete.push_back(accumulable);
|
||||
|
||||
return accumulable;
|
||||
@@ -67,40 +144,196 @@ G4AccumulableManager::CreateAccumulable(
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4Accumulable<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 CreateAccumulable(G4String(), value, mergeMode);
|
||||
return CreateAccValue<T>(value, mergeMode);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
template <typename T>
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4Accumulable<T>& accumulable)
|
||||
G4bool G4AccumulableManager::Register(G4AccValue<T>& accumulable)
|
||||
{
|
||||
return RegisterAccumulable(&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>
|
||||
G4Accumulable<T>*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
G4AccValue<T>*
|
||||
G4AccumulableManager::GetAccValue(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
// get G4VAccummulable 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
|
||||
template <class T, std::size_t N>
|
||||
G4AccArray<T, N>*
|
||||
G4AccumulableManager::GetAccArray(const G4String& name, G4bool warn) const
|
||||
{
|
||||
// get G4VParammeter from the map
|
||||
// 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
|
||||
{
|
||||
@@ -132,3 +365,15 @@ G4AccumulableManager::EndConst() const
|
||||
{
|
||||
return fVector.end();
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4AccumulableManager::SetVerboseLevel(G4int value)
|
||||
{
|
||||
G4Accumulables::VerboseLevel = value;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4int G4AccumulableManager::GetVerboseLevel() const
|
||||
{
|
||||
return G4Accumulables::VerboseLevel;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 04/07/2012
|
||||
|
||||
#ifndef G4MergeMode_h
|
||||
#define G4MergeMode_h 1
|
||||
@@ -58,18 +58,15 @@ G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode)
|
||||
{
|
||||
switch ( mergeMode ) {
|
||||
case G4MergeMode::kAddition:
|
||||
// return std::bind([](const T& x, const T& y) { return x + y; });
|
||||
return [](const T& x, const T& y) { return x + y; };
|
||||
return std::plus<T>();
|
||||
|
||||
case G4MergeMode::kMultiplication:
|
||||
return [](const T& x, const T& y) { return x * y; };
|
||||
return std::multiplies<T>();
|
||||
|
||||
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); };
|
||||
|
||||
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); };
|
||||
}
|
||||
|
||||
|
||||
@@ -26,21 +26,22 @@
|
||||
|
||||
// Value type independent base class for accumulables handled by Geant4 analysis
|
||||
//
|
||||
// Author: Ivana Hrivnacova, 04/09/2015 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 04/09/2015
|
||||
|
||||
#ifndef G4VAccumulable_h
|
||||
#define G4VAccumulable_h 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include "G4AccType.hh"
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
#include "globals.hh"
|
||||
|
||||
class G4VAccumulable
|
||||
{
|
||||
// To allow G4AccumulableManager set name if not defined by user
|
||||
friend class G4AccumulableManager;
|
||||
|
||||
public:
|
||||
G4VAccumulable(G4String name = "");
|
||||
G4VAccumulable(G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4VAccumulable(const G4String& name,
|
||||
G4MergeMode mergeMode = G4MergeMode::kAddition);
|
||||
G4VAccumulable(const G4VAccumulable& rhs) = default;
|
||||
G4VAccumulable(G4VAccumulable&& rhs) = default;
|
||||
virtual ~G4VAccumulable() = default;
|
||||
@@ -52,12 +53,26 @@ class G4VAccumulable
|
||||
// Methods
|
||||
virtual void Merge(const G4VAccumulable& other) = 0;
|
||||
virtual void Reset() = 0;
|
||||
virtual void Print(G4PrintOptions options = G4PrintOptions()) const;
|
||||
virtual void SetMergeMode(G4MergeMode value);
|
||||
|
||||
// Set methods
|
||||
void SetName(const G4String& name);
|
||||
void SetId(G4int id);
|
||||
|
||||
// Get methods
|
||||
G4String GetName() const;
|
||||
G4MergeMode GetMergeMode() const;
|
||||
G4int GetId() const;
|
||||
|
||||
virtual G4AccType GetType() const { return G4AccType::kUser; }
|
||||
|
||||
protected:
|
||||
void PrintBase(G4PrintOptions options) const;
|
||||
|
||||
G4String fName;
|
||||
G4MergeMode fMergeMode = G4MergeMode::kAddition;
|
||||
G4int fId = G4Accumulables::kInvalidId;
|
||||
};
|
||||
|
||||
#include "G4VAccumulable.icc"
|
||||
|
||||
@@ -24,15 +24,92 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 04/09/2015
|
||||
|
||||
#include <utility>
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(G4String name)
|
||||
: fName(std::move(name))
|
||||
inline G4VAccumulable::G4VAccumulable(G4MergeMode mergeMode)
|
||||
: fMergeMode(mergeMode)
|
||||
{}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4VAccumulable::G4VAccumulable(const G4String& name, G4MergeMode mergeMode)
|
||||
: fName(name),
|
||||
fMergeMode(mergeMode)
|
||||
{}
|
||||
|
||||
//
|
||||
// protected methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4VAccumulable::PrintBase(G4PrintOptions options) const
|
||||
{
|
||||
if (options.Has(G4PrintOptions::kName)) {
|
||||
G4cout << "\"" << GetName() << "\", ";
|
||||
}
|
||||
if (options.Has(G4PrintOptions::kId)) {
|
||||
G4cout << "id: " << fId << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4VAccumulable::SetName(const G4String& name)
|
||||
{
|
||||
if ( fId != G4Accumulables::kInvalidId) {
|
||||
G4Exception(
|
||||
"G4VAccumulable::SetName", "Analysis_W001",
|
||||
JustWarning, "Accumulable was already registered. Setting is ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
fName = name;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4VAccumulable::Print(G4PrintOptions options) const
|
||||
{
|
||||
PrintBase(options);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4VAccumulable::SetMergeMode(G4MergeMode value)
|
||||
{
|
||||
fMergeMode = value;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline void G4VAccumulable::SetId(G4int id)
|
||||
{
|
||||
if ( fId != G4Accumulables::kInvalidId) {
|
||||
G4Exception(
|
||||
"G4VAccumulable::SetId", "Analysis_W001",
|
||||
JustWarning, "Accumulable was already registered. Setting is ignored");
|
||||
return;
|
||||
}
|
||||
|
||||
fId = id;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4String G4VAccumulable::GetName() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4MergeMode G4VAccumulable::GetMergeMode() const
|
||||
{
|
||||
return fMergeMode;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
inline G4int G4VAccumulable::GetId() const
|
||||
{
|
||||
return fId;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,20 @@
|
||||
geant4_add_module(G4accumulables
|
||||
PUBLIC_HEADERS
|
||||
G4MergeMode.hh
|
||||
G4Accumulable.hh
|
||||
G4AccumulableManager.hh
|
||||
G4AccumulableManager.icc
|
||||
G4Accumulable.hh
|
||||
G4Accumulable.icc
|
||||
G4AccValue.hh
|
||||
G4AccValue.icc
|
||||
G4AccArray.hh
|
||||
G4AccArray.icc
|
||||
G4AccMap.hh
|
||||
G4AccMap.icc
|
||||
G4AccUnorderedMap.hh
|
||||
G4AccUnorderedMap.icc
|
||||
G4AccVector.hh
|
||||
G4AccVector.icc
|
||||
G4AccType.hh
|
||||
G4VAccumulable.hh
|
||||
G4VAccumulable.icc
|
||||
SOURCES
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 18/06/2013
|
||||
|
||||
#include "G4AccumulableManager.hh"
|
||||
#include "G4ThreadLocalSingleton.hh"
|
||||
@@ -36,6 +36,15 @@
|
||||
namespace {
|
||||
//Mutex to lock master manager when merging accumulables
|
||||
G4Mutex mergeMutex = G4MUTEX_INITIALIZER;
|
||||
|
||||
void RangeException(const G4String& where, const G4String& message)
|
||||
{
|
||||
G4ExceptionDescription description;
|
||||
description << "Invalid range " << message;
|
||||
G4String method("G4AccumulableManager::");
|
||||
method.append(where);
|
||||
G4Exception(where, "Analysis_W001", JustWarning, description);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -48,7 +57,9 @@ G4AccumulableManager* G4AccumulableManager::Instance()
|
||||
//_____________________________________________________________________________
|
||||
G4AccumulableManager::G4AccumulableManager()
|
||||
{
|
||||
if ( ! G4Threading::IsWorkerThread() ) fgMasterInstance = this;
|
||||
if (!G4Threading::IsWorkerThread()) {
|
||||
fgMasterInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -76,9 +87,12 @@ G4String G4AccumulableManager::GenerateName() const
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& where) const
|
||||
G4bool G4AccumulableManager::CheckName(
|
||||
const G4String& name, const G4String& where) const
|
||||
{
|
||||
if ( fMap.find(name) == fMap.end() ) return true;
|
||||
if (fMap.find(name) == fMap.end()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description << "Name " << name << " is already used." << G4endl;
|
||||
@@ -89,29 +103,66 @@ G4bool G4AccumulableManager::CheckName(const G4String& name, const G4String& whe
|
||||
return false;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::CheckType(
|
||||
G4VAccumulable* accumulable, G4AccType type, G4bool warn) const
|
||||
{
|
||||
if (accumulable->GetType() != type) {
|
||||
if (warn) {
|
||||
G4ExceptionDescription description;
|
||||
description << " " << accumulable->GetName() << ": Incompatible type.";
|
||||
G4Exception("G4AccumulableManager::CheckType",
|
||||
"Analysis_W001", JustWarning, description);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// public methods
|
||||
//
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
|
||||
G4bool G4AccumulableManager::Register(G4VAccumulable* accumulable)
|
||||
{
|
||||
auto name = accumulable->GetName();
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 1 ) {
|
||||
G4cout << "Going to register accumulable \"" << name << "\"" << G4endl;
|
||||
}
|
||||
|
||||
// do not accept name if it is already used
|
||||
if ( ! CheckName(name, "RegisterAccumulable") ) return false;
|
||||
if (!CheckName(name, "RegisterAccumulable")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// generate name if empty
|
||||
if (name.length() == 0u) {
|
||||
name = GenerateName();
|
||||
accumulable->fName = name;
|
||||
accumulable->SetName(name);
|
||||
}
|
||||
|
||||
// set Id
|
||||
accumulable->SetId((G4int)fVector.size());
|
||||
|
||||
fMap[name] = accumulable;
|
||||
fVector.push_back(accumulable);
|
||||
|
||||
if (G4Accumulables::VerboseLevel > 0 ) {
|
||||
G4cout << "Accumulable registered as \"" << accumulable->GetName() << "\"" << G4endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Deprecated functions with long name
|
||||
//_____________________________________________________________________________
|
||||
G4bool G4AccumulableManager::RegisterAccumulable(G4VAccumulable* accumulable)
|
||||
{
|
||||
return Register(accumulable);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
G4VAccumulable*
|
||||
G4AccumulableManager::GetAccumulable(const G4String& name, G4bool warn) const
|
||||
@@ -154,7 +205,9 @@ void G4AccumulableManager::Merge()
|
||||
{
|
||||
// Do nothing if there are no accumulables registered
|
||||
// or if master thread
|
||||
if ((fVector.size() == 0u) || (! G4Threading::IsWorkerThread())) return;
|
||||
if ((fVector.size() == 0u) || (!G4Threading::IsWorkerThread())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The manager on mastter must exist
|
||||
if (fgMasterInstance == nullptr) {
|
||||
@@ -186,11 +239,59 @@ void G4AccumulableManager::Merge()
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Reset()
|
||||
{
|
||||
// Reset histograms and profiles
|
||||
// Reset all accummulables
|
||||
|
||||
for ( auto it : fVector ) {
|
||||
it->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Print(G4PrintOptions options) const
|
||||
{
|
||||
for ( auto it : fVector ) {
|
||||
it->Print(options);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Print(
|
||||
G4int startId, G4int count, G4PrintOptions options) const
|
||||
{
|
||||
// check if range is within limits
|
||||
if ( startId < 0 || startId >= G4int(fVector.size()) ||
|
||||
count <= 0 || startId + count > G4int(fVector.size()) ) {
|
||||
RangeException("Print",
|
||||
std::to_string(startId) + ", " + std::to_string(count));
|
||||
return;
|
||||
}
|
||||
|
||||
for ( auto id = startId; id < startId + count; ++id ) {
|
||||
fVector[id]->Print(options);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Print(
|
||||
std::vector<G4VAccumulable*>::iterator startIt,
|
||||
std::vector<G4VAccumulable*>::iterator endIt,
|
||||
G4PrintOptions options) const
|
||||
{
|
||||
// check if range is within limits
|
||||
if ( startIt == fVector.end() || endIt == fVector.end() ) {
|
||||
RangeException("Print", "[startIt, endIt]");
|
||||
return;
|
||||
}
|
||||
|
||||
for ( auto it = startIt; it != endIt; ++it ) {
|
||||
(*it)->Print(options);
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4AccumulableManager::Print(
|
||||
std::vector<G4VAccumulable*>::iterator startIt, std::size_t count,
|
||||
G4PrintOptions options) const
|
||||
{
|
||||
Print(startIt, startIt+count, options);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
|
||||
// Author: Ivana Hrivnacova, 22/08/2013 (ivana@ipno.in2p3.fr)
|
||||
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 22/08/2013
|
||||
|
||||
#include "G4MergeMode.hh"
|
||||
|
||||
@@ -34,8 +34,12 @@ namespace G4Accumulables
|
||||
//_____________________________________________________________________________
|
||||
G4MergeMode GetMergeMode(const G4String& mergeModeName)
|
||||
{
|
||||
if (mergeModeName == "+") return G4MergeMode::kAddition;
|
||||
if (mergeModeName == "*") return G4MergeMode::kMultiplication;
|
||||
if (mergeModeName == "+") {
|
||||
return G4MergeMode::kAddition;
|
||||
}
|
||||
if (mergeModeName == "*") {
|
||||
return G4MergeMode::kMultiplication;
|
||||
}
|
||||
|
||||
G4ExceptionDescription description;
|
||||
description << "\"" << mergeModeName << "\" merge mode is not supported." << G4endl
|
||||
|
||||
@@ -122,7 +122,7 @@ G4bool G4CsvHnFileManager<HT>::Write(
|
||||
G4Analysis::Warn("Failed to get Csv file " + fileName, fkClass, "Write");
|
||||
return false;
|
||||
}
|
||||
fileName = hnFileName;
|
||||
fileName = std::move(hnFileName);
|
||||
}
|
||||
|
||||
return Write(*hnFile, ht);
|
||||
|
||||
@@ -62,7 +62,7 @@ G4CsvAnalysisManager::G4CsvAnalysisManager()
|
||||
// Ntuple file manager
|
||||
fNtupleFileManager = std::make_shared<G4CsvNtupleFileManager>(fState);
|
||||
SetNtupleFileManager(fNtupleFileManager);
|
||||
fNtupleFileManager->SetFileManager(fileManager);
|
||||
fNtupleFileManager->SetFileManager(std::move(fileManager));
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class G4GenericFileManager : public G4VFileManager
|
||||
G4bool OpenFile(const G4String& fileName) final;
|
||||
|
||||
// Methods applied to all registered files
|
||||
virtual G4bool OpenFiles() final;
|
||||
G4bool OpenFiles() final;
|
||||
G4bool WriteFiles() final;
|
||||
G4bool CloseFiles() final;
|
||||
G4bool DeleteEmptyFiles() final;
|
||||
@@ -75,6 +75,7 @@ class G4GenericFileManager : public G4VFileManager
|
||||
|
||||
G4bool SetHistoDirectoryName(const G4String& dirName) override;
|
||||
G4bool SetNtupleDirectoryName(const G4String& dirName) override;
|
||||
void SetCompressionLevel(G4int level) override;
|
||||
|
||||
G4String GetFileType() const final { return ""; }
|
||||
|
||||
|
||||
@@ -390,6 +390,18 @@ G4bool G4GenericFileManager::SetNtupleDirectoryName(const G4String& dirName)
|
||||
return result;
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::SetCompressionLevel(G4int level)
|
||||
{
|
||||
G4BaseFileManager::SetCompressionLevel(level);
|
||||
|
||||
for (auto& fileManager : fFileManagers ) {
|
||||
if ( fileManager != nullptr ) {
|
||||
fileManager->SetCompressionLevel(level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
void G4GenericFileManager::SetDefaultFileType(const G4String& value)
|
||||
{
|
||||
|
||||
@@ -92,7 +92,7 @@ void G4PlotMessenger::SetStyleCmd()
|
||||
"inlib_default";
|
||||
#endif
|
||||
|
||||
fSetStyleCmd = CreateCommand<G4UIcmdWithAString>("setStyle", guidance);
|
||||
fSetStyleCmd = CreateCommand<G4UIcmdWithAString>("setStyle", std::move(guidance));
|
||||
fSetStyleCmd->SetParameterName("Style", false);
|
||||
fSetStyleCmd->SetCandidates("inlib_default");
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ G4bool G4THnToolsManager<kDim1, tools::histo::h1d>::FillHT(
|
||||
tools::histo::h1d* ht, const G4HnInformation& hnInformation,
|
||||
std::array<G4double, kDim1>& value, G4double weight)
|
||||
{
|
||||
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
const auto& xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
|
||||
// Apply hn information to value
|
||||
Update(value[kX], xInfo);
|
||||
|
||||
@@ -90,8 +90,8 @@ G4bool G4THnToolsManager<kDim2, tools::histo::h2d>::FillHT(
|
||||
tools::histo::h2d* ht, const G4HnInformation& hnInformation,
|
||||
std::array<G4double, kDim2>& value, G4double weight)
|
||||
{
|
||||
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
const auto& xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
const auto& yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
|
||||
// Apply hn information to value
|
||||
Update(value[kX], xInfo);
|
||||
|
||||
@@ -99,9 +99,9 @@ G4bool G4THnToolsManager<kDim3, tools::histo::h3d>::FillHT(
|
||||
tools::histo::h3d* ht, const G4HnInformation& hnInformation,
|
||||
std::array<G4double, kDim3>& value, G4double weight)
|
||||
{
|
||||
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
auto zInfo = hnInformation.GetHnDimensionInformation(kZ);
|
||||
const auto& xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
const auto& yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
const auto& zInfo = hnInformation.GetHnDimensionInformation(kZ);
|
||||
|
||||
// Apply hn information to value
|
||||
Update(value[kX], xInfo);
|
||||
|
||||
@@ -107,8 +107,8 @@ G4bool G4THnToolsManager<kDim2, tools::histo::p1d>::FillHT(
|
||||
tools::histo::p1d* ht, const G4HnInformation& hnInformation,
|
||||
std::array<G4double, kDim2>& value, G4double weight)
|
||||
{
|
||||
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
const auto& xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
const auto& yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
|
||||
// Apply hn information to value
|
||||
Update(value[kX], xInfo);
|
||||
|
||||
@@ -117,9 +117,9 @@ G4bool G4THnToolsManager<kDim3, tools::histo::p2d>::FillHT(
|
||||
tools::histo::p2d* ht, const G4HnInformation& hnInformation,
|
||||
std::array<G4double, kDim3>& value, G4double weight)
|
||||
{
|
||||
auto xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
auto yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
auto zInfo = hnInformation.GetHnDimensionInformation(kZ);
|
||||
const auto& xInfo = hnInformation.GetHnDimensionInformation(kX);
|
||||
const auto& yInfo = hnInformation.GetHnDimensionInformation(kY);
|
||||
const auto& zInfo = hnInformation.GetHnDimensionInformation(kZ);
|
||||
|
||||
// Apply hn information to value
|
||||
Update(value[kX], xInfo);
|
||||
|
||||
@@ -43,7 +43,7 @@ class G4BaseFileManager
|
||||
G4BaseFileManager() = delete;
|
||||
virtual ~G4BaseFileManager() = default;
|
||||
|
||||
void SetCompressionLevel(G4int level);
|
||||
virtual void SetCompressionLevel(G4int level);
|
||||
// Set the compression level
|
||||
virtual G4bool SetFileName(const G4String& fileName);
|
||||
// Set the base file name (without extension)
|
||||
|
||||
@@ -54,12 +54,7 @@ struct G4HnDimension
|
||||
}
|
||||
|
||||
G4HnDimension(const std::vector<G4double>& edges)
|
||||
: fNBins(0),
|
||||
fMinValue(0.),
|
||||
fMaxValue(0.),
|
||||
fEdges(edges)
|
||||
{}
|
||||
|
||||
: fEdges(edges) {}
|
||||
G4HnDimension() = default;
|
||||
G4HnDimension(const G4HnDimension& rhs) = default;
|
||||
G4HnDimension& operator=(const G4HnDimension& rhs) = default;
|
||||
|
||||
@@ -359,14 +359,14 @@ G4THnMessenger<DIM, HT>::CreateSetAxisCommand(unsigned int idim)
|
||||
G4String commandName = "set" + axis + "axis";
|
||||
G4String guidance = "Set " + axis + "-axis title for the ";;
|
||||
|
||||
auto command = CreateCommand(commandName, guidance);
|
||||
auto command = CreateCommand(std::move(commandName), guidance);
|
||||
command->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
|
||||
// Add Id parameter
|
||||
AddIdParameter(*command);
|
||||
|
||||
auto parAxis = new G4UIparameter("axis", 's', false);
|
||||
guidance = GetObjectType() + " " + axis + "-axis title";
|
||||
guidance = GetObjectType() + " " + std::move(axis) + "-axis title";
|
||||
parAxis->SetGuidance(guidance.c_str());
|
||||
command->SetParameter(parAxis);
|
||||
|
||||
@@ -497,8 +497,8 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
|
||||
if ( command == fCreateCmd.get() ) {
|
||||
auto counter = 0;
|
||||
auto name = parameters[counter++];
|
||||
auto title = parameters[counter++];
|
||||
const auto& name = parameters[counter++];
|
||||
const auto& title = parameters[counter++];
|
||||
GetData(counter, parameters, bins, info);
|
||||
fManager->Create(name, title, bins, info);
|
||||
return;
|
||||
@@ -506,7 +506,7 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
|
||||
if ( command == fSetCmd.get() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
const auto& id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
GetData(counter, parameters, bins, info);
|
||||
fManager->Set(id, bins, info);
|
||||
return;
|
||||
@@ -514,16 +514,16 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
|
||||
if ( command == fDeleteCmd.get() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
const auto& id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
const auto& keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
fManager->Delete(id, keepSetting);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( command == fSetTitleCmd.get() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto title = parameters[counter++];
|
||||
const auto& id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
const auto& title = parameters[counter++];
|
||||
fManager->SetTitle(id, title);
|
||||
return;
|
||||
}
|
||||
@@ -553,8 +553,8 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
|
||||
if ( command == fSetTitleCmd.get() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto title = parameters[counter++];
|
||||
const auto& id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
const auto& title = parameters[counter++];
|
||||
fManager->SetTitle(id, title);
|
||||
return;
|
||||
}
|
||||
@@ -563,8 +563,8 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
for (unsigned int idim = 0; idim < maxDim; ++idim) {
|
||||
if ( command == fSetAxisCmd[idim].get() ) {
|
||||
auto counter = 0;
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
auto axisTitle = parameters[counter++];
|
||||
const auto& id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
const auto& axisTitle = parameters[counter++];
|
||||
fManager->SetAxisTitle(idim, id, axisTitle);
|
||||
return;
|
||||
}
|
||||
@@ -577,7 +577,7 @@ void G4THnMessenger<DIM, HT>::SetNewValue(G4UIcommand* command, G4String newValu
|
||||
}
|
||||
|
||||
if ( command == fGetTCmd.get() ) {
|
||||
auto id = G4UIcommand::ConvertToInt(newValues);
|
||||
const auto& id = G4UIcommand::ConvertToInt(newValues);
|
||||
fTValue = GetTAddress(id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
|
||||
|
||||
public:
|
||||
G4THnToolsManager(const G4AnalysisManagerState& state);
|
||||
virtual ~G4THnToolsManager() = default;
|
||||
~G4THnToolsManager() override = default;
|
||||
|
||||
// deleted copy constructor & assignment operator
|
||||
G4THnToolsManager(const G4THnToolsManager& rhs) = delete;
|
||||
@@ -70,40 +70,42 @@ class G4THnToolsManager : public G4VTBaseHnManager<DIM>,
|
||||
const std::array<G4HnDimension, DIM>& bins,
|
||||
const std::array<G4HnDimensionInformation, DIM>& hnInfo) override;
|
||||
|
||||
virtual G4bool Scale(G4int id, G4double factor) override;
|
||||
virtual G4int GetNofHns(G4bool onlyIfExist) const override;
|
||||
G4bool Scale(G4int id, G4double factor) override;
|
||||
G4int GetNofHns(G4bool onlyIfExist) const override;
|
||||
|
||||
// Methods to fill histograms
|
||||
virtual G4bool Fill(G4int id, std::array<G4double, DIM> value, G4double weight = 1.0) override;
|
||||
G4bool Fill(G4int id, std::array<G4double, DIM> value,
|
||||
G4double weight = 1.0) override;
|
||||
|
||||
// Access methods
|
||||
virtual G4int GetId(const G4String& name, G4bool warn = true) const override;
|
||||
G4int GetId(const G4String &name, G4bool warn = true) const override;
|
||||
|
||||
// Access to bins parameters
|
||||
virtual G4int GetNbins(unsigned int idim, G4int id) const override;
|
||||
virtual G4double GetMinValue(unsigned int idim, G4int id) const override;
|
||||
virtual G4double GetMaxValue(unsigned int idim, G4int id) const override;
|
||||
virtual G4double GetWidth(unsigned int idim, G4int id) const override;
|
||||
G4int GetNbins(unsigned int idim, G4int id) const override;
|
||||
G4double GetMinValue(unsigned int idim, G4int id) const override;
|
||||
G4double GetMaxValue(unsigned int idim, G4int id) const override;
|
||||
G4double GetWidth(unsigned int idim, G4int id) const override;
|
||||
|
||||
// Setters for attributes for plotting
|
||||
virtual G4bool SetTitle(G4int id, const G4String& title) override;
|
||||
virtual G4bool SetAxisTitle(unsigned int idim, G4int id, const G4String& title) override;
|
||||
G4bool SetTitle(G4int id, const G4String &title) override;
|
||||
G4bool SetAxisTitle(unsigned int idim, G4int id,
|
||||
const G4String &title) override;
|
||||
|
||||
// Access attributes for plotting
|
||||
virtual G4String GetTitle(G4int id) const override;
|
||||
virtual G4String GetAxisTitle(unsigned int idim, G4int id) const override;
|
||||
G4String GetTitle(G4int id) const override;
|
||||
G4String GetAxisTitle(unsigned int idim, G4int id) const override;
|
||||
|
||||
// Methods to list/print histograms
|
||||
virtual G4bool WriteOnAscii(std::ofstream& output) override;
|
||||
// Function with specialization per histo type
|
||||
virtual G4bool List(std::ostream& output, G4bool onlyIfActive = true) override;
|
||||
G4bool WriteOnAscii(std::ofstream &output) override;
|
||||
// Function with specialization per histo type
|
||||
G4bool List(std::ostream &output, G4bool onlyIfActive = true) override;
|
||||
|
||||
// Methods to delete selected histograms
|
||||
virtual G4bool Delete(G4int id, G4bool keepSetting) override;
|
||||
G4bool Delete(G4int id, G4bool keepSetting) override;
|
||||
|
||||
// // Access to Hn manager
|
||||
virtual std::shared_ptr<G4HnManager> GetHnManager() override;
|
||||
virtual const std::shared_ptr<G4HnManager> GetHnManager() const override;
|
||||
std::shared_ptr<G4HnManager> GetHnManager() override;
|
||||
const std::shared_ptr<G4HnManager> GetHnManager() const override;
|
||||
|
||||
protected:
|
||||
// Functions from base class
|
||||
|
||||
@@ -83,7 +83,7 @@ class G4TNtupleDescription
|
||||
|
||||
template <typename NT, typename FT>
|
||||
void G4TNtupleDescription<NT, FT>::SetFile(std::shared_ptr<FT> file)
|
||||
{ fFile = file; }
|
||||
{ fFile = std::move(file); }
|
||||
|
||||
template <typename NT, typename FT>
|
||||
void G4TNtupleDescription<NT, FT>::SetNtuple(NT* ntuple)
|
||||
|
||||
@@ -163,7 +163,7 @@ template <typename NT>
|
||||
G4int G4TRNtupleManager<NT>::SetNtuple(
|
||||
G4TRNtupleDescription<NT>* rntupleDescription)
|
||||
{
|
||||
G4int id = G4int(fNtupleDescriptionVector.size() + fFirstId);
|
||||
auto id = G4int(fNtupleDescriptionVector.size() + fFirstId);
|
||||
|
||||
fNtupleDescriptionVector.push_back(rntupleDescription);
|
||||
|
||||
|
||||
@@ -173,14 +173,14 @@ G4HnMessenger::CreateSetAxisLogCommand(unsigned int idim)
|
||||
G4String commandName = "set" + axis + "axisLog";
|
||||
G4String guidance = "Activate " + axis + "-axis log scale for plotting of the ";
|
||||
|
||||
auto command = CreateCommand<G4UIcommand>(commandName, guidance);
|
||||
auto command = CreateCommand<G4UIcommand>(std::move(commandName), guidance);
|
||||
command->AvailableForStates(G4State_PreInit, G4State_Idle);
|
||||
|
||||
// Add Id parameter
|
||||
AddIdParameter(*command);
|
||||
|
||||
auto parAxisLog = new G4UIparameter("axis", 'b', false);
|
||||
guidance = GetObjectType() + " " + axis + "-axis log scale";
|
||||
guidance = GetObjectType() + " " + std::move(axis) + "-axis log scale";
|
||||
parAxisLog->SetGuidance(guidance.c_str());
|
||||
command->SetParameter(parAxisLog);
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ void G4NtupleBookingManager::SetFileName(
|
||||
// Save the fileName in booking
|
||||
// If extension is still missing (possible with generic manager),
|
||||
// it will be completed with the default one at OpenFile
|
||||
ntupleBooking->fFileName = ntupleFileName;
|
||||
ntupleBooking->fFileName = std::move(ntupleFileName);
|
||||
}
|
||||
|
||||
//_____________________________________________________________________________
|
||||
@@ -426,7 +426,7 @@ void G4NtupleBookingManager::SetFileType(const G4String& fileType)
|
||||
}
|
||||
|
||||
// Save the info in ntuple description
|
||||
ntupleBooking->fFileName = ntupleFileName;
|
||||
ntupleBooking->fFileName = std::move(ntupleFileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ void G4NtupleMessenger::CreateColumnCmds()
|
||||
G4String guidance = "Create ntuple column";
|
||||
name.insert(6, 1, colType);
|
||||
guidance.insert(7, 1, colType);
|
||||
auto cmd = CreateCommand<G4UIcmdWithAString>(name, guidance);
|
||||
auto cmd = CreateCommand<G4UIcmdWithAString>(std::move(name), std::move(guidance));
|
||||
fCreateColumnCmds[colType] = std::move(cmd);
|
||||
}
|
||||
}
|
||||
@@ -221,15 +221,15 @@ void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
// commands without Id parameter
|
||||
|
||||
if ( command == fCreateCmd.get() ) {
|
||||
auto name = parameters[counter++];
|
||||
auto title = parameters[counter++];
|
||||
const auto& name = parameters[counter++];
|
||||
const auto& title = parameters[counter++];
|
||||
fTmpNtupleId = fManager->CreateNtuple(name, title);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& [colType, checkCommand] : fCreateColumnCmds) {
|
||||
if ( command == checkCommand.get() ) {
|
||||
auto name = parameters[counter++];
|
||||
const auto& name = parameters[counter++];
|
||||
switch (colType) {
|
||||
case 'I':
|
||||
fManager->CreateNtupleIColumn(fTmpNtupleId, name);
|
||||
@@ -260,7 +260,7 @@ void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
auto id = G4UIcommand::ConvertToInt(parameters[counter++]);
|
||||
|
||||
if ( command == fDeleteCmd.get() ) {
|
||||
auto keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
const auto& keepSetting = G4UIcommand::ConvertToBool(parameters[counter++]);
|
||||
fManager->DeleteNtuple(id, keepSetting);
|
||||
return;
|
||||
}
|
||||
@@ -276,7 +276,7 @@ void G4NtupleMessenger::SetNewValue(G4UIcommand* command, G4String newValues)
|
||||
}
|
||||
|
||||
if ( command == fListCmd.get() ) {
|
||||
auto onlyIfActive = G4UIcommand::ConvertToBool(parameters[0]);
|
||||
const auto& onlyIfActive = G4UIcommand::ConvertToBool(parameters[0]);
|
||||
fManager->ListNtuple(onlyIfActive);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ void G4RootMainNtupleManager::CreateNtuple(RootNtupleDescription* ntupleDescript
|
||||
|
||||
// Allocate the ntuple description pair vector element(s) if needed
|
||||
while ( index >= G4int(fNtupleDescriptionVector.size()) ) {
|
||||
fNtupleDescriptionVector.push_back(std::make_pair(nullptr, nullptr));
|
||||
fNtupleDescriptionVector.emplace_back(nullptr, nullptr);
|
||||
}
|
||||
|
||||
// Save ntuple description pair in vectors
|
||||
@@ -224,7 +224,7 @@ void G4RootMainNtupleManager::CreateNtuplesFromBooking()
|
||||
// This function is triggered from workers at new cycle.
|
||||
|
||||
for (auto [ntupleDescription, ntupleFile] : fNtupleDescriptionVector) {
|
||||
CreateNtupleFromBooking(ntupleDescription->GetG4NtupleBooking(), ntupleFile);
|
||||
CreateNtupleFromBooking(ntupleDescription->GetG4NtupleBooking(), std::move(ntupleFile));
|
||||
}
|
||||
|
||||
SetNewCycle(false);
|
||||
|
||||
@@ -62,7 +62,7 @@ G4XmlAnalysisManager::G4XmlAnalysisManager()
|
||||
// Ntuple file manager
|
||||
fNtupleFileManager = std::make_shared<G4XmlNtupleFileManager>(fState);
|
||||
SetNtupleFileManager(fNtupleFileManager);
|
||||
fNtupleFileManager->SetFileManager(fileManager);
|
||||
fNtupleFileManager->SetFileManager(std::move(fileManager));
|
||||
fNtupleFileManager->SetBookingManager(fNtupleBookingManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ G4bool G4XmlFileManager::CreateNtupleFile(
|
||||
ntupleFile = CreateTFile(ntupleFileName);
|
||||
}
|
||||
|
||||
ntupleDescription->SetFile(ntupleFile);
|
||||
ntupleDescription->SetFile(std::move(ntupleFile));
|
||||
|
||||
return (ntupleDescription->GetFile() != nullptr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user