Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-02 08:28:14

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 12/07/2024
0028 
0029 #include <algorithm>
0030 
0031 //
0032 // public functions
0033 //
0034 
0035 // Default constructor (1)
0036 //_____________________________________________________________________________
0037 template <class T, class Allocator>
0038 G4AccVector<T, Allocator>::G4AccVector(
0039   const G4String& name,
0040   G4MergeMode mergeMode)
0041 : G4VAccumulable(name, mergeMode),
0042   fVector(),
0043   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0044 {
0045   if (G4Accumulables::VerboseLevel > 1 ) {
0046     G4cout << "G4AccVector ctor1" << G4endl;
0047   }
0048 }
0049 
0050 // Constructor (2)
0051 //_____________________________________________________________________________
0052 template <class T, class Allocator>
0053 G4AccVector<T, Allocator>::G4AccVector(
0054   const Allocator& allocator,
0055   G4MergeMode mergeMode)
0056 : G4VAccumulable(mergeMode),
0057   fVector(allocator),
0058   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0059 {
0060   if (G4Accumulables::VerboseLevel > 1 ) {
0061     G4cout << "G4AccVector ctor2" << G4endl;
0062   }
0063 }
0064 
0065 // Constructor (2) with name
0066 //_____________________________________________________________________________
0067 template <class T, class Allocator>
0068 G4AccVector<T, Allocator>::G4AccVector(
0069   const G4String& name,
0070   const Allocator& allocator,
0071   G4MergeMode mergeMode)
0072 : G4VAccumulable(name, mergeMode),
0073   fVector(allocator),
0074   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0075 {
0076   if (G4Accumulables::VerboseLevel > 1 ) {
0077     G4cout << "G4AccVector ctor2n" << G4endl;
0078   }
0079 }
0080 
0081 // Constructor (3)
0082 //_____________________________________________________________________________
0083 template <class T, class Allocator>
0084 G4AccVector<T, Allocator>::G4AccVector(
0085   std::size_t count, const T& value,
0086   G4MergeMode mergeMode, const Allocator& allocator)
0087 : G4VAccumulable(mergeMode),
0088   fVector(count, value, allocator),
0089   fInitValue(value),
0090   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0091 {
0092   if (G4Accumulables::VerboseLevel > 1 ) {
0093     G4cout << "G4AccVector ctor3" << G4endl;
0094   }
0095 }
0096 
0097 // Constructor (3) with name
0098 //_____________________________________________________________________________
0099 template <class T, class Allocator>
0100 G4AccVector<T, Allocator>::G4AccVector(
0101   const G4String& name,
0102   std::size_t count, const T& value,
0103   G4MergeMode mergeMode, const Allocator& allocator)
0104 : G4VAccumulable(name, mergeMode),
0105   fVector(count, value, allocator),
0106   fInitValue(value),
0107   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0108 {
0109   if (G4Accumulables::VerboseLevel > 1 ) {
0110     G4cout << "G4AccVector ctor3n" << G4endl;
0111   }
0112 }
0113 
0114 // Constructor (4)
0115 //_____________________________________________________________________________
0116 template <class T, class Allocator>
0117 G4AccVector<T, Allocator>::G4AccVector(
0118   std::size_t count,
0119   G4MergeMode mergeMode, const Allocator& allocator)
0120 : G4VAccumulable(mergeMode),
0121   fVector(count, allocator),
0122   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0123 {
0124   if (G4Accumulables::VerboseLevel > 1 ) {
0125     G4cout << "G4AccVector ctor4" << G4endl;
0126   }
0127 }
0128 
0129 // Constructor (4) with name
0130 //_____________________________________________________________________________
0131 template <class T, class Allocator>
0132 G4AccVector<T, Allocator>::G4AccVector(
0133   const G4String& name,
0134   std::size_t count,
0135   G4MergeMode mergeMode, const Allocator& allocator)
0136 : G4VAccumulable(name, mergeMode),
0137   fVector(count, allocator),
0138   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0139 {
0140   if (G4Accumulables::VerboseLevel > 1 ) {
0141     G4cout << "G4AccVector ctor4n" << G4endl;
0142   }
0143 }
0144 
0145 // Constructor (10)
0146 //_____________________________________________________________________________
0147 template <class T, class Allocator>
0148 G4AccVector<T, Allocator>::G4AccVector(
0149   std::initializer_list<T> init,
0150   G4MergeMode mergeMode, const Allocator& allocator)
0151 : G4VAccumulable(mergeMode),
0152   fVector(init, allocator),
0153   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0154 {
0155   if (G4Accumulables::VerboseLevel > 1 ) {
0156     G4cout << "G4AccVector ctor10" << G4endl;
0157   }
0158 }
0159 
0160 // Constructor (10) with name
0161 //_____________________________________________________________________________
0162 template <class T, class Allocator>
0163 G4AccVector<T, Allocator>::G4AccVector(
0164   const G4String& name,
0165   std::initializer_list<T> init,
0166   G4MergeMode mergeMode, const Allocator& allocator)
0167 : G4VAccumulable(name, mergeMode),
0168   fVector(init, allocator),
0169   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0170 {
0171   if (G4Accumulables::VerboseLevel > 1 ) {
0172     G4cout << "G4AccVector ctor10n" << G4endl;
0173   }
0174 }
0175 
0176 // Copy ctor
0177 //_____________________________________________________________________________
0178 template <class T, class Allocator>
0179 G4AccVector<T, Allocator>::G4AccVector(
0180   const G4AccVector& rhs, const Allocator& allocator)
0181 : G4VAccumulable(rhs),
0182   fVector(rhs, allocator),
0183   fMergeFunction(rhs.fMergeFunction)
0184 {}
0185 
0186 // Move ctor
0187 //_____________________________________________________________________________
0188 template <class T, class Allocator>
0189 G4AccVector<T, Allocator>::G4AccVector(
0190    G4AccVector&& rhs, const Allocator& allocator)
0191 : G4VAccumulable(std::move(rhs)),
0192   fVector(std::move(rhs), allocator),
0193   fMergeFunction(rhs.fMergeFunction)
0194 {}
0195 
0196 //_____________________________________________________________________________
0197 template <class T, class Allocator>
0198 void G4AccVector<T, Allocator>::Merge(const G4VAccumulable& other)
0199 {
0200   const auto& otherVector = static_cast<const G4AccVector<T, Allocator>&>(other);
0201 
0202   if (G4Accumulables::VerboseLevel > 2 ) {
0203     G4cout << "G4AccVector<T, Allocator>::Merge: " << G4endl;
0204     G4cout << "destination: ";
0205     for (const auto& v : fVector) {
0206       G4cout << v << ", ";
0207     }
0208     G4cout << G4endl;
0209     G4cout << "merged data: ";
0210     for (const auto& v : otherVector.fVector) {
0211       G4cout << v << ", ";
0212     }
0213     G4cout << G4endl;
0214   }
0215 
0216   std::transform(fVector.begin(), fVector.end(), otherVector.fVector.begin(),
0217                  fVector.begin(), fMergeFunction);
0218 }
0219 
0220 //_____________________________________________________________________________
0221 template <class T, class Allocator>
0222 void G4AccVector<T, Allocator>::Reset()
0223 {
0224   for (auto& value : fVector) {
0225     value = fInitValue;
0226   }
0227 }
0228 
0229 //_____________________________________________________________________________
0230 template <class T, class Allocator>
0231 void G4AccVector<T, Allocator>::Print(G4PrintOptions options) const
0232 {
0233   if (options.Has(G4PrintOptions::kType)) {
0234     G4cout << "vector<" << typeid(T).name() << ">: ";
0235   }
0236 
0237   PrintBase(options);
0238 
0239   bool first = true;
0240   for (const auto& value : fVector) {
0241     if (! first) { G4cout << ", "; }
0242     G4cout << value;
0243     first = false;
0244   }
0245   G4cout << G4endl;
0246 }
0247 
0248 //_____________________________________________________________________________
0249 template <class T, class Allocator>
0250 void G4AccVector<T, Allocator>::SetMergeMode(G4MergeMode value)
0251 {
0252   G4VAccumulable::SetMergeMode(value);
0253   fMergeFunction = G4Accumulables::GetMergeFunction<T>(fMergeMode);
0254 }