ATLAS Offline Software
Loading...
Searching...
No Matches
VertexView.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
13
14
15#ifndef TRIGIDR4MONITORING_VERTEXVIEW_H
16#define TRIGIDR4MONITORING_VERTEXVIEW_H
17
18#include <vector>
19#include <cstdint>
20#include <iostream>
21#include <typeinfo>
22
23#include "VertexTraits.h"
24
40
41
43
44public:
45
46 template<typename T>
47 VertexView(const T* pobj) : m_ptr(pobj), m_vtable(&table<T>) {
48#if 0
52 using BareT = std::remove_cv_t<T>;
53 static_assert( std::is_same_v<BareT, xAOD::Vertex> || std::is_same_v<BareT, xAOD::TruthVertex>,
54 "unsupported VertexView type" );
55#endif
56 }
57
58 template<typename T,
59 typename=std::enable_if_t< !std::is_pointer_v<T> && !std::is_same_v<std::decay_t<T>, VertexView> > >
60 VertexView(const T& obj) : m_ptr(&obj), m_vtable(&table<T>) { }
61
62 VertexView( const VertexView& t ) = default;
63
64 VertexView( const VertexView* ) = delete; // don't want implicitly creating a VertexView with an internal VertexView*
65 VertexView( VertexView* ) = delete;
66
67 virtual ~VertexView() = default;
68
69 const void* ptr() const { return m_ptr; }
70
71 float x() const { return m_vtable->x(m_ptr); }
72 float y() const { return m_vtable->y(m_ptr); }
73 float z() const { return m_vtable->z(m_ptr); }
74
75 float dx() const { return m_vtable->dx(m_ptr); }
76 float dy() const { return m_vtable->dy(m_ptr); }
77 float dz() const { return m_vtable->dz(m_ptr); }
78
79 size_t nTrackParticles() const { return m_vtable->nTrackParticles(m_ptr); }
80 float chiSquared() const { return m_vtable->chiSquared(m_ptr); }
81 float numberDoF() const { return m_vtable->numberDoF(m_ptr); }
82
83 float time() const { return m_vtable->time(m_ptr); }
84
85 int vertexType() const { return m_vtable->vertexType(m_ptr); }
86
87 const std::type_info& type() const { return *m_vtable->m_type; }
88
89 template<typename T> bool is() const { return type()==typeid(T); }
90
91 template<typename T> const T* as() const { return is<T>() ? static_cast<const T*>(m_ptr) : 0; }
92
93
94private:
95
96 struct VTable;
97
98 const void* m_ptr;
100
101private:
102
103 struct VTable {
104 float (*x)(const void*);
105 float (*y)(const void*);
106 float (*z)(const void*);
107
108 float (*dx)(const void*);
109 float (*dy)(const void*);
110 float (*dz)(const void*);
111
112 size_t (*nTrackParticles)(const void*);
113 float (*chiSquared)(const void*);
114 float (*numberDoF)(const void*);
115
116 float (*time)(const void*);
117
118 int (*vertexType)(const void*);
119
120 const std::type_info* m_type;
121 };
122
123 template<typename T> static const VTable table;
124
125 template<typename T>
126 static const T& deref(const void* p) { return *static_cast<const T*>(p); }
127
128 template<typename T> static float x_impl(const void* p) { return VertexTraits<T>::x(deref<T>(p)); }
129 template<typename T> static float y_impl(const void* p) { return VertexTraits<T>::y(deref<T>(p)); }
130 template<typename T> static float z_impl(const void* p) { return VertexTraits<T>::z(deref<T>(p)); }
131
132 template<typename T> static float dx_impl(const void* p) { return VertexTraits<T>::dx(deref<T>(p)); }
133 template<typename T> static float dy_impl(const void* p) { return VertexTraits<T>::dy(deref<T>(p)); }
134 template<typename T> static float dz_impl(const void* p) { return VertexTraits<T>::dz(deref<T>(p)); }
135
136 template<typename T> static size_t nTrackParticles_impl(const void* p) { return VertexTraits<T>::nTrackParticles(deref<T>(p)); }
137 template<typename T> static float chiSquared_impl(const void* p) { return VertexTraits<T>::chiSquared(deref<T>(p)); }
138 template<typename T> static float numberDoF_impl(const void* p) { return VertexTraits<T>::numberDoF(deref<T>(p)); }
139
140 template<typename T> static float time_impl(const void* p) { return VertexTraits<T>::time(deref<T>(p)); }
141
142 template<typename T> static int vertexType_impl(const void* p) { return VertexTraits<T>::vertexType(deref<T>(p)); }
143
144
145};
146
147template<typename T>
162
163
164inline std::ostream& operator<<( std::ostream& s, const VertexView& v ) {
165 s << "[ x=" << v.x()
166 << "\ty=" << v.y()
167 << "\tz=" << v.z()
168 << "\tntracks= " << v.nTrackParticles()
169 << "\ttype=" << v.vertexType()
170 << "\t : ptr=" << v.ptr()
171 << " ]";
172 return s;
173}
174
175
177inline bool dummyVertex(const VertexView& v) { return v.vertexType()==0; }
178
179
180template<typename T>
181std::vector<VertexView> makevertexview( const std::vector<const T*>& v ) {
182 std::vector<VertexView> tv( v.begin(), v.end() );
184 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
185 return tv;
186}
187
188template<typename T>
189std::vector<VertexView> makevertexview( const std::vector<T*>& v ) {
190 std::vector<VertexView> tv( v.begin(), v.end() );
192 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
193 return tv;
194}
195
196template<typename T>
197std::vector<VertexView> makevertexview( const std::vector<T>& v ) {
198 std::vector<VertexView> tv( v.begin(), v.end() );
199 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
200 return tv;
201}
202
203
204template<typename T>
205std::vector<VertexView> makevertexview( typename T::const_iterator ibegin, typename T::const_iterator iend ) {
206 std::vector<VertexView> tv( ibegin, iend );
207 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex), tv.end());
208 return tv;
209}
210
211
212#endif // TRIGIDR4MONITORING_VERTEXVIEW_H
213
214
215
216
217
218
219
220
221
222
bool dummyVertex(const VertexView &v)
annoying that they always include this "dummy" vertex ...
Definition VertexView.h:177
std::ostream & operator<<(std::ostream &s, const VertexView &v)
Definition VertexView.h:164
std::vector< VertexView > makevertexview(const std::vector< const T * > &v)
Definition VertexView.h:181
Type-erased view on a generic vertex class - implementation won't bother with any VertexTraits at the...
Definition VertexView.h:42
static float numberDoF_impl(const void *p)
Definition VertexView.h:138
VertexView(const T &obj)
Definition VertexView.h:60
static int vertexType_impl(const void *p)
Definition VertexView.h:142
static size_t nTrackParticles_impl(const void *p)
Definition VertexView.h:136
static const T & deref(const void *p)
Definition VertexView.h:126
int vertexType() const
Definition VertexView.h:85
static float z_impl(const void *p)
Definition VertexView.h:130
static float chiSquared_impl(const void *p)
Definition VertexView.h:137
float z() const
Definition VertexView.h:73
const void * m_ptr
Definition VertexView.h:98
float time() const
Definition VertexView.h:83
const VTable * m_vtable
Definition VertexView.h:99
const void * ptr() const
Definition VertexView.h:69
float y() const
Definition VertexView.h:72
static float x_impl(const void *p)
Definition VertexView.h:128
float x() const
Definition VertexView.h:71
VertexView(VertexView *)=delete
float numberDoF() const
Definition VertexView.h:81
VertexView(const T *pobj)
Definition VertexView.h:47
static float dz_impl(const void *p)
Definition VertexView.h:134
VertexView(const VertexView &t)=default
size_t nTrackParticles() const
Definition VertexView.h:79
float dz() const
Definition VertexView.h:77
const std::type_info & type() const
Definition VertexView.h:87
static float y_impl(const void *p)
Definition VertexView.h:129
const T * as() const
Definition VertexView.h:91
float dy() const
Definition VertexView.h:76
float dx() const
Definition VertexView.h:75
static float dx_impl(const void *p)
Definition VertexView.h:132
static float time_impl(const void *p)
Definition VertexView.h:140
float chiSquared() const
Definition VertexView.h:80
static float dy_impl(const void *p)
Definition VertexView.h:133
bool is() const
Definition VertexView.h:89
static const VTable table
Definition VertexView.h:148
virtual ~VertexView()=default
VertexView(const VertexView *)=delete
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
static float time(const T &)
static float z(const T &v)
static float x(const T &v)
static float y(const T &v)
static int vertexType(const T &)
static float dx(const T &)
static float dy(const T &)
static float numberDoF(const T &)
static float dz(const T &)
static float chiSquared(const T &)
static size_t nTrackParticles(const T &)
float(* x)(const void *)
Definition VertexView.h:104
float(* y)(const void *)
Definition VertexView.h:105
float(* time)(const void *)
Definition VertexView.h:116
const std::type_info * m_type
Definition VertexView.h:120
float(* z)(const void *)
Definition VertexView.h:106
size_t(* nTrackParticles)(const void *)
Definition VertexView.h:112
float(* dx)(const void *)
Definition VertexView.h:108
float(* chiSquared)(const void *)
Definition VertexView.h:113
float(* numberDoF)(const void *)
Definition VertexView.h:114
float(* dy)(const void *)
Definition VertexView.h:109
float(* dz)(const void *)
Definition VertexView.h:110
int(* vertexType)(const void *)
Definition VertexView.h:118