Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/podio/detail/LinkSIOBlock.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #ifndef PODIO_DETAIL_LINKSIOBLOCK_H
0002 #define PODIO_DETAIL_LINKSIOBLOCK_H
0003 
0004 #include "podio/detail/LinkCollectionImpl.h"
0005 
0006 #include "podio/CollectionBufferFactory.h"
0007 #include "podio/CollectionBuffers.h"
0008 #include "podio/SIOBlock.h"
0009 
0010 #include <sio/api.h>
0011 #include <sio/io_device.h>
0012 #include <sio/version.h>
0013 
0014 #include <string>
0015 
0016 namespace podio {
0017 template <typename FromT, typename ToT>
0018 class LinkSIOBlock : public podio::SIOBlock {
0019 public:
0020   LinkSIOBlock() :
0021       SIOBlock(podio::detail::linkSIOName<FromT, ToT>(),
0022                sio::version::encode_version(LinkCollection<FromT, ToT>::schemaVersion, 0)) {
0023     podio::SIOBlockFactory::instance().registerBlockForCollection(
0024         std::string(podio::detail::linkTypeName<FromT, ToT>()), this);
0025   }
0026 
0027   LinkSIOBlock(const std::string& name) :
0028       SIOBlock(name, sio::version::encode_version(LinkCollection<FromT, ToT>::schemaVersion, 0)) {
0029   }
0030 
0031   void read(sio::read_device& device, sio::version_type version) override {
0032     auto& bufferFactory = podio::CollectionBufferFactory::instance();
0033     // TODO:
0034     // - Error handling of empty optional
0035     auto maybeBuffers = bufferFactory.createBuffers(std::string(podio::detail::linkCollTypeName<FromT, ToT>()),
0036                                                     sio::version::major_version(version), m_subsetColl);
0037     m_buffers = maybeBuffers.value();
0038 
0039     if (!m_subsetColl) {
0040       unsigned size{0};
0041       device.data(size);
0042       auto* dataVec = m_buffers.dataAsVector<float>();
0043       dataVec->resize(size);
0044       podio::handlePODDataSIO(device, dataVec->data(), size);
0045     }
0046 
0047     // ---- read ref collections
0048     auto* refColls = m_buffers.references;
0049     for (auto& refC : *refColls) {
0050       unsigned size{0};
0051       device.data(size);
0052       refC->resize(size);
0053       podio::handlePODDataSIO(device, refC->data(), size);
0054     }
0055   }
0056 
0057   void write(sio::write_device& device) override {
0058     if (!m_subsetColl) {
0059       auto* dataVec = podio::CollectionWriteBuffers::asVector<float>(m_buffers.data);
0060       unsigned size = dataVec->size();
0061       device.data(size);
0062       podio::handlePODDataSIO(device, dataVec->data(), size);
0063     }
0064 
0065     // ---- write ref collections ------
0066     auto* refColls = m_buffers.references;
0067     for (auto& refC : *refColls) {
0068       unsigned size = refC->size();
0069       device.data(size);
0070       podio::handlePODDataSIO(device, refC->data(), size);
0071     }
0072   }
0073 
0074   SIOBlock* create(const std::string& name) const override {
0075     return new LinkSIOBlock(name);
0076   }
0077 };
0078 
0079 } // namespace podio
0080 
0081 #endif // PODIO_DETAIL_LINKSIOBLOCK_H