PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::DatamodelRegistry Class Reference

#include <DatamodelRegistry.h>

Public Member Functions

 ~DatamodelRegistry ()=default
 
 DatamodelRegistry (const DatamodelRegistry &)=delete
 
DatamodelRegistryoperator= (const DatamodelRegistry &)=delete
 
 DatamodelRegistry (DatamodelRegistry &&)=delete
 
DatamodelRegistryoperator= (const DatamodelRegistry &&)=delete
 
const std::string_view getDatamodelDefinition (std::string_view name) const
 
const std::string_view getDatamodelDefinition (size_t index) const
 
const std::string & getDatamodelName (size_t index) const
 
size_t registerDatamodel (std::string name, std::string_view definition)
 

Static Public Member Functions

static const DatamodelRegistryinstance ()
 Get the registry.
 
static DatamodelRegistrymutInstance ()
 

Static Public Attributes

static constexpr size_t NoDefinitionNecessary = -1
 
static constexpr size_t NoDefinitionAvailable = -2
 Dedicated index value for error checking, used to default init the generated RegistryIndex.
 

Detailed Description

Global registry holding information about datamodels and datatypes defined therein that are currently known by podio (i.e. which have been dynamically loaded).

This is a singleton which is (statically) populated during dynamic loading of generated EDMs. In this context an EDM refers to the shared library that is compiled from the generated code from a datamodel definition in YAML format. When we refer to a datamodel in this context we talk about the entity as a whole, i.e. its definition in a YAML file, but also the concrete implementation as an EDM, as well as all other information that is related to it. In the API of this registry this will be used, unless we want to highlight that we are referring to a specific part of a datamodel.

Definition at line 25 of file DatamodelRegistry.h.

Constructor & Destructor Documentation

◆ ~DatamodelRegistry()

podio::DatamodelRegistry::~DatamodelRegistry ( )
default

◆ DatamodelRegistry() [1/2]

podio::DatamodelRegistry::DatamodelRegistry ( const DatamodelRegistry )
delete

◆ DatamodelRegistry() [2/2]

podio::DatamodelRegistry::DatamodelRegistry ( DatamodelRegistry &&  )
delete

Member Function Documentation

◆ getDatamodelDefinition() [1/2]

const std::string_view podio::DatamodelRegistry::getDatamodelDefinition ( size_t  index) const

Get the defintion (in JSON format) of the datamodel wth the given index.

If no datamodel is found under the given index, an empty datamodel definition, i.e. an empty JSON object ("{}"), is returned.

Parameters
indexThe datamodel definition index that can be obtained from each collection

Definition at line 44 of file DatamodelRegistry.cc.

44 {
45 if (index >= m_definitions.size()) {
46 std::cerr << "PODIO WARNING: Cannot find the definition for the EDM with the index " << index << std::endl;
47 static constexpr std::string_view emptyDef = "{}"; // valid empty JSON
48 return emptyDef;
49 }
50
51 return m_definitions[index].second;
52}

◆ getDatamodelDefinition() [2/2]

const std::string_view podio::DatamodelRegistry::getDatamodelDefinition ( std::string_view  name) const

Get the definition (in JSON format) of the datamodel with the given edmName.

If no datamodel with the given name can be found, an empty datamodel definition, i.e. an empty JSON object ("{}"), is returned.

Parameters
nameThe name of the datamodel

Definition at line 32 of file DatamodelRegistry.cc.

32 {
33 const auto it = std::find_if(m_definitions.cbegin(), m_definitions.cend(),
34 [&name](const auto& kvPair) { return kvPair.first == name; });
35 if (it == m_definitions.cend()) {
36 std::cerr << "PODIO WARNING: Cannot find the definition for the EDM with the name " << name << std::endl;
37 static constexpr std::string_view emptyDef = "{}"; // valid empty JSON
38 return emptyDef;
39 }
40
41 return it->second;
42}

◆ getDatamodelName()

const std::string & podio::DatamodelRegistry::getDatamodelName ( size_t  index) const

Get the name of the datamodel that is stored under the given index.

If no datamodel is found under the given index, an empty string is returned

Parameters
indexThe datamodel definition index that can be obtained from each collection

Definition at line 54 of file DatamodelRegistry.cc.

54 {
55 if (index >= m_definitions.size()) {
56 std::cout << "PODIO WARNING: Cannot find the name of the EDM with the index " << index << std::endl;
57 static const std::string emptyName = "";
58 return emptyName;
59 }
60 return m_definitions[index].first;
61}

◆ instance()

const DatamodelRegistry & podio::DatamodelRegistry::instance ( )
static

Get the registry.

Definition at line 9 of file DatamodelRegistry.cc.

9 {
10 return mutInstance();
11}
static DatamodelRegistry & mutInstance()

Referenced by podio::DatamodelDefinitionCollector::getDatamodelDefinitionsToWrite().

◆ mutInstance()

DatamodelRegistry & podio::DatamodelRegistry::mutInstance ( )
static

Definition at line 13 of file DatamodelRegistry.cc.

13 {
14 static DatamodelRegistry registryInstance;
15 return registryInstance;
16}
DatamodelRegistry(const DatamodelRegistry &)=delete

Referenced by instance().

◆ operator=() [1/2]

DatamodelRegistry & podio::DatamodelRegistry::operator= ( const DatamodelRegistry &&  )
delete

◆ operator=() [2/2]

DatamodelRegistry & podio::DatamodelRegistry::operator= ( const DatamodelRegistry )
delete

◆ registerDatamodel()

size_t podio::DatamodelRegistry::registerDatamodel ( std::string  name,
std::string_view  definition 
)

Register a datamodel return the index in the registry.

This is the hook that is called during dynamic loading of an EDM to register information for this EDM. If an EDM has already been registered under this name, than the index to the existing EDM in the registry will be returned.

Parameters
nameThe name of the EDM that should be registered
definitionThe datamodel definition from which this EDM has been generated in JSON format

Definition at line 18 of file DatamodelRegistry.cc.

18 {
19 const auto it = std::find_if(m_definitions.cbegin(), m_definitions.cend(),
20 [&name](const auto& kvPair) { return kvPair.first == name; });
21
22 if (it == m_definitions.cend()) {
23 int index = m_definitions.size();
24 m_definitions.emplace_back(name, definition);
25 return index;
26 }
27
28 // TODO: Output?
29 return std::distance(m_definitions.cbegin(), it);
30}

Member Data Documentation

◆ NoDefinitionAvailable

constexpr size_t podio::DatamodelRegistry::NoDefinitionAvailable = -2
staticconstexpr

Dedicated index value for error checking, used to default init the generated RegistryIndex.

Definition at line 43 of file DatamodelRegistry.h.

Referenced by podio::DatamodelDefinitionCollector::registerDatamodelDefinition().

◆ NoDefinitionNecessary

constexpr size_t podio::DatamodelRegistry::NoDefinitionNecessary = -1
staticconstexpr

Dedicated index value for collections that don't have a datamodel definition (e.g. UserDataCollection)

Definition at line 41 of file DatamodelRegistry.h.

Referenced by podio::UserDataCollection< BasicType, typename >::getDatamodelRegistryIndex(), and podio::DatamodelDefinitionCollector::registerDatamodelDefinition().


The documentation for this class was generated from the following files: