28 #ifndef G4THitsVector_h
29 #define G4THitsVector_h 1
39 #include <unordered_map>
51 template <
typename T,
typename Vector_t = std::deque<T*> >
58 typedef typename vector_type::iterator
iterator;
62 typedef std::pair<G4int, store_type>
pair_t;
63 typedef std::map<G4int, store_type>
map_t;
64 typedef std::unordered_map<G4int, store_type>
uomap_t;
65 typedef std::multimap<G4int, store_type>
mmap_t;
66 typedef std::unordered_multimap<G4int, store_type>
uommap_t;
69 #define is_same_t(_Tp, _Up) std::is_same<_Tp, _Up>::value
70 #define is_fundamental_t(_Tp) std::is_fundamental<_Tp>::value
72 #define is_std_map_t(_Mp) std::is_same<_Mp, map_t>::value
73 #define is_std_uomap_t(_Mp) std::is_same<_Mp, uomap_t>::value
74 #define is_std_mmap_t(_Mp) std::is_same<_Mp, mmap_t>::value
75 #define is_std_uommap_t(_Mp) std::is_same<_Mp, uommap_t>::value
76 #define is_map_t(_Mp) ( is_std_map_t(_Mp) ||\\
77 is_std_mmap_t(_Mp) || \\
78 is_std_uomap_t(_Mp) || \\
79 is_std_uommap_t(_Mp) )
80 #define is_pointer_t(_Tp) std::is_pointer<_Tp>::value
81 #define scast(_Tp) static_cast<_Tp>
83 template <
bool _Bp,
typename _Tp =
void>
105 inline typename Vector_t::size_type
size()
109 {
return std::distance(
begin(), itr); }
112 {
return std::distance(
begin(), itr); }
114 template <
typename U = store_type, enable_if_t< (is_po
inter_t(U)),
int> = 0>
118 template <
typename U = store_type, enable_if_t< (is_po
inter_t(U)),
int> = 0>
122 template <
typename U = store_type, enable_if_t< (is_po
inter_t(U)),
int> = 0>
126 template <
typename U = store_type, enable_if_t< (!is_po
inter_t(U)),
int> = 0>
130 template <
typename U = store_type, enable_if_t< (!is_po
inter_t(U)),
int> = 0>
134 template <
typename U = store_type, enable_if_t< (!is_po
inter_t(U)),
int> = 0>
168 template <
typename U =
T,
173 {
return new T(0.); }
177 template <
typename U =
T,
186 enable_if_t< (is_pointer_t(U)), int> = 0>
194 template <
typename U =
T,
202 template <
typename U =
T,
211 enable_if_t< (!is_pointer_t(U)), int> = 0>
220 template <
typename U,
typename VectorU_t,
221 enable_if_t< (is_pointer_t(typename VectorU_t::value_type)), int> = 0>
224 VectorU_t* aHitsVector = right.
GetVector();
225 for(
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr)
227 auto _ptr = (*itr) ? (*itr) :
null();
229 add<U>(std::distance(aHitsVector->begin(), itr), *_ptr);
234 template <
typename U,
typename VectorU_t,
235 enable_if_t< (!is_pointer_t(typename VectorU_t::value_type)), int> = 0>
238 VectorU_t* aHitsVector = right.
GetVector();
239 for(
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr)
241 auto _ptr = (*itr) ? (*itr) :
allocate();
242 add<U>(std::distance(aHitsVector->begin(), itr), _ptr);
247 template <
typename U,
typename MapU_t,
248 enable_if_t< (is_pointer_t(typename MapU_t::mapped_type)), int> = 0>
251 MapU_t* aHitsMap = right.
GetMap();
252 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
253 add<U>(itr->first, *(itr->second));
257 template <
typename U,
typename MapU_t,
258 enable_if_t< !(is_pointer_t(typename MapU_t::mapped_type)), int> = 0>
261 MapU_t* aHitsMap = right.
GetMap();
262 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
263 add<U>(itr->first, itr->second);
276 template <
typename U =
T,
277 enable_if_t< is_same_t(U, T), int> = 0>
281 _add(theHitsVector, key, *aHit);
282 return theHitsVector->size();
287 template <
typename U =
T,
288 enable_if_t< !is_same_t(U, T), int> = 0>
294 _add(theHitsVector, key, *hit);
295 return theHitsVector->size();
300 template <
typename U =
T,
301 enable_if_t< is_same_t(U, T), int> = 0>
305 _add(theHitsVector, key, aHit);
306 return theHitsVector->size();
311 template <
typename U =
T,
312 enable_if_t< !is_same_t(U, T), int> = 0>
316 _add(theHitsVector, key, aHit);
317 return theHitsVector->size();
328 template <
typename U =
T,
329 enable_if_t< is_same_t(U, T), int> = 0>
330 inline std::size_t
set(
const G4int& key, U*& aHit)
const
333 _assign(theHitsVector, key, aHit);
334 return theHitsVector->size();
339 template <
typename U =
T,
340 enable_if_t< !is_same_t(U, T), int> = 0>
341 inline std::size_t
set(
const G4int & key, U*& aHit)
const
346 _assign(theHitsVector, key, hit);
347 return theHitsVector->size();
358 template <
typename U =
T,
359 enable_if_t< is_same_t(U, T), int> = 0>
360 inline std::size_t
set(
const G4int& key, U& aHit)
const
363 _assign(theHitsVector, key, &aHit);
364 return theHitsVector->size();
369 template <
typename U =
T,
370 enable_if_t< !is_same_t(U, T), int> = 0>
371 inline std::size_t
set(
const G4int & key, U& aHit)
const
376 _assign(theHitsVector, key, &aHit);
377 return theHitsVector->size();
386 resize(theHitsVector, key);
393 resize(theHitsVector, key);
400 enable_if_t< (is_pointer_t(U)), int> = 0>
402 const G4int& key)
const
405 if(key >= theHitsVector->size())
406 theHitsVector->resize(key+1,
null());
409 if(!theHitsVector->at(key))
412 _assign(theHitsVector, key, init);
417 enable_if_t< (!is_pointer_t(U)), int> = 0>
419 const G4int& key)
const
422 if(key >= theHitsVector->size())
423 theHitsVector->resize(key+1,
null());
429 resize(theHitsVector, key);
430 return theHitsVector;
438 enable_if_t< is_pointer_t(U), int> = 0>
441 delete (*theHitsVector)[key];
442 *(*theHitsVector)[key] = val;
446 enable_if_t< is_pointer_t(U), int> = 0>
449 delete (*theHitsVector)[key];
450 (*theHitsVector)[key] = val;
454 enable_if_t< is_pointer_t(U), int> = 0>
457 *(*theHitsVector)[key] += val;
461 enable_if_t< is_pointer_t(U), int> = 0>
464 *(*theHitsVector)[key] += *val;
467 template <
typename V,
typename U =
store_type,
468 enable_if_t< is_pointer_t(U), int> = 0>
471 *(*theHitsVector)[key] += val;
474 template <
typename V,
typename U =
store_type,
475 enable_if_t< is_pointer_t(U), int> = 0>
478 *(*theHitsVector)[key] += *val;
482 enable_if_t< is_pointer_t(U), int> = 0>
489 enable_if_t< is_pointer_t(U), int> = 0>
492 for(
iterator itr = theHitsVector->begin(); itr != theHitsVector->end(); ++itr)
497 enable_if_t< is_pointer_t(U), int> = 0>
508 enable_if_t< !is_pointer_t(U), int> = 0>
511 (*theHitsVector)[key] = val;
515 enable_if_t< !is_pointer_t(U), int> = 0>
518 delete (*theHitsVector)[key];
519 (*theHitsVector)[key] = *val;
523 enable_if_t< !is_pointer_t(U), int> = 0>
526 (*theHitsVector)[key] += val;
530 enable_if_t< !is_pointer_t(U), int> = 0>
533 (*theHitsVector)[key] += *val;
536 template <
typename V,
538 enable_if_t< !is_pointer_t(U), int> = 0>
541 (*theHitsVector)[key] += val;
544 template <
typename V,
546 enable_if_t< !is_pointer_t(U), int> = 0>
549 (*theHitsVector)[key] += *val;
553 enable_if_t< !is_pointer_t(U), int> = 0>
558 enable_if_t< !is_pointer_t(U), int> = 0>
565 #undef is_fundamental_t
568 #undef is_std_uomap_t
569 #undef is_std_uommap_t
577 template <
typename T,
typename Vector_t>
580 theCollection =
static_cast<void*
>(
new Vector_t);
584 resize(theHitsVector, init_size-1);
590 template <
typename T,
typename Vector_t>
599 resize(theHitsVector, init_size-1);
605 template <
typename T,
typename Vector_t>
609 delete_contents(theHitsVector);
610 delete theHitsVector;
615 template <
typename T,
typename Vector_t>
623 template <
typename T,
typename Vector_t>
630 for(std::size_t i = 0; i < theHitsVector->size(); ++i)
634 (*theHitsMap)[i] = _obj;
640 template <
typename T,
typename Vector_t>
646 template <
typename T,
typename Vector_t>
649 G4cout <<
"G4THitsVector " << SDname <<
" / " << collectionName <<
" --- "
650 << entries() <<
" entries" <<
G4endl;
667 template <
typename T,
typename Vector_t>
671 delete_contents(theHitsVector);
672 theHitsVector->clear();
683 template <
typename _Tp>
694 using parent_type::operator +=;
695 using parent_type::operator ==;
696 using parent_type::operator [];
715 template <
typename _Tp>
726 using parent_type::operator +=;
727 using parent_type::operator ==;
728 using parent_type::operator [];