30 #define G4THitsMap_h 1
36 #include <unordered_map>
50 template <
typename T,
typename Map_t = std::map<G4
int, T*> >
54 typedef std::multimap<G4int, T*>
mmap_t;
56 typedef std::unordered_multimap<G4int, T*>
uommap_t;
58 #define is_same_t(_Tp, _Up) std::is_same<_Tp, _Up>::value
59 #define is_multimap_t(_Mp) std::is_same<_Mp, mmap_t>::value
60 #define is_uommap_t(_Mp) std::is_same<_Mp, uommap_t>::value
61 #define is_mmap_t(_Mp) (is_multimap_t(_Mp) || is_uommap_t(_Mp))
62 #define is_fundamental_t(_Tp) std::is_fundamental<_Tp>::value
64 template <
bool _Bp,
typename _Tp =
void>
68 template <
typename U = T, enable_if_t<is_fundamental_t(U),
int> = 0>
74 template <
typename U = T, enable_if_t<! is_fundamental_t(U),
int> = 0>
99 template <
typename U,
typename MapU_t>
102 MapU_t* aHitsMap = right.
GetMap();
103 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); itr++)
104 add<U, map_type>(itr->first, *(itr->second));
147 template <
typename U = T,
148 typename MapU_t = Map_t,
149 enable_if_t<is_same_t(U, T) && ! is_mmap_t(MapU_t), int> = 0>
153 if(theHitsMap->find(key) == theHitsMap->end())
154 theHitsMap->insert(
pair_t(key,
new T(*aHit)));
156 *theHitsMap->find(key)->second += *aHit;
157 return theHitsMap->size();
162 template <
typename U = T,
163 typename MapU_t = Map_t,
164 enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
168 theHitsMap->insert(
pair_t(key, aHit));
169 return theHitsMap->size();
175 template <
typename U = T,
176 typename MapU_t = Map_t,
177 enable_if_t<(!is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
183 theHitsMap->insert(
pair_t(key, hit));
184 return theHitsMap->size();
194 template <
typename U = T,
195 typename MapU_t = Map_t,
196 enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
200 if(theHitsMap->find(key) == theHitsMap->end())
201 theHitsMap->insert(
pair_t(key,
new T(aHit)));
203 *theHitsMap->find(key)->second += aHit;
204 return theHitsMap->size();
210 template <
typename U = T,
211 typename MapU_t = Map_t,
212 enable_if_t<(! is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
216 if(theHitsMap->find(key) == theHitsMap->end())
218 *theHitsMap->find(key)->second += aHit;
219 return theHitsMap->size();
224 template <
typename U = T,
225 typename MapU_t = Map_t,
226 enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
230 theHitsMap->insert(
pair_t(key,
new T(aHit)));
231 return theHitsMap->size();
237 template <
typename U = T,
238 typename MapU_t = Map_t,
239 enable_if_t<(!is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
245 theHitsMap->insert(
pair_t(key, hit));
246 return theHitsMap->size();
257 template <
typename U = T,
258 typename MapU_t = Map_t,
259 enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
263 if(theHitsMap->find(key) != theHitsMap->end())
264 delete theHitsMap->find(key)->second;
265 theHitsMap->find(key)->second = aHit;
266 return theHitsMap->size();
271 template <
typename U = T,
272 typename MapU_t = Map_t,
273 enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
277 if(theHitsMap->find(key) != theHitsMap->end())
278 theHitsMap->insert(
pair_t(key, aHit));
281 delete theHitsMap->find(key)->second;
282 theHitsMap->find(key)->second = aHit;
284 return theHitsMap->size();
289 template <
typename U = T,
290 typename MapU_t = Map_t,
291 enable_if_t<(!is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
296 if(theHitsMap->find(key) == theHitsMap->end())
297 theHitsMap->insert(std::make_pair(key, hit =
allocate()));
299 hit = theHitsMap->find(key)->second;
301 return theHitsMap->size();
306 template <
typename U = T,
307 typename MapU_t = Map_t,
308 enable_if_t<(!is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
314 if(theHitsMap->find(key) != theHitsMap->end())
315 theHitsMap->insert(
pair_t(key, hit));
318 delete theHitsMap->find(key)->second;
319 theHitsMap->find(key)->second = hit;
321 return theHitsMap->size();
332 template <
typename U = T,
333 typename MapU_t = Map_t,
334 enable_if_t<(is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
339 if(theHitsMap->find(key) != theHitsMap->end())
340 hit = theHitsMap->find(key)->second;
344 return theHitsMap->size();
349 template <
typename U = T,
350 typename MapU_t = Map_t,
351 enable_if_t<(is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
355 if(theHitsMap->find(key) != theHitsMap->end())
356 *theHitsMap->find(key)->second = aHit;
358 theHitsMap->insert(
pair_t(key,
new T(aHit)));
359 return theHitsMap->size();
364 template <
typename U = T,
365 typename MapU_t = Map_t,
366 enable_if_t<(!is_same_t(U, T) && ! is_mmap_t(MapU_t)), int> = 0>
371 if(theHitsMap->find(key) == theHitsMap->end())
372 theHitsMap->insert(std::make_pair(key, hit =
allocate()));
374 hit = theHitsMap->find(key)->second;
376 return theHitsMap->size();
381 template <
typename U = T,
382 typename MapU_t = Map_t,
383 enable_if_t<(!is_same_t(U, T) && is_mmap_t(MapU_t)), int> = 0>
389 if(theHitsMap->find(key) != theHitsMap->end())
390 *theHitsMap->find(key)->second = *hit;
392 theHitsMap->insert(
pair_t(key, hit));
393 return theHitsMap->size();
403 template <
typename MapU_t = Map_t,
404 enable_if_t<! is_mmap_t(MapU_t), int> = 0>
408 if(theHitsMap->find(key) != theHitsMap->end())
409 return theHitsMap->find(key)->second;
413 template <
typename MapU_t = Map_t,
414 enable_if_t<is_mmap_t(MapU_t), int> = 0>
418 static bool _first =
true;
422 G4Exception(
"G4THitsMap operator[]",
"calling [] on multimap",
427 iterator itr = theHitsMap->find(key);
428 if(itr != theHitsMap->end())
430 std::advance(itr, theHitsMap->count(key)-1);
441 #undef is_fundamental_t
446 template <
typename T,
typename Map_t>
449 theCollection = (
void*)
new Map_t;
454 template <
typename T,
typename Map_t>
463 template <
typename T,
typename Map_t>
467 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); itr++)
474 template <
typename T,
typename Map_t>
482 template <
typename T,
typename Map_t>
488 template <
typename T,
typename Map_t>
491 G4cout <<
"G4THitsMap " << SDname <<
" / " << collectionName <<
" --- "
492 << entries() <<
" entries" <<
G4endl;
509 template <
typename T,
typename Map_t>
512 Map_t * theHitsMap = GetMap();
513 for(
iterator itr = theHitsMap->begin(); itr != theHitsMap->end(); itr++)
526 template <
typename _Tp>
537 using parent_type::operator +=;
538 using parent_type::operator ==;
539 using parent_type::operator [];
557 template <
typename _Tp>
568 using parent_type::operator +=;
569 using parent_type::operator ==;
570 using parent_type::operator [];
588 template <
typename _Tp>
590 :
public G4VTHitsMap<_Tp, std::unordered_map<G4int, _Tp*>>
600 using parent_type::operator +=;
601 using parent_type::operator ==;
602 using parent_type::operator [];
620 template <
typename _Tp>
622 :
public G4VTHitsMap<_Tp, std::unordered_multimap<G4int, _Tp*>>
632 using parent_type::operator +=;
633 using parent_type::operator ==;
634 using parent_type::operator [];
std::multimap< G4int, T * > mmap_t
typename std::enable_if< _Bp, _Tp >::type enable_if_t
const_iterator begin() const
G4VTHitsMap< T, Map_t > this_type
G4VTHitsMap< _Tp, std::multimap< G4int, _Tp * > > parent_type
G4int add(const G4int &key, U *&aHit) const
G4VTHitsMap< _Tp, std::map< G4int, _Tp * > > parent_type
G4THitsUnorderedMultiMap()
const_iterator cbegin() const
T * operator[](G4int key) const
virtual void PrintAllHits()
const_iterator cend() const
G4int add(const G4int &key, U &aHit) const
G4VTHitsMap< _Tp, std::unordered_map< G4int, _Tp * > > parent_type
this_type & operator+=(const G4VTHitsMap< U, MapU_t > &right) const
map_type::const_iterator const_iterator
G4VTHitsMap< _Tp, std::unordered_multimap< G4int, _Tp * > > parent_type
G4int operator==(const G4VTHitsMap< T, Map_t > &right) const
virtual G4VHit * GetHit(size_t) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
virtual void DrawAllHits()
virtual size_t GetSize() const
G4THitsMap(G4String detName, G4String colName)
G4int set(const G4int &key, U &aHit) const
std::unordered_multimap< G4int, T * > uommap_t
G4int set(const G4int &key, U *&aHit) const
G4GLOB_DLL std::ostream G4cout
std::pair< G4int, T * > pair_t
G4THitsUnorderedMap(G4String detName, G4String colName)
const_iterator end() const
G4THitsUnorderedMultiMap(G4String detName, G4String colName)
map_type::iterator iterator
G4THitsMultiMap(G4String detName, G4String colName)