Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:17:26

0001 #ifndef PODIO_UTILITIES_DATAMODELREGISTRYIOHELPERS_H
0002 #define PODIO_UTILITIES_DATAMODELREGISTRYIOHELPERS_H
0003 
0004 #include "podio/CollectionBase.h"
0005 #include "podio/DatamodelRegistry.h"
0006 
0007 #include <set>
0008 #include <string>
0009 #include <tuple>
0010 #include <vector>
0011 
0012 namespace podio {
0013 
0014 /// Helper class to collect the datamodel (JSON) definitions that should be
0015 /// written.
0016 class DatamodelDefinitionCollector {
0017 public:
0018   /// Register the datamodel definition of the EDM this collection is from to be
0019   /// written.
0020   ///
0021   /// @param coll A collection of an EDM
0022   /// @param name The name under which this collection is stored on file
0023   void registerDatamodelDefinition(const podio::CollectionBase* coll, const std::string& name);
0024 
0025   /// Get all the names and JSON definitions that need to be written
0026   std::vector<std::tuple<std::string, std::string>> getDatamodelDefinitionsToWrite() const;
0027 
0028 private:
0029   std::set<size_t> m_edmDefRegistryIdcs{}; ///< The indices in the EDM definition registry that need to be written
0030 };
0031 
0032 /// Helper class to hold and provide the datamodel (JSON) definitions for reader
0033 /// classes.
0034 class DatamodelDefinitionHolder {
0035 public:
0036   /// The "map" type that is used internally
0037   using MapType = std::vector<std::tuple<std::string, std::string>>;
0038   /// The "map" mapping names and datamodel versions (where available)
0039   using VersionList = std::vector<std::tuple<std::string, podio::version::Version>>;
0040 
0041   /// Constructor from an existing collection of names and datamodel definitions and versions
0042   DatamodelDefinitionHolder(MapType&& definitions, VersionList&& versions) :
0043       m_availEDMDefs(std::move(definitions)), m_edmVersions(std::move(versions)) {
0044   }
0045 
0046   DatamodelDefinitionHolder() = default;
0047   ~DatamodelDefinitionHolder() = default;
0048   DatamodelDefinitionHolder(const DatamodelDefinitionHolder&) = delete;
0049   DatamodelDefinitionHolder& operator=(const DatamodelDefinitionHolder&) = delete;
0050   DatamodelDefinitionHolder(DatamodelDefinitionHolder&&) = default;
0051   DatamodelDefinitionHolder& operator=(DatamodelDefinitionHolder&&) = default;
0052 
0053   /// Get the datamodel definition for the given datamodel name.
0054   ///
0055   /// Returns an empty model definition if no model is stored under the given
0056   /// name.
0057   ///
0058   /// @param name The name of the datamodel
0059   const std::string_view getDatamodelDefinition(const std::string& name) const;
0060 
0061   /// Get all names of the datamodels that have been read from file
0062   std::vector<std::string> getAvailableDatamodels() const;
0063 
0064   std::optional<podio::version::Version> getDatamodelVersion(const std::string& name) const;
0065 
0066 protected:
0067   MapType m_availEDMDefs{};
0068   VersionList m_edmVersions{};
0069 };
0070 
0071 } // namespace podio
0072 
0073 #endif // PODIO_UTILITIES_DATAMODELREGISTRYIOHELPERS_H