Type matching
PureGadget
, ChannelGadget
as well as several other classes in Gadgetron have a template argument defining what type of data they accept.
In the simplest case, this is simply a list of types. For instance
ChannelGadget<ISMRMRD::AcquisitionHeader, hoNDArray<std::complex<float>>>
will match any message starting with a AcquisitionHeader
followed by a hoNDArray
.
If the message has more parts, these will simply be discarded. Also note that this is equivalent to
ChannelGadget<tuple<ISMRMRD::AcquisitionHeader, hoNDArray<std::complex<float>>>>
Optional
If we want to include an element that will only appear some times, we can define it as optional. For instance, acquisitions can have a trajectory attached to them. This would look like
ChannelGadget<ISMRMRD::AcquisitionHeader, hoNDArray<std::complex<float>>, optional<hoNDArray<float>>>
and in fact Types.h defines Acquisition
as
using Acquisition = tuple<ISMRMRD::AcquisitionHeader, hoNDArray<std::complex<float>>,optional<hoNDArray<float>>>;
Variant
What if you need to create a ChannelGadget that accepts multiple types? For instance, one which receives both Acquisition and Waveform. In this case we can use a variant.
In order to work with the data, you call Core::visit
, which is modelled from std::visit.
For instance, a toy example which counts the number of data points in all waveforms and acquisitions could look like