All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GaudiHistoID.h
Go to the documentation of this file.
1 // $Id:
2 // ============================================================================
3 #ifndef GAUDIALG_GAUDIHISTOID_H
4 #define GAUDIALG_GAUDIHISTOID_H 1
5 // ============================================================================
6 // Include files
7 // ============================================================================
8 // STD&STL
9 // ============================================================================
10 #include <string>
11 // ============================================================================
12 // GaudiKernel
13 // ============================================================================
14 #include "GaudiKernel/Kernel.h"
15 #include "GaudiKernel/Hash.h"
16 // ============================================================================
17 /* @file
18  *
19  * Header file for class GaudiAlg::ID
20  *
21  * @author Chris Jones Christopher.Rob.Jones@cern.ch
22  * @author Vanya BELYAEV Ivan.Belyaev@itep.ru
23  * @date 2004-01-23
24  */
25 // ============================================================================
34 // ============================================================================
35 namespace GaudiAlg
36 {
37  // ==========================================================================
46  class GAUDI_API ID
47  {
48  public:
49  // ========================================================================
51  typedef int NumericID;
53  typedef std::string LiteralID;
54  // ========================================================================
55  public:
56  // ========================================================================
58  ID ( const NumericID id = -1 ) ;
60  ID ( const LiteralID& id ) ;
62  ID ( const char* id ) ;
64  ~ID ( ) {} ;
66  inline bool numeric () const { return -1 != m_nID ; }
68  inline bool literal () const { return !m_aID.empty() ; }
70  inline bool undefined () const { return !numeric() && !literal(); }
72  inline const LiteralID& literalID() const { return m_aID; }
74  inline NumericID numericID() const { return m_nID; }
76  GAUDI_API LiteralID idAsString() const ;
78  operator std::string () const { return idAsString () ; }
83  inline bool operator==( const ID& id ) const
84  {
85  return
86  hash () != id.hash () ? false :
87  numeric () && id.numeric () ? id.numericID () == numericID () :
88  literal () && id.literal () ? id.literalID () == literalID () :
89  idAsString () == id.idAsString() ;
90  }
92  inline bool operator!=( const ID& id ) const { return ! ( *this == id ) ; }
97  inline bool operator<( const ID& id ) const
98  {
99  return
100  //hash () < id.hash () ? true :
101  //hash () > id.hash () ? false :
102  numeric () && id.numeric() ? numericID() < id.numericID() :
103  literal () && id.literal() ? literalID() < id.literalID() :
104  idAsString () < id.idAsString() ;
105  }
106  // ========================================================================
107  GAUDI_API std::ostream& fillStream ( std::ostream& s ) const ;
108  // ========================================================================
109  public:
110  // ========================================================================
112  bool operator!() const { return undefined() ; }
113  // ========================================================================
114  public:
115  // ========================================================================
117  inline size_t hash () const { return m_hash ; }
119  inline size_t __hash__ () const { return hash () ; }
120  // ========================================================================
121  private:
122  // ========================================================================
124  NumericID m_nID ; // Internal numeric ID
126  LiteralID m_aID ; // Internal alpha-numeric ID
127  // ========================================================================
128  private:
129  // ========================================================================
131  size_t m_hash ; // the hash value of ID
132  // ========================================================================
133  };
134  // ==========================================================================
136  inline std::ostream& operator << ( std::ostream& str , const GaudiAlg::ID& id )
137  { return id.fillStream ( str ) ; }
138  // ==========================================================================
139 } // end of namespace GaudiAlg
140 // ============================================================================
141 namespace GaudiUtils
142 {
143  // ==========================================================================
145  template <>
146  inline size_t Hash<GaudiAlg::ID>::operator()
147  ( const GaudiAlg::ID& key ) const { return key.hash () ; }
148  // ==========================================================================
149 } // end of namespace GaudiUtils
150 // ============================================================================
151 // The END
152 // ============================================================================
153 #endif // GAUDIALG_GAUDIHISTOID_H
154 // ============================================================================
size_t m_hash
the hash value of ID
Definition: GaudiHistoID.h:131
int NumericID
type for internal numeric ID
Definition: GaudiHistoID.h:51
size_t hash() const
return hash value (for python)
Definition: GaudiHistoID.h:117
bool operator!=(const ID &id) const
Implement the != operator, using the == operator.
Definition: GaudiHistoID.h:92
NumericID m_nID
Internal numeric ID.
Definition: GaudiHistoID.h:124
bool operator==(const ID &id) const
Implement the operator == Implementation depends on type of ID.
Definition: GaudiHistoID.h:83
NumericID numericID() const
Returns the numerical ID.
Definition: GaudiHistoID.h:74
bool operator!() const
good ID?
Definition: GaudiHistoID.h:112
Simple hash function.
Definition: Hash.h:98
const LiteralID & literalID() const
Returns the ID as a LiteralID.
Definition: GaudiHistoID.h:72
std::string LiteralID
type for internal literal ID
Definition: GaudiHistoID.h:53
size_t __hash__() const
return hash value (for python)
Definition: GaudiHistoID.h:119
~ID()
Destructor.
Definition: GaudiHistoID.h:64
bool undefined() const
Is this ID undefined.
Definition: GaudiHistoID.h:70
bool operator<(const ID &id) const
Implement the operator < Implementation depends on type of ID.
Definition: GaudiHistoID.h:97
string s
Definition: gaudirun.py:210
LiteralID m_aID
Internal alpha-numeric ID.
Definition: GaudiHistoID.h:126
bool literal() const
Is this ID numeric.
Definition: GaudiHistoID.h:68
#define GAUDI_API
Definition: Kernel.h:108
ID class for Histogram and Ntuples.
Definition: GaudiHistoID.h:46
bool numeric() const
Is this ID numeric.
Definition: GaudiHistoID.h:66
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:136