Back to home page

EIC code displayed by LXR

 
 

    


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

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