File indexing completed on 2024-04-06 12:13:03
0001 #include "FWCore/ServiceRegistry/interface/StreamContext.h"
0002 #include "FWCore/ServiceRegistry/interface/ProcessContext.h"
0003 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0004
0005 #include <ostream>
0006
0007 namespace edm {
0008
0009 StreamContext::StreamContext(StreamID const& streamID, ProcessContext const* processContext)
0010 : streamID_(streamID),
0011 transition_(Transition::kInvalid),
0012 eventID_(EventID(0, 0, 0)),
0013 runIndex_(RunIndex::invalidRunIndex()),
0014 luminosityBlockIndex_(LuminosityBlockIndex::invalidLuminosityBlockIndex()),
0015 timestamp_(),
0016 processContext_(processContext) {}
0017
0018 StreamContext::StreamContext(StreamID const& streamID,
0019 Transition transition,
0020 EventID const& eventID,
0021 RunIndex const& runIndex,
0022 LuminosityBlockIndex const& luminosityBlockIndex,
0023 Timestamp const& timestamp,
0024 ProcessContext const* processContext)
0025 : streamID_(streamID),
0026 transition_(transition),
0027 eventID_(eventID),
0028 runIndex_(runIndex),
0029 luminosityBlockIndex_(luminosityBlockIndex),
0030 timestamp_(timestamp),
0031 processContext_(processContext) {}
0032
0033 std::ostream& operator<<(std::ostream& os, StreamContext const& sc) {
0034 os << "StreamContext: StreamID = " << sc.streamID() << " transition = ";
0035 switch (sc.transition()) {
0036 case StreamContext::Transition::kBeginStream:
0037 os << "BeginStream";
0038 break;
0039 case StreamContext::Transition::kBeginRun:
0040 os << "BeginRun";
0041 break;
0042 case StreamContext::Transition::kBeginLuminosityBlock:
0043 os << "BeginLuminosityBlock";
0044 break;
0045 case StreamContext::Transition::kEvent:
0046 os << "Event";
0047 break;
0048 case StreamContext::Transition::kEndLuminosityBlock:
0049 os << "EndLuminosityBlock";
0050 break;
0051 case StreamContext::Transition::kEndRun:
0052 os << "EndRun";
0053 break;
0054 case StreamContext::Transition::kEndStream:
0055 os << "EndStream";
0056 break;
0057 case StreamContext::Transition::kInvalid:
0058 os << "Invalid";
0059 break;
0060 }
0061 os << "\n " << sc.eventID() << "\n runIndex = " << sc.runIndex().value()
0062 << " luminosityBlockIndex = " << sc.luminosityBlockIndex().value()
0063 << " unixTime = " << sc.timestamp().unixTime() << " microsecondOffset = " << sc.timestamp().microsecondOffset()
0064 << "\n";
0065 if (sc.processContext()) {
0066 os << " " << *sc.processContext();
0067 }
0068 return os;
0069 }
0070
0071 void exceptionContext(std::ostream& os, StreamContext const& sc) {
0072 os << "Processing ";
0073 auto id = sc.eventID();
0074 switch (sc.transition()) {
0075 case StreamContext::Transition::kBeginStream:
0076 os << "begin Stream";
0077 break;
0078 case StreamContext::Transition::kBeginRun:
0079 os << "stream begin Run " << RunID(id.run());
0080 break;
0081 case StreamContext::Transition::kBeginLuminosityBlock:
0082 os << "stream begin LuminosityBlock " << LuminosityBlockID(id.run(), id.luminosityBlock());
0083 break;
0084 case StreamContext::Transition::kEvent:
0085 os << "Event " << sc.eventID();
0086 break;
0087 case StreamContext::Transition::kEndLuminosityBlock:
0088 os << "stream end LuminosityBlock " << LuminosityBlockID(id.run(), id.luminosityBlock());
0089 break;
0090 case StreamContext::Transition::kEndRun:
0091 os << "stream end Run " << RunID(id.run());
0092 break;
0093 case StreamContext::Transition::kEndStream:
0094 os << "end Stream";
0095 break;
0096 case StreamContext::Transition::kInvalid:
0097 os << "Invalid";
0098 break;
0099 }
0100 os << " stream: " << sc.streamID();
0101 }
0102
0103 std::string_view transitionName(StreamContext::Transition iTrans) {
0104 switch (iTrans) {
0105 case StreamContext::Transition::kBeginStream:
0106 return "begin Stream";
0107 case StreamContext::Transition::kBeginRun:
0108 return "stream begin Run";
0109 case StreamContext::Transition::kBeginLuminosityBlock:
0110 return "stream begin LuminosityBlock";
0111 case StreamContext::Transition::kEvent:
0112 return "Event";
0113 case StreamContext::Transition::kEndLuminosityBlock:
0114 return "stream end LuminosityBlock";
0115 case StreamContext::Transition::kEndRun:
0116 return "stream end Run";
0117 case StreamContext::Transition::kEndStream:
0118 return "end Stream";
0119 case StreamContext::Transition::kInvalid:
0120 return "Invalid";
0121 }
0122 return "Unknown";
0123 }
0124
0125 }