The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
DataObjID.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <GaudiKernel/ClassID.h>
14 #include <GaudiKernel/StatusCode.h>
15 
16 #include <iostream>
17 #include <memory>
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& other )
53  : m_clid( other.m_clid ), m_hash( other.m_hash ), m_key( other.m_key ), m_className( other.m_className ) {}
54 
55  DataObjID( std::string key );
56  DataObjID( const CLID& clid, std::string key );
57  DataObjID( std::string className, std::string key );
58 
59  DataObjID& operator=( const DataObjID& other ) {
60  m_clid = other.m_clid;
61  m_hash = other.m_hash;
62  m_key = other.m_key;
63  m_className = other.m_className;
64  return *this;
65  }
66 
68  const std::string& key() const { return m_key; }
69 
71  const std::string& className() const;
72 
74  std::string fullKey() const;
75 
76  CLID clid() const { return m_clid; }
77  std::size_t hash() const { return m_hash; }
78 
79  void updateKey( std::string key );
80 
81  friend bool operator<( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash < rhs.m_hash; }
82  friend bool operator==( const DataObjID& lhs, const DataObjID& rhs ) { return lhs.m_hash == rhs.m_hash; }
83  friend bool operator!=( const DataObjID& lhs, const DataObjID& rhs ) { return !( lhs == rhs ); }
84 
85  friend StatusCode parse( DataObjID& dest, std::string_view src );
86  friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
87  friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
88 
89 private:
90  void hashGen();
91  void setClid();
92 
93  CLID m_clid{ 0 };
94  std::size_t m_hash{ 0 };
95 
96  std::string m_key{ "INVALID" };
97  mutable std::string m_className;
98  mutable std::once_flag m_setClassName;
99 };
100 
101 inline DataObjID::DataObjID( std::string key ) : m_key( std::move( key ) ) { hashGen(); }
102 
103 inline DataObjID::DataObjID( const CLID& clid, std::string key ) : m_clid( clid ), m_key( std::move( key ) ) {
104  hashGen();
105 }
106 
107 inline DataObjID::DataObjID( std::string className, std::string key )
108  : m_key( std::move( key ) ), m_className( std::move( className ) ) {
109  setClid();
110  hashGen();
111 }
112 
113 inline void DataObjID::updateKey( std::string key ) {
114  m_key = std::move( key );
115  hashGen();
116 }
117 
119  std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
120 };
121 
122 using DataObjIDColl = std::unordered_set<DataObjID, DataObjID_Hasher>;
123 using DataObjIDVector = std::vector<DataObjID>;
124 
125 namespace Gaudi {
126  namespace Details {
127  namespace Property {
128  template <typename T>
129  struct StringConverter;
130 
131  template <>
133  std::string toString( const DataObjIDColl& v );
134  DataObjIDColl fromString( const DataObjIDColl&, const std::string& );
135  };
136 
137  template <>
139  std::string toString( const DataObjIDVector& v );
140  DataObjIDVector fromString( const DataObjIDVector&, const std::string& );
141  };
142  } // namespace Property
143  } // namespace Details
144 } // namespace Gaudi
DataObjID::operator<<
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition: DataObjID.h:87
DataObjID::updateKey
void updateKey(std::string key)
Definition: DataObjID.h:113
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
DataObjID::operator<
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:81
DataObjID::DataObjID_Hasher
friend DataObjID_Hasher
Definition: DataObjID.h:49
ClassID.h
Gaudi::Details::Property::DefaultStringConverter::fromString
TYPE fromString(const TYPE &ref_value, const std::string &s) final override
Definition: Property.h:85
StatusCode.h
DataObjID::DataObjID
DataObjID(const DataObjID &other)
Definition: DataObjID.h:52
DataObjID::operator==
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:82
DataObjID::clid
CLID clid() const
Definition: DataObjID.h:76
DataObjID::fullKey
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
Definition: DataObjID.cpp:103
DataObjIDVector
std::vector< DataObjID > DataObjIDVector
Definition: DataObjID.h:123
DataObjID::m_className
std::string m_className
Definition: DataObjID.h:97
StatusCode
Definition: StatusCode.h:64
Gaudi::Details::Property::StringConverter
Definition: Property.h:104
DataObjID_Hasher::operator()
std::size_t operator()(const DataObjID &k) const
Definition: DataObjID.h:119
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:16
DataObjID::operator!=
friend bool operator!=(const DataObjID &lhs, const DataObjID &rhs)
Definition: DataObjID.h:83
DataObjIDColl
std::unordered_set< DataObjID, DataObjID_Hasher > DataObjIDColl
Definition: DataObjID.h:122
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 &other)
Definition: DataObjID.h:59
DataObjID::m_clid
CLID m_clid
Definition: DataObjID.h:93
DataObjID::className
const std::string & className() const
return the ClassName (if available)
Definition: DataObjID.cpp:90
DataObjID::hashGen
void hashGen()
Definition: DataObjID.cpp:76
DataObjID::m_hash
std::size_t m_hash
Definition: DataObjID.h:94
DataObjID::m_key
std::string m_key
Definition: DataObjID.h:96
DataObjID::DataObjID
DataObjID()=default
DataObjID::setClid
void setClid()
Definition: DataObjID.cpp:68
Properties.v
v
Definition: Properties.py:122
DataObjID::key
const std::string & key() const
only return the last part of the key
Definition: DataObjID.h:68
DataObjID::hash
std::size_t hash() const
Definition: DataObjID.h:77
DataObjID::toStream
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition: DataObjID.cpp:84
DataObjID::parse
friend StatusCode parse(DataObjID &dest, std::string_view src)
Definition: DataObjID.cpp:58
IClassIDSvc
interface to the CLID database
Definition: IClassIDSvc.h:24
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:118
DataObjID::m_setClassName
std::once_flag m_setClassName
Definition: DataObjID.h:98