| The Gaudi Framework v32r1 (f65d50dc)

DataObjID.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_DATAOBJID
2 #define GAUDIKERNEL_DATAOBJID 1
3
4 #include "GaudiKernel/ClassID.h"
5 #include "GaudiKernel/StatusCode.h"
6
7 #include <iostream>
8 #include <mutex>
9 #include <string>
10 #include <unordered_set>
11
12 //---------------------------------------------------------------------------
13
32 //---------------------------------------------------------------------------
33
34 struct DataObjID_Hasher;
35 class IClassIDSvc;
36
37 class DataObjID {
38 public:
39 friend DataObjID_Hasher;
40
41 DataObjID() = default;
42 DataObjID( const DataObjID& ) = default;
43 DataObjID( const std::string& key );
44 DataObjID( const CLID& clid, const std::string& key );
45 DataObjID( const std::string& className, const std::string& key );
46
47 // only return the last part of the key
48 const std::string& key() const { return m_key; }
49
50 // combination of the key and the ClassName, mostly for debugging
51 std::string fullKey() const;
52
53 CLID clid() const { return m_clid; }
54
55 void updateKey( const std::string& key );
56
57 friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
58 friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
59 friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
60
61 friend StatusCode parse( DataObjID& dest, const std::string& src );
62 friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
63 friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
64
65 private:
66 void hashGen();
67 void setClid();
68 void setClassName();
69
70 CLID m_clid{0};
71 std::size_t m_hash{0};
72
73 std::string m_key{"INVALID"};
74 std::string m_className;
75
76 static IClassIDSvc* p_clidSvc;
77 static std::once_flag m_ip;
78 };
79
80 inline DataObjID::DataObjID( const std::string& key ) : m_key( key ) { hashGen(); }
81
82 inline DataObjID::DataObjID( const CLID& clid, const std::string& key ) : m_clid( clid ), m_key( key ) {
83 setClassName();
84 hashGen();
85 }
86
87 inline DataObjID::DataObjID( const std::string& className, const std::string& key )
88 : m_key( key ), m_className( className ) {
89 setClid();
90 hashGen();
91 }
92
93 inline void DataObjID::updateKey( const std::string& key ) {
94 m_key = key;
95 hashGen();
96 }
97
98 struct DataObjID_Hasher {
99 std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
100 };
101
102 using DataObjIDColl = std::unordered_set<DataObjID, DataObjID_Hasher>;
103
104 namespace Gaudi {
105 namespace Details {
106 namespace Property {
107 template <typename T>
108 struct StringConverter;
109
110 template <>
111 struct StringConverter<DataObjIDColl> {
112 std::string toString( const DataObjIDColl& v );
113 DataObjIDColl fromString( const DataObjIDColl&, const std::string& );
114 };
115 } // namespace Property
116 } // namespace Details
117 } // namespace Gaudi
118
119 #endif
DataObjID::toStream
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition: DataObjID.cpp:82
ClassID.h
Gaudi::Details::Property::DefaultStringConverter::fromString
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:202
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
DataObjID
Definition: DataObjID.h:37
DataObjID::operator!=
friend bool operator!=(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:59
DataObjID::p_clidSvc
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:76
DataObjID::updateKey
void updateKey(const std::string &key)
Definition: DataObjID.h:93
Gaudi::Details::Property::DefaultStringConverterImpl::toString
std::string toString(const TYPE &v)
Definition: Property.h:169
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:73
std::size_t
std::once_flag
DataObjID::fullKey
std::string fullKey() const
Definition: DataObjID.cpp:88
DataObjID::DataObjID_Hasher
friend DataObjID_Hasher
Definition: DataObjID.h:39
std::string
STL class.
DataObjID::m_ip
static std::once_flag m_ip
Definition: DataObjID.h:77
IClassIDSvc
interface to the CLID database
Definition: IClassIDSvc.h:22
DataObjID::parse
friend StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:46
gaudirun.dest
dest
Definition: gaudirun.py:201
DataObjID::clid
CLID clid() const
Definition: DataObjID.h:53
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
DataObjID_Hasher::operator()
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:99
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:70
std::unordered_set
STL class.
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:71
DataObjID_Hasher
Definition: DataObjID.h:98
Gaudi::Details::Property::StringConverter
Definition: DataObjID.h:108
DataObjID::key
const std::string & key() const
Definition: DataObjID.h:48
DataObjID::DataObjID
DataObjID()=default
DataObjID::operator==
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:58
StatusCode.h
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:56
DataObjID::setClassName
void setClassName()
Definition: DataObjID.cpp:65
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:74
std::ostream
STL class.
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:73
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
DataObjID::operator<
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:57
DataObjID::operator<<
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition: DataObjID.h:63