Warning, file /include/Geant4/G4MoleculeCounterTemplates.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef G4MOLECULECOUNTERTEMPLATES_HH
0029 #define G4MOLECULECOUNTERTEMPLATES_HH 1
0030
0031 #include "G4Types.hh"
0032 #include "G4VMoleculeCounter.hh"
0033
0034 #include <map>
0035 #include <set>
0036 #include <vector>
0037
0038 namespace G4
0039 {
0040 namespace MoleculeCounter
0041 {
0042
0043
0044
0045 template<typename T>
0046 G4String GetTemplateTypeName()
0047 {
0048 return G4String(typeid(T).name());
0049 }
0050
0051
0052
0053 template<typename T>
0054 G4bool Contains(const std::set<T>& _set, const T& _value)
0055 {
0056 return std::binary_search(_set.cbegin(), _set.cend(), _value);
0057 }
0058
0059 template<typename T>
0060 G4bool Contains(const std::vector<T>& _vector, const T& _value)
0061 {
0062 auto p = std::find(_vector.cbegin(), _vector.cend(), _value);
0063 return p != _vector.cend();
0064 }
0065
0066 template<typename T, typename U>
0067 G4bool ContainsKey(const std::map<T, U>& _map, const T& _key)
0068 {
0069 auto keys = GetMapIndices(_map);
0070 return Contains(keys, _key);
0071 }
0072
0073
0074
0075 template<typename T, typename U>
0076 const std::vector<T> GetMapIndices(const std::map<T, U>& _map)
0077 {
0078 std::vector<T> output;
0079 for (auto const& it : _map)
0080 output.push_back(it.first);
0081 return output;
0082 }
0083
0084
0085
0086 template<typename T>
0087 void DumpCounterMapIndices(const std::map<T, InnerCounterMapType>& map, G4bool includeEmpty = false)
0088 {
0089 G4cout << "--- BEGIN COUNTER MAP INDEX DUMP ---" << G4endl;
0090 auto i = 0;
0091 for (auto const& it : map) {
0092 if (!includeEmpty && it.second.size() == 0) continue;
0093 G4cout << i++ << ": " << it.first.GetInfo() << G4endl;
0094 }
0095 G4cout << "--- END COUNTER MAP INDEX DUMP ---" << G4endl;
0096 }
0097
0098
0099
0100 template<typename T>
0101 void DumpCounterMapContents(const std::map<T, InnerCounterMapType>& map,
0102 G4bool includeEmpty = false)
0103 {
0104 G4cout << "--- BEGIN COUNTER MAP DUMP ---" << G4endl;
0105 for (auto const& it : map) {
0106 if (!includeEmpty && it.second.size() == 0) continue;
0107 G4cout << " :: " << it.first.GetInfo() << G4endl;
0108 for (auto const& it2 : it.second) {
0109 G4cout << std::setw(3) << std::setprecision(3) << " " << G4BestUnit(it2.first, "Time")
0110 << " " << std::setw(5) << it2.second << G4endl;
0111 }
0112 }
0113 G4cout << "--- END COUNTER MAP DUMP ---" << G4endl;
0114 }
0115
0116
0117
0118 template<typename T>
0119 std::set<G4double> GetRecordedTimes(const std::map<T, InnerCounterMapType>& map)
0120 {
0121 std::set<G4double> output{};
0122 for (const auto& it : map) {
0123 G4cerr << it.second.size() << G4endl;
0124 for (const auto& it2 : it.second) {
0125 output.insert(it2.first);
0126 }
0127 }
0128 return output;
0129 }
0130
0131
0132
0133 template<typename TKey, typename TValue, typename TComp>
0134 typename std::map<TKey, TValue, TComp>::iterator
0135 FindClosestEntryForKey(std::map<TKey, TValue, TComp>& map, TKey key)
0136 {
0137 if (map.empty()) return map.end();
0138
0139 auto it_lb = map.lower_bound(key);
0140
0141 if (it_lb == map.begin()) return it_lb;
0142 if (it_lb == map.end()) return --it_lb;
0143
0144 auto prev_it = std::prev(it_lb);
0145
0146 if (std::abs(it_lb->first - key) < std::abs(prev_it->first - key))
0147 return it_lb;
0148 else
0149 return prev_it;
0150 }
0151
0152
0153
0154 }
0155 }
0156
0157 #endif