35#include <unordered_map>
48template <
typename T,
typename Map_t = std::map<G4
int, T*>>
52 using mmap_t = std::multimap<G4int, T *>;
53 using pair_t = std::pair<G4int, T *>;
54 using uommap_t = std::unordered_multimap<G4int, T *>;
56#define is_same_t(_Tp, _Up) std::is_same<_Tp, _Up>::value
57#define is_multimap_t(_Mp) std::is_same<_Mp, mmap_t>::value
58#define is_uommap_t(_Mp) std::is_same<_Mp, uommap_t>::value
59#define is_mmap_t(_Mp) (is_multimap_t(_Mp) || is_uommap_t(_Mp))
60#define is_fundamental_t(_Tp) std::is_fundamental<_Tp>::value
62 template <
bool _Bp,
typename _Tp =
void>
63 using enable_if_t =
typename std::enable_if<_Bp, _Tp>::type;
66 template <
typename U = T, enable_if_t<is_fundamental_t(U), G4
int> = 0>
74 template <
typename U = T, enable_if_t<! is_fundamental_t(U), G4
int> = 0>
101 template <
typename U,
typename MapU_t>
104 MapU_t* aHitsMap = right.
GetMap();
105 for (
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
127 template <
typename MapU_t = Map_t, enable_if_t<! is_mmap_t(MapU_t), G4
int> = 0>
133 template <
typename MapU_t = Map_t, enable_if_t<is_mmap_t(MapU_t), G4
int> = 0>
172 template <
typename U = T,
typename MapU_t = Map_t,
177 if (theHitsMap->find(key) == theHitsMap->end())
178 theHitsMap->insert(pair_t(key,
new T(*aHit)));
180 *theHitsMap->find(key)->second += *aHit;
181 return theHitsMap->size();
186 template <
typename U = T,
typename MapU_t = Map_t,
191 theHitsMap->insert(pair_t(key, aHit));
192 return theHitsMap->size();
198 template <
typename U = T,
typename MapU_t = Map_t,
205 theHitsMap->insert(pair_t(key, hit));
206 return theHitsMap->size();
216 template <
typename U = T,
typename MapU_t = Map_t,
221 if (theHitsMap->find(key) == theHitsMap->end())
222 theHitsMap->insert(pair_t(key,
new T(aHit)));
224 *theHitsMap->find(key)->second += aHit;
225 return theHitsMap->size();
231 template <
typename U = T,
typename MapU_t = Map_t,
236 if (theHitsMap->find(key) == theHitsMap->end()) theHitsMap->insert(pair_t(key, allocate()));
237 *theHitsMap->find(key)->second += aHit;
238 return theHitsMap->size();
243 template <
typename U = T,
typename MapU_t = Map_t,
248 theHitsMap->insert(pair_t(key,
new T(aHit)));
249 return theHitsMap->size();
255 template <
typename U = T,
typename MapU_t = Map_t,
262 theHitsMap->insert(pair_t(key, hit));
263 return theHitsMap->size();
274 template <
typename U = T,
typename MapU_t = Map_t,
276 inline size_t set(
const G4int& key, U*& aHit)
const
279 if (theHitsMap->find(key) != theHitsMap->end())
delete theHitsMap->find(key)->second;
280 theHitsMap->find(key)->second = aHit;
281 return theHitsMap->size();
286 template <
typename U = T,
typename MapU_t = Map_t,
288 inline size_t set(
const G4int& key, U*& aHit)
const
291 if (theHitsMap->find(key) != theHitsMap->end())
292 theHitsMap->insert(pair_t(key, aHit));
294 delete theHitsMap->find(key)->second;
295 theHitsMap->find(key)->second = aHit;
297 return theHitsMap->size();
302 template <
typename U = T,
typename MapU_t = Map_t,
304 inline size_t set(
const G4int& key, U*& aHit)
const
308 if (theHitsMap->find(key) == theHitsMap->end())
309 theHitsMap->insert(std::make_pair(key, hit = allocate()));
311 hit = theHitsMap->find(key)->second;
313 return theHitsMap->size();
318 template <
typename U = T,
typename MapU_t = Map_t,
320 inline size_t set(
const G4int& key, U*& aHit)
const
325 if (theHitsMap->find(key) != theHitsMap->end())
326 theHitsMap->insert(pair_t(key, hit));
328 delete theHitsMap->find(key)->second;
329 theHitsMap->find(key)->second = hit;
331 return theHitsMap->size();
342 template <
typename U = T,
typename MapU_t = Map_t,
348 if (theHitsMap->find(key) != theHitsMap->end())
349 hit = theHitsMap->find(key)->second;
351 theHitsMap->insert(pair_t(key, hit = allocate()));
353 return theHitsMap->size();
358 template <
typename U = T,
typename MapU_t = Map_t,
363 if (theHitsMap->find(key) != theHitsMap->end())
364 *theHitsMap->find(key)->second = aHit;
366 theHitsMap->insert(pair_t(key,
new T(aHit)));
367 return theHitsMap->size();
372 template <
typename U = T,
typename MapU_t = Map_t,
378 if (theHitsMap->find(key) == theHitsMap->end())
379 theHitsMap->insert(std::make_pair(key, hit = allocate()));
381 hit = theHitsMap->find(key)->second;
383 return theHitsMap->size();
388 template <
typename U = T,
typename MapU_t = Map_t,
395 if (theHitsMap->find(key) != theHitsMap->end())
396 *theHitsMap->find(key)->second = *hit;
398 theHitsMap->insert(pair_t(key, hit));
399 return theHitsMap->size();
409 template <
typename MapU_t = Map_t, enable_if_t<! is_mmap_t(MapU_t), G4
int> = 0>
413 if (theHitsMap->find(key) != theHitsMap->end())
return theHitsMap->find(key)->second;
417 template <
typename MapU_t = Map_t, enable_if_t<is_mmap_t(MapU_t), G4
int> = 0>
421 static bool _first =
true;
425 "Returning the last matching entry");
429 iterator itr = theHitsMap->find(key);
430 if (itr != theHitsMap->end()) {
431 std::advance(itr, theHitsMap->count(key) - 1);
442#undef is_fundamental_t
447template <
typename T,
typename Map_t>
450 theCollection = (
void*)
new Map_t;
455template <
typename T,
typename Map_t>
464template <
typename T,
typename Map_t>
468 for (
auto itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
475template <
typename T,
typename Map_t>
483template <
typename T,
typename Map_t>
491template <
typename T,
typename Map_t>
494 G4cout <<
"G4THitsMap " << SDname <<
" / " << collectionName <<
" --- " << entries() <<
" entries"
512template <
typename T,
typename Map_t>
515 Map_t* theHitsMap = GetMap();
516 for (
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
529template <
typename _Tp>
539 using parent_type::operator+=;
540 using parent_type::operator==;
541 using parent_type::operator[];
542 using parent_type::add;
543 using parent_type::begin;
544 using parent_type::cbegin;
545 using parent_type::cend;
546 using parent_type::clear;
547 using parent_type::DrawAllHits;
548 using parent_type::end;
549 using parent_type::entries;
550 using parent_type::GetHit;
551 using parent_type::GetMap;
552 using parent_type::GetSize;
553 using parent_type::PrintAllHits;
554 using parent_type::set;
559template <
typename _Tp>
569 using parent_type::operator+=;
570 using parent_type::operator==;
571 using parent_type::operator[];
589template <
typename _Tp>
599 using parent_type::operator+=;
600 using parent_type::operator==;
601 using parent_type::operator[];
619template <
typename _Tp>
629 using parent_type::operator+=;
630 using parent_type::operator==;
631 using parent_type::operator[];
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define is_same_t(_Tp, _Up)
G4GLOB_DLL std::ostream G4cout
G4THitsMap(G4String detName, G4String colName)
G4THitsMultiMap(G4String detName, G4String colName)
G4THitsUnorderedMap(G4String detName, G4String colName)
G4THitsUnorderedMultiMap()
G4THitsUnorderedMultiMap(G4String detName, G4String colName)
G4VHit * GetHit(size_t) const override
const_iterator cbegin() const
this_type & operator+=(const G4VTHitsMap< U, MapU_t > &right) const
typename map_type::iterator iterator
const T * GetObject(const_iterator itr) const
size_t set(const G4int &key, U *&aHit) const
G4bool operator==(const G4VTHitsMap< T, Map_t > &right) const
size_t set(const G4int &key, U &aHit) const
Map_t * GetContainer() const
Map_t::size_type GetIndex(iterator itr)
const_iterator end() const
void DrawAllHits() override
G4VTHitsMap(G4String detName, G4String colNam)
const_iterator begin() const
T * operator[](G4int key) const
const_iterator cend() const
void PrintAllHits() override
T * GetObject(iterator itr) const
size_t GetSize() const override
Map_t::size_type GetIndex(const_iterator itr) const
size_t add(const G4int &key, U &aHit) const
typename map_type::const_iterator const_iterator
size_t add(const G4int &key, U *&aHit) const
T * GetObject(G4int idx) const