The Gaudi Framework  v33r1 (b1225454)
DataObjID.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_DATAOBJID
12 #define GAUDIKERNEL_DATAOBJID 1
13 
14 #include "GaudiKernel/ClassID.h"
15 #include "GaudiKernel/StatusCode.h"
16 
17 #include <iostream>
18 #include <mutex>
19 #include <string>
20 #include <unordered_set>
21 
22 //---------------------------------------------------------------------------
23 
42 //---------------------------------------------------------------------------
43 
44 struct DataObjID_Hasher;
45 class IClassIDSvc;
46 
47 class DataObjID {
48 public:
50 
51  DataObjID() = default;
52  DataObjID( const DataObjID& ) = default;
54  DataObjID( const CLID& clid, std::string key );
55  DataObjID( std::string className, std::string key );
56 
57  // only return the last part of the key
58  const std::string& key() const { return m_key; }
59 
60  // combination of the key and the ClassName, mostly for debugging
61  std::string fullKey() const;
62 
63  CLID clid() const { return m_clid; }
64 
65  void updateKey( std::string key );
66 
67  friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
68  friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
69  friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
70 
71  friend StatusCode parse( DataObjID& dest, const std::string& src );
72  friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
73  friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
74 
75 private:
76  void hashGen();
77  void setClid();
78  void setClassName();
79 
82 
83  std::string m_key{"INVALID"};
85 
88 };
89 
90 inline DataObjID::DataObjID( std::string key ) : m_key( std::move( key ) ) { hashGen(); }
91 
92 inline DataObjID::DataObjID( const CLID& clid, std::string key ) : m_clid( clid ), m_key( std::move( key ) ) {
93  setClassName();
94  hashGen();
95 }
96 
98  : m_key( std::move( key ) ), m_className( std::move( className ) ) {
99  setClid();
100  hashGen();
101 }
102 
103 inline void DataObjID::updateKey( std::string key ) {
104  m_key = std::move( key );
105  hashGen();
106 }
107 
109  std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
110 };
111 
113 
114 namespace Gaudi {
115  namespace Details {
116  namespace Property {
117  template <typename T>
119 
120  template <>
122  std::string toString( const DataObjIDColl& v );
124  };
125  } // namespace Property
126  } // namespace Details
127 } // namespace Gaudi
128 
129 #endif
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition: DataObjID.cpp:93
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:220
Implementation of property with value of concrete type.
Definition: Property.h:370
friend bool operator!=(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:69
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:86
STL namespace.
std::string m_key
Definition: DataObjID.h:83
std::string fullKey() const
Definition: DataObjID.cpp:99
friend DataObjID_Hasher
Definition: DataObjID.h:49
STL class.
static std::once_flag m_ip
Definition: DataObjID.h:87
interface to the CLID database
Definition: IClassIDSvc.h:32
friend StatusCode parse(DataObjID &dest, const std::string &src)
Definition: DataObjID.cpp:57
CLID clid() const
Definition: DataObjID.h:63
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:109
CLID m_clid
Definition: DataObjID.h:80
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
std::size_t m_hash
Definition: DataObjID.h:81
T move(T... args)
const std::string & key() const
Definition: DataObjID.h:58
DataObjID()=default
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:68
void setClid()
Definition: DataObjID.cpp:67
void setClassName()
Definition: DataObjID.cpp:76
std::string m_className
Definition: DataObjID.h:84
STL class.
void updateKey(std::string key)
Definition: DataObjID.h:103
void hashGen()
Definition: DataObjID.cpp:84
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:67
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition: DataObjID.h:73