PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
CollectionIDTable.cc
Go to the documentation of this file.
1// podio specific includes
3#include <algorithm>
4#include <iostream>
5
6namespace podio {
7
8CollectionIDTable::CollectionIDTable() : m_mutex(std::make_unique<std::mutex>()) {
9}
10
11CollectionIDTable::CollectionIDTable(std::vector<int>&& ids, std::vector<std::string>&& names) :
12 m_collectionIDs(std::move(ids)), m_names(std::move(names)), m_mutex(std::make_unique<std::mutex>()) {
13}
14
15CollectionIDTable::CollectionIDTable(const std::vector<int>& ids, const std::vector<std::string>& names) :
16 m_collectionIDs(ids), m_names(names), m_mutex(std::make_unique<std::mutex>()) {
17}
18
19const std::string CollectionIDTable::name(int ID) const {
20 std::lock_guard<std::mutex> lock(*m_mutex);
21 const auto result = std::find(begin(m_collectionIDs), end(m_collectionIDs), ID);
22 const auto index = std::distance(m_collectionIDs.begin(), result);
23 return m_names[index];
24}
25
26int CollectionIDTable::collectionID(const std::string& name) const {
27 std::lock_guard<std::mutex> lock(*m_mutex);
28 const auto result = std::find(begin(m_names), end(m_names), name);
29 const auto index = std::distance(m_names.begin(), result);
30 return m_collectionIDs[index];
31}
32
34 std::lock_guard<std::mutex> lock(*m_mutex);
35 std::cout << "CollectionIDTable" << std::endl;
36 for (unsigned i = 0; i < m_names.size(); ++i) {
37 std::cout << "\t" << m_names[i] << " : " << m_collectionIDs[i] << std::endl;
38 }
39}
40
41bool CollectionIDTable::present(const std::string& name) const {
42 std::lock_guard<std::mutex> lock(*m_mutex);
43 const auto result = std::find(begin(m_names), end(m_names), name);
44 return result != end(m_names);
45}
46
47int CollectionIDTable::add(const std::string& name) {
48 std::lock_guard<std::mutex> lock(*m_mutex);
49 const auto result = std::find(begin(m_names), end(m_names), name);
50 int ID = 0;
51 if (result == m_names.end()) {
52 m_names.emplace_back(name);
53 ID = m_names.size();
54 m_collectionIDs.emplace_back(ID);
55 } else {
56 const auto index = std::distance(m_names.begin(), result);
57 ID = m_collectionIDs[index];
58 }
59 return ID;
60}
61
62} // namespace podio
void print() const
Prints collection information.
bool present(const std::string &name) const
Check if collection name is known.
int add(const std::string &name)
int collectionID(const std::string &name) const
return collection ID for given name
const std::string name(int collectionID) const
return name for given collection ID