// // ******************************************************************** // * 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 // // public functions // // Default constructor (1) //_____________________________________________________________________________ template G4AccMap::G4AccMap( const G4String& name, G4MergeMode mergeMode) : G4VAccumulable(name, mergeMode), fMap(), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor1" << G4endl; } } // Constructor (2) //_____________________________________________________________________________ template G4AccMap::G4AccMap( const Compare& comp, G4MergeMode mergeMode, const Allocator& allocator) : G4VAccumulable(mergeMode), fMap(comp, allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor2" << G4endl; } } // Constructor (2) with name //_____________________________________________________________________________ template G4AccMap::G4AccMap( const G4String& name, const Compare& comp, G4MergeMode mergeMode, const Allocator& allocator) : G4VAccumulable(name, mergeMode), fMap(comp, allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor2n" << G4endl; } } // Constructor (3) //_____________________________________________________________________________ template G4AccMap::G4AccMap( const Allocator& allocator, G4MergeMode mergeMode) : G4VAccumulable(mergeMode), fMap(allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor3" << G4endl; } } // Constructor (3) with name //_____________________________________________________________________________ template G4AccMap::G4AccMap( const G4String& name, const Allocator& allocator, G4MergeMode mergeMode) : G4VAccumulable(name, mergeMode), fMap(allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor3n" << G4endl; } } // Constructor (10) //_____________________________________________________________________________ template G4AccMap::G4AccMap( std::initializer_list> init, G4MergeMode mergeMode, const Compare& comp, const Allocator& allocator) : G4VAccumulable(mergeMode), fMap(init, comp, allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor10" << G4endl; } } // Constructor (10) with name //_____________________________________________________________________________ template G4AccMap::G4AccMap( const G4String& name, std::initializer_list> init, G4MergeMode mergeMode, const Compare& comp, const Allocator& allocator) : G4VAccumulable(name, mergeMode), fMap(init, comp, allocator), fMergeFunction(G4Accumulables::GetMergeFunction(mergeMode)) { if (G4Accumulables::VerboseLevel > 1 ) { G4cout << "G4AccMap ctor10n" << G4endl; } } // Copy ctor //_____________________________________________________________________________ template G4AccMap::G4AccMap( const G4AccMap& rhs, const Allocator& allocator) : G4VAccumulable(rhs), fMap(rhs, allocator), fMergeFunction(rhs.fMergeFunction) {} // Move ctor //_____________________________________________________________________________ template G4AccMap::G4AccMap( G4AccMap&& rhs, const Allocator& allocator) : G4VAccumulable(std::move(rhs)), fMap(std::move(rhs), allocator), fMergeFunction(rhs.fMergeFunction) {} //_____________________________________________________________________________ template void G4AccMap::Merge(const G4VAccumulable& other) { const auto& otherMap = static_cast&>(other); if (G4Accumulables::VerboseLevel > 2 ) { G4cout << "G4AccMap::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 void G4AccMap::Reset() { for (auto& [key, value] :fMap) { fMap[key] = fInitValue; } } //_____________________________________________________________________________ template void G4AccMap::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 void G4AccMap::SetMergeMode(G4MergeMode value) { G4VAccumulable::SetMergeMode(value); fMergeFunction = G4Accumulables::GetMergeFunction(fMergeMode); } //_____________________________________________________________________________ template void G4AccMap::SetInitValue(const T& value) { fInitValue = value; }