Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:18:31

0001 #ifndef PODIO_ARROWCONVERTERREGISTRY_H
0002 #define PODIO_ARROWCONVERTERREGISTRY_H
0003 
0004 #include "podio/CollectionBuffers.h"
0005 #include "podio/SchemaEvolution.h"
0006 #include <cstdint>
0007 #include <functional>
0008 #include <map>
0009 #include <memory>
0010 #include <optional>
0011 #include <string>
0012 
0013 namespace arrow {
0014 class Array;
0015 }
0016 
0017 namespace podio {
0018 class CollectionBase;
0019 
0020 /**
0021  * @brief Global singleton registry mapping PODIO type name strings to their
0022  * corresponding Apache Arrow array converter callbacks.
0023  *
0024  * Registration happens lazily on the first call to getConverter or getReader,
0025  * when the necessary datamodel-specific Arrow converter libraries (e.g.,
0026  * libedm4hepArrow.so, libTestDataModelArrow.so) are loaded. It is expected that this
0027  * happens before worker threads query the registry. Once populated, the registry
0028  * is read-only and can be safely accessed from multiple threads concurrently.
0029  */
0030 class ArrowConverterRegistry {
0031 public:
0032   using CreatorFunc = std::function<std::shared_ptr<arrow::Array>(const podio::CollectionBase*)>;
0033   using BufferReaderFunc = std::function<std::optional<podio::CollectionReadBuffers>(std::shared_ptr<arrow::Array>,
0034                                                                                      int64_t, bool, SchemaVersionT)>;
0035 
0036   ArrowConverterRegistry(const ArrowConverterRegistry&) = delete;
0037   ArrowConverterRegistry& operator=(const ArrowConverterRegistry&) = delete;
0038   ArrowConverterRegistry(ArrowConverterRegistry&&) = delete;
0039   ArrowConverterRegistry& operator=(ArrowConverterRegistry&&) = delete;
0040   ~ArrowConverterRegistry() = default;
0041 
0042   /// Get the mutable singleton instance for registration
0043   static ArrowConverterRegistry& mutInstance();
0044 
0045   /// Get the read-only singleton instance
0046   static ArrowConverterRegistry const& instance();
0047 
0048   /**
0049    * @brief Register an Arrow array converter callback for a specific type name.
0050    */
0051   void registerConverter(const std::string& typeName, CreatorFunc&& converter);
0052 
0053   /**
0054    * @brief Retrieve the Arrow collection converter registered for a specific type name.
0055    * @return The registered CreatorFunc, or nullptr if not registered.
0056    */
0057   CreatorFunc getConverter(const std::string& typeName) const;
0058 
0059   /**
0060    * @brief Register an Arrow array reader callback for a specific type name.
0061    */
0062   void registerReader(const std::string& typeName, BufferReaderFunc&& reader);
0063 
0064   /**
0065    * @brief Retrieve the Arrow collection reader registered for a specific type name.
0066    * @return The registered BufferReaderFunc, or nullptr if not registered.
0067    */
0068   BufferReaderFunc getReader(const std::string& typeName) const;
0069 
0070 private:
0071   ArrowConverterRegistry() : m_registry(), m_readerRegistry() {
0072   }
0073 
0074   std::map<std::string, CreatorFunc> m_registry;
0075   std::map<std::string, BufferReaderFunc> m_readerRegistry;
0076 };
0077 
0078 void loadArrowLibraries();
0079 
0080 } // namespace podio
0081 
0082 #endif // PODIO_ARROWCONVERTERREGISTRY_H