artdaq_demo_hdf5  v1_00_00
ToyFragmentNtuple_dataset.cc
1 #include "tracemf.h"
2 #define TRACE_NAME "ToyFragmentNtuple"
3 
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"
8 
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
14 
15 #define DO_COMPRESSION 0
16 #if DO_COMPRESSION
17 #define SCALAR_PROPERTIES \
18  { \
19  hep_hpc::hdf5::PropertyList{H5P_DATASET_CREATE}(&H5Pset_deflate, 7u) \
20  }
21 #define ARRAY_PROPERTIES \
22  { \
23  hep_hpc::hdf5::PropertyList{H5P_DATASET_CREATE}(&H5Pset_deflate, 7u) \
24  }
25 #else
26 #define SCALAR_PROPERTIES \
27  {}
28 #define ARRAY_PROPERTIES \
29  {}
30 #endif
31 
33 
34  : FragmentDataset(ps, ps.get<std::string>("mode", "write"))
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())
51 {
52  TLOG(TLVL_DEBUG) << "ToyFragmentNtuple CONSTRUCTOR START";
53  if (mode_ == FragmentDatasetMode::Read)
54  {
55  TLOG(TLVL_ERROR) << "ToyFragmentDataset configured in read mode but is not capable of reading!";
56  }
57  TLOG(TLVL_DEBUG) << "ToyFragmentNtuple CONSTRUCTOR END";
58 }
59 
61 {
62  TLOG(TLVL_DEBUG) << "ToyFragmentNtuple DESTRUCTOR START";
63  output_.flush();
64  TLOG(TLVL_DEBUG) << "ToyFragmentNtuple DESTRUCTOR END";
65 }
66 
67 void artdaq::hdf5::ToyFragmentNtuple::insertOne(artdaq::Fragment const& f)
68 {
69  TLOG(TLVL_TRACE) << "ToyFragmentNtuple::insertOne BEGIN";
70  if (f.type() != demo::FragmentType::TOY1 && f.type() != demo::FragmentType::TOY2)
71  {
72  TLOG(TLVL_TRACE) << "insertOne: Inserting generic Fragment";
73  fragments_.insertOne(f);
74  }
75  else
76  {
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_)
82  {
83  if (ii + nWordsPerRow_ <= event_size)
84  {
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]);
88  }
89  else
90  {
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]);
96  }
97  }
98  }
99  TLOG(TLVL_TRACE) << "ToyFragmentNtuple::insertOne: END";
100 }
101 
102 void artdaq::hdf5::ToyFragmentNtuple::insertHeader(artdaq::detail::RawEventHeader const& evtHdr)
103 {
104  TLOG(TLVL_TRACE) << "ToyFragmentNtuple::insertHeader: Calling FragmentNtuple::insertHeader";
105  fragments_.insertHeader(evtHdr);
106 }
107 
108 DEFINE_ARTDAQ_DATASET_PLUGIN(artdaq::hdf5::ToyFragmentNtuple)
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.