// EdoId.cxx #include "EdoId.h" #include #include "FileId.h" #include "EventId.h" #include "EdoType.h" #include "EdoKey.h" #include "EdoTypeKey.h" using std::ostream; using hes::Index; using hes::MAX_INDEX; using hes::IndexVector; using hes::FileId; using hes::EventId; using hes::EdoType; using hes::EdoKey; using hes::EdoTypeKey; using hes::EdoId; typedef vector IdVector; //********************************************************************** // Local data. //********************************************************************** namespace { // Vector of ID index vectors. // This may change to a hash table. IdVector IDVS; // Empty vector. const IndexVector EMPTY_VECTOR; // Maximum value for the ID index. Index MAX_VECTOR_INDEX = 0; int initialize() { // Clear the vector. IDVS.clear(); // Insert an invalid index vector in the first position. IDVS.push_back(IndexVector()); // Assign MAX_INDEX. MAX_VECTOR_INDEX = MAX_INDEX; if ( MAX_VECTOR_INDEX > IDVS.max_size() ) { MAX_VECTOR_INDEX = IDVS.max_size(); } // Test that the vector index range is less than the capacity of the vector. assert( MAX_VECTOR_INDEX <= IDVS.max_size() ); // Test that the vector index range fits in Index. assert( MAX_VECTOR_INDEX <= MAX_INDEX ); return 0; } // Force initialization. int init = initialize(); // Find the matching entry in the table. // Add a matching entry if it is not present. Index find(const IndexVector& idxs) { Index idx = 0; for ( Index jdx=1; jdx= IDVS.size() ) { return false; } if ( IDVS[m_idx].size() < 6 ) { return false; } Index keysize = IDVS[m_idx][5]; keysize >>= 24; Index nwords = keysize/4 + 6; if ( IDVS[m_idx].size() != nwords ) { return false; } return true; } //********************************************************************** // Return the file ID. FileId EdoId::file_id() const { if ( ! is_valid() ) { return FileId(); } const IndexVector& idxs = IDVS[m_idx]; return FileId(idxs[0], idxs[1]); } //********************************************************************** // Return the event ID. EventId EdoId::event_id() const { if ( ! is_valid() ) { return EventId(); } const IndexVector& idxs = IDVS[m_idx]; return EventId(idxs[2], idxs[3]); } //********************************************************************** // Return the type. EdoType EdoId::type() const { if ( ! is_valid() ) { return EdoType(); } const IndexVector& idxs = IDVS[m_idx]; return EdoType(idxs[4]); } //********************************************************************** // Return the key. EdoKey EdoId::key() const { if ( ! is_valid() ) { return EdoKey(); } const IndexVector& idxs = IDVS[m_idx]; IndexVector::const_iterator iidx = idxs.begin() + 5; return EdoKey(iidx); } //********************************************************************** // Return the type and key. EdoTypeKey EdoId::type_key() const { return EdoTypeKey(type(), key()); } //********************************************************************** // Return the indices. const IndexVector& EdoId::indices() const { if ( ! is_valid() ) { return EMPTY_VECTOR; } return IDVS[m_idx]; } //********************************************************************** // Free functions. //********************************************************************** // Equality. bool operator==(const EdoId& lhs, const EdoId& rhs) { return lhs.indices() == rhs.indices(); } //********************************************************************** // Inquality. bool operator!=(const EdoId& lhs, const EdoId& rhs) { return ! (lhs == rhs); } //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const EdoId& rhs) { string sep = " "; lhs << rhs.file_id(); lhs << sep; lhs << rhs.event_id(); lhs << sep; lhs << rhs.type(); lhs << sep; lhs << rhs.key(); return lhs; } //**********************************************************************