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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 
 27 // Author: Ivana Hrivnacova, IJCLab IN2P3/CNRS, 12/07/2024
 28 
 29 #include <algorithm>
 30 
 31 //
 32 // public functions
 33 //
 34 
 35 // Default constructor (1)
 36 //_____________________________________________________________________________
 37 template <class T, class Allocator>
 38 G4AccVector<T, Allocator>::G4AccVector(
 39   const G4String& name,
 40   G4MergeMode mergeMode)
 41 : G4VAccumulable(name, mergeMode),
 42   fVector(),
 43   fMergeFunction(GetMergeFunction<T>(mergeMode))
 44 {
 45   if (G4Accumulables::VerboseLevel > 1 ) {
 46     G4cout << "G4AccVector ctor1" << G4endl;
 47   }
 48 }
 49 
 50 // Constructor (2)
 51 //_____________________________________________________________________________
 52 template <class T, class Allocator>
 53 G4AccVector<T, Allocator>::G4AccVector(
 54   const Allocator& allocator,
 55   G4MergeMode mergeMode)
 56 : G4VAccumulable(mergeMode),
 57   fVector(allocator),
 58   fMergeFunction(GetMergeFunction<T>(mergeMode))
 59 {
 60   if (G4Accumulables::VerboseLevel > 1 ) {
 61     G4cout << "G4AccVector ctor2" << G4endl;
 62   }
 63 }
 64 
 65 // Constructor (2) with name
 66 //_____________________________________________________________________________
 67 template <class T, class Allocator>
 68 G4AccVector<T, Allocator>::G4AccVector(
 69   const G4String& name,
 70   const Allocator& allocator,
 71   G4MergeMode mergeMode)
 72 : G4VAccumulable(name, mergeMode),
 73   fVector(allocator),
 74   fMergeFunction(GetMergeFunction<T>(mergeMode))
 75 {
 76   if (G4Accumulables::VerboseLevel > 1 ) {
 77     G4cout << "G4AccVector ctor2n" << G4endl;
 78   }
 79 }
 80 
 81 // Constructor (3)
 82 //_____________________________________________________________________________
 83 template <class T, class Allocator>
 84 G4AccVector<T, Allocator>::G4AccVector(
 85   std::size_t count, const T& value,
 86   G4MergeMode mergeMode, const Allocator& allocator)
 87 : G4VAccumulable(mergeMode),
 88   fVector(count, value, allocator),
 89   fInitValue(value),
 90   fMergeFunction(GetMergeFunction<T>(mergeMode))
 91 {
 92   if (G4Accumulables::VerboseLevel > 1 ) {
 93     G4cout << "G4AccVector ctor3" << G4endl;
 94   }
 95 }
 96 
 97 // Constructor (3) with name
 98 //_____________________________________________________________________________
 99 template <class T, class Allocator>
100 G4AccVector<T, Allocator>::G4AccVector(
101   const G4String& name,
102   std::size_t count, const T& value,
103   G4MergeMode mergeMode, const Allocator& allocator)
104 : G4VAccumulable(name, mergeMode),
105   fVector(count, value, allocator),
106   fInitValue(value),
107   fMergeFunction(GetMergeFunction<T>(mergeMode))
108 {
109   if (G4Accumulables::VerboseLevel > 1 ) {
110     G4cout << "G4AccVector ctor3n" << G4endl;
111   }
112 }
113 
114 // Constructor (4)
115 //_____________________________________________________________________________
116 template <class T, class Allocator>
117 G4AccVector<T, Allocator>::G4AccVector(
118   std::size_t count,
119   G4MergeMode mergeMode, const Allocator& allocator)
120 : G4VAccumulable(mergeMode),
121   fVector(count, allocator),
122   fMergeFunction(GetMergeFunction<T>(mergeMode))
123 {
124   if (G4Accumulables::VerboseLevel > 1 ) {
125     G4cout << "G4AccVector ctor4" << G4endl;
126   }
127 }
128 
129 // Constructor (4) with name
130 //_____________________________________________________________________________
131 template <class T, class Allocator>
132 G4AccVector<T, Allocator>::G4AccVector(
133   const G4String& name,
134   std::size_t count,
135   G4MergeMode mergeMode, const Allocator& allocator)
136 : G4VAccumulable(name, mergeMode),
137   fVector(count, allocator),
138   fMergeFunction(GetMergeFunction<T>(mergeMode))
139 {
140   if (G4Accumulables::VerboseLevel > 1 ) {
141     G4cout << "G4AccVector ctor4n" << G4endl;
142   }
143 }
144 
145 // Constructor (10)
146 //_____________________________________________________________________________
147 template <class T, class Allocator>
148 G4AccVector<T, Allocator>::G4AccVector(
149   std::initializer_list<T> init,
150   G4MergeMode mergeMode, const Allocator& allocator)
151 : G4VAccumulable(mergeMode),
152   fVector(init, allocator),
153   fMergeFunction(GetMergeFunction<T>(mergeMode))
154 {
155   if (G4Accumulables::VerboseLevel > 1 ) {
156     G4cout << "G4AccVector ctor10" << G4endl;
157   }
158 }
159 
160 // Constructor (10) with name
161 //_____________________________________________________________________________
162 template <class T, class Allocator>
163 G4AccVector<T, Allocator>::G4AccVector(
164   const G4String& name,
165   std::initializer_list<T> init,
166   G4MergeMode mergeMode, const Allocator& allocator)
167 : G4VAccumulable(name, mergeMode),
168   fVector(init, allocator),
169   fMergeFunction(GetMergeFunction<T>(mergeMode))
170 {
171   if (G4Accumulables::VerboseLevel > 1 ) {
172     G4cout << "G4AccVector ctor10n" << G4endl;
173   }
174 }
175 
176 // Copy ctor
177 //_____________________________________________________________________________
178 template <class T, class Allocator>
179 G4AccVector<T, Allocator>::G4AccVector(
180   const G4AccVector& rhs, const Allocator& allocator)
181 : G4VAccumulable(rhs),
182   fVector(rhs, allocator),
183   fMergeFunction(rhs.fMergeFunction)
184 {}
185 
186 // Move ctor
187 //_____________________________________________________________________________
188 template <class T, class Allocator>
189 G4AccVector<T, Allocator>::G4AccVector(
190    G4AccVector&& rhs, const Allocator& allocator)
191 : G4VAccumulable(std::move(rhs)),
192   fVector(std::move(rhs), allocator),
193   fMergeFunction(rhs.fMergeFunction)
194 {}
195 
196 //_____________________________________________________________________________
197 template <class T, class Allocator>
198 void G4AccVector<T, Allocator>::Merge(const G4VAccumulable& other)
199 {
200   const auto& otherVector = static_cast<const G4AccVector<T, Allocator>&>(other);
201 
202   if (G4Accumulables::VerboseLevel > 2 ) {
203     G4cout << "G4AccVector<T, Allocator>::Merge: " << G4endl;
204     G4cout << "destination: ";
205     for (const auto& v : fVector) {
206       G4cout << v << ", ";
207     }
208     G4cout << G4endl;
209     G4cout << "merged data: ";
210     for (const auto& v : otherVector.fVector) {
211       G4cout << v << ", ";
212     }
213     G4cout << G4endl;
214   }
215 
216   std::transform(fVector.begin(), fVector.end(), otherVector.fVector.begin(),
217                  fVector.begin(), fMergeFunction);
218 }
219 
220 //_____________________________________________________________________________
221 template <class T, class Allocator>
222 void G4AccVector<T, Allocator>::Reset()
223 {
224   for (auto& value : fVector) {
225     value = fInitValue;
226   }
227 }
228 
229 //_____________________________________________________________________________
230 template <class T, class Allocator>
231 void G4AccVector<T, Allocator>::Print(G4PrintOptions options) const
232 {
233   if (options.Has(G4PrintOptions::kType)) {
234     G4cout << "vector<" << typeid(T).name() << ">: ";
235   }
236 
237   PrintBase(options);
238 
239   bool first = true;
240   for (const auto& value : fVector) {
241     if (! first) { G4cout << ", "; }
242     G4cout << value;
243     first = false;
244   }
245   G4cout << G4endl;
246 }
247 
248 //_____________________________________________________________________________
249 template <class T, class Allocator>
250 void G4AccVector<T, Allocator>::SetMergeMode(G4MergeMode value)
251 {
252   G4VAccumulable::SetMergeMode(value);
253   fMergeFunction = GetMergeFunction<T>(fMergeMode);
254 }
255