The Gaudi Framework  v36r1 (3e2fb5a8)
GaudiHistoID.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 GAUDIALG_GAUDIHISTOID_H
12 #define GAUDIALG_GAUDIHISTOID_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 // STD&STL
17 // ============================================================================
18 #include <string>
19 // ============================================================================
20 // GaudiKernel
21 // ============================================================================
22 #include "GaudiKernel/Hash.h"
23 #include "GaudiKernel/Kernel.h"
24 // ============================================================================
25 /* @file
26  *
27  * Header file for class GaudiAlg::ID
28  *
29  * @author Chris Jones Christopher.Rob.Jones@cern.ch
30  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
31  * @date 2004-01-23
32  */
33 // ============================================================================
42 // ============================================================================
43 namespace GaudiAlg {
44  // ==========================================================================
53  class GAUDI_API ID {
54  public:
55  // ========================================================================
57  typedef int NumericID;
60  // ========================================================================
61  public:
62  // ========================================================================
64  ID( const NumericID id = -1 ) : m_nID( id ), m_hash( boost::hash_value( id ) ) {}
66  ID( LiteralID&& id ) : m_aID( std::move( id ) ), m_hash( boost::hash_value( m_aID ) ) {}
68  ID( const LiteralID& id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
70  ID( const char* id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
72  ~ID() = default;
74  inline bool numeric() const noexcept { return -1 != m_nID; }
76  inline bool literal() const noexcept { return !m_aID.empty(); }
78  inline bool undefined() const noexcept { return !numeric() && !literal(); }
80  inline const LiteralID& literalID() const noexcept { return m_aID; }
82  inline NumericID numericID() const noexcept { return m_nID; }
84  GAUDI_API LiteralID idAsString() const;
86  operator std::string() const { return idAsString(); }
91  inline bool operator==( const ID& id ) const noexcept {
92  return hash() != id.hash()
93  ? false
94  : numeric() && id.numeric()
95  ? id.numericID() == numericID()
96  : literal() && id.literal() ? id.literalID() == literalID() : idAsString() == id.idAsString();
97  }
99  inline bool operator!=( const ID& id ) const { return !( *this == id ); }
104  inline bool operator<( const ID& id ) const noexcept {
105  return
106  // hash () < id.hash () ? true :
107  // hash () > id.hash () ? false :
108  numeric() && id.numeric()
109  ? numericID() < id.numericID()
110  : literal() && id.literal() ? literalID() < id.literalID() : idAsString() < id.idAsString();
111  }
112  // ========================================================================
113  GAUDI_API std::ostream& fillStream( std::ostream& s ) const;
114  // ========================================================================
115  public:
116  // ========================================================================
118  bool operator!() const noexcept { return undefined(); }
119  // ========================================================================
120  public:
121  // ========================================================================
123  inline size_t hash() const noexcept { return m_hash; }
125  inline size_t __hash__() const noexcept { return hash(); }
126  // ========================================================================
127  private:
128  // ========================================================================
130  NumericID m_nID{-1}; // Internal numeric ID
132  LiteralID m_aID; // Internal alpha-numeric ID
133  // ========================================================================
134  private:
135  // ========================================================================
137  size_t m_hash{0}; // the hash value of ID
138  // ========================================================================
139  };
140  // ==========================================================================
142  inline std::ostream& operator<<( std::ostream& str, const GaudiAlg::ID& id ) { return id.fillStream( str ); }
143  // ==========================================================================
144 } // end of namespace GaudiAlg
145 // ============================================================================
146 namespace GaudiUtils {
147  // ==========================================================================
149  template <>
150  inline size_t Hash<GaudiAlg::ID>::operator()( const GaudiAlg::ID& key ) const {
151  return key.hash();
152  }
153  // ==========================================================================
154 } // end of namespace GaudiUtils
155 // ============================================================================
156 // The END
157 // ============================================================================
158 #endif // GAUDIALG_GAUDIHISTOID_H
GaudiAlg::ID::ID
ID(const NumericID id=-1)
Implicit constructor from a numeric ID.
Definition: GaudiHistoID.h:64
GaudiAlg::ID::__hash__
size_t __hash__() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:125
std::string
STL class.
GaudiAlg
GaudiAlg::ID
Definition: GaudiHistoID.h:53
GaudiAlg::ID::operator<
bool operator<(const ID &id) const noexcept
Implement the operator < Implementation depends on type of ID.
Definition: GaudiHistoID.h:104
GaudiAlg::ID::LiteralID
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:59
gaudirun.s
string s
Definition: gaudirun.py:328
GaudiAlg::ID::hash
size_t hash() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:123
GaudiAlg::ID::operator!=
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:99
boost
Definition: WatchdogThread.h:24
GaudiAlg::ID::numericID
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:82
GaudiAlg::ID::operator==
bool operator==(const ID &id) const noexcept
Implement the operator == Implementation depends on type of ID.
Definition: GaudiHistoID.h:91
GaudiAlg::operator<<
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:142
std::ostream
STL class.
GaudiAlg::ID::ID
ID(const LiteralID &id)
Implicit 'copy' constructor from a literal ID.
Definition: GaudiHistoID.h:68
GaudiUtils::Hash::operator()
std::size_t operator()(const T &key) const
the hash-function
Definition: Hash.h:151
GaudiAlg::ID::undefined
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:78
GaudiAlg::ID::operator!
bool operator!() const noexcept
good ID?
Definition: GaudiHistoID.h:118
GaudiAlg::ID::ID
ID(LiteralID &&id)
Implicit 'move' constructor from a literal ID.
Definition: GaudiHistoID.h:66
GaudiAlg::ID::NumericID
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:57
std
STL namespace.
Kernel.h
GaudiAlg::ID::~ID
~ID()=default
Destructor.
GaudiAlg::ID::m_aID
LiteralID m_aID
Internal alpha-numeric ID.
Definition: GaudiHistoID.h:132
GaudiUtils
Definition: GaudiHistoID.h:146
GaudiAlg::ID::ID
ID(const char *id)
Implicit constructor from a literal ID.
Definition: GaudiHistoID.h:70
GaudiAlg::ID::literalID
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:80
ProduceConsume.key
key
Definition: ProduceConsume.py:52
GaudiAlg::ID::numeric
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:74
GaudiAlg::hash_value
std::size_t hash_value(TupleID const &b)
Definition: TupleID.h:41
Hash.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
GaudiAlg::ID::literal
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:76