PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
DatamodelRegistry.cc
Go to the documentation of this file.
2
3#include <algorithm>
4#include <iostream>
5#include <iterator>
6#include <string_view>
7
8namespace podio {
10 return mutInstance();
11}
12
14 static DatamodelRegistry registryInstance;
15 return registryInstance;
16}
17
18size_t DatamodelRegistry::registerDatamodel(std::string name, std::string_view definition) {
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}
31
32const std::string_view DatamodelRegistry::getDatamodelDefinition(std::string_view name) const {
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}
43
44const std::string_view DatamodelRegistry::getDatamodelDefinition(size_t index) const {
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}
53
54const std::string& DatamodelRegistry::getDatamodelName(size_t index) const {
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}
62
63} // namespace podio
static const DatamodelRegistry & instance()
Get the registry.
static DatamodelRegistry & mutInstance()
const std::string & getDatamodelName(size_t index) const
size_t registerDatamodel(std::string name, std::string_view definition)
const std::string_view getDatamodelDefinition(std::string_view name) const