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 <string>
8 #include <unordered_set>
9 #include <iostream>
10 #include <mutex>
11 
12 //---------------------------------------------------------------------------
13 
32 //---------------------------------------------------------------------------
33 
34 
35 class DataObjID_Hasher;
36 class IClassIDSvc;
37 
38 class DataObjID {
39 public:
40  friend DataObjID_Hasher;
41 
42  DataObjID();
43  DataObjID(const std::string& key);
44  DataObjID(const std::string& key, const CLID& clid);
45  DataObjID(const std::string& key, const std::string& className);
46  DataObjID(const DataObjID& d);
47 
48  // only return the last part of the key
49  const std::string& key() const { return m_key; }
50 
51  // combination of the key and the ClassName, mostly for debugging
52  std::string fullKey() const;
53 
54  CLID clid() const { return m_clid; }
55 
56  void updateKey(const std::string& key);
57 
58  friend std::ostream& operator<< (std::ostream& str, const DataObjID& d);
59 
60  bool operator< ( const DataObjID& other ) const {
61  return (m_hash < other.m_hash);
62  }
63 
64  bool operator==( const DataObjID& other ) const {
65  return (m_hash == other.m_hash);
66  }
67 
68 private:
69 
70  void hashGen();
71  void parse(const std::string& key);
72  void setClid();
73  void setClassName();
74 
75  CLID m_clid;
76  std::size_t m_hash;
77 
78  std::string m_key;
79  std::string m_className;
80 
81  static void getClidSvc();
82  static IClassIDSvc* p_clidSvc;
83  static std::once_flag m_ip;
84 
85 };
86 
87 inline DataObjID::DataObjID():
88  m_clid(0), m_hash(0), m_key("INVALID"), m_className("") {}
89 
90 inline DataObjID::DataObjID(const std::string& key):
91  m_clid(0), m_key(key), m_className("") {
92  hashGen();
93 
94 }
95 
96 inline DataObjID::DataObjID(const std::string& key, const CLID& clid):
97  m_clid(clid), m_key(key) {
98  setClassName();
99  hashGen();
100 }
101 
102 inline DataObjID::DataObjID(const std::string& key, const std::string& className):
103  m_key(key), m_className(className) {
104  setClid();
105  hashGen();
106 }
107 
108 
109 inline DataObjID::DataObjID(const DataObjID& d):
110  m_clid(d.m_clid), m_hash(d.m_hash), m_key(d.m_key), m_className(d.m_className) {}
111 
112 inline void DataObjID::updateKey(const std::string& key) {
113  m_key = key;
114  hashGen();
115 }
116 
117 class DataObjID_Hasher {
118 public:
119  std::size_t operator()(const DataObjID& k) const {
120  return (k.m_hash);
121  }
122 };
123 
124 typedef std::unordered_set<DataObjID, DataObjID_Hasher> DataObjIDColl;
125 
126 namespace Gaudi {
127  namespace Parsers {
128  StatusCode parse(DataObjID&, const std::string&);
129  StatusCode parse(DataObjIDColl&, const std::string&);
130  }
131  namespace Utils {
132  GAUDI_API std::ostream& toStream(const DataObjID& v, std::ostream& o);
133  GAUDI_API std::ostream& toStream(const DataObjIDColl& v, std::ostream& o);
134  }
135 }
136 
137 
138 #endif
#define GAUDI_API
Definition: Kernel.h:107
void updateKey(const std::string &key)
Definition: DataObjID.h:112
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
std::string m_key
Definition: DataObjID.h:78
DataObjID()
Definition: DataObjID.h:87
interface to the CLID database
Definition: IClassIDSvc.h:23
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:82
std::ostream & toStream(ITERATOR first, ITERATOR last, std::ostream &s, const std::string &open, const std::string &close, const std::string &delim)
the helper function to print the sequence
Definition: ToStream.h:338
CLID clid() const
Definition: DataObjID.h:54
friend DataObjID_Hasher
Definition: DataObjID.h:40
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
const std::string & key() const
Definition: DataObjID.h:49
CLID m_clid
Definition: DataObjID.h:75
std::size_t m_hash
Definition: DataObjID.h:76
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
static void getClidSvc()
Definition: DataObjID.cpp:23
void parse(const std::string &key)
bool operator==(const DataObjID &other) const
Definition: DataObjID.h:64
void setClid()
Definition: DataObjID.cpp:29
void setClassName()
Definition: DataObjID.cpp:42
bool operator<(const DataObjID &other) const
Definition: DataObjID.h:60
std::string fullKey() const
Definition: DataObjID.cpp:64
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:119
std::string m_className
Definition: DataObjID.h:79
static std::once_flag m_ip
Definition: DataObjID.h:83
void hashGen()
Definition: DataObjID.cpp:11
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::unordered_set< DataObjID, DataObjID_Hasher > DataObjIDColl
Definition: DataObjID.h:124
friend std::ostream & operator<<(std::ostream &str, const DataObjID &d)
Definition: DataObjID.cpp:54