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), channel{p->channel}, pos{p->pos}, adc{p->adc} {}
71 template<
class T>
void add(T & readout)
const {
73 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
86 :
Event(r, f, t, w), om{p->om}, cathode{p->cathode}, anode{p->anode} {}
87 template<
class T>
void add(T & readout)
const {
89 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
105 :
Event(r, f, t, w), bc{p->bc}, otadc{p->otadc}, geo{p->geo}, tdc{p->tdc}, vmm{p->vmm}, channel{p->channel} {}
106 template<
class T>
void add(T & readout)
const {
107 auto r =
VMM3_readout{bc, otadc, geo, tdc, vmm, channel};
108 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
119 :
Event(r, f, t, w), channel{p->channel} {}
120 template<
class T>
void add(T & readout)
const {
122 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
134 :
Event(r, f, t, w), channel{p->channel} , pos_x{p->pos_x}, pos_y{p->pos_y} {}
135 template<
class T>
void add(T & readout)
const {
137 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
149 :
Event(r, f, t, w), channel{p->channel} , sum{p->sum}, adc{p->adc} {}
150 template<
class T>
void add(T & readout)
const {
152 readout.addReadout(ring, fen, time, weight,
static_cast<void *
>(&r));
157inline HighFive::CompoundType create_compound_caen_readout(){
159 {
"ring", HighFive::create_datatype<uint8_t>()},
160 {
"FEN", HighFive::create_datatype<uint8_t>()},
161 {
"time", HighFive::create_datatype<double>()},
162 {
"weight", HighFive::create_datatype<double>()},
163 {
"channel", HighFive::create_datatype<uint8_t>()},
164 {
"a", HighFive::create_datatype<uint16_t>()},
165 {
"b", HighFive::create_datatype<uint16_t>()},
166 {
"c", HighFive::create_datatype<uint16_t>()},
167 {
"d", HighFive::create_datatype<uint16_t>()},
171inline HighFive::CompoundType create_compound_ttlmonitor_readout(){
173 {
"ring", HighFive::create_datatype<uint8_t>()},
174 {
"FEN", HighFive::create_datatype<uint8_t>()},
175 {
"time", HighFive::create_datatype<double>()},
176 {
"weight", HighFive::create_datatype<double>()},
177 {
"channel", HighFive::create_datatype<uint8_t>()},
178 {
"pos", HighFive::create_datatype<uint8_t>()},
179 {
"adc", HighFive::create_datatype<uint16_t>()},
183inline HighFive::CompoundType create_compound_dream_readout(){
185 {
"ring", HighFive::create_datatype<uint8_t>()},
186 {
"FEN", HighFive::create_datatype<uint8_t>()},
187 {
"time", HighFive::create_datatype<double>()},
188 {
"weight", HighFive::create_datatype<double>()},
189 {
"om", HighFive::create_datatype<uint8_t>()},
190 {
"cathode", HighFive::create_datatype<uint8_t>()},
191 {
"anode", HighFive::create_datatype<uint8_t>()},
195inline HighFive::CompoundType create_compound_vmm3_readout(){
197 {
"ring", HighFive::create_datatype<uint8_t>()},
198 {
"FEN", HighFive::create_datatype<uint8_t>()},
199 {
"time", HighFive::create_datatype<double>()},
200 {
"weight", HighFive::create_datatype<double>()},
201 {
"bc", HighFive::create_datatype<uint16_t>()},
202 {
"otadc", HighFive::create_datatype<uint16_t>()},
203 {
"geo", HighFive::create_datatype<uint8_t>()},
204 {
"tdc", HighFive::create_datatype<uint8_t>()},
205 {
"vmm", HighFive::create_datatype<uint8_t>()},
206 {
"channel", HighFive::create_datatype<uint8_t>()},
210inline HighFive::CompoundType create_compound_bm0_readout(){
212 {
"ring", HighFive::create_datatype<uint8_t>()},
213 {
"FEN", HighFive::create_datatype<uint8_t>()},
214 {
"time", HighFive::create_datatype<double>()},
215 {
"weight", HighFive::create_datatype<double>()},
216 {
"channel", HighFive::create_datatype<uint8_t>()},
220inline HighFive::CompoundType create_compound_bm2_readout(){
222 {
"ring", HighFive::create_datatype<uint8_t>()},
223 {
"FEN", HighFive::create_datatype<uint8_t>()},
224 {
"time", HighFive::create_datatype<double>()},
225 {
"weight", HighFive::create_datatype<double>()},
226 {
"channel", HighFive::create_datatype<uint8_t>()},
227 {
"pos_x", HighFive::create_datatype<uint16_t>()},
228 {
"pos_y", HighFive::create_datatype<uint16_t>()},
232inline HighFive::CompoundType create_compound_bmi_readout(){
234 {
"ring", HighFive::create_datatype<uint8_t>()},
235 {
"FEN", HighFive::create_datatype<uint8_t>()},
236 {
"time", HighFive::create_datatype<double>()},
237 {
"weight", HighFive::create_datatype<double>()},
238 {
"channel", HighFive::create_datatype<uint8_t>()},
239 {
"sum", HighFive::create_datatype<uint8_t>()},
240 {
"adc", HighFive::create_datatype<uint32_t>()},
245 template<>
inline DataType create_datatype<CAEN_event>(){
return create_compound_caen_readout();}
246 template<>
inline DataType create_datatype<TTLMonitor_event>(){
return create_compound_ttlmonitor_readout();}
247 template<>
inline DataType create_datatype<CDT_event>(){
return create_compound_dream_readout();}
248 template<>
inline DataType create_datatype<VMM3_event>(){
return create_compound_vmm3_readout();}
249 template<>
inline DataType create_datatype<BM0_event>(){
return create_compound_bm0_readout();}
250 template<>
inline DataType create_datatype<BM2_event>(){
return create_compound_bm2_readout();}
251 template<>
inline DataType create_datatype<BMI_event>(){
return create_compound_bmi_readout();}
255inline HighFive::CompoundType hdf_compound_type(
const ReadoutType readout) {
257 case ReadoutType::CAEN:
return create_compound_caen_readout();
258 case ReadoutType::TTLMonitor:
return create_compound_ttlmonitor_readout();
259 case ReadoutType::CDT:
return create_compound_dream_readout();
260 case ReadoutType::VMM3:
return create_compound_vmm3_readout();
261 case ReadoutType::BM0:
return create_compound_bm0_readout();
262 case ReadoutType::BM2:
return create_compound_bm2_readout();
263 case ReadoutType::BMI:
return create_compound_bmi_readout();
264 default:
throw std::runtime_error(
"Saving this readout type is not implemented yet!");
269inline HighFive::DataType hdf5_type_for(
const std::string& canonical_type) {
270 if (canonical_type ==
"int8_t")
return HighFive::create_datatype<int8_t>();
271 if (canonical_type ==
"int16_t")
return HighFive::create_datatype<int16_t>();
272 if (canonical_type ==
"int32_t")
return HighFive::create_datatype<int32_t>();
273 if (canonical_type ==
"int64_t")
return HighFive::create_datatype<int64_t>();
274 if (canonical_type ==
"uint8_t")
return HighFive::create_datatype<uint8_t>();
275 if (canonical_type ==
"uint16_t")
return HighFive::create_datatype<uint16_t>();
276 if (canonical_type ==
"uint32_t")
return HighFive::create_datatype<uint32_t>();
277 if (canonical_type ==
"uint64_t")
return HighFive::create_datatype<uint64_t>();
278 if (canonical_type ==
"float")
return HighFive::create_datatype<float>();
279 if (canonical_type ==
"double")
return HighFive::create_datatype<double>();
280 throw std::runtime_error(
"No HDF5 type mapping for: " + canonical_type);
287inline HighFive::CompoundType build_hdf5_compound_type(
const TypeSchema & schema) {
288 std::vector<HighFive::CompoundType::member_def> members;
289 members.reserve(schema.fields.size());
291 for (
const auto& field : schema.fields) {
292 if (field.array_count > 0) {
293 throw std::runtime_error(
294 "build_hdf5_compound_type: array fields are not supported (field: " + field.name +
")"
297 members.push_back({field.name, hdf5_type_for(field.type), field.offset});
300 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...
TTL beam-monitor readout event: channel, position, ADC.
Complete description of a parsed struct.
VMM3 readout event: BC, OTADC, GEO, TDC, VMM, channel.