DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
This repository contains utilities for serializing/deserializing C++ objects for DUNE DAQ. Serialization allows objects to be sent across the network or persisted to disk.
An appropriately-defined C++ type (see below) can be serialized/deserialized as follows:
Classes can be made serializable by adding convertor functions for msgpack
.
The easiest way to make your class (de)serializable is with the DUNE_DAQ_SERIALIZE()
and DUNE_DAQ_SERIALIZABLE()
convenience macros provided in Serialization.hpp
:
You may not be able to change the type itself, either because you don't have access to it, or because it lives in a package that cannot depend on the serialization
package. In this case, you can use the DUNE_DAQ_SERIALIZE_NON_INTRUSIVE()
macro instead. In the global namespace, call DUNE_DAQ_SERIALIZE_NON_INTRUSIVE()
with first argument the namespace of your class, second argument the class name, and the rest of the arguments listing the member variables. For example:
A complete example, showing both intrusive and non-intrusive strategies, can be found in serialization_simple_test.cxx
.
Full instructions for serializing arbitrary types with msgpack
are available here. These include instructions for (de)serializing classes that are not default-constructible. Several custom serializers have been implemented, such as Fragment_serialization.hpp in dfmessages
.
Choice of serialization methods: there are many, many libraries and formats for serialization/deserialization, with a range of tradeoffs. For the binary format, we wanted a library that allows serialization of arbitrary types, rather than requiring types to be specified in, eg the library's DSL (this rules out, eg, protobuf
). We may have to revisit that requirement if we find that msgpack
does not meet performance requirements.