Back to home page

EIC code displayed by LXR

 
 

    


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

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, 18/07/2024
0028 
0029 #include <algorithm>
0030 
0031 //
0032 // public functions
0033 //
0034 
0035 //_____________________________________________________________________________
0036 template <class T, std::size_t N>
0037 G4AccArray<T, N>::G4AccArray(
0038   const G4String& name, const T& value, G4MergeMode mergeMode)
0039 : G4VAccumulable(name, mergeMode),
0040   fInitValue(value),
0041   fMergeFunction(G4Accumulables::GetMergeFunction<T>(mergeMode))
0042 {
0043   if (G4Accumulables::VerboseLevel > 1 ) {
0044     G4cout << "G4AccArray ctor1" << G4endl;
0045   }
0046 
0047   for (auto& element : fArray ) {
0048     element = fInitValue;
0049   }
0050 }
0051 
0052 //_____________________________________________________________________________
0053 template <class T, std::size_t N>
0054 template <typename... Args>
0055 G4AccArray<T, N>::G4AccArray(Args&&... args)
0056 : G4VAccumulable(),
0057   fArray{{std::forward<Args>(args)...}}, fMergeFunction(G4Accumulables::GetMergeFunction<T>(fMergeMode))
0058 {
0059   if (G4Accumulables::VerboseLevel > 1 ) {
0060     G4cout << "G4AccArray ctor2" << G4endl;
0061   }
0062 }
0063 
0064 //_____________________________________________________________________________
0065 template <class T, std::size_t N>
0066 template <typename First, typename... Args>
0067 G4AccArray<T, N>::G4AccArray(const First& firstArg, Args&&... args)
0068 : G4VAccumulable(firstArg),
0069   fArray{{std::forward<Args>(args)...}}, 
0070   fMergeFunction(G4Accumulables::GetMergeFunction<T>(fMergeMode))
0071 {
0072   if (G4Accumulables::VerboseLevel > 1 ) {
0073     G4cout << "G4AccArray ctor3" << G4endl;
0074   }
0075 }
0076 
0077 //_____________________________________________________________________________
0078 template <class T, std::size_t N>
0079 void G4AccArray<T, N>::Merge(const G4VAccumulable& other)
0080 {
0081   const auto& otherArrayAcc = static_cast<const G4AccArray<T,N>&>(other);
0082   const auto& otherArray = otherArrayAcc.GetArray();
0083 
0084   if (G4Accumulables::VerboseLevel > 2 ) {
0085     G4cout << "G4AccArray<T, N>::Merge: " << G4endl;
0086     G4cout << "destination: ";
0087     for (auto v : this->fArray) {
0088       G4cout << v << ", ";
0089     }
0090     G4cout << G4endl;
0091     G4cout << "merged data: ";
0092     for (auto v : otherArray) {
0093       G4cout << v << ", ";
0094     }
0095     G4cout << G4endl;
0096   }
0097 
0098   std::transform(fArray.begin(), fArray.end(), otherArray.begin(),
0099                  fArray.begin(), fMergeFunction);
0100 
0101   if (G4Accumulables::VerboseLevel > 1 ) {
0102     G4cout << "G4AccArray<T, N>::Merge: done" << G4endl;
0103   }
0104 }
0105 
0106 //_____________________________________________________________________________
0107 template <class T, std::size_t N>
0108 void G4AccArray<T, N>::Reset()
0109 {
0110   for (auto& value : fArray) {
0111     value = fInitValue;
0112   }
0113 }
0114 
0115 //_____________________________________________________________________________
0116 template <class T, std::size_t N>
0117 void G4AccArray<T, N>::Print(G4PrintOptions options) const
0118 {
0119   if (options.Has(G4PrintOptions::kType)) {
0120     G4cout << "array<" << typeid(fInitValue).name() << ">: ";
0121   }
0122 
0123   PrintBase(options);
0124 
0125   bool first = true;
0126   for (auto& value : fArray) {
0127     if (! first) { G4cout << ", "; }
0128     G4cout << value;
0129     first = false;
0130   }
0131   G4cout << G4endl;
0132 }
0133 
0134 //_____________________________________________________________________________
0135 template <class T, std::size_t N>
0136 void G4AccArray<T, N>::SetMergeMode(G4MergeMode value)
0137 {
0138   G4VAccumulable::SetMergeMode(value);
0139   fMergeFunction = G4Accumulables::GetMergeFunction<T>(value);
0140 }
0141 
0142 //_____________________________________________________________________________
0143 template <class T, std::size_t N>
0144 std::array<T,N>&  G4AccArray<T, N>::GetArray()
0145 {
0146   return fArray;
0147 }
0148 
0149 //_____________________________________________________________________________
0150 template <class T, std::size_t N>
0151 const std::array<T,N>&  G4AccArray<T, N>::GetArray() const
0152 {
0153   return fArray;
0154 }