14 #ifndef DD4HEP_DDG4_GEANT4HITCOLLECTION_H
15 #define DD4HEP_DDG4_GEANT4HITCOLLECTION_H
20 #include "G4VHitsCollection.hh"
34 namespace Simulation {
37 class Geant4Sensitive;
38 class Geant4HitCollection;
39 class Geant4HitWrapper;
68 typedef std::pair<void*, HitManipulator*>
Wrapper;
92 throw std::runtime_error(
"Invalid hit pointer passed to collection!");
96 TYPE* p = (TYPE*) obj.first;
115 m_data.second = manipulator<InvalidHit>();
131 void *
operator new(size_t);
133 void operator delete(
void *ptr);
152 return HitManipulator::instance<TYPE>();
164 template <
typename TYPE>
operator TYPE*()
const {
165 return (TYPE*)
m_data.second->
166 cast.apply_dynCast(ComponentCast::instance<TYPE>(),
m_data.first);
209 typedef std::map<VolumeID, size_t>
Keys;
271 template <
typename TYPE>
282 template <
typename TYPE>
299 virtual void clear();
329 template <
typename TYPE>
void add(TYPE* hit_pointer) {
335 template <
typename TYPE>
void add(
VolumeID key, TYPE* hit_pointer) {
337 std::pair<Keys::iterator,bool> ret =
m_keys.insert(std::make_pair(key,
m_lastHit));
343 throw std::runtime_error(
"Attempt to insert hit with same key to G4 hit-collection "+
GetName());
351 Keys::const_iterator i=
m_keys.find(key);
352 if ( i ==
m_keys.end() )
return 0;
359 std::vector<TYPE*> vec;
361 releaseData(ComponentCast::instance<TYPE>(), (std::vector<void*>*) &vec);
371 template <
typename TYPE> std::vector<TYPE*>
getHits() {
372 std::vector<TYPE*> vec;
374 getData(ComponentCast::instance<TYPE>(), (std::vector<void*>*) &vec);
400 template <
typename TYPE,
typename POS>
403 return pos == h->position ? h : 0;
423 template <
typename TYPE>
426 if (
id == h->cellID )
434 #endif // DD4HEP_DDG4_GEANT4HITCOLLECTION_H
void releaseData(const ComponentCast &cast, std::vector< void * > *result)
Release all hits from the Geant4 container and pass ownership to the caller.
Geant4HitWrapper(const Wrapper &v)
Copy constructor.
struct DD4hep::Simulation::Geant4HitCollection::CollectionFlags::BitItems bits
virtual void * operator()(const Geant4HitWrapper &w) const =0
Comparison function.
void * findHit(const Compare &cmp)
Find hit in a collection by comparison of attributes.
std::vector< Geant4HitWrapper > WrappedHits
Hit wrapper.
Geant4HitCollection(const std::string &det, const std::string &coll, Geant4Sensitive *sd, const TYPE *)
Initializing constructor.
void setSensitive(Geant4Sensitive *detector)
Set the sensitive detector.
size_t m_lastHit
Memorize for speedup the last searched hit.
void * data() const
Pointer/Object access (CONST)
Helper class to indicate invalid hit wrappers or containers.
Specialized hit selector based on the hit's position.
TYPE * findByKey(VolumeID key)
Find hits in a collection by comparison of key value.
Geant4HitWrapper & hit(size_t which)
Access the hit wrapper.
static HitManipulator * manipulator()
Generate manipulator object.
Geant4HitWrapper * findHitByKey(VolumeID key)
Find hit in a collection by comparison of the key.
CollectionFlags m_flags
Optimization flags.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
std::pair< void *, HitManipulator * > Wrapper
void * release()
Pointer/Object release.
Class of the Geant4 toolkit. See http://www-geant4.kek.jp/Reference.
std::vector< TYPE * > getHits()
Release all hits from the Geant4 container. Ownership stays with the container.
const ComponentCast & vector_type() const
Type information of the vector type for extracting data.
virtual void * operator()(const Geant4HitWrapper &w) const
Comparison function.
virtual G4VHit * GetHit(size_t which) const
Access individual hits.
void newInstance()
Notification to increase the instance counter.
void add(VolumeID key, TYPE *hit_pointer)
Add a new hit with a check, that the hit is of the same type.
HitManipulator(const ComponentCast &c, const ComponentCast &v)
Initializing Constructor.
Generic wrapper class for hit structures created in Geant4 sensitive detectors.
virtual void * operator()(const Geant4HitWrapper &w) const
Comparison function.
Geant4HitCollection(const std::string &det, const std::string &coll, Geant4Sensitive *sd)
Initializing constructor (C++ version)
Specialized hit selector based on the hit's cell identifier.
Geant4HitWrapper & operator=(const Geant4HitWrapper &v)
Assignment transfers the pointer ownership.
const Geant4HitWrapper & hit(size_t which) const
Access the hit wrapper (CONST)
The base class for Geant4 sensitive detector actions implemented by users.
void getData(const ComponentCast &cast, std::vector< void * > *result)
Release all hits from the Geant4 container. Ownership stays with the container.
const char * GetName(T *p)
Geant4HitWrapper::HitManipulator Manip
Hit manipulator.
std::map< VolumeID, size_t > Keys
Hit key map for fast random lookup.
WrappedHits m_hits
The collection of hit pointers in the wrapped format.
void * apply_dynCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Generic class template to compare/select hits in Geant4HitCollection objects.
void add(TYPE *hit_pointer)
Add a new hit with a check, that the hit is of the same type.
Keys m_keys
Hit key map for fast random lookup.
Geant4Sensitive * m_detector
Handle to the sensitive detector.
HitManipulator::Wrapper Wrapper
virtual ~Geant4HitWrapper()
Default destructor.
static HitManipulator * instance()
void releaseHitsUnchecked(std::vector< void * > &result)
Release all hits from the Geant4 container and pass ownership to the caller.
Generic hit container class using Geant4HitWrapper objects.
TYPE * find(const Compare &cmp)
Find hits in a collection by comparison of attributes.
Geant4Sensitive * sensitive() const
Access the sensitive detector.
Class to perform dynamic casts using unknown pointers.
CellIDCompare(long long int i)
Constructor.
static void deleteHit(Wrapper &obj)
Static function to delete contained hits.
virtual ~Geant4HitCollection()
Default destructor.
void setOptimize(int flag)
Set optimization flags.
~HitManipulator()
Default destructor.
static ComponentCast & instance()
virtual ~Compare()
Default destructor.
Wrapper castHit(TYPE *obj)
Check pointer to be of proper type.
enum DD4hep::Simulation::Geant4HitCollection::@10 OptimizationFlags
virtual size_t GetSize() const
Access the collection size.
HitManipulator * manip() const
Access to cast grammar.
Manip * m_manipulator
The type of the objects in this collection. Set by the constructor.
void * data()
Pointer/Object access.
PositionCompare(const POS &p)
Constructor.
const ComponentCast & type() const
Type information of the object stored.
const ComponentCast & cast
void getHitsUnchecked(std::vector< void * > &result)
Release all hits from the Geant4 container. Ownership stays with the container.
Wrapper releaseData()
Release data for copy.
Generic type manipulation class for generic hit structures created in Geant4 sensitive detectors...
std::vector< TYPE * > releaseHits()
Release all hits from the Geant4 container and pass ownership to the caller.
Geant4HitWrapper(const Geant4HitWrapper &v)
Copy constructor.
virtual void clear()
Clear the collection (Deletes all valid references to real hits)
Geant4HitWrapper()
Default constructor.
const ComponentCast & vec_type