|
|
|||
File indexing completed on 2025-10-26 08:44:34
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, 04/07/2012 0028 0029 #ifndef G4MergeMode_h 0030 #define G4MergeMode_h 1 0031 0032 #include "globals.hh" 0033 #include "G4Exception.hh" 0034 0035 #include <functional> 0036 #include <cmath> 0037 0038 // Enumeration for definition available binning schemes 0039 0040 enum class G4MergeMode { 0041 kAddition, // "Or" if boolean type 0042 kMultiplication, // "And" if boolean type 0043 kMaximum, // "Or" if boolean type 0044 kMinimum // "And" if boolean type 0045 }; 0046 0047 // Generic merge function 0048 template <typename T> 0049 using G4MergeFunction = std::function<T(const T&, const T&)>; 0050 0051 // Utility functions 0052 namespace G4Accumulables { 0053 0054 G4MergeMode GetMergeMode(const G4String& mergeModeName); 0055 0056 template <typename T> 0057 G4MergeFunction<T> GetMergeFunction(G4MergeMode mergeMode) 0058 { 0059 switch ( mergeMode ) { 0060 case G4MergeMode::kAddition: 0061 return std::plus<T>(); 0062 0063 case G4MergeMode::kMultiplication: 0064 return std::multiplies<T>(); 0065 0066 case G4MergeMode::kMaximum: 0067 return [](const T& x, const T& y) { return std::max(x,y); }; 0068 0069 case G4MergeMode::kMinimum: 0070 return [](const T& x, const T& y) { return std::min(x,y); }; 0071 } 0072 0073 // Must never get here, but we need a return to satisfy MSVC 0074 G4Exception("G4Accumulables::GetMergeFunction<T>", 0075 "Analysis_F001", FatalException, 0076 "Undefined merge mode"); 0077 return [](const T&, const T&) { return T(); }; 0078 } 0079 0080 template <G4bool> 0081 G4MergeFunction<G4bool> GetMergeFunction(G4MergeMode mergeMode) 0082 { 0083 switch ( mergeMode ) { 0084 case G4MergeMode::kAddition: 0085 case G4MergeMode::kMaximum: 0086 // return std::bind([](const T& x, const T& y) { return x + y; }); 0087 return [](const G4bool& x, const G4bool& y) { return x || y; }; 0088 0089 case G4MergeMode::kMultiplication: 0090 case G4MergeMode::kMinimum: 0091 return [](const G4bool& x, const G4bool& y) { return x && y; }; 0092 } 0093 } 0094 0095 } 0096 0097 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|