2 #define TRACE_NAME "ToyFragmentNtuple"
4 #include "artdaq-core-demo/Overlays/FragmentType.hh"
5 #include "artdaq-core-demo/Overlays/ToyFragment.hh"
6 #include "artdaq-demo-hdf5/HDF5/FragmentDataset.hh"
7 #include "artdaq-demo-hdf5/HDF5/hep-hpc/ToyFragmentNtuple.hh"
9 #pragma GCC diagnostic push
10 #pragma GCC diagnostic ignored "-Wmissing-braces"
11 #include "hep_hpc/hdf5/make_column.hpp"
12 #include "hep_hpc/hdf5/make_ntuple.hpp"
13 #pragma GCC diagnostic pop
15 #define DO_COMPRESSION 0
17 #define SCALAR_PROPERTIES \
19 hep_hpc::hdf5::PropertyList{H5P_DATASET_CREATE}(&H5Pset_deflate, 7u) \
21 #define ARRAY_PROPERTIES \
23 hep_hpc::hdf5::PropertyList{H5P_DATASET_CREATE}(&H5Pset_deflate, 7u) \
26 #define SCALAR_PROPERTIES \
28 #define ARRAY_PROPERTIES \
35 , nWordsPerRow_(ps.get<size_t>(
"nWordsPerRow", 10240))
36 , output_(hep_hpc::hdf5::make_ntuple({ps.get<std::string>(
"fileName",
"toyFragments.hdf5"),
"TOYFragments"},
38 hep_hpc::hdf5::make_scalar_column<uint64_t>(
"sequenceID", SCALAR_PROPERTIES),
39 hep_hpc::hdf5::make_scalar_column<uint16_t>(
"fragmentID", SCALAR_PROPERTIES),
40 hep_hpc::hdf5::make_scalar_column<uint64_t>(
"timestamp", SCALAR_PROPERTIES),
41 hep_hpc::hdf5::make_scalar_column<uint8_t>(
"type", SCALAR_PROPERTIES),
42 hep_hpc::hdf5::make_scalar_column<uint16_t>(
"board_serial_number", SCALAR_PROPERTIES),
43 hep_hpc::hdf5::make_scalar_column<uint8_t>(
"num_adc_bits", SCALAR_PROPERTIES),
44 hep_hpc::hdf5::make_scalar_column<uint32_t>(
"trigger_number", SCALAR_PROPERTIES),
45 hep_hpc::hdf5::make_scalar_column<uint8_t>(
"distribution_type", SCALAR_PROPERTIES),
46 hep_hpc::hdf5::make_scalar_column<uint32_t>(
"total_adcs", SCALAR_PROPERTIES),
47 hep_hpc::hdf5::make_scalar_column<uint32_t>(
"start_adc", SCALAR_PROPERTIES),
48 hep_hpc::hdf5::make_column<uint16_t, 1>(
"ADCs", nWordsPerRow_, ARRAY_PROPERTIES)))
50 , fragments_(ps, output_.file())
52 TLOG(TLVL_DEBUG) <<
"ToyFragmentNtuple CONSTRUCTOR START";
53 if (
mode_ == FragmentDatasetMode::Read)
55 TLOG(TLVL_ERROR) <<
"ToyFragmentDataset configured in read mode but is not capable of reading!";
57 TLOG(TLVL_DEBUG) <<
"ToyFragmentNtuple CONSTRUCTOR END";
62 TLOG(TLVL_DEBUG) <<
"ToyFragmentNtuple DESTRUCTOR START";
64 TLOG(TLVL_DEBUG) <<
"ToyFragmentNtuple DESTRUCTOR END";
69 TLOG(TLVL_TRACE) <<
"ToyFragmentNtuple::insertOne BEGIN";
70 if (f.type() != demo::FragmentType::TOY1 && f.type() != demo::FragmentType::TOY2)
72 TLOG(TLVL_TRACE) <<
"insertOne: Inserting generic Fragment";
77 TLOG(TLVL_TRACE) <<
"insertOne: Decoding ToyFragment";
78 demo::ToyFragment frag(f);
79 auto m = f.metadata<demo::ToyFragment::Metadata>();
80 auto event_size = frag.total_adc_values();
81 for (
size_t ii = 0; ii < event_size; ii += nWordsPerRow_)
83 if (ii + nWordsPerRow_ <= event_size)
85 output_.insert(f.sequenceID(), f.fragmentID(), f.timestamp(), f.type(),
86 m->board_serial_number, m->num_adc_bits, frag.hdr_trigger_number(),
87 frag.hdr_distribution_type(), event_size, ii, &frag.dataBeginADCs()[ii]);
91 std::vector<demo::ToyFragment::adc_t> adcs(nWordsPerRow_, 0);
92 std::copy(frag.dataBeginADCs() + ii, frag.dataEndADCs(), adcs.begin());
93 output_.insert(f.sequenceID(), f.fragmentID(), f.timestamp(), f.type(),
94 m->board_serial_number, m->num_adc_bits, frag.hdr_trigger_number(),
95 frag.hdr_distribution_type(), event_size, ii, &adcs[0]);
99 TLOG(TLVL_TRACE) <<
"ToyFragmentNtuple::insertOne: END";
104 TLOG(TLVL_TRACE) <<
"ToyFragmentNtuple::insertHeader: Calling FragmentNtuple::insertHeader";
void insertOne(artdaq::Fragment const &f) override
Insert a Fragment into the Fragment Ntuple Dataset (write it to the HDF5 file)
ToyFragmentNtuple(fhicl::ParameterSet const &ps)
ToyFragmentNtuple Constructor.
void insertOne(artdaq::Fragment const &frag) override
Insert a Fragment into the Fragment Ntuple Dataset (write it to the HDF5 file)
An implementation of FragmentDataset for ToyFragment. Uses a FragmentNtuple dataset plugin for any Fr...
void insertHeader(artdaq::detail::RawEventHeader const &evtHdr) override
Insert a RawEventHeader into the Event Header Ntuple Dataset (write it to the HDF5 file) ...
void insertHeader(artdaq::detail::RawEventHeader const &hdr) override
Insert a RawEventHeader into the Event Header Ntuple Dataset (write it to the HDF5 file) ...
FragmentDatasetMode mode_
Mode of this FragmentDataset, either FragmentDatasetMode::Write or FragmentDatasetMode::Read.
Base class that defines methods for reading and writing to HDF5 files via various implementation plug...
virtual ~ToyFragmentNtuple()
ToyFragmentNtuple Destructor.