The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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>
15
16#include <iostream>
17#include <memory>
18#include <mutex>
19#include <string>
20#include <unordered_set>
21
22//---------------------------------------------------------------------------
23
41
42//---------------------------------------------------------------------------
43
44struct DataObjID_Hasher;
45class IClassIDSvc;
46
47class DataObjID {
48public:
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;
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
84 friend StatusCode parse( DataObjID& dest, std::string_view src );
85 friend std::ostream& toStream( const DataObjID& v, std::ostream& o );
86 friend std::ostream& operator<<( std::ostream& os, const DataObjID& d ) { return toStream( d, os ); }
87
88private:
89 void hashGen();
90 void setClid();
91
93 std::size_t m_hash{ 0 };
94
95 std::string m_key{ "INVALID" };
96 mutable std::string m_className;
97 mutable std::once_flag m_setClassName;
98};
99
100inline DataObjID::DataObjID( std::string key ) : m_key( std::move( key ) ) { hashGen(); }
101
102inline DataObjID::DataObjID( const CLID& clid, std::string key ) : m_clid( clid ), m_key( std::move( key ) ) {
103 hashGen();
104}
105
106inline DataObjID::DataObjID( std::string className, std::string key )
107 : m_key( std::move( key ) ), m_className( std::move( className ) ) {
108 setClid();
109 hashGen();
110}
111
112inline void DataObjID::updateKey( std::string key ) {
113 m_key = std::move( key );
114 hashGen();
115}
116
118 std::size_t operator()( const DataObjID& k ) const { return k.m_hash; }
119};
120
121using DataObjIDColl = std::unordered_set<DataObjID, DataObjID_Hasher>;
122using DataObjIDVector = std::vector<DataObjID>;
123
124namespace Gaudi {
125 namespace Details {
126 namespace Property {
127 template <typename T>
129
130 template <>
132 std::string toString( const DataObjIDColl& v );
133 DataObjIDColl fromString( const DataObjIDColl&, const std::string& );
134 };
135
136 template <>
138 std::string toString( const DataObjIDVector& v );
139 DataObjIDVector fromString( const DataObjIDVector&, const std::string& );
140 };
141 } // namespace Property
142 } // namespace Details
143} // namespace Gaudi
unsigned int CLID
Class ID definition.
Definition ClassID.h:16
std::unordered_set< DataObjID, DataObjID_Hasher > DataObjIDColl
Definition DataObjID.h:121
std::vector< DataObjID > DataObjIDVector
Definition DataObjID.h:122
void setClid()
Definition DataObjID.cpp:68
std::size_t m_hash
Definition DataObjID.h:93
const std::string & key() const
only return the last part of the key
Definition DataObjID.h:68
std::string fullKey() const
combination of the key and the ClassName, mostly for debugging
CLID clid() const
Definition DataObjID.h:76
void hashGen()
Definition DataObjID.cpp:76
const std::string & className() const
return the ClassName (if available)
Definition DataObjID.cpp:90
std::string m_key
Definition DataObjID.h:95
std::once_flag m_setClassName
Definition DataObjID.h:97
friend bool operator==(const DataObjID &lhs, const DataObjID &rhs)
Definition DataObjID.h:82
CLID m_clid
Definition DataObjID.h:92
DataObjID(const DataObjID &other)
Definition DataObjID.h:52
friend bool operator<(const DataObjID &lhs, const DataObjID &rhs)
Definition DataObjID.h:81
DataObjID & operator=(const DataObjID &other)
Definition DataObjID.h:59
friend DataObjID_Hasher
Definition DataObjID.h:49
DataObjID()=default
std::string m_className
Definition DataObjID.h:96
friend std::ostream & operator<<(std::ostream &os, const DataObjID &d)
Definition DataObjID.h:86
void updateKey(std::string key)
Definition DataObjID.h:112
friend StatusCode parse(DataObjID &dest, std::string_view src)
Definition DataObjID.cpp:58
std::size_t hash() const
Definition DataObjID.h:77
friend std::ostream & toStream(const DataObjID &v, std::ostream &o)
Definition DataObjID.cpp:84
interface to the CLID database
Definition IClassIDSvc.h:24
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1
STL namespace.
std::size_t operator()(const DataObjID &k) const
Definition DataObjID.h:118
TYPE fromString(const TYPE &, const std::string &s) final override
Definition Property.h:95