The Gaudi Framework  v37r1 (a7f61348)
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() ? false
93  : numeric() && id.numeric() ? id.numericID() == numericID()
94  : literal() && id.literal() ? id.literalID() == literalID()
95  : idAsString() == id.idAsString();
96  }
98  inline bool operator!=( const ID& id ) const { return !( *this == id ); }
103  inline bool operator<( const ID& id ) const noexcept {
104  return
105  // hash () < id.hash () ? true :
106  // hash () > id.hash () ? false :
107  numeric() && id.numeric() ? numericID() < id.numericID()
108  : literal() && id.literal() ? literalID() < id.literalID()
109  : idAsString() < id.idAsString();
110  }
111  // ========================================================================
112  GAUDI_API std::ostream& fillStream( std::ostream& s ) const;
113  // ========================================================================
114  public:
115  // ========================================================================
117  bool operator!() const noexcept { return undefined(); }
118  // ========================================================================
119  public:
120  // ========================================================================
122  inline size_t hash() const noexcept { return m_hash; }
124  inline size_t __hash__() const noexcept { return hash(); }
125  // ========================================================================
126  private:
127  // ========================================================================
129  NumericID m_nID{ -1 }; // Internal numeric ID
131  LiteralID m_aID; // Internal alpha-numeric ID
132  // ========================================================================
133  private:
134  // ========================================================================
136  size_t m_hash{ 0 }; // the hash value of ID
137  // ========================================================================
138  };
139  // ==========================================================================
141  inline std::ostream& operator<<( std::ostream& str, const GaudiAlg::ID& id ) { return id.fillStream( str ); }
142  // ==========================================================================
143 } // end of namespace GaudiAlg
144 // ============================================================================
145 namespace GaudiUtils {
146  // ==========================================================================
148  template <>
149  inline size_t Hash<GaudiAlg::ID>::operator()( const GaudiAlg::ID& key ) const {
150  return key.hash();
151  }
152  // ==========================================================================
153 } // end of namespace GaudiUtils
154 // ============================================================================
155 // The END
156 // ============================================================================
157 #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:124
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:103
GaudiAlg::ID::LiteralID
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:59
gaudirun.s
string s
Definition: gaudirun.py:348
GaudiAlg::ID::hash
size_t hash() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:122
GaudiAlg::ID::operator!=
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:98
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:141
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:117
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:131
GaudiUtils
Definition: GaudiHistoID.h:145
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:81
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