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) ( 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>
84 using enable_if_t =
typename std::enable_if<_Bp, _Tp>::type;
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)), G4
int> = 0>
118 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>
126 template <
typename U = store_type, enable_if_t< (!is_po
inter_t(U)), G4
int> = 0>
130 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>
168 template <
typename U = T,
173 {
return new T(0.); }
177 template <
typename U = T,
194 template <
typename U = T,
202 template <
typename U = T,
220 template <
typename U,
typename VectorU_t,
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,
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,
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,
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,
281 _add(theHitsVector, key, *aHit);
282 return theHitsVector->size();
287 template <
typename U = T,
294 _add(theHitsVector, key, *hit);
295 return theHitsVector->size();
300 template <
typename U = T,
305 _add(theHitsVector, key, aHit);
306 return theHitsVector->size();
311 template <
typename U = T,
316 _add(theHitsVector, key, aHit);
317 return theHitsVector->size();
328 template <
typename U = T,
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,
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,
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,
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);
402 const G4int& key)
const
405 if(key >= (
G4int)theHitsVector->size())
406 theHitsVector->resize(key+1,
null());
409 if(!theHitsVector->at(key))
412 _assign(theHitsVector, key, init);
419 const G4int& key)
const
422 if(key >= (
G4int)theHitsVector->size())
423 theHitsVector->resize(key+1,
null());
429 resize(theHitsVector, key);
430 return theHitsVector;
441 delete (*theHitsVector)[key];
442 *(*theHitsVector)[key] = val;
449 delete (*theHitsVector)[key];
450 (*theHitsVector)[key] = val;
457 *(*theHitsVector)[key] += val;
464 *(*theHitsVector)[key] += *val;
467 template <
typename V,
typename U =
store_type,
471 *(*theHitsVector)[key] += val;
474 template <
typename V,
typename U =
store_type,
478 *(*theHitsVector)[key] += *val;
492 for(
iterator itr = theHitsVector->begin(); itr != theHitsVector->end(); ++itr)
511 (*theHitsVector)[key] = val;
518 delete (*theHitsVector)[key];
519 (*theHitsVector)[key] = *val;
526 (*theHitsVector)[key] += val;
533 (*theHitsVector)[key] += *val;
536 template <
typename V,
541 (*theHitsVector)[key] += val;
544 template <
typename V,
549 (*theHitsVector)[key] += *val;
565 #undef is_fundamental_t
568 #undef is_std_uomap_t
569 #undef is_std_uommap_t
577template <
typename T,
typename Vector_t>
580 theCollection =
static_cast<void*
>(
new Vector_t);
584 resize(theHitsVector, init_size-1);
590template <
typename T,
typename Vector_t>
599 resize(theHitsVector, init_size-1);
605template <
typename T,
typename Vector_t>
609 delete_contents(theHitsVector);
610 delete theHitsVector;
615template <
typename T,
typename Vector_t>
623template <
typename T,
typename Vector_t>
630 for(std::size_t i = 0; i < theHitsVector->size(); ++i)
634 (*theHitsMap)[i] = _obj;
640template <
typename T,
typename Vector_t>
646template <
typename T,
typename Vector_t>
649 G4cout <<
"G4THitsVector " << SDname <<
" / " << collectionName <<
" --- "
650 << entries() <<
" entries" <<
G4endl;
667template <
typename T,
typename Vector_t>
671 delete_contents(theHitsVector);
672 theHitsVector->clear();
683template <
typename _Tp>
694 using parent_type::operator +=;
695 using parent_type::operator ==;
696 using parent_type::operator [];
715template <
typename _Tp>
726 using parent_type::operator +=;
727 using parent_type::operator ==;
728 using parent_type::operator [];
#define is_fundamental_t(_Tp)
#define is_pointer_t(_Tp)
#define is_same_t(_Tp, _Up)
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