File indexing completed on 2025-12-15 10:14:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GAUDIKERNEL_DATAOBJID
0012 #define GAUDIKERNEL_DATAOBJID 1
0013
0014 #include <GaudiKernel/ClassID.h>
0015 #include <GaudiKernel/StatusCode.h>
0016
0017 #include <iostream>
0018 #include <memory>
0019 #include <mutex>
0020 #include <string>
0021 #include <unordered_set>
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 struct DataObjID_Hasher;
0046 class IClassIDSvc;
0047
0048 class DataObjID {
0049 public:
0050 friend DataObjID_Hasher;
0051
0052 DataObjID() = default;
0053 DataObjID( const DataObjID& other )
0054 : m_clid( other.m_clid ), m_hash( other.m_hash ), m_key( other.m_key ), m_className( other.m_className ) {}
0055
0056 DataObjID( std::string key );
0057 DataObjID( const CLID& clid, std::string key );
0058 DataObjID( std::string className, std::string key );
0059
0060 DataObjID& operator=( const DataObjID& other ) {
0061 m_clid = other.m_clid;
0062 m_hash = other.m_hash;
0063 m_key = other.m_key;
0064 m_className = other.m_className;
0065 return *this;
0066 }
0067
0068
0069 const std::string& key() const { return m_key; }
0070
0071
0072 const std::string& className() const;
0073
0074
0075 std::string fullKey() const;
0076
0077 CLID clid() const { return m_clid; }
0078 std::size_t hash() const { return m_hash; }
0079
0080 void updateKey( std::string key );
0081
0082 friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
0083 friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
0084 friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
0085
0086 friend StatusCode parse( DataObjID& dest, std::string_view src );
0087 friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
0088 friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
0089
0090 private:
0091 void hashGen();
0092 void setClid();
0093
0094 CLID m_clid{ 0 };
0095 std::size_t m_hash{ 0 };
0096
0097 std::string m_key{ "INVALID" };
0098 mutable std::string m_className;
0099 mutable std::once_flag m_setClassName;
0100 };
0101
0102 inline DataObjID::DataObjID( std::string key ) : m_key( std::move( key ) ) { hashGen(); }
0103
0104 inline DataObjID::DataObjID( const CLID& clid, std::string key ) : m_clid( clid ), m_key( std::move( key ) ) {
0105 hashGen();
0106 }
0107
0108 inline DataObjID::DataObjID( std::string className, std::string key )
0109 : m_key( std::move( key ) ), m_className( std::move( className ) ) {
0110 setClid();
0111 hashGen();
0112 }
0113
0114 inline void DataObjID::updateKey( std::string key ) {
0115 m_key = std::move( key );
0116 hashGen();
0117 }
0118
0119 struct DataObjID_Hasher {
0120 std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
0121 };
0122
0123 using DataObjIDColl = std::unordered_set<DataObjID, DataObjID_Hasher>;
0124 using DataObjIDVector = std::vector<DataObjID>;
0125
0126 namespace Gaudi {
0127 namespace Details {
0128 namespace Property {
0129 template <typename T>
0130 struct StringConverter;
0131
0132 template <>
0133 struct StringConverter<DataObjIDColl> {
0134 std::string toString( const DataObjIDColl& v );
0135 DataObjIDColl fromString( const DataObjIDColl&, const std::string& );
0136 };
0137
0138 template <>
0139 struct StringConverter<DataObjIDVector> {
0140 std::string toString( const DataObjIDVector& v );
0141 DataObjIDVector fromString( const DataObjIDVector&, const std::string& );
0142 };
0143 }
0144 }
0145 }
0146
0147 #endif