Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-03 08:33:24

0001 #ifndef EDM4HEP_GENERATORTOOLINFO_H
0002 #define EDM4HEP_GENERATORTOOLINFO_H
0003 
0004 #include "edm4hep/Constants.h"
0005 #include "podio/Frame.h"
0006 #include <string>
0007 #include <vector>
0008 
0009 namespace edm4hep {
0010 
0011 /// Meta information class to group information about the used generator (tools)
0012 /// to create a file
0013 ///
0014 /// @note Since this is all rather loosely coupled and stored via podio Frame
0015 /// parameters, use of the @ref getGenToolInfos and @ref putGenToolInfos utility
0016 /// functions for retrieval, resp. storage of this information is crucial to
0017 /// ensure consistent information.
0018 struct GeneratorToolInfo {
0019   std::string name{};        ///< The name of the tool
0020   std::string version{};     ///< The version of the tool
0021   std::string description{}; ///< A brief description of the tool
0022 
0023   /// Construct a generator tool info object with all empty fields
0024   GeneratorToolInfo() = default;
0025 
0026   /// Construct a complete tool info object from all ingredients
0027   ///
0028   /// @param nameTool        The name of the tool
0029   /// @param versionTool     The version of the tool
0030   /// @param descrTool       The brief description of the tool
0031   GeneratorToolInfo(const std::string& nameTool, const std::string& versionTool, const std::string& descrTool) :
0032       name(nameTool), version(versionTool), description(descrTool){};
0033 };
0034 
0035 namespace utils {
0036 
0037   /// Get all the generator tool infos that are available from the passed
0038   /// (metadata) frame.
0039   ///
0040   /// Tries to retrieve all meta information that are available and that have
0041   /// been stored via the @ref putGenToolInfos function.
0042   ///
0043   /// @param frame The (metadata) frame that should be queried for the
0044   ///              information
0045   ///
0046   /// @returns The GeneratorToolInfo that were found in the Frame. If none ar
0047   ///          found an empty vector will be returned.
0048   const inline std::vector<GeneratorToolInfo> getGenToolInfos(const podio::Frame& frame) {
0049     using namespace edm4hep::labels;
0050     auto toolInfos = std::vector<GeneratorToolInfo>();
0051     const auto names =
0052         frame.getParameter<std::vector<std::string>>(GeneratorToolNames).value_or(std::vector<std::string>{});
0053     const auto versions =
0054         frame.getParameter<std::vector<std::string>>(GeneratorToolVersions).value_or(std::vector<std::string>{});
0055     const auto descriptions =
0056         frame.getParameter<std::vector<std::string>>(GeneratorToolDescriptions).value_or(std::vector<std::string>{});
0057     for (unsigned int i = 0; i < names.size(); ++i) {
0058       toolInfos.emplace_back(names[i], versions[i], descriptions[i]);
0059     }
0060     return toolInfos;
0061   };
0062 
0063   /// Put the generator tool meta information into a (metadata) frame
0064   ///
0065   /// In order to guarantee consistent storage and retrieval of these metadata
0066   /// it is necessary to use this utility function.
0067   ///
0068   /// @param frame     The (metadata) Frame into which the generator tool info should go
0069   /// @param toolInfos The generator tool infos that should be stored
0070   void inline putGenToolInfos(podio::Frame& frame, const std::vector<GeneratorToolInfo>& toolInfos) {
0071     auto names = std::vector<std::string>();
0072     auto versions = std::vector<std::string>();
0073     auto descriptions = std::vector<std::string>();
0074     for (auto& toolInfo : toolInfos) {
0075       names.push_back(toolInfo.name);
0076       versions.push_back(toolInfo.version);
0077       descriptions.push_back(toolInfo.description);
0078     }
0079 
0080     using namespace edm4hep::labels;
0081     frame.putParameter(GeneratorToolNames, std::move(names));
0082     frame.putParameter(GeneratorToolVersions, std::move(versions));
0083     frame.putParameter(GeneratorToolDescriptions, std::move(descriptions));
0084   };
0085 } // namespace utils
0086 } // namespace edm4hep
0087 
0088 #endif // EDM4HEP_GENERATORTOOLINFO_H