35#include <unordered_map>
47template <
typename T,
typename Map_t = std::map<G4
int, T*>>
51 typedef std::multimap<G4int, T*> mmap_t;
52 typedef std::pair<G4int, T*> pair_t;
53 typedef std::unordered_multimap<G4int, T*> uommap_t;
55#define is_same_t(_Tp, _Up) std::is_same<_Tp, _Up>::value
56#define is_multimap_t(_Mp) std::is_same<_Mp, mmap_t>::value
57#define is_uommap_t(_Mp) std::is_same<_Mp, uommap_t>::value
58#define is_mmap_t(_Mp) (is_multimap_t(_Mp) || is_uommap_t(_Mp))
59#define is_fundamental_t(_Tp) std::is_fundamental<_Tp>::value
61 template <
bool _Bp,
typename _Tp =
void>
62 using enable_if_t =
typename std::enable_if<_Bp, _Tp>::type;
65 template <
typename U = T, enable_if_t<is_fundamental_t(U), G4
int> = 0>
73 template <
typename U = T, enable_if_t<!is_fundamental_t(U), G4
int> = 0>
100 template <
typename U,
typename MapU_t>
103 MapU_t* aHitsMap = right.
GetMap();
104 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
105 add<U, map_type>(itr->first, *(itr->second));
129 template <
typename MapU_t = Map_t, enable_if_t<!is_mmap_t(MapU_t), G4
int> = 0>
135 template <
typename MapU_t = Map_t, enable_if_t<is_mmap_t(MapU_t), G4
int> = 0>
175 template <
typename U = T,
typename MapU_t = Map_t,
180 if(theHitsMap->find(key) == theHitsMap->end())
181 theHitsMap->insert(pair_t(key,
new T(*aHit)));
183 *theHitsMap->find(key)->second += *aHit;
184 return theHitsMap->size();
189 template <
typename U = T,
typename MapU_t = Map_t,
194 theHitsMap->insert(pair_t(key, aHit));
195 return theHitsMap->size();
201 template <
typename U = T,
typename MapU_t = Map_t,
208 theHitsMap->insert(pair_t(key, hit));
209 return theHitsMap->size();
219 template <
typename U = T,
typename MapU_t = Map_t,
224 if(theHitsMap->find(key) == theHitsMap->end())
225 theHitsMap->insert(pair_t(key,
new T(aHit)));
227 *theHitsMap->find(key)->second += aHit;
228 return theHitsMap->size();
234 template <
typename U = T,
typename MapU_t = Map_t,
239 if(theHitsMap->find(key) == theHitsMap->end())
240 theHitsMap->insert(pair_t(key, allocate()));
241 *theHitsMap->find(key)->second += aHit;
242 return theHitsMap->size();
247 template <
typename U = T,
typename MapU_t = Map_t,
252 theHitsMap->insert(pair_t(key,
new T(aHit)));
253 return theHitsMap->size();
259 template <
typename U = T,
typename MapU_t = Map_t,
266 theHitsMap->insert(pair_t(key, hit));
267 return theHitsMap->size();
278 template <
typename U = T,
typename MapU_t = Map_t,
280 inline size_t set(
const G4int& key, U*& aHit)
const
283 if(theHitsMap->find(key) != theHitsMap->end())
284 delete theHitsMap->find(key)->second;
285 theHitsMap->find(key)->second = aHit;
286 return theHitsMap->size();
291 template <
typename U = T,
typename MapU_t = Map_t,
293 inline size_t set(
const G4int& key, U*& aHit)
const
296 if(theHitsMap->find(key) != theHitsMap->end())
297 theHitsMap->insert(pair_t(key, aHit));
300 delete theHitsMap->find(key)->second;
301 theHitsMap->find(key)->second = aHit;
303 return theHitsMap->size();
308 template <
typename U = T,
typename MapU_t = Map_t,
310 inline size_t set(
const G4int& key, U*& aHit)
const
314 if(theHitsMap->find(key) == theHitsMap->end())
315 theHitsMap->insert(std::make_pair(key, hit = allocate()));
317 hit = theHitsMap->find(key)->second;
319 return theHitsMap->size();
324 template <
typename U = T,
typename MapU_t = Map_t,
326 inline size_t set(
const G4int& key, U*& aHit)
const
331 if(theHitsMap->find(key) != theHitsMap->end())
332 theHitsMap->insert(pair_t(key, hit));
335 delete theHitsMap->find(key)->second;
336 theHitsMap->find(key)->second = hit;
338 return theHitsMap->size();
349 template <
typename U = T,
typename MapU_t = Map_t,
355 if(theHitsMap->find(key) != theHitsMap->end())
356 hit = theHitsMap->find(key)->second;
358 theHitsMap->insert(pair_t(key, hit = allocate()));
360 return theHitsMap->size();
365 template <
typename U = T,
typename MapU_t = Map_t,
370 if(theHitsMap->find(key) != theHitsMap->end())
371 *theHitsMap->find(key)->second = aHit;
373 theHitsMap->insert(pair_t(key,
new T(aHit)));
374 return theHitsMap->size();
379 template <
typename U = T,
typename MapU_t = Map_t,
385 if(theHitsMap->find(key) == theHitsMap->end())
386 theHitsMap->insert(std::make_pair(key, hit = allocate()));
388 hit = theHitsMap->find(key)->second;
390 return theHitsMap->size();
395 template <
typename U = T,
typename MapU_t = Map_t,
402 if(theHitsMap->find(key) != theHitsMap->end())
403 *theHitsMap->find(key)->second = *hit;
405 theHitsMap->insert(pair_t(key, hit));
406 return theHitsMap->size();
416 template <
typename MapU_t = Map_t, enable_if_t<!is_mmap_t(MapU_t), G4
int> = 0>
420 if(theHitsMap->find(key) != theHitsMap->end())
421 return theHitsMap->find(key)->second;
425 template <
typename MapU_t = Map_t, enable_if_t<is_mmap_t(MapU_t), G4
int> = 0>
429 static bool _first =
true;
433 G4Exception(
"G4THitsMap operator[]",
"calling [] on multimap",
438 iterator itr = theHitsMap->find(key);
439 if(itr != theHitsMap->end())
441 std::advance(itr, theHitsMap->count(key) - 1);
452#undef is_fundamental_t
457template <
typename T,
typename Map_t>
460 theCollection = (
void*)
new Map_t;
465template <
typename T,
typename Map_t>
474template <
typename T,
typename Map_t>
478 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
485template <
typename T,
typename Map_t>
494template <
typename T,
typename Map_t>
502template <
typename T,
typename Map_t>
505 G4cout <<
"G4THitsMap " << SDname <<
" / " << collectionName <<
" --- "
506 << entries() <<
" entries" <<
G4endl;
523template <
typename T,
typename Map_t>
526 Map_t* theHitsMap = GetMap();
527 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
540template <
typename _Tp>
554 using parent_type::operator+=;
555 using parent_type::operator==;
556 using parent_type::operator[];
557 using parent_type::add;
558 using parent_type::begin;
559 using parent_type::cbegin;
560 using parent_type::cend;
561 using parent_type::clear;
562 using parent_type::DrawAllHits;
563 using parent_type::end;
564 using parent_type::entries;
565 using parent_type::GetHit;
566 using parent_type::GetMap;
567 using parent_type::GetSize;
568 using parent_type::PrintAllHits;
569 using parent_type::set;
574template <
typename _Tp>
588 using parent_type::operator+=;
589 using parent_type::operator==;
590 using parent_type::operator[];
608template <
typename _Tp>
610 :
public G4VTHitsMap<_Tp, std::unordered_map<G4int, _Tp*>>
623 using parent_type::operator+=;
624 using parent_type::operator==;
625 using parent_type::operator[];
643template <
typename _Tp>
645 :
public G4VTHitsMap<_Tp, std::unordered_multimap<G4int, _Tp*>>
658 using parent_type::operator+=;
659 using parent_type::operator==;
660 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
G4VTHitsMap< _Tp, std::map< G4int, _Tp * > > parent_type
G4THitsMap(G4String detName, G4String colName)
G4VTHitsMap< _Tp, std::multimap< G4int, _Tp * > > parent_type
G4THitsMultiMap(G4String detName, G4String colName)
G4THitsUnorderedMap(G4String detName, G4String colName)
G4VTHitsMap< _Tp, std::unordered_map< G4int, _Tp * > > parent_type
G4THitsUnorderedMultiMap()
G4THitsUnorderedMultiMap(G4String detName, G4String colName)
G4VTHitsMap< _Tp, std::unordered_multimap< G4int, _Tp * > > parent_type
map_type::iterator iterator
const_iterator cbegin() const
this_type & operator+=(const G4VTHitsMap< U, MapU_t > &right) const
const T * GetObject(const_iterator itr) const
size_t set(const G4int &key, U *&aHit) const
virtual size_t GetSize() const
virtual void PrintAllHits()
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
virtual void DrawAllHits()
virtual G4VHit * GetHit(size_t) const
G4VTHitsMap(G4String detName, G4String colNam)
map_type::const_iterator const_iterator
const_iterator begin() const
T * operator[](G4int key) const
const_iterator cend() const
T * GetObject(iterator itr) const
G4VTHitsMap< T, Map_t > this_type
Map_t::size_type GetIndex(const_iterator itr) const
size_t add(const G4int &key, U &aHit) const
size_t add(const G4int &key, U *&aHit) const
T * GetObject(G4int idx) const