28#ifndef G4THitsVector_h
29#define G4THitsVector_h 1
37#include <unordered_map>
50template <
typename T,
typename Vector_t = std::deque<T*>>
57 using iterator =
typename vector_type::iterator;
61 using pair_t = std::pair<G4int, store_type>;
62 using map_t = std::map<G4int, store_type>;
63 using uomap_t = std::unordered_map<G4int, store_type>;
64 using mmap_t = std::multimap<G4int, store_type>;
65 using uommap_t = std::unordered_multimap<G4int, store_type>;
68#define is_same_t(_Tp, _Up) std::is_same<_Tp, _Up>::value
69#define is_fundamental_t(_Tp) std::is_fundamental<_Tp>::value
71#define is_std_map_t(_Mp) std::is_same<_Mp, map_t>::value
72#define is_std_uomap_t(_Mp) std::is_same<_Mp, uomap_t>::value
73#define is_std_mmap_t(_Mp) std::is_same<_Mp, mmap_t>::value
74#define is_std_uommap_t(_Mp) std::is_same<_Mp, uommap_t>::value
75#define is_map_t(_Mp) \
76 (is_std_map_t(_Mp) ||\ is_std_mmap_t(_Mp) || \ is_std_uomap_t(_Mp) || \ is_std_uommap_t(_Mp))
77#define is_pointer_t(_Tp) std::is_pointer<_Tp>::value
78#define scast(_Tp) static_cast<_Tp>
80 template <
bool _Bp,
typename _Tp =
void>
81 using enable_if_t =
typename std::enable_if<_Bp, _Tp>::type;
107 return std::distance(
begin(), itr);
110 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
116 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
122 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
128 template <
typename U = store_type, enable_if_t<(! is_po
inter_t(U)), G4
int> = 0>
134 template <
typename U = store_type, enable_if_t<(! is_po
inter_t(U)), G4
int> = 0>
140 template <
typename U = store_type, enable_if_t<(! is_po
inter_t(U)), G4
int> = 0>
173 template <
typename U = T,
typename V =
store_type,
182 template <
typename U = T,
typename V =
store_type,
190 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
200 template <
typename U = T,
typename V =
store_type,
208 template <
typename U = T,
typename V =
store_type,
216 template <
typename U = store_type, enable_if_t<(! is_po
inter_t(U)), G4
int> = 0>
227 template <
typename U,
typename VectorU_t,
231 VectorU_t* aHitsVector = right.
GetVector();
232 for (
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr) {
233 auto _ptr = (*itr) ? (*itr) :
null();
234 if (_ptr)
add<U>(std::distance(aHitsVector->begin(), itr), *_ptr);
239 template <
typename U,
typename VectorU_t,
243 VectorU_t* aHitsVector = right.
GetVector();
244 for (
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr) {
245 auto _ptr = (*itr) ? (*itr) :
allocate();
246 add<U>(std::distance(aHitsVector->begin(), itr), _ptr);
251 template <
typename U,
typename MapU_t,
255 MapU_t* aHitsMap = right.
GetMap();
256 for (
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
257 add<U>(itr->first, *(itr->second));
261 template <
typename U,
typename MapU_t,
265 MapU_t* aHitsMap = right.
GetMap();
266 for (
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
267 add<U>(itr->first, itr->second);
280 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
284 _add(theHitsVector, key, *aHit);
285 return theHitsVector->size();
290 template <
typename U = T, enable_if_t<! is_same_t(U, T), G4
int> = 0>
296 _add(theHitsVector, key, *hit);
297 return theHitsVector->size();
302 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
306 _add(theHitsVector, key, aHit);
307 return theHitsVector->size();
312 template <
typename U = T, enable_if_t<! is_same_t(U, T), G4
int> = 0>
316 _add(theHitsVector, key, aHit);
317 return theHitsVector->size();
328 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
329 inline std::size_t
set(
const G4int& key, U*& aHit)
const
332 _assign(theHitsVector, key, aHit);
333 return theHitsVector->size();
338 template <
typename U = T, enable_if_t<! is_same_t(U, T), G4
int> = 0>
339 inline std::size_t
set(
const G4int& key, U*& aHit)
const
344 _assign(theHitsVector, key, hit);
345 return theHitsVector->size();
356 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
357 inline std::size_t
set(
const G4int& key, U& aHit)
const
360 _assign(theHitsVector, key, &aHit);
361 return theHitsVector->size();
366 template <
typename U = T, enable_if_t<! is_same_t(U, T), G4
int> = 0>
367 inline std::size_t
set(
const G4int& key, U& aHit)
const
372 _assign(theHitsVector, key, &aHit);
373 return theHitsVector->size();
382 resize(theHitsVector, key);
389 resize(theHitsVector, key);
395 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
399 if (key >= (
G4int)theHitsVector->size()) theHitsVector->resize(key + 1,
null());
402 if (! theHitsVector->at(key)) {
404 _assign(theHitsVector, key, init);
408 template <
typename U = store_type, enable_if_t<(! is_po
inter_t(U)), G4
int> = 0>
412 if (key >= (
G4int)theHitsVector->size()) theHitsVector->resize(key + 1,
null());
418 resize(theHitsVector, key);
419 return theHitsVector;
426 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
429 delete (*theHitsVector)[key];
430 *(*theHitsVector)[key] = val;
433 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
436 delete (*theHitsVector)[key];
437 (*theHitsVector)[key] = val;
440 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
443 *(*theHitsVector)[key] += val;
446 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
449 *(*theHitsVector)[key] += *val;
452 template <
typename V,
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
455 *(*theHitsVector)[key] += val;
458 template <
typename V,
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
461 *(*theHitsVector)[key] += *val;
464 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
470 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
473 for (
auto itr = theHitsVector->begin(); itr != theHitsVector->end(); ++itr)
477 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
487 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
490 (*theHitsVector)[key] = val;
493 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
496 delete (*theHitsVector)[key];
497 (*theHitsVector)[key] = *val;
500 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
503 (*theHitsVector)[key] += val;
506 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
509 (*theHitsVector)[key] += *val;
512 template <
typename V,
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
515 (*theHitsVector)[key] += val;
518 template <
typename V,
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
521 (*theHitsVector)[key] += *val;
524 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
528 template <
typename U = store_type, enable_if_t<! is_po
inter_t(U), G4
int> = 0>
535#undef is_fundamental_t
539#undef is_std_uommap_t
547template <
typename T,
typename Vector_t>
550 theCollection =
static_cast<void*
>(
new Vector_t);
553 resize(theHitsVector, init_size - 1);
559template <
typename T,
typename Vector_t>
566 resize(theHitsVector, init_size - 1);
572template <
typename T,
typename Vector_t>
576 delete_contents(theHitsVector);
577 delete theHitsVector;
582template <
typename T,
typename Vector_t>
590template <
typename T,
typename Vector_t>
596 for (std::size_t i = 0; i < theHitsVector->size(); ++i) {
598 if (_obj) (*theHitsMap)[i] = _obj;
604template <
typename T,
typename Vector_t>
612template <
typename T,
typename Vector_t>
615 G4cout <<
"G4THitsVector " << SDname <<
" / " << collectionName <<
" --- " << entries()
633template <
typename T,
typename Vector_t>
637 delete_contents(theHitsVector);
638 theHitsVector->clear();
649template <
typename _Tp>
661 using parent_type::operator+=;
662 using parent_type::operator==;
663 using parent_type::operator[];
664 using parent_type::add;
665 using parent_type::begin;
666 using parent_type::cbegin;
667 using parent_type::cend;
668 using parent_type::clear;
669 using parent_type::DrawAllHits;
670 using parent_type::end;
671 using parent_type::entries;
672 using parent_type::GetHit;
673 using parent_type::GetMap;
674 using parent_type::GetSize;
675 using parent_type::GetVector;
676 using parent_type::PrintAllHits;
677 using parent_type::set;
682template <
typename _Tp>
694 using parent_type::operator+=;
695 using parent_type::operator==;
696 using parent_type::operator[];
#define is_fundamental_t(_Tp)
#define is_pointer_t(_Tp)
G4GLOB_DLL std::ostream G4cout
G4THitsDeque(G4int init_size=0)
G4THitsDeque(G4String detName, G4String colName, G4int init_size=0)
G4THitsVector(G4int init_size=0)
G4THitsVector(G4String detName, G4String colName, G4int init_size=0)
void _assign(vector_type *&theHitsVector, const G4int &key, T &val) const
typename vector_type::iterator iterator
std::size_t GetSize() const override
T * GetObject(G4int idx) const
const_iterator cend() const
void delete_contents(vector_type *&theHitsVector) const
std::multimap< G4int, store_type > mmap_t
void _add(vector_type *&theHitsVector, const G4int &key, V *&val) const
G4bool operator==(const this_type &rhs) const
G4VHit * GetHit(std::size_t) const override
void _add(vector_type *&theHitsVector, const G4int &key, V &val) const
std::pair< G4int, store_type > pair_t
~G4VTHitsVector() override
void _add(vector_type *&theHitsVector, const G4int &key, T &val) const
Vector_t::size_type GetIndex(iterator itr)
std::size_t set(const G4int &key, U &aHit) const
void _add(vector_type *&theHitsVector, const G4int &key, T *&val) const
Vector_t::size_type size()
Vector_t::size_type GetIndex(const_iterator itr) const
void delete_contents(vector_type *&) const
const_iterator cbegin() const
std::map< G4int, store_type > map_t
typename Vector_t::value_type store_type
typename vector_type::const_iterator const_iterator
Vector_t * GetVector() const
std::unordered_map< G4int, store_type > uomap_t
const_iterator begin() const
G4VTHitsVector(G4int init_size=0)
std::size_t set(const G4int &key, U *&aHit) const
void _assign(vector_type *&theHitsVector, const G4int &key, T *&val) const
void resize(vector_type *&theHitsVector, const G4int &key) const
void DrawAllHits() override
std::size_t add(const G4int &key, U *&aHit) const
void PrintAllHits() override
const T * GetObject(const_iterator itr) const
T * GetObject(iterator itr) const
std::unordered_multimap< G4int, store_type > uommap_t
T * operator[](G4int key) const
G4VTHitsVector(G4String detName, G4String colNam, G4int init_size=0)
vector_type * GetVector(const G4int &key) const
Vector_t * GetContainer() const
store_type allocate() const
std::size_t add(const G4int &key, U &aHit) const
std::size_t entries() const
const_iterator end() const
T & get_reference(U &val) const
#define G4ThreadLocalStatic