28#ifndef G4THitsVector_h
29#define G4THitsVector_h 1
39#include <unordered_map>
51template <
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) \
77 (is_std_map_t(_Mp) ||\ is_std_mmap_t(_Mp) || \ is_std_uomap_t( \
78 _Mp) || \ is_std_uommap_t(_Mp))
79#define is_pointer_t(_Tp) std::is_pointer<_Tp>::value
80#define scast(_Tp) static_cast<_Tp>
82 template <
bool _Bp,
typename _Tp =
void>
83 using enable_if_t =
typename std::enable_if<_Bp, _Tp>::type;
110 return std::distance(
begin(), itr);
115 return std::distance(
begin(), itr);
118 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
125 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
131 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
137 template <
typename U = store_type, enable_if_t<(!is_po
inter_t(U)), G4
int> = 0>
144 template <
typename U = store_type, enable_if_t<(!is_po
inter_t(U)), G4
int> = 0>
150 template <
typename U = store_type, enable_if_t<(!is_po
inter_t(U)), G4
int> = 0>
189 template <
typename U = T,
typename V =
store_type,
198 template <
typename U = T,
typename V =
store_type,
206 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
216 template <
typename U = T,
typename V =
store_type,
224 template <
typename U = T,
typename V =
store_type,
232 template <
typename U = store_type, enable_if_t<(!is_po
inter_t(U)), G4
int> = 0>
244 typename U,
typename VectorU_t,
248 VectorU_t* aHitsVector = right.
GetVector();
249 for(
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr)
251 auto _ptr = (*itr) ? (*itr) :
null();
253 add<U>(std::distance(aHitsVector->begin(), itr), *_ptr);
259 typename U,
typename VectorU_t,
263 VectorU_t* aHitsVector = right.
GetVector();
264 for(
auto itr = aHitsVector->begin(); itr != aHitsVector->end(); ++itr)
266 auto _ptr = (*itr) ? (*itr) :
allocate();
267 add<U>(std::distance(aHitsVector->begin(), itr), _ptr);
273 typename U,
typename MapU_t,
277 MapU_t* aHitsMap = right.
GetMap();
278 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
279 add<U>(itr->first, *(itr->second));
284 typename U,
typename MapU_t,
288 MapU_t* aHitsMap = right.
GetMap();
289 for(
auto itr = aHitsMap->begin(); itr != aHitsMap->end(); ++itr)
290 add<U>(itr->first, itr->second);
303 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
307 _add(theHitsVector, key, *aHit);
308 return theHitsVector->size();
313 template <
typename U = T, enable_if_t<!is_same_t(U, T), G4
int> = 0>
319 _add(theHitsVector, key, *hit);
320 return theHitsVector->size();
325 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
329 _add(theHitsVector, key, aHit);
330 return theHitsVector->size();
335 template <
typename U = T, enable_if_t<!is_same_t(U, T), G4
int> = 0>
339 _add(theHitsVector, key, aHit);
340 return theHitsVector->size();
351 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
352 inline std::size_t
set(
const G4int& key, U*& aHit)
const
355 _assign(theHitsVector, key, aHit);
356 return theHitsVector->size();
361 template <
typename U = T, enable_if_t<!is_same_t(U, T), G4
int> = 0>
362 inline std::size_t
set(
const G4int& key, U*& aHit)
const
367 _assign(theHitsVector, key, hit);
368 return theHitsVector->size();
379 template <
typename U = T, enable_if_t<is_same_t(U, T), G4
int> = 0>
380 inline std::size_t
set(
const G4int& key, U& aHit)
const
383 _assign(theHitsVector, key, &aHit);
384 return theHitsVector->size();
389 template <
typename U = T, enable_if_t<!is_same_t(U, T), G4
int> = 0>
390 inline std::size_t
set(
const G4int& key, U& aHit)
const
395 _assign(theHitsVector, key, &aHit);
396 return theHitsVector->size();
405 resize(theHitsVector, key);
412 resize(theHitsVector, key);
418 template <
typename U = store_type, enable_if_t<(is_po
inter_t(U)), G4
int> = 0>
422 if(key >= (
G4int) theHitsVector->size())
423 theHitsVector->resize(key + 1,
null());
426 if(!theHitsVector->at(key))
429 _assign(theHitsVector, key, init);
433 template <
typename U = store_type, enable_if_t<(!is_po
inter_t(U)), G4
int> = 0>
437 if(key >= (
G4int) theHitsVector->size())
438 theHitsVector->resize(key + 1,
null());
444 resize(theHitsVector, key);
445 return theHitsVector;
452 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
455 delete(*theHitsVector)[key];
456 *(*theHitsVector)[key] = val;
459 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
462 delete(*theHitsVector)[key];
463 (*theHitsVector)[key] = val;
466 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
469 *(*theHitsVector)[key] += val;
472 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
475 *(*theHitsVector)[key] += *val;
478 template <
typename V,
typename U =
store_type,
482 *(*theHitsVector)[key] += val;
485 template <
typename V,
typename U =
store_type,
489 *(*theHitsVector)[key] += *val;
492 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
498 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
501 for(
iterator itr = theHitsVector->begin(); itr != theHitsVector->end();
506 template <
typename U = store_type, enable_if_t<is_po
inter_t(U), G4
int> = 0>
516 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
519 (*theHitsVector)[key] = val;
522 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
525 delete(*theHitsVector)[key];
526 (*theHitsVector)[key] = *val;
529 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
532 (*theHitsVector)[key] += val;
535 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
538 (*theHitsVector)[key] += *val;
541 template <
typename V,
typename U =
store_type,
545 (*theHitsVector)[key] += val;
548 template <
typename V,
typename U =
store_type,
552 (*theHitsVector)[key] += *val;
555 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
559 template <
typename U = store_type, enable_if_t<!is_po
inter_t(U), G4
int> = 0>
566#undef is_fundamental_t
570#undef is_std_uommap_t
578template <
typename T,
typename Vector_t>
581 theCollection =
static_cast<void*
>(
new Vector_t);
585 resize(theHitsVector, init_size - 1);
591template <
typename T,
typename Vector_t>
600 resize(theHitsVector, init_size - 1);
606template <
typename T,
typename Vector_t>
610 delete_contents(theHitsVector);
611 delete theHitsVector;
616template <
typename T,
typename Vector_t>
625template <
typename T,
typename Vector_t>
632 for(std::size_t i = 0; i < theHitsVector->size(); ++i)
636 (*theHitsMap)[i] = _obj;
642template <
typename T,
typename Vector_t>
650template <
typename T,
typename Vector_t>
653 G4cout <<
"G4THitsVector " << SDname <<
" / " << collectionName <<
" --- "
654 << entries() <<
" entries" <<
G4endl;
671template <
typename T,
typename Vector_t>
675 delete_contents(theHitsVector);
676 theHitsVector->clear();
687template <
typename _Tp>
701 using parent_type::operator+=;
702 using parent_type::operator==;
703 using parent_type::operator[];
722template <
typename _Tp>
736 using parent_type::operator+=;
737 using parent_type::operator==;
738 using parent_type::operator[];
#define is_fundamental_t(_Tp)
#define is_pointer_t(_Tp)
G4GLOB_DLL std::ostream G4cout
G4VTHitsVector< _Tp, std::deque< _Tp * > > parent_type
G4THitsDeque(G4int init_size=0)
G4THitsDeque(G4String detName, G4String colName, G4int init_size=0)
G4THitsVector(G4int init_size=0)
G4VTHitsVector< _Tp, std::vector< _Tp * > > parent_type
G4THitsVector(G4String detName, G4String colName, G4int init_size=0)
void _assign(vector_type *&theHitsVector, const G4int &key, T &val) const
T * GetObject(G4int idx) const
vector_type::const_iterator const_iterator
const_iterator cend() const
void delete_contents(vector_type *&theHitsVector) const
std::unordered_multimap< G4int, store_type > uommap_t
void _add(vector_type *&theHitsVector, const G4int &key, V *&val) const
G4bool operator==(const this_type &rhs) const
void _add(vector_type *&theHitsVector, const G4int &key, V &val) const
virtual ~G4VTHitsVector()
void _add(vector_type *&theHitsVector, const G4int &key, T &val) const
std::map< G4int, store_type > map_t
Vector_t::size_type GetIndex(iterator itr)
std::unordered_map< G4int, store_type > uomap_t
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
virtual void PrintAllHits()
std::multimap< G4int, store_type > mmap_t
Vector_t * GetVector() const
const_iterator begin() const
G4VTHitsVector(G4int init_size=0)
std::size_t set(const G4int &key, U *&aHit) const
Vector_t::value_type store_type
vector_type::iterator iterator
void _assign(vector_type *&theHitsVector, const G4int &key, T *&val) const
virtual void DrawAllHits()
void resize(vector_type *&theHitsVector, const G4int &key) const
std::size_t add(const G4int &key, U *&aHit) const
const T * GetObject(const_iterator itr) const
T * GetObject(iterator itr) const
virtual std::size_t GetSize() const
T * operator[](G4int key) const
G4VTHitsVector(G4String detName, G4String colNam, G4int init_size=0)
vector_type * GetVector(const G4int &key) const
std::pair< G4int, store_type > pair_t
Vector_t * GetContainer() const
store_type allocate() const
std::size_t add(const G4int &key, U &aHit) const
std::size_t entries() const
G4VTHitsVector< T, Vector_t > this_type
const_iterator end() const
virtual G4VHit * GetHit(std::size_t) const
T & get_reference(U &val) const
#define G4ThreadLocalStatic