Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GaudiHistoID.h
Go to the documentation of this file.
1 #ifndef GAUDIALG_GAUDIHISTOID_H
2 #define GAUDIALG_GAUDIHISTOID_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD&STL
7 // ============================================================================
8 #include <string>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/Hash.h"
13 #include "GaudiKernel/Kernel.h"
14 // ============================================================================
15 /* @file
16  *
17  * Header file for class GaudiAlg::ID
18  *
19  * @author Chris Jones Christopher.Rob.Jones@cern.ch
20  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
21  * @date 2004-01-23
22  */
23 // ============================================================================
32 // ============================================================================
33 namespace GaudiAlg {
34  // ==========================================================================
43  class GAUDI_API ID {
44  public:
45  // ========================================================================
47  typedef int NumericID;
50  // ========================================================================
51  public:
52  // ========================================================================
54  ID( const NumericID id = -1 ) : m_nID( id ), m_hash( boost::hash_value( id ) ) {}
56  ID( LiteralID&& id ) : m_aID( std::move( id ) ), m_hash( boost::hash_value( m_aID ) ) {}
58  ID( const LiteralID& id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
60  ID( const char* id ) : m_aID( id ), m_hash( boost::hash_value( m_aID ) ) {}
62  ~ID() = default;
64  inline bool numeric() const noexcept { return -1 != m_nID; }
66  inline bool literal() const noexcept { return !m_aID.empty(); }
68  inline bool undefined() const noexcept { return !numeric() && !literal(); }
70  inline const LiteralID& literalID() const noexcept { return m_aID; }
72  inline NumericID numericID() const noexcept { return m_nID; }
74  GAUDI_API LiteralID idAsString() const;
76  operator std::string() const { return idAsString(); }
81  inline bool operator==( const ID& id ) const noexcept {
82  return hash() != id.hash()
83  ? false
84  : numeric() && id.numeric()
85  ? id.numericID() == numericID()
86  : literal() && id.literal() ? id.literalID() == literalID() : idAsString() == id.idAsString();
87  }
89  inline bool operator!=( const ID& id ) const { return !( *this == id ); }
94  inline bool operator<( const ID& id ) const noexcept {
95  return
96  // hash () < id.hash () ? true :
97  // hash () > id.hash () ? false :
98  numeric() && id.numeric()
99  ? numericID() < id.numericID()
100  : literal() && id.literal() ? literalID() < id.literalID() : idAsString() < id.idAsString();
101  }
102  // ========================================================================
103  GAUDI_API std::ostream& fillStream( std::ostream& s ) const;
104  // ========================================================================
105  public:
106  // ========================================================================
108  bool operator!() const noexcept { return undefined(); }
109  // ========================================================================
110  public:
111  // ========================================================================
113  inline size_t hash() const noexcept { return m_hash; }
115  inline size_t __hash__() const noexcept { return hash(); }
116  // ========================================================================
117  private:
118  // ========================================================================
120  NumericID m_nID{-1}; // Internal numeric ID
122  LiteralID m_aID; // Internal alpha-numeric ID
123  // ========================================================================
124  private:
125  // ========================================================================
127  size_t m_hash{0}; // the hash value of ID
128  // ========================================================================
129  };
130  // ==========================================================================
132  inline std::ostream& operator<<( std::ostream& str, const GaudiAlg::ID& id ) { return id.fillStream( str ); }
133  // ==========================================================================
134 } // end of namespace GaudiAlg
135 // ============================================================================
136 namespace GaudiUtils {
137  // ==========================================================================
139  template <>
140  inline size_t Hash<GaudiAlg::ID>::operator()( const GaudiAlg::ID& key ) const {
141  return key.hash();
142  }
143  // ==========================================================================
144 } // end of namespace GaudiUtils
145 // ============================================================================
146 // The END
147 // ============================================================================
148 #endif // GAUDIALG_GAUDIHISTOID_H
ID(const LiteralID &id)
Implicit &#39;copy&#39; constructor from a literal ID.
Definition: GaudiHistoID.h:58
bool operator!() const noexcept
good ID?
Definition: GaudiHistoID.h:108
bool operator==(const ID &id) const noexcept
Implement the operator == Implementation depends on type of ID.
Definition: GaudiHistoID.h:81
ID(LiteralID &&id)
Implicit &#39;move&#39; constructor from a literal ID.
Definition: GaudiHistoID.h:56
NumericID numericID() const noexcept
Returns the numerical ID.
Definition: GaudiHistoID.h:72
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:47
STL namespace.
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:89
bool operator<(const ID &id) const noexcept
Implement the operator < Implementation depends on type of ID.
Definition: GaudiHistoID.h:94
STL class.
size_t __hash__() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:115
ID(const NumericID id=-1)
Implicit constructor from a numeric ID.
Definition: GaudiHistoID.h:54
std::size_t hash_value(TupleID const &b)
Definition: TupleID.h:31
bool literal() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:66
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:49
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:136
const LiteralID & literalID() const noexcept
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:70
string s
Definition: gaudirun.py:312
LiteralID m_aID
Internal alpha-numeric ID.
Definition: GaudiHistoID.h:122
bool numeric() const noexcept
Is this ID numeric.
Definition: GaudiHistoID.h:64
size_t hash() const noexcept
return hash value (for python)
Definition: GaudiHistoID.h:113
bool undefined() const noexcept
Is this ID undefined.
Definition: GaudiHistoID.h:68
#define GAUDI_API
Definition: Kernel.h:71
GaudiAlg.h GaudiAlg/GaudiAlg.h Namespace with definition of useful constants, types and function...
STL class.
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:43
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:132
ID(const char *id)
Implicit constructor from a literal ID.
Definition: GaudiHistoID.h:60