// EventId.cxx #include "EventId.h" #include #include using std::ostream; using std::ios_base; using std::endl; using std::setw; using std::hex; using hes::Index; using hes::EventId; #ifdef DEFECT_GCC_2_95 namespace std { typedef ios ios_base; } #endif namespace { // Bit masks. long LOMASK = 0xFF000000L; long HIMASK = 0x00FFFFFFL; } //********************************************************************** // Static member functions. //********************************************************************** // Return the version. int EventId::version() { return 1; } //********************************************************************** // Member functions. //********************************************************************** // Default constructor. EventId::EventId() : m_hi(0), m_lo(0) { } //********************************************************************** // Constructor from hi and lo. EventId::EventId(Index hi, Index lo) : m_hi(hi), m_lo(lo) { if ( m_hi==0 || m_lo==0 ) { m_hi = 0; m_lo = 0; } } //********************************************************************** // Validity check. bool EventId::is_valid() const { return m_hi > 0 && m_lo > 0; } //********************************************************************** // Return the hi index. Index EventId::hi_index() const { if ( ! is_valid() ) return 0; return m_hi; } //********************************************************************** // Return the lo index. Index EventId::lo_index() const { if ( ! is_valid() ) return 0; return m_lo; } //********************************************************************** // Free functions. //********************************************************************** // Ordering. bool operator<(const EventId& lhs, const EventId& rhs) { if ( lhs.hi_index() == rhs.hi_index() ) { return lhs.lo_index() < rhs.lo_index(); } else { return lhs.hi_index() < rhs.hi_index(); } } //********************************************************************** // Equality. bool operator==(const EventId& lhs, const EventId& rhs) { if ( lhs.is_valid() ) { if ( rhs.is_valid() ) { return lhs.hi_index()==rhs.hi_index() && lhs.lo_index()==rhs.lo_index(); } else { return false; } } else { return rhs.is_valid(); } } //********************************************************************** bool operator!=(const EventId& lhs, const EventId& rhs) { return ! ( lhs == rhs ); } //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const EventId& rhs) { std::ios_base::fmtflags flags = lhs.flags(); char fillchar = lhs.fill(); if ( rhs.is_valid() ) { lhs << hex << setfill('0') << setw(8) << rhs.hi_index() << "-" << setw(8) << rhs.lo_index(); } else { lhs << "invalid event id"; } lhs.flags(flags); lhs.fill(fillchar); return lhs; } //**********************************************************************