The Gaudi Framework  v30r4 (9b837755)
DataObjID.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_DATAOBJID
2 #define GAUDIKERNEL_DATAOBJID 1
3 
4 #include "GaudiKernel/ClassID.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 {
39 public:
41 
42  DataObjID() = default;
43  DataObjID( const DataObjID& ) = default;
44  DataObjID( const std::string& key );
45  DataObjID( const CLID& clid, const std::string& key );
46  DataObjID( const std::string& className, const std::string& key );
47 
48  // only return the last part of the key
49  const std::string& key() const { return m_key; }
50 
53  bool empty() const { return m_key.empty(); }
54 
55  // combination of the key and the ClassName, mostly for debugging
56  std::string fullKey() const;
57 
58  CLID clid() const { return m_clid; }
59 
60  void updateKey( const std::string& key );
61 
62  friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
63  friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
64  friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
65 
66  friend StatusCode parse( DataObjID& dest, const std::string& src );
67  friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
68  friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
69 
70 private:
71  void hashGen();
72  void setClid();
73  void setClassName();
74 
77 
78  std::string m_key{"INVALID"};
80 
83 };
84 
85 inline DataObjID::DataObjID( const std::string& key ) : m_key( key ) { hashGen(); }
86 
87 inline DataObjID::DataObjID( const CLID& clid, const std::string& key ) : m_clid( clid ), m_key( key )
88 {
89  setClassName();
90  hashGen();
91 }
92 
93 inline DataObjID::DataObjID( const std::string& className, const std::string& key )
94  : m_key( key ), m_className( className )
95 {
96  setClid();
97  hashGen();
98 }
99 
100 inline void DataObjID::updateKey( const std::string& key )
101 {
102  m_key = key;
103  hashGen();
104 }
105 
107  std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
108 };
109 
111 
112 namespace Gaudi
113 {
114  namespace Details
115  {
116  namespace Property
117  {
118  template <typename T>
120 
121  template <>
123  std::string toString( const DataObjIDColl& v );
124  DataObjIDColl fromString( const DataObjIDColl&, const std::string& );
125  };
126  }
127  }
128 }
129 
130 #endif
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition: DataObjID.cpp:92
T empty(T...args)
Implementation of property with value of concrete type.
Definition: Property.h:383
friend bool operator!=(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:64
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:81
void updateKey(const std::string &key)
Definition: DataObjID.h:100
std::string m_key
Definition: DataObjID.h:78
friend DataObjID_Hasher
Definition: DataObjID.h:40
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:82
interface to the CLID database
Definition: IClassIDSvc.h:23
friend StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:52
CLID clid() const
Definition: DataObjID.h:58
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
const std::string & key() const
Definition: DataObjID.h:49
CLID m_clid
Definition: DataObjID.h:75
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::size_t m_hash
Definition: DataObjID.h:76
bool empty() const
Tell if this DataObjID is has an empty key.
Definition: DataObjID.h:53
DataObjID()=default
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:107
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:63
void setClid()
Definition: DataObjID.cpp:63
void setClassName()
Definition: DataObjID.cpp:73
std::string fullKey() const
Definition: DataObjID.cpp:99
std::string m_className
Definition: DataObjID.h:79
STL class.
void hashGen()
Definition: DataObjID.cpp:82
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::string toString(const Type &)
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:62
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition: DataObjID.h:68