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 VertexView& operator=( const VertexView& v) = default;
70
71 const void* ptr() const { return m_ptr; }
72
73 float x() const { return m_vtable->x(m_ptr); }
74 float y() const { return m_vtable->y(m_ptr); }
75 float z() const { return m_vtable->z(m_ptr); }
76
77 float dx() const { return m_vtable->dx(m_ptr); }
78 float dy() const { return m_vtable->dy(m_ptr); }
79 float dz() const { return m_vtable->dz(m_ptr); }
80
81 size_t nTrackParticles() const { return m_vtable->nTrackParticles(m_ptr); }
82 float chiSquared() const { return m_vtable->chiSquared(m_ptr); }
83 float numberDoF() const { return m_vtable->numberDoF(m_ptr); }
84
85 float time() const { return m_vtable->time(m_ptr); }
86
87 int vertexType() const { return m_vtable->vertexType(m_ptr); }
88
89 const std::type_info& type() const { return *m_vtable->m_type; }
90
91 template<typename T> bool is() const { return type()==typeid(T); }
92
93 template<typename T> const T* as() const { return is<T>() ? static_cast<const T*>(m_ptr) : 0; }
94
95
96private:
97
98 struct VTable;
99
100 const void* m_ptr;
102
103private:
104
105 struct VTable {
106 float (*x)(const void*);
107 float (*y)(const void*);
108 float (*z)(const void*);
109
110 float (*dx)(const void*);
111 float (*dy)(const void*);
112 float (*dz)(const void*);
113
114 size_t (*nTrackParticles)(const void*);
115 float (*chiSquared)(const void*);
116 float (*numberDoF)(const void*);
117
118 float (*time)(const void*);
119
120 int (*vertexType)(const void*);
121
122 const std::type_info* m_type;
123 };
124
125 template<typename T> static const VTable table;
126
127 template<typename T>
128 static const T& deref(const void* p) { return *static_cast<const T*>(p); }
129
130 template<typename T> static float x_impl(const void* p) { return VertexTraits<T>::x(deref<T>(p)); }
131 template<typename T> static float y_impl(const void* p) { return VertexTraits<T>::y(deref<T>(p)); }
132 template<typename T> static float z_impl(const void* p) { return VertexTraits<T>::z(deref<T>(p)); }
133
134 template<typename T> static float dx_impl(const void* p) { return VertexTraits<T>::dx(deref<T>(p)); }
135 template<typename T> static float dy_impl(const void* p) { return VertexTraits<T>::dy(deref<T>(p)); }
136 template<typename T> static float dz_impl(const void* p) { return VertexTraits<T>::dz(deref<T>(p)); }
137
138 template<typename T> static size_t nTrackParticles_impl(const void* p) { return VertexTraits<T>::nTrackParticles(deref<T>(p)); }
139 template<typename T> static float chiSquared_impl(const void* p) { return VertexTraits<T>::chiSquared(deref<T>(p)); }
140 template<typename T> static float numberDoF_impl(const void* p) { return VertexTraits<T>::numberDoF(deref<T>(p)); }
141
142 template<typename T> static float time_impl(const void* p) { return VertexTraits<T>::time(deref<T>(p)); }
143
144 template<typename T> static int vertexType_impl(const void* p) { return VertexTraits<T>::vertexType(deref<T>(p)); }
145
146
147};
148
149template<typename T>
164
165
166inline std::ostream& operator<<( std::ostream& s, const VertexView& v ) {
167 s << "[ x=" << v.x()
168 << "\ty=" << v.y()
169 << "\tz=" << v.z()
170 << "\tntracks= " << v.nTrackParticles()
171 << "\ttype=" << v.vertexType()
172 << "\t : ptr=" << v.ptr()
173 << " ]";
174 return s;
175}
176
177
179inline bool dummyVertex(const VertexView& v) { return v.vertexType()==0; }
180
181
182template<typename T>
183std::vector<VertexView> makevertexview( const std::vector<const T*>& v ) {
184 std::vector<VertexView> tv( v.begin(), v.end() );
186 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
187 return tv;
188}
189
190template<typename T>
191std::vector<VertexView> makevertexview( const std::vector<T*>& v ) {
192 std::vector<VertexView> tv( v.begin(), v.end() );
194 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
195 return tv;
196}
197
198template<typename T>
199std::vector<VertexView> makevertexview( const std::vector<T>& v ) {
200 std::vector<VertexView> tv( v.begin(), v.end() );
201 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex ), tv.end());
202 return tv;
203}
204
205
206template<typename T>
207std::vector<VertexView> makevertexview( typename T::const_iterator ibegin, typename T::const_iterator iend ) {
208 std::vector<VertexView> tv( ibegin, iend );
209 tv.erase( std::remove_if(tv.begin(), tv.end(), dummyVertex), tv.end());
210 return tv;
211}
212
213
214#endif // TRIGIDR4MONITORING_VERTEXVIEW_H
215
216
217
218
219
220
221
222
223
224
bool dummyVertex(const VertexView &v)
annoying that they always include this "dummy" vertex ...
Definition VertexView.h:179
std::ostream & operator<<(std::ostream &s, const VertexView &v)
Definition VertexView.h:166
std::vector< VertexView > makevertexview(const std::vector< const T * > &v)
Definition VertexView.h:183
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:140
VertexView(const T &obj)
Definition VertexView.h:60
static int vertexType_impl(const void *p)
Definition VertexView.h:144
static size_t nTrackParticles_impl(const void *p)
Definition VertexView.h:138
static const T & deref(const void *p)
Definition VertexView.h:128
int vertexType() const
Definition VertexView.h:87
static float z_impl(const void *p)
Definition VertexView.h:132
static float chiSquared_impl(const void *p)
Definition VertexView.h:139
float z() const
Definition VertexView.h:75
const void * m_ptr
Definition VertexView.h:100
float time() const
Definition VertexView.h:85
const VTable * m_vtable
Definition VertexView.h:101
const void * ptr() const
Definition VertexView.h:71
float y() const
Definition VertexView.h:74
static float x_impl(const void *p)
Definition VertexView.h:130
float x() const
Definition VertexView.h:73
VertexView(VertexView *)=delete
float numberDoF() const
Definition VertexView.h:83
VertexView(const T *pobj)
Definition VertexView.h:47
static float dz_impl(const void *p)
Definition VertexView.h:136
VertexView(const VertexView &t)=default
size_t nTrackParticles() const
Definition VertexView.h:81
float dz() const
Definition VertexView.h:79
const std::type_info & type() const
Definition VertexView.h:89
VertexView & operator=(const VertexView &v)=default
static float y_impl(const void *p)
Definition VertexView.h:131
const T * as() const
Definition VertexView.h:93
float dy() const
Definition VertexView.h:78
float dx() const
Definition VertexView.h:77
static float dx_impl(const void *p)
Definition VertexView.h:134
static float time_impl(const void *p)
Definition VertexView.h:142
float chiSquared() const
Definition VertexView.h:82
static float dy_impl(const void *p)
Definition VertexView.h:135
bool is() const
Definition VertexView.h:91
static const VTable table
Definition VertexView.h:150
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:106
float(* y)(const void *)
Definition VertexView.h:107
float(* time)(const void *)
Definition VertexView.h:118
const std::type_info * m_type
Definition VertexView.h:122
float(* z)(const void *)
Definition VertexView.h:108
size_t(* nTrackParticles)(const void *)
Definition VertexView.h:114
float(* dx)(const void *)
Definition VertexView.h:110
float(* chiSquared)(const void *)
Definition VertexView.h:115
float(* numberDoF)(const void *)
Definition VertexView.h:116
float(* dy)(const void *)
Definition VertexView.h:111
float(* dz)(const void *)
Definition VertexView.h:112
int(* vertexType)(const void *)
Definition VertexView.h:120