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

#include <CollectionIDTable.h>

Public Member Functions

 CollectionIDTable ()
 
 ~CollectionIDTable ()=default
 
 CollectionIDTable (const CollectionIDTable &)=delete
 
CollectionIDTableoperator= (const CollectionIDTable &)=delete
 
 CollectionIDTable (CollectionIDTable &&)=default
 
CollectionIDTableoperator= (CollectionIDTable &&)=default
 
 CollectionIDTable (std::vector< int > &&ids, std::vector< std::string > &&names)
 constructor from existing ID:name mapping
 
 CollectionIDTable (const std::vector< int > &ids, const std::vector< std::string > &names)
 
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
 
bool present (const std::string &name) const
 Check if collection name is known.
 
const std::vector< std::string > & names () const
 return registered names
 
const std::vector< int > & ids () const
 return the ids
 
int add (const std::string &name)
 
void print () const
 Prints collection information.
 
bool empty () const
 Does this table hold any information?
 

Detailed Description

Definition at line 11 of file CollectionIDTable.h.

Constructor & Destructor Documentation

◆ CollectionIDTable() [1/5]

podio::CollectionIDTable::CollectionIDTable ( )

Definition at line 8 of file CollectionIDTable.cc.

8 : m_mutex(std::make_unique<std::mutex>()) {
9}

◆ ~CollectionIDTable()

podio::CollectionIDTable::~CollectionIDTable ( )
default

◆ CollectionIDTable() [2/5]

podio::CollectionIDTable::CollectionIDTable ( const CollectionIDTable )
delete

◆ CollectionIDTable() [3/5]

podio::CollectionIDTable::CollectionIDTable ( CollectionIDTable &&  )
default

◆ CollectionIDTable() [4/5]

podio::CollectionIDTable::CollectionIDTable ( std::vector< int > &&  ids,
std::vector< std::string > &&  names 
)

constructor from existing ID:name mapping

Definition at line 11 of file CollectionIDTable.cc.

11 :
12 m_collectionIDs(std::move(ids)), m_names(std::move(names)), m_mutex(std::make_unique<std::mutex>()) {
13}
const std::vector< int > & ids() const
return the ids
const std::vector< std::string > & names() const
return registered names

◆ CollectionIDTable() [5/5]

podio::CollectionIDTable::CollectionIDTable ( const std::vector< int > &  ids,
const std::vector< std::string > &  names 
)

Definition at line 15 of file CollectionIDTable.cc.

15 :
16 m_collectionIDs(ids), m_names(names), m_mutex(std::make_unique<std::mutex>()) {
17}

Member Function Documentation

◆ add()

int podio::CollectionIDTable::add ( const std::string &  name)

register new name to the table returns assigned collection ID

Definition at line 47 of file CollectionIDTable.cc.

47 {
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}
const std::string name(int collectionID) const
return name for given collection ID

◆ collectionID()

int podio::CollectionIDTable::collectionID ( const std::string &  name) const

return collection ID for given name

Definition at line 26 of file CollectionIDTable.cc.

26 {
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}

Referenced by podio::sio_utils::createCollIDBlock().

◆ empty()

bool podio::CollectionIDTable::empty ( ) const
inline

Does this table hold any information?

Definition at line 54 of file CollectionIDTable.h.

54 {
55 return m_names.empty();
56 }

Referenced by podio::SIOFrameData::getIDTable().

◆ ids()

const std::vector< int > & podio::CollectionIDTable::ids ( ) const
inline

return the ids

Definition at line 42 of file CollectionIDTable.h.

42 {
43 return m_collectionIDs;
44 }

Referenced by podio::SIOFrameData::getIDTable(), and podio::root_utils::reconstructCollectionInfo().

◆ name()

const std::string podio::CollectionIDTable::name ( int  collectionID) const

return name for given collection ID

Definition at line 19 of file CollectionIDTable.cc.

19 {
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}

Referenced by add(), collectionID(), podio::createCollectionBranches(), podio::SIOFrameData::getAvailableCollections(), and present().

◆ names()

const std::vector< std::string > & podio::CollectionIDTable::names ( ) const
inline

return registered names

Definition at line 37 of file CollectionIDTable.h.

37 {
38 return m_names;
39 };

Referenced by podio::SIOFrameData::getCollectionBuffers(), podio::SIOFrameData::getIDTable(), and podio::root_utils::reconstructCollectionInfo().

◆ operator=() [1/2]

CollectionIDTable & podio::CollectionIDTable::operator= ( CollectionIDTable &&  )
default

◆ operator=() [2/2]

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

◆ present()

bool podio::CollectionIDTable::present ( const std::string &  name) const

Check if collection name is known.

Definition at line 41 of file CollectionIDTable.cc.

41 {
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}

Referenced by podio::SIOFrameData::getCollectionBuffers().

◆ print()

void podio::CollectionIDTable::print ( ) const

Prints collection information.

Definition at line 33 of file CollectionIDTable.cc.

33 {
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}

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