DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
This directory contains definitions of the objects used in the data selection system (TriggerPrimitive
, TriggerActivity
and TriggerCandidate
, collectively TX
) along with corresponding overlay classes to allow them to be serialized into fragments.
The design is a little convoluted in order to respect some requirements:
TX
classes inside data selection should be straightforward. In particular, the inputs
data members of TA and TC should be accessible as std::vector
.TX
classes into fragments and reading them back should not require a third-party library, which might not be available for the full life of the experiment (and beyond). This rules out using the dunedaq serialization
package, which uses third-party JSON and MsgPack libraries.Requirement 2 naturally leads towards the "overlay" class style used elsewhere in detdataformats
. But the existence of a std::vector
member means the representation of the classes as used inside DS is not contiguous in memory, so we need a separate overlay class, along with conversion functions to go from TX
to the corresponding overlay class (and back).
The TriggerActivity and TriggerCandidate classes consist conceptually of two parts:
time_start
, algorithm
, etc)An obvious implementation (and the one used previously in the triggeralgs
package) has both items 1 and 2 as fields in the TA/TC object, eg:
Here, TriggerCandidate
contains a std::vector
of TriggerActivity
, which in turn contains a std::vector
of TriggerPrimitive
. Converting these nested vectors to a contiguous set of bytes that's representable as an overlay class is not straightforward (though probably possible). Instead, we split out the two conceptual parts of TA/TC like this:
The inputs
member of TriggerCandidate
now holds TriggerActivityData
instead of TriggerActivity
. Since TriggerActivityData
is a "flat" class with no std::vector
members, there are no nested vector
s to unroll, and a simple overlay class implementation is possible:
(The last member is a "flexible array member", which is not standard C++, but is supported by GCC. An alternative would be to remove this data member and have member functions that get and set TriggerActivityData
objects by index, stored contiguously in memory after the TriggerCandidateOverlay
object itself. The flexible array member approach is more in keeping with the "overlay" style, but either way would work).
The implementation of the overlay type is in the file TriggerObjectOverlay.hpp
. The actual implementation uses templates to allow TriggerActivityOverlay
and TriggerCandidateOverlay
to use common functions.
To convert a TA or TC into its corresponding overlay class and write it into a buffer, first find the required buffer size using get_overlay_nbytes()
, passing the TriggerActivity
or TriggerCandidate
as an argument. With a buffer of the correct size, the overlay class can be written using write_overlay(object,
buffer)
. To read the overlay object from the buffer, you can either use reinterpret_cast<TriggerXOverlay*>(buffer)
or get a TA/TC object back using read_overlay()
. Example: