5#include <highfive/H5File.hpp>
6#include <highfive/H5DataSet.hpp>
7#include <highfive/H5DataSpace.hpp>
17 #define RL_API __declspec(dllexport)
19 #define RL_API __declspec(dllimport)
40 Event(uint8_t ring, uint8_t fen,
double time,
double weight)
41 : ring(ring), fen(fen), time(time), weight(weight) {}
54 :
Event(r, f, t, w), channel{ro->channel}, a{ro->a}, b{ro->b}, c{ro->c}, d{ro->d} {}
55 template<
class T>
void add(T & readout)
const {
57 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
70 :
Event(r, f, t, w), om{p->om}, cathode{p->cathode}, anode{p->anode} {}
71 template<
class T>
void add(T & readout)
const {
73 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
89 :
Event(r, f, t, w), bc{p->bc}, otadc{p->otadc}, geo{p->geo}, tdc{p->tdc}, vmm{p->vmm}, channel{p->channel} {}
90 template<
class T>
void add(T & readout)
const {
91 auto r =
VMM3_readout{bc, otadc, geo, tdc, vmm, channel};
92 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
103 :
Event(r, f, t, w), channel{p->channel} {}
104 template<
class T>
void add(T & readout)
const {
106 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
118 :
Event(r, f, t, w), channel{p->channel} , pos_x{p->pos_x}, pos_y{p->pos_y} {}
119 template<
class T>
void add(T & readout)
const {
121 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
133 :
Event(r, f, t, w), channel{p->channel} , sum{p->sum}, adc{p->adc} {}
134 template<
class T>
void add(T & readout)
const {
136 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
141inline HighFive::CompoundType create_compound_caen_readout(){
143 {
"ring", HighFive::create_datatype<uint8_t>()},
144 {
"FEN", HighFive::create_datatype<uint8_t>()},
145 {
"time", HighFive::create_datatype<double>()},
146 {
"weight", HighFive::create_datatype<double>()},
147 {
"channel", HighFive::create_datatype<uint8_t>()},
148 {
"a", HighFive::create_datatype<uint16_t>()},
149 {
"b", HighFive::create_datatype<uint16_t>()},
150 {
"c", HighFive::create_datatype<uint16_t>()},
151 {
"d", HighFive::create_datatype<uint16_t>()},
155inline HighFive::CompoundType create_compound_dream_readout(){
157 {
"ring", HighFive::create_datatype<uint8_t>()},
158 {
"FEN", HighFive::create_datatype<uint8_t>()},
159 {
"time", HighFive::create_datatype<double>()},
160 {
"weight", HighFive::create_datatype<double>()},
161 {
"om", HighFive::create_datatype<uint8_t>()},
162 {
"cathode", HighFive::create_datatype<uint8_t>()},
163 {
"anode", HighFive::create_datatype<uint8_t>()},
167inline HighFive::CompoundType create_compound_vmm3_readout(){
169 {
"ring", HighFive::create_datatype<uint8_t>()},
170 {
"FEN", HighFive::create_datatype<uint8_t>()},
171 {
"time", HighFive::create_datatype<double>()},
172 {
"weight", HighFive::create_datatype<double>()},
173 {
"bc", HighFive::create_datatype<uint16_t>()},
174 {
"otadc", HighFive::create_datatype<uint16_t>()},
175 {
"geo", HighFive::create_datatype<uint8_t>()},
176 {
"tdc", HighFive::create_datatype<uint8_t>()},
177 {
"vmm", HighFive::create_datatype<uint8_t>()},
178 {
"channel", HighFive::create_datatype<uint8_t>()},
182inline HighFive::CompoundType create_compound_bm0_readout(){
184 {
"ring", HighFive::create_datatype<uint8_t>()},
185 {
"FEN", HighFive::create_datatype<uint8_t>()},
186 {
"time", HighFive::create_datatype<double>()},
187 {
"weight", HighFive::create_datatype<double>()},
188 {
"channel", HighFive::create_datatype<uint8_t>()},
192inline HighFive::CompoundType create_compound_bm2_readout(){
194 {
"ring", HighFive::create_datatype<uint8_t>()},
195 {
"FEN", HighFive::create_datatype<uint8_t>()},
196 {
"time", HighFive::create_datatype<double>()},
197 {
"weight", HighFive::create_datatype<double>()},
198 {
"channel", HighFive::create_datatype<uint8_t>()},
199 {
"pos_x", HighFive::create_datatype<uint16_t>()},
200 {
"pos_y", HighFive::create_datatype<uint16_t>()},
204inline HighFive::CompoundType create_compound_bmi_readout(){
206 {
"ring", HighFive::create_datatype<uint8_t>()},
207 {
"FEN", HighFive::create_datatype<uint8_t>()},
208 {
"time", HighFive::create_datatype<double>()},
209 {
"weight", HighFive::create_datatype<double>()},
210 {
"channel", HighFive::create_datatype<uint8_t>()},
211 {
"sum", HighFive::create_datatype<uint8_t>()},
212 {
"adc", HighFive::create_datatype<uint32_t>()},
217 template<>
inline DataType create_datatype<CAEN_event>(){
return create_compound_caen_readout();}
218 template<>
inline DataType create_datatype<CDT_event>(){
return create_compound_dream_readout();}
219 template<>
inline DataType create_datatype<VMM3_event>(){
return create_compound_vmm3_readout();}
220 template<>
inline DataType create_datatype<BM0_event>(){
return create_compound_bm0_readout();}
221 template<>
inline DataType create_datatype<BM2_event>(){
return create_compound_bm2_readout();}
222 template<>
inline DataType create_datatype<BMI_event>(){
return create_compound_bmi_readout();}
226inline HighFive::CompoundType hdf_compound_type(
const ReadoutType readout) {
228 case ReadoutType::CAEN:
return create_compound_caen_readout();
229 case ReadoutType::CDT:
return create_compound_dream_readout();
230 case ReadoutType::VMM3:
return create_compound_vmm3_readout();
231 case ReadoutType::BM0:
return create_compound_bm0_readout();
232 case ReadoutType::BM2:
return create_compound_bm2_readout();
233 case ReadoutType::BMI:
return create_compound_bmi_readout();
234 default:
throw std::runtime_error(
"Saving this readout type is not implemented yet!");
239inline HighFive::DataType hdf5_type_for(
const std::string& canonical_type) {
240 if (canonical_type ==
"int8_t")
return HighFive::create_datatype<int8_t>();
241 if (canonical_type ==
"int16_t")
return HighFive::create_datatype<int16_t>();
242 if (canonical_type ==
"int32_t")
return HighFive::create_datatype<int32_t>();
243 if (canonical_type ==
"int64_t")
return HighFive::create_datatype<int64_t>();
244 if (canonical_type ==
"uint8_t")
return HighFive::create_datatype<uint8_t>();
245 if (canonical_type ==
"uint16_t")
return HighFive::create_datatype<uint16_t>();
246 if (canonical_type ==
"uint32_t")
return HighFive::create_datatype<uint32_t>();
247 if (canonical_type ==
"uint64_t")
return HighFive::create_datatype<uint64_t>();
248 if (canonical_type ==
"float")
return HighFive::create_datatype<float>();
249 if (canonical_type ==
"double")
return HighFive::create_datatype<double>();
250 throw std::runtime_error(
"No HDF5 type mapping for: " + canonical_type);
257inline HighFive::CompoundType build_hdf5_compound_type(
const TypeSchema & schema) {
258 std::vector<HighFive::CompoundType::member_def> members;
259 members.reserve(schema.fields.size());
261 for (
const auto& field : schema.fields) {
262 if (field.array_count > 0) {
263 throw std::runtime_error(
264 "build_hdf5_compound_type: array fields are not supported (field: " + field.name +
")"
267 members.push_back({field.name, hdf5_type_for(field.type), field.offset});
270 return HighFive::CompoundType(members, schema.total_size);
Umbrella header for the C API used by the McStas components.
Parser for C struct type descriptions into a runtime type schema.
Minimal beam-monitor readout event: channel only.
Position-resolving beam-monitor readout event: channel, x, y.
Integrating beam-monitor readout event: channel, sum, 24-bit ADC.
CAEN readout event: group channel and amplitudes A-D.
CDT (DREAM-family) readout event: output module, cathode, anode.
Common fields of every stored readout event: routing (ring, FEN), time-of-flight, and the statistical...
Complete description of a parsed struct.
VMM3 readout event: BC, OTADC, GEO, TDC, VMM, channel.