DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TriggerRecord_serialization.hpp
Go to the documentation of this file.
1
9#ifndef DFMESSAGES_INCLUDE_DFMESSAGES_TRIGGERRECORD_SERIALIZATION_HPP_
10#define DFMESSAGES_INCLUDE_DFMESSAGES_TRIGGERRECORD_SERIALIZATION_HPP_
11
16#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
17
18#include <memory>
19#include <utility>
20#include <vector>
21
22namespace dunedaq {
23// Disable coverage collection LCOV_EXCL_START
24ERS_DECLARE_ISSUE(dfmessages,
25 CannotDeserializeTriggerRecord,
26 "Cannot deserialize TriggerRecord from JSON due to type mismatch", )
27// Re-enable coverage collection LCOV_EXCL_STOP
28} // namespace dunedaq
29
30// MsgPack serialization functions (which just put the raw bytes of
31// the fragment array into a MsgPack message)
32namespace msgpack {
33MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
34{
35 namespace adaptor {
36
37 template<>
38 struct pack<dunedaq::daqdataformats::TriggerRecord>
39 {
40 template<typename Stream>
41 packer<Stream>& operator()(msgpack::packer<Stream>& o, dunedaq::daqdataformats::TriggerRecord const& tr) const
42 {
43 auto& trh = tr.get_header_ref();
44 auto& frags = tr.get_fragments_ref();
45
46 o.pack_array(1 + frags.size());
47 o.pack(trh);
48 for (auto& fragptr : frags) {
49 o.pack(fragptr);
50 }
51 return o;
52 }
53 };
54
55 // Typically we use convert<> for deserialization, but TriggerRecord isn't
56 // default constructible, so we have to use as<>. See:
57 // https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-default-constructible-class-support-c11-only-since-120
58 template<>
59 struct as<dunedaq::daqdataformats::TriggerRecord>
60 {
61 dunedaq::daqdataformats::TriggerRecord operator()(msgpack::object const& o) const
62 {
64
65 for (size_t ii = 1; ii < o.via.array.size; ++ii) {
66 auto fragptr = o.via.array.ptr[ii].as<std::unique_ptr<dunedaq::daqdataformats::Fragment>>();
67 tr.add_fragment(std::move(fragptr));
68 }
69
70 return tr;
71 }
72 };
73
74 template<>
75 struct pack<std::unique_ptr<dunedaq::daqdataformats::TriggerRecord>>
76 {
77 template<typename Stream>
78 packer<Stream>& operator()(msgpack::packer<Stream>& o,
79 std::unique_ptr<dunedaq::daqdataformats::TriggerRecord> const& tr) const
80 {
81 auto& trh = tr->get_header_ref();
82 auto& frags = tr->get_fragments_ref();
83
84 o.pack_array(1 + frags.size());
85 o.pack(trh);
86 for (auto& fragptr : frags) {
87 o.pack(fragptr);
88 }
89 return o;
90 }
91 };
92
93 // Typically we use convert<> for deserialization, but TriggerRecord isn't
94 // default constructible, so we have to use as<>. See:
95 // https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-default-constructible-class-support-c11-only-since-120
96 template<>
97 struct as<std::unique_ptr<dunedaq::daqdataformats::TriggerRecord>>
98 {
99 std::unique_ptr<dunedaq::daqdataformats::TriggerRecord> operator()(msgpack::object const& o) const
100 {
101 auto tr = std::make_unique<dunedaq::daqdataformats::TriggerRecord>(
102 o.via.array.ptr[0].as<dunedaq::daqdataformats::TriggerRecordHeader>());
103
104 for (size_t ii = 1; ii < o.via.array.size; ++ii) {
105 auto fragptr = o.via.array.ptr[ii].as<std::unique_ptr<dunedaq::daqdataformats::Fragment>>();
106 tr->add_fragment(std::move(fragptr));
107 }
108
109 return tr;
110 }
111 };
112 } // namespace adaptor
113} // namespace MSGPACK_DEFAULT_API_NS
114} // namespace msgpack
115
117DUNE_DAQ_SERIALIZABLE(std::unique_ptr<dunedaq::daqdataformats::TriggerRecord>, "TriggerRecord");
118
119#endif // DFMESSAGES_INCLUDE_DFMESSAGES_TRIGGERRECORD_SERIALIZATION_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
#define DUNE_DAQ_SERIALIZABLE(Type, typestring)
C++ representation of a TriggerRecordHeader, which wraps a flat array that is the TriggerRecordHeader...
C++ Representation of a DUNE TriggerRecord, consisting of a TriggerRecordHeader object and a vector o...
const std::vector< std::unique_ptr< Fragment > > & get_fragments_ref() const
Get a handle to the Fragments.
void add_fragment(std::unique_ptr< Fragment > &&fragment)
Add a Fragment pointer to the Fragments vector.
const TriggerRecordHeader & get_header_ref() const
Get a handle to the TriggerRecordHeader.
Including Qt Headers.
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)