DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Geant4HitCollection.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/InstanceCount.h"
18 #include "DDG4/Geant4Data.h"
19 #include "G4Allocator.hh"
20 
21 using namespace DD4hep;
22 using namespace DD4hep::Simulation;
23 
24 G4ThreadLocal G4Allocator<Geant4HitWrapper>* HitWrapperAllocator = 0;
25 
27 }
28 
31  : cast(c), vec_type(v) {
33 }
34 
38 }
39 
42  if (m_data.first && m_data.second) {
43  (*m_data.second->cast.destroy)(m_data.first);
44  m_data.first = 0;
45  }
46 }
47 
49 void* Geant4HitWrapper::operator new(size_t) {
50  if ( HitWrapperAllocator )
51  return HitWrapperAllocator->MallocSingle();
52  HitWrapperAllocator = new G4Allocator<Geant4HitWrapper>;
53  return HitWrapperAllocator->MallocSingle();
54 }
55 
57 void Geant4HitWrapper::operator delete(void *p) {
58  HitWrapperAllocator->FreeSingle((Geant4HitWrapper*) p);
59 }
60 
63  void* p = m_data.first;
64  m_data.first = 0;
65  m_data.second = manipulator<InvalidHit>();
66  return p;
67 }
68 
71  Wrapper w = m_data;
72  m_data.first = 0;
73  m_data.second = manipulator<InvalidHit>();
74  return w;
75 }
76 
79 }
80 
83  m_hits.clear();
84  m_keys.clear();
86 }
87 
90  return m_manipulator->cast;
91 }
92 
95  return m_manipulator->vec_type;
96 }
97 
101 }
102 
105  m_lastHit = ULONG_MAX;
106  m_hits.clear();
107  m_keys.clear();
108 }
109 
112  void* p = 0;
113  WrappedHits::const_iterator i = m_hits.begin();
114  if ( m_flags.bits.repeatedLookup && m_lastHit < m_hits.size() ) {
115  if ( (p = cmp(*(i+m_lastHit))) != 0 ) return p;
116  }
117  for (size_t cnt=0; i != m_hits.end(); ++i, ++cnt) {
118  if ((p = cmp(*i)) != 0) {
119  m_lastHit = cnt;
120  return p;
121  }
122  }
123  return p;
124 }
125 
128  Keys::const_iterator i=m_keys.find(key);
129  if ( i == m_keys.end() ) return 0;
130  m_lastHit = (*i).second;
131  return &m_hits.at(m_lastHit);
132 }
133 
135 void Geant4HitCollection::releaseData(const ComponentCast& cast, std::vector<void*>* result) {
136  for (size_t j = 0, n = m_hits.size(); j < n; ++j) {
137  Geant4HitWrapper& w = m_hits.at(j);
138  Manip* m = w.manip();
139  if (&cast == &m->cast)
140  result->push_back(w.release());
141  else
142  result->push_back(m->cast.apply_downCast(cast, w.release()));
143  }
144  m_lastHit = ULONG_MAX;
145  m_keys.clear();
146 }
147 
149 void Geant4HitCollection::getData(const ComponentCast& cast, std::vector<void*>* result) {
150  for (size_t j = 0, n = m_hits.size(); j < n; ++j) {
151  Geant4HitWrapper& w = m_hits.at(j);
152  Manip* m = w.manip();
153  if (&cast == &m->cast)
154  result->push_back(w.data());
155  else
156  result->push_back(m->cast.apply_downCast(cast, w.data()));
157  }
158 }
159 
161 void Geant4HitCollection::releaseHitsUnchecked(std::vector<void*>& result) {
162  for (size_t j = 0, n = m_hits.size(); j < n; ++j) {
163  Geant4HitWrapper& w = m_hits.at(j);
164  result.push_back(w.release());
165  }
166  m_lastHit = ULONG_MAX;
167  m_keys.clear();
168 }
169 
171 void Geant4HitCollection::getHitsUnchecked(std::vector<void*>& result) {
172  for (size_t j = 0, n = m_hits.size(); j < n; ++j) {
173  Geant4HitWrapper& w = m_hits.at(j);
174  result.push_back(w.data());
175  }
176 }
void releaseData(const ComponentCast &cast, std::vector< void * > *result)
Release all hits from the Geant4 container and pass ownership to the caller.
void * findHit(const Compare &cmp)
Find hit in a collection by comparison of attributes.
static void decrement(T *)
Decrement count according to type information.
Geant4HitWrapper * findHitByKey(VolumeID key)
Find hit in a collection by comparison of the key.
void * release()
Pointer/Object release.
const ComponentCast & vector_type() const
Type information of the vector type for extracting data.
void newInstance()
Notification to increase the instance counter.
G4ThreadLocal G4Allocator< Geant4HitWrapper > * HitWrapperAllocator
HitManipulator(const ComponentCast &c, const ComponentCast &v)
Initializing Constructor.
Generic wrapper class for hit structures created in Geant4 sensitive detectors.
void getData(const ComponentCast &cast, std::vector< void * > *result)
Release all hits from the Geant4 container. Ownership stays with the container.
Generic class template to compare/select hits in Geant4HitCollection objects.
void * apply_downCast(const ComponentCast &to, const void *ptr) const
Apply cast using typeinfo instead of dynamic_cast.
Definition: Primitives.cpp:367
virtual ~Geant4HitWrapper()
Default destructor.
void releaseHitsUnchecked(std::vector< void * > &result)
Release all hits from the Geant4 container and pass ownership to the caller.
Class to perform dynamic casts using unknown pointers.
Definition: Primitives.h:168
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
virtual ~Geant4HitCollection()
Default destructor.
View * v
Definition: MultiView.cpp:30
long long int VolumeID
Definition: Primitives.h:35
HitManipulator * manip() const
Access to cast grammar.
void * data()
Pointer/Object access.
const ComponentCast & type() const
Type information of the object stored.
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...
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294
virtual void clear()
Clear the collection (Deletes all valid references to real hits)
static unsigned long m_flags