255 lines
8.4 KiB
Plaintext
255 lines
8.4 KiB
Plaintext
//
|
|
// ********************************************************************
|
|
// * License and Disclaimer *
|
|
// * *
|
|
// * The Geant4 software is copyright of the Copyright Holders of *
|
|
// * the Geant4 Collaboration. It is provided under the terms and *
|
|
// * conditions of the Geant4 Software License, included in the file *
|
|
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
|
// * include a list of copyright holders. *
|
|
// * *
|
|
// * Neither the authors of this software system, nor their employing *
|
|
// * institutes,nor the agencies providing financial support for this *
|
|
// * work make any representation or warranty, express or implied, *
|
|
// * regarding this software system or assume any liability for its *
|
|
// * use. Please see the license in the file LICENSE and URL above *
|
|
// * for the full disclaimer and the limitation of liability. *
|
|
// * *
|
|
// * This code implementation is the result of the scientific and *
|
|
// * technical work of the GEANT4 collaboration. *
|
|
// * By using, copying, modifying or distributing the software (or *
|
|
// * any work based on the software) you agree to acknowledge its *
|
|
// * use in resulting scientific publications, and indicate your *
|
|
// * acceptance of all terms of the Geant4 Software license. *
|
|
// ********************************************************************
|
|
//
|
|
|
|
// Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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(G4Accumulables::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 = G4Accumulables::GetMergeFunction<T>(fMergeMode);
|
|
}
|