From eb58892df41b29752bccddb02c06b50f106ecf0e Mon Sep 17 00:00:00 2001 From: Frank Berghaus <frank.berghaus@cern.ch> Date: Mon, 20 Jul 2020 14:04:57 +0200 Subject: [PATCH] Add an output stream operator to event stream info Allow the intuitive printing of EventStreamInfo objects to any output stream. Similar to the existing print function that dumps the object to the debug log, but more gerneral. --- Event/EventInfo/EventInfo/EventStreamInfo.h | 3 ++ Event/EventInfo/src/EventStreamInfo.cxx | 49 ++++++++++++--------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Event/EventInfo/EventInfo/EventStreamInfo.h b/Event/EventInfo/EventInfo/EventStreamInfo.h index ba3bc1d4680..f499e30cdee 100644 --- a/Event/EventInfo/EventInfo/EventStreamInfo.h +++ b/Event/EventInfo/EventInfo/EventStreamInfo.h @@ -17,6 +17,7 @@ #include <string> #include <set> +#include <iostream> // Forward declarations class MsgStream; @@ -76,6 +77,8 @@ private: std::set<EventType> m_eventTypes; // EventTypes }; +std::ostream& operator<<(std::ostream& os, const EventStreamInfo& esi); + inline EventStreamInfo::EventStreamInfo() : m_numberOfEvents(0), m_runNumbers(), m_lumiBlockNumbers(), diff --git a/Event/EventInfo/src/EventStreamInfo.cxx b/Event/EventInfo/src/EventStreamInfo.cxx index 99842d84c92..960370a32ab 100644 --- a/Event/EventInfo/src/EventStreamInfo.cxx +++ b/Event/EventInfo/src/EventStreamInfo.cxx @@ -87,28 +87,37 @@ EventStreamInfo::insertEventType(const EventType& event) { //______________________________________________________________________________ void EventStreamInfo::print(MsgStream& log) const { - log << MSG::DEBUG << "EventStreamInfo number of events: " << m_numberOfEvents << endmsg; - log << MSG::DEBUG << "EventStreamInfo Run Numbers: "; - for (unsigned int rn : m_runNumbers) { - log << MSG::DEBUG << rn << ", "; + log << MSG::DEBUG << (*this) << endmsg; + return; +} + +//______________________________________________________________________________ +std::ostream& +operator<<(std::ostream& os, const EventStreamInfo& esi){ + os << "EventStreamInfo number of events: " << esi.getNumberOfEvents() << '\n'; + + os << "EventStreamInfo Run Numbers: "; + for (unsigned int rn : esi.getRunNumbers()) { + os << rn << ", "; } - log << MSG::DEBUG << endmsg; - log << MSG::DEBUG << "EventStreamInfo LumiBlock Numbers: "; - for (unsigned int lbn : m_lumiBlockNumbers) { - log << MSG::DEBUG << lbn << ", "; + os << '\n'; + + os << "EventStreamInfo LumiBlock Numbers: "; + for (unsigned int lbn : esi.getLumiBlockNumbers()) { + os << lbn << ", "; } - log << MSG::DEBUG << endmsg; - log << MSG::DEBUG << "EventStreamInfo Processing Tags: "; - for (const std::string& tag : m_processingTags) { - log << MSG::DEBUG << tag << ", "; + os << '\n'; + + os << "EventStreamInfo Processing Tags: "; + for (const std::string& tag : esi.getProcessingTags()) { + os << tag << ", "; } - log << MSG::DEBUG << endmsg; - log << MSG::DEBUG << "EventStreamInfo Event Types: "; - for (const EventType& typ : m_eventTypes) { - log << MSG::DEBUG << typ.typeToString() << ", "; + os << '\n'; + + os << "EventStreamInfo Event Types: "; + for (const EventType& typ : esi.getEventTypes()) { + os << typ.typeToString() << ", "; } - log << MSG::DEBUG << endmsg; - return; -} -//______________________________________________________________________________ + return os; +} -- GitLab