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>
71 template <
typename U = T, enable_if_t<! is_fundamental_t(U), G4
int> = 0>
96 template <
typename U,
typename MapU_t>
99 MapU_t* aHitsMap = right.
GetMap();
100 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
101 add<U, map_type>(itr->first, *(itr->second));
117 inline typename Map_t::size_type
size()
121 {
return itr->first; }
124 {
return itr->first; }
126 template <
typename MapU_t = Map_t, enable_if_t< !is_mmap_t(MapU_t), G4
int> = 0>
130 template <
typename MapU_t = Map_t, enable_if_t< is_mmap_t(MapU_t), G4
int> = 0>
137 {
return itr->second; }
140 {
return itr->second; }
174 template <
typename U = T,
175 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,
190 typename MapU_t = Map_t,
195 theHitsMap->insert(pair_t(key, aHit));
196 return theHitsMap->size();
202 template <
typename U = T,
203 typename MapU_t = Map_t,
210 theHitsMap->insert(pair_t(key, hit));
211 return theHitsMap->size();
221 template <
typename U = T,
222 typename MapU_t = Map_t,
227 if(theHitsMap->find(key) == theHitsMap->end())
228 theHitsMap->insert(pair_t(key,
new T(aHit)));
230 *theHitsMap->find(key)->second += aHit;
231 return theHitsMap->size();
237 template <
typename U = T,
238 typename MapU_t = Map_t,
243 if(theHitsMap->find(key) == theHitsMap->end())
244 theHitsMap->insert(pair_t(key, allocate()));
245 *theHitsMap->find(key)->second += aHit;
246 return theHitsMap->size();
251 template <
typename U = T,
252 typename MapU_t = Map_t,
257 theHitsMap->insert(pair_t(key,
new T(aHit)));
258 return theHitsMap->size();
264 template <
typename U = T,
265 typename MapU_t = Map_t,
272 theHitsMap->insert(pair_t(key, hit));
273 return theHitsMap->size();
284 template <
typename U = T,
285 typename MapU_t = Map_t,
287 inline size_t set(
const G4int& key, U*& aHit)
const
290 if(theHitsMap->find(key) != theHitsMap->end())
291 delete theHitsMap->find(key)->second;
292 theHitsMap->find(key)->second = aHit;
293 return theHitsMap->size();
298 template <
typename U = T,
299 typename MapU_t = Map_t,
301 inline size_t set(
const G4int& key, U*& aHit)
const
304 if(theHitsMap->find(key) != theHitsMap->end())
305 theHitsMap->insert(pair_t(key, aHit));
308 delete theHitsMap->find(key)->second;
309 theHitsMap->find(key)->second = aHit;
311 return theHitsMap->size();
316 template <
typename U = T,
317 typename MapU_t = Map_t,
319 inline size_t set(
const G4int & key, U*& aHit)
const
323 if(theHitsMap->find(key) == theHitsMap->end())
324 theHitsMap->insert(std::make_pair(key, hit = allocate()));
326 hit = theHitsMap->find(key)->second;
328 return theHitsMap->size();
333 template <
typename U = T,
334 typename MapU_t = Map_t,
336 inline size_t set(
const G4int& key, U*& aHit)
const
341 if(theHitsMap->find(key) != theHitsMap->end())
342 theHitsMap->insert(pair_t(key, hit));
345 delete theHitsMap->find(key)->second;
346 theHitsMap->find(key)->second = hit;
348 return theHitsMap->size();
359 template <
typename U = T,
360 typename MapU_t = Map_t,
366 if(theHitsMap->find(key) != theHitsMap->end())
367 hit = theHitsMap->find(key)->second;
369 theHitsMap->insert(pair_t(key, hit = allocate()));
371 return theHitsMap->size();
376 template <
typename U = T,
377 typename MapU_t = Map_t,
382 if(theHitsMap->find(key) != theHitsMap->end())
383 *theHitsMap->find(key)->second = aHit;
385 theHitsMap->insert(pair_t(key,
new T(aHit)));
386 return theHitsMap->size();
391 template <
typename U = T,
392 typename MapU_t = Map_t,
394 inline size_t set(
const G4int & key, U& aHit)
const
398 if(theHitsMap->find(key) == theHitsMap->end())
399 theHitsMap->insert(std::make_pair(key, hit = allocate()));
401 hit = theHitsMap->find(key)->second;
403 return theHitsMap->size();
408 template <
typename U = T,
409 typename MapU_t = Map_t,
416 if(theHitsMap->find(key) != theHitsMap->end())
417 *theHitsMap->find(key)->second = *hit;
419 theHitsMap->insert(pair_t(key, hit));
420 return theHitsMap->size();
430 template <
typename MapU_t = Map_t,
435 if(theHitsMap->find(key) != theHitsMap->end())
436 return theHitsMap->find(key)->second;
440 template <
typename MapU_t = Map_t,
445 static bool _first =
true;
449 G4Exception(
"G4THitsMap operator[]",
"calling [] on multimap",
454 iterator itr = theHitsMap->find(key);
455 if(itr != theHitsMap->end())
457 std::advance(itr, theHitsMap->count(key)-1);
468 #undef is_fundamental_t
473template <
typename T,
typename Map_t>
476 theCollection = (
void*)
new Map_t;
481template <
typename T,
typename Map_t>
490template <
typename T,
typename Map_t>
494 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
501template <
typename T,
typename Map_t>
509template <
typename T,
typename Map_t>
515template <
typename T,
typename Map_t>
518 G4cout <<
"G4THitsMap " << SDname <<
" / " << collectionName <<
" --- "
519 << entries() <<
" entries" <<
G4endl;
536template <
typename T,
typename Map_t>
539 Map_t * theHitsMap = GetMap();
540 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); ++itr)
553template <
typename _Tp>
564 using parent_type::operator +=;
565 using parent_type::operator ==;
566 using parent_type::operator [];
584template <
typename _Tp>
595 using parent_type::operator +=;
596 using parent_type::operator ==;
597 using parent_type::operator [];
615template <
typename _Tp>
617 :
public G4VTHitsMap<_Tp, std::unordered_map<G4int, _Tp*>>
627 using parent_type::operator +=;
628 using parent_type::operator ==;
629 using parent_type::operator [];
647template <
typename _Tp>
649 :
public G4VTHitsMap<_Tp, std::unordered_multimap<G4int, _Tp*>>
659 using parent_type::operator +=;
660 using parent_type::operator ==;
661 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