PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
DatamodelRegistry.h
Go to the documentation of this file.
1#ifndef PODIO_DATAMODELREGISTRY_H
2#define PODIO_DATAMODELREGISTRY_H
3
4#include <string>
5#include <string_view>
6#include <utility>
7#include <vector>
8
9namespace podio {
10
11/**
12 * Global registry holding information about datamodels and datatypes defined
13 * therein that are currently known by podio (i.e. which have been dynamically
14 * loaded).
15 *
16 * This is a singleton which is (statically) populated during dynamic loading of
17 * generated EDMs. In this context an **EDM refers to the shared library** that
18 * is compiled from the generated code from a datamodel definition in YAML
19 * format. When we refer to a **datamodel** in this context we talk about the
20 * entity as a whole, i.e. its definition in a YAML file, but also the concrete
21 * implementation as an EDM, as well as all other information that is related to
22 * it. In the API of this registry this will be used, unless we want to
23 * highlight that we are referring to a specific part of a datamodel.
24 */
26public:
27 /// Get the registry
28 static const DatamodelRegistry& instance();
29
30 // Mutable instance only used for the initial registration!
32
33 ~DatamodelRegistry() = default;
38
39 /// Dedicated index value for collections that don't have a datamodel
40 /// definition (e.g. UserDataCollection)
41 static constexpr size_t NoDefinitionNecessary = -1;
42 /// Dedicated index value for error checking, used to default init the generated RegistryIndex
43 static constexpr size_t NoDefinitionAvailable = -2;
44
45 /**
46 * Get the definition (in JSON format) of the datamodel with the given
47 * edmName.
48 *
49 * If no datamodel with the given name can be found, an empty datamodel
50 * definition, i.e. an empty JSON object ("{}"), is returned.
51 *
52 * @param name The name of the datamodel
53 */
54 const std::string_view getDatamodelDefinition(std::string_view name) const;
55
56 /**
57 * Get the defintion (in JSON format) of the datamodel wth the given index.
58 *
59 * If no datamodel is found under the given index, an empty datamodel
60 * definition, i.e. an empty JSON object ("{}"), is returned.
61 *
62 * @param index The datamodel definition index that can be obtained from each
63 * collection
64 */
65 const std::string_view getDatamodelDefinition(size_t index) const;
66
67 /**
68 * Get the name of the datamodel that is stored under the given index.
69 *
70 * If no datamodel is found under the given index, an empty string is returned
71 *
72 * @param index The datamodel definition index that can be obtained from each
73 * collection
74 */
75 const std::string& getDatamodelName(size_t index) const;
76
77 /**
78 * Register a datamodel return the index in the registry.
79 *
80 * This is the hook that is called during dynamic loading of an EDM to
81 * register information for this EDM. If an EDM has already been registered
82 * under this name, than the index to the existing EDM in the registry will be
83 * returned.
84 *
85 * @param name The name of the EDM that should be registered
86 * @param definition The datamodel definition from which this EDM has been
87 * generated in JSON format
88 *
89 */
90 size_t registerDatamodel(std::string name, std::string_view definition);
91
92private:
93 DatamodelRegistry() = default;
94 /// The stored definitions
95 std::vector<std::pair<std::string, std::string_view>> m_definitions{};
96};
97} // namespace podio
98
99#endif // PODIO_DATAMODELREGISTRY_H
DatamodelRegistry & operator=(const DatamodelRegistry &&)=delete
static const DatamodelRegistry & instance()
Get the registry.
DatamodelRegistry(DatamodelRegistry &&)=delete
static constexpr size_t NoDefinitionAvailable
Dedicated index value for error checking, used to default init the generated RegistryIndex.
DatamodelRegistry(const DatamodelRegistry &)=delete
static DatamodelRegistry & mutInstance()
const std::string & getDatamodelName(size_t index) const
size_t registerDatamodel(std::string name, std::string_view definition)
static constexpr size_t NoDefinitionNecessary
DatamodelRegistry & operator=(const DatamodelRegistry &)=delete
const std::string_view getDatamodelDefinition(std::string_view name) const