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/Kernel.h"
13 #include "GaudiKernel/Hash.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 {
35  // ==========================================================================
44  class GAUDI_API ID
45  {
46  public:
47  // ========================================================================
49  typedef int NumericID;
52  // ========================================================================
53  public:
54  // ========================================================================
56  ID ( const NumericID id = -1 ) ;
58  ID ( const LiteralID& id ) ;
60  ID ( const char* id ) ;
62  ~ID ( ) = default;
64  inline bool numeric () const { return -1 != m_nID ; }
66  inline bool literal () const { return !m_aID.empty() ; }
68  inline bool undefined () const { return !numeric() && !literal(); }
70  inline const LiteralID& literalID() const { return m_aID; }
72  inline NumericID numericID() const { return m_nID; }
74  GAUDI_API LiteralID idAsString() const ;
76  operator std::string () const { return idAsString () ; }
81  inline bool operator==( const ID& id ) const
82  {
83  return
84  hash () != id.hash () ? false :
85  numeric () && id.numeric () ? id.numericID () == numericID () :
86  literal () && id.literal () ? id.literalID () == literalID () :
87  idAsString () == id.idAsString() ;
88  }
90  inline bool operator!=( const ID& id ) const { return ! ( *this == id ) ; }
95  inline bool operator<( const ID& id ) const
96  {
97  return
98  //hash () < id.hash () ? true :
99  //hash () > id.hash () ? false :
100  numeric () && id.numeric() ? numericID() < id.numericID() :
101  literal () && id.literal() ? literalID() < id.literalID() :
102  idAsString () < id.idAsString() ;
103  }
104  // ========================================================================
105  GAUDI_API std::ostream& fillStream ( std::ostream& s ) const ;
106  // ========================================================================
107  public:
108  // ========================================================================
110  bool operator!() const { return undefined() ; }
111  // ========================================================================
112  public:
113  // ========================================================================
115  inline size_t hash () const { return m_hash ; }
117  inline size_t __hash__ () const { return hash () ; }
118  // ========================================================================
119  private:
120  // ========================================================================
122  NumericID m_nID ; // Internal numeric ID
124  LiteralID m_aID ; // Internal alpha-numeric ID
125  // ========================================================================
126  private:
127  // ========================================================================
129  size_t m_hash ; // the hash value of ID
130  // ========================================================================
131  };
132  // ==========================================================================
135  { return id.fillStream ( str ) ; }
136  // ==========================================================================
137 } // end of namespace GaudiAlg
138 // ============================================================================
139 namespace GaudiUtils
140 {
141  // ==========================================================================
143  template <>
144  inline size_t Hash<GaudiAlg::ID>::operator()
145  ( const GaudiAlg::ID& key ) const { return key.hash () ; }
146  // ==========================================================================
147 } // end of namespace GaudiUtils
148 // ============================================================================
149 // The END
150 // ============================================================================
151 #endif // GAUDIALG_GAUDIHISTOID_H
152 // ============================================================================
size_t m_hash
the hash value of ID
Definition: GaudiHistoID.h:129
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:49
size_t hash() const
return hash value (for python)
Definition: GaudiHistoID.h:115
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:90
NumericID m_nID
Internal numeric ID.
Definition: GaudiHistoID.h:122
STL class.
bool operator==(const ID &id) const
Implement the operator == Implementation depends on type of ID.
Definition: GaudiHistoID.h:81
NumericID numericID() const
Returns the numerical ID.
Definition: GaudiHistoID.h:72
bool operator!() const
good ID?
Definition: GaudiHistoID.h:110
Simple hash function.
Definition: Hash.h:96
const LiteralID & literalID() const
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:70
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:51
size_t __hash__() const
return hash value (for python)
Definition: GaudiHistoID.h:117
bool undefined() const
Is this ID undefined.
Definition: GaudiHistoID.h:68
bool operator<(const ID &id) const
Implement the operator < Implementation depends on type of ID.
Definition: GaudiHistoID.h:95
Forward declarations for the functions in SerializeSTL.h.
Definition: GaudiHistoID.h:139
string s
Definition: gaudirun.py:245
LiteralID m_aID
Internal alpha-numeric ID.
Definition: GaudiHistoID.h:124
bool literal() const
Is this ID numeric.
Definition: GaudiHistoID.h:66
#define GAUDI_API
Definition: Kernel.h:107
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:44
bool numeric() const
Is this ID numeric.
Definition: GaudiHistoID.h:64
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:134