Skip to content

Add support to DataWriteHandle for writing (partially type erased) 'views' into the TES

Gerhard Raven requested to merge add-view-support into master

Allow a second template argument on DataObjectWriteHandle eg. DataObjectWriteHandle<GetType,PutType> (note: by default, in case of a single template argument, PutType=GetType, and the original behaviour is kept). In this case, DataObjectWriteHandle::put will accept an rvalue reference to PutType, which will create a dedicated 'wrapper' which contains both the moved instance of PutType, as well as a GetType constructed from the moved instance, into the event store. This wrapper can be retrieved and unwrapped by a DataObjectReadHandle<GetType>.

Note that the following constrains apply to GetType and PutType:

    const PutType& pt = ... ;
    GetType gt{};
    gt = GetType{ pt };

i.e. GetType must both be default constructible and constructible from const PutType&, and it must be assignable. In addition, GetType can not inherit from DataObject.

In addition, add a 'trait' to Gaudi::Functional to ease the use of the above. All that is required is to annotate a producer (which produces PutType) with the writeViewFor<PutType,GetType> trait -- see for example, from GaudiExamples:

struct ProduceIntView
    : Gaudi::Functional::Producer< std::vector<int>(), 
                                   writeViewFor< std::vector<int>, gsl::span<const int> > > 
{
  ProduceIntView( const std::string& name, ISvcLocator* svcLoc )
      : Producer{name, svcLoc, {"Output", "/Event/Test/IntView"}} {}
  std::vector<int> operator()() const override {
    std::vector<int> vi{1, 2, 3, 5, 8, 13, 21, 34};
    info() << "made vector with data at : " << vi.data() << endmsg;
    return vi;
  }
};

As a result, it is now possible to benefit from (partially) type erased objects in the TES, i.e. one can write an std::vector<RecVertex, std::scoped_allocator_adaptor<LHCb::Allocators::EventLocal<RecVertex>>> in combination with an std::span<const RecVertex>, and retrieve this as std::span<const RecVertex> without the reader ever having to know about the specific type of the allocator used.

Edited by Gerhard Raven

Merge request reports