// EventId.cxx #include "dataset_id/EventId.h" #include #include "dataset_util/XmlElement.h" #include "dataset_util/DtdRegistry.h" using std::ostream; typedef EventId::RunNumber RunNumber; typedef EventId::EventNumber EventNumber; //********************************************************************** // Local definitions. //********************************************************************** namespace { // Register the DTD. DtdRegistry::Status ISTAT = DtdRegistry::register_dtd("dataset"); // Invalid values. RunNumber BADRUN(-1); RunNumber BADEVT(-1); } // end unnamed namespace //********************************************************************** // Static member functions. //********************************************************************** // DTD. const Text& EventId::dtd() { static Text txt; if ( txt.size() == 0 ) { txt.append(""); txt.append(""); } return txt; } //********************************************************************** // Member functions. //********************************************************************** // Default constructor. EventId::EventId() : _run(BADRUN), _evt(BADEVT) { } //********************************************************************** // Constructor. EventId::EventId(RunNumber run, EventNumber evt) : _run(run), _evt(evt) { } //********************************************************************** // XML constructor. EventId::EventId(const XmlElement& ele) : _run(0), _evt(0) { assert( ele.name() == xml_name() ); if ( ele.name() == xml_name() ) { if ( ele.has_attribute("run") && ele.has_attribute("event") ) { int errcount = ele.error_count(); EventId::RunNumber run = ele.attribute_as_int("run"); EventId::EventNumber evt = ele.attribute_as_int("event"); assert( errcount == ele.error_count() ); if ( errcount == ele.error_count() ) { _run = run; _evt = evt; } } } } //********************************************************************** // Validity. bool EventId::is_valid() const { return _run != BADRUN; } //********************************************************************** // Increment. EventId& EventId::operator++() { ++_evt; return *this; } //********************************************************************** // Write to XML. const XmlElement* EventId::xml() const { XmlElement* pele = new XmlElement(xml_name()); pele->add_attribute_as_int("run", _run); pele->add_attribute_as_int("event", _evt); return pele; } //********************************************************************** // Free functions. //********************************************************************** // Ordering. bool operator<(const EventId& lhs, const EventId& rhs) { if ( lhs.run() < rhs.run() ) return true; if ( rhs.run() < lhs.run() ) return false; return lhs.event() < rhs.event(); } //********************************************************************** // Equality. bool operator==(const EventId& lhs, const EventId& rhs) { return lhs.run()== rhs.run() && lhs.event()==rhs.event(); } //********************************************************************** // Inquality. bool operator!=(const EventId& lhs, const EventId& rhs) { return ! (lhs == rhs); } //********************************************************************** // Output stream. ostream& operator<<(ostream& lhs, const EventId& rhs) { if ( rhs.is_valid() ) { lhs << "run " << rhs.run() << " event " << rhs.event(); } else { lhs << "invalid event identifier"; } return lhs; } //**********************************************************************