forked from key4hep/EDM4hep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add datatypes for storing generator (meta)data in a structured and de…
…fined way (key4hep#310) * add GeneratorInformation definition * add better member documentation * cut of GeneratorPDFInfo * add more explicit docs; fix types * add new types to documentation and tests * add new generator data and metadata to the write example * fix renamed class in readme file * move signalVertex member to generatorEventParameters * add doc for generator information * rename generator related members to fit naming conventions * address PR comments about util namespaces and string naming convention * parameters are now optional * Update all label spellings to compile again * Rename GeneratorToolInfo for more consistency * Add documentation to generator tool info handling utilities * Rename header for consistency and fix occurences --------- Co-authored-by: Thomas Madlener <[email protected]> Co-authored-by: Andre Sailer <[email protected]> Co-authored-by: Juan Miguel Carceller <[email protected]>
- Loading branch information
1 parent
f1b2d82
commit bd9f450
Showing
8 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Dealing with Generator (meta-)data | ||
|
||
EDM4hep provides data types and helper functions to handle the storage of generator meta data, both at run and event level. | ||
|
||
## Storing and retrieving run level information | ||
At run level, information about generator tools (name, version, description) are being stored. They can be written via | ||
|
||
|
||
```cpp | ||
#include "edm4hep/GeneratorToolInfo.h" | ||
// ... | ||
// write some generator tool info into the run | ||
auto toolInfo = edm4hep::GeneratorToolInfo(); | ||
auto toolInfos = std::vector<edm4hep::GeneratorToolInfo>(); | ||
toolInfo.name = "something"; | ||
toolInfo.version = "v1"; | ||
toolInfo.description = "some tool"; | ||
toolInfos.emplace_back(std::move(toolInfo)); | ||
|
||
edm4hep::utils::putGenToolInfos(run, toolInfos); | ||
``` | ||
and read-back via: | ||
```cpp | ||
#include "edm4hep/GeneratorToolInfo.h" | ||
// ... | ||
auto toolInfos = edm4hep::utils::getGenToolInfos(run); | ||
``` | ||
|
||
### Storing and retrieving event specific generator parameters and PDF information | ||
|
||
For storing information about event level parameters of generators one can use the type `GeneratorEventParameters`. | ||
For storing information about PDFs, one can use the type `GeneratorPdfInfo`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#ifndef EDM4HEP_GENERATORTOOLINFO_H | ||
#define EDM4HEP_GENERATORTOOLINFO_H | ||
|
||
#include "edm4hep/Constants.h" | ||
#include "podio/Frame.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace edm4hep { | ||
|
||
/// Meta information class to group information about the used generator (tools) | ||
/// to create a file | ||
/// | ||
/// @note Since this is all rather loosely coupled and stored via podio Frame | ||
/// parameters, use of the @ref getGenToolInfos and @ref putGenToolInfos utility | ||
/// functions for retrieval, resp. storage of this information is crucial to | ||
/// ensure consistent information. | ||
struct GeneratorToolInfo { | ||
std::string name{}; ///< The name of the tool | ||
std::string version{}; ///< The version of the tool | ||
std::string description{}; ///< A brief description of the tool | ||
|
||
/// Construct a generator tool info object with all empty fields | ||
GeneratorToolInfo() = default; | ||
|
||
/// Construct a complete tool info object from all ingredients | ||
/// | ||
/// @param name The name of the tool | ||
/// @param version The version of the tool | ||
/// @param description The brief description of the tool | ||
GeneratorToolInfo(const std::string& name, const std::string& version, const std::string& description) : | ||
name(name), version(version), description(description){}; | ||
}; | ||
|
||
namespace utils { | ||
|
||
/// Get all the generator tool infos that are available from the passed | ||
/// (metadata) frame. | ||
/// | ||
/// Tries to retrieve all meta information that are available and that have | ||
/// been stored via the @ref putGenToolInfos function. | ||
/// | ||
/// @param frame The (metadata) frame that should be queried for the | ||
/// information | ||
/// | ||
/// @returns The GeneratorToolInfo that were found in the Frame. If none ar | ||
/// found an empty vector will be returned. | ||
const inline std::vector<GeneratorToolInfo> getGenToolInfos(const podio::Frame& frame) { | ||
using namespace edm4hep::labels; | ||
auto toolInfos = std::vector<GeneratorToolInfo>(); | ||
const auto names = | ||
frame.getParameter<std::vector<std::string>>(GeneratorToolNames).value_or(std::vector<std::string>{}); | ||
const auto versions = | ||
frame.getParameter<std::vector<std::string>>(GeneratorToolVersions).value_or(std::vector<std::string>{}); | ||
const auto descriptions = | ||
frame.getParameter<std::vector<std::string>>(GeneratorToolDescriptions).value_or(std::vector<std::string>{}); | ||
for (unsigned int i = 0; i < names.size(); ++i) { | ||
toolInfos.emplace_back(names[i], versions[i], descriptions[i]); | ||
} | ||
return toolInfos; | ||
}; | ||
|
||
/// Put the generator tool meta information into a (metadata) frame | ||
/// | ||
/// In order to guarantee consistent storage and retrieval of these metadata | ||
/// it is necessary to use this utility function. | ||
/// | ||
/// @param frame The (metadata) Frame into which the generator tool info should go | ||
/// @param toolInfos The generator tool infos that should be stored | ||
void inline putGenToolInfos(podio::Frame& frame, const std::vector<GeneratorToolInfo>& toolInfos) { | ||
auto names = std::vector<std::string>(); | ||
auto versions = std::vector<std::string>(); | ||
auto descriptions = std::vector<std::string>(); | ||
for (auto& toolInfo : toolInfos) { | ||
names.push_back(toolInfo.name); | ||
versions.push_back(toolInfo.version); | ||
descriptions.push_back(toolInfo.description); | ||
} | ||
|
||
using namespace edm4hep::labels; | ||
frame.putParameter(GeneratorToolNames, std::move(names)); | ||
frame.putParameter(GeneratorToolVersions, std::move(versions)); | ||
frame.putParameter(GeneratorToolDescriptions, std::move(descriptions)); | ||
}; | ||
} // namespace utils | ||
} // namespace edm4hep | ||
|
||
#endif // EDM4HEP_GENERATORTOOLINFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters