The Gaudi Framework  master (37c0b60a)
DataObjID.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 );
56 
57  DataObjID& operator=( const DataObjID& ) = default;
58 
60  const std::string& key() const { return m_key; }
61 
63  const std::string& className() const { return m_className; }
64 
66  std::string fullKey() const;
67 
68  CLID clid() const { return m_clid; }
69  std::size_t hash() const { return m_hash; }
70 
71  void updateKey( std::string key );
72 
73  friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
74  friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
75  friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
76 
77  friend StatusCode parse( DataObjID& dest, std::string_view src );
78  friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
79  friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
80 
81 private:
82  void hashGen();
83  void setClid();
84  void setClassName();
85 
86  CLID m_clid{ 0 };
88 
89  std::string m_key{ "INVALID" };
91 
94 };
95 
96 inline DataObjID::DataObjID( std::string key ) : m_key( std::move( key ) ) { hashGen(); }
97 
98 inline DataObjID::DataObjID( const CLID& clid, std::string key ) : m_clid( clid ), m_key( std::move( key ) ) {
99  setClassName();
100  hashGen();
101 }
102 
104  : m_key( std::move( key ) ), m_className( std::move( className ) ) {
105  setClid();
106  hashGen();
107 }
108 
110  m_key = std::move( key );
111  hashGen();
112 }
113 
115  std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
116 };
117 
120 
121 namespace Gaudi {
122  namespace Details {
123  namespace Property {
124  template <typename T>
125  struct StringConverter;
126 
127  template <>
131  };
132 
133  template <>
137  };
138  } // namespace Property
139  } // namespace Details
140 } // namespace Gaudi
141 
142 #endif
DataObjID::operator<<
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition: DataObjID.h:79
DataObjID::m_ip
static std::once_flag m_ip
Definition: DataObjID.h:93
std::string
STL class.
DataObjID::setClassName
void setClassName()
Definition: DataObjID.cpp:76
std::move
T move(T... args)
DataObjID::updateKey
void updateKey(std::string key)
Definition: DataObjID.h:109
std::unordered_set< DataObjID, DataObjID_Hasher >
DataObjID::operator<
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:73
DataObjID::DataObjID_Hasher
friend DataObjID_Hasher
Definition: DataObjID.h:49
std::vector
STL class.
ClassID.h
StatusCode.h
DataObjID::operator==
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:74
DataObjID::clid
CLID clid() const
Definition: DataObjID.h:68
DataObjID::fullKey
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
Definition: DataObjID.cpp:99
std::once_flag
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:90
StatusCode
Definition: StatusCode.h:65
std::ostream
STL class.
Gaudi::Details::Property::DefaultStringConverter< TYPE >::fromString
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:85
Gaudi::Details::Property::StringConverter
Definition: Property.h:104
DataObjID_Hasher::operator()
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:115
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:18
DataObjID::operator!=
friend bool operator!=(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:75
DataObjID::className
const std::string & className() const
return the ClassName (if available)
Definition: DataObjID.h:63
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
DataObjID
Definition: DataObjID.h:47
gaudirun.dest
dest
Definition: gaudirun.py:224
DataObjID::operator=
DataObjID & operator=(const DataObjID &)=default
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:86
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:84
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:87
std
STL namespace.
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:89
DataObjID::DataObjID
DataObjID()=default
DataObjID::p_clidSvc
static IClassIDSvc * p_clidSvc
Definition: DataObjID.h:92
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:67
Properties.v
v
Definition: Properties.py:122
DataObjID::DataObjID
DataObjID(const DataObjID &)=default
DataObjID::key
const std::string & key() const
only return the last part of the key
Definition: DataObjID.h:60
std::size_t
DataObjID::hash
std::size_t hash() const
Definition: DataObjID.h:69
DataObjID::toStream
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition: DataObjID.cpp:93
DataObjID::parse
friend StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:57
IClassIDSvc
interface to the CLID database
Definition: IClassIDSvc.h:25
ProduceConsume.key
key
Definition: ProduceConsume.py:84
Gaudi::Details::Property::DefaultStringConverterImpl::toString
std::string toString(const TYPE &v)
Definition: Property.h:51
DataObjID_Hasher
Definition: DataObjID.h:114