File indexing completed on 2024-05-11 03:34:17
0001 #include "FWCore/ServiceRegistry/interface/ParentContext.h"
0002 #include "FWCore/ServiceRegistry/interface/GlobalContext.h"
0003 #include "FWCore/ServiceRegistry/interface/InternalContext.h"
0004 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0005 #include "FWCore/ServiceRegistry/interface/PlaceInPathContext.h"
0006 #include "FWCore/ServiceRegistry/interface/PathContext.h"
0007 #include "FWCore/ServiceRegistry/interface/StreamContext.h"
0008
0009 #include "FWCore/Utilities/interface/EDMException.h"
0010
0011 #include <ostream>
0012
0013 namespace edm {
0014
0015 ParentContext::ParentContext() noexcept : type_(Type::kInvalid) { parent_.global = nullptr; }
0016
0017 ParentContext::ParentContext(GlobalContext const* global) noexcept : type_(Type::kGlobal) { parent_.global = global; }
0018
0019 ParentContext::ParentContext(InternalContext const* internal) noexcept : type_(Type::kInternal) {
0020 parent_.internal = internal;
0021 }
0022
0023 ParentContext::ParentContext(ModuleCallingContext const* module) noexcept : type_(Type::kModule) {
0024 parent_.module = module;
0025 }
0026
0027 ParentContext::ParentContext(PlaceInPathContext const* placeInPath) noexcept : type_(Type::kPlaceInPath) {
0028 parent_.placeInPath = placeInPath;
0029 }
0030
0031 ParentContext::ParentContext(StreamContext const* stream) noexcept : type_(Type::kStream) { parent_.stream = stream; }
0032
0033 ModuleCallingContext const* ParentContext::moduleCallingContext() const noexcept(false) {
0034 if (type_ != Type::kModule) {
0035 throw Exception(errors::LogicError) << "ParentContext::moduleCallingContext called for incorrect type of context";
0036 }
0037 return parent_.module;
0038 }
0039
0040 PlaceInPathContext const* ParentContext::placeInPathContext() const noexcept(false) {
0041 if (type_ != Type::kPlaceInPath) {
0042 throw Exception(errors::LogicError) << "ParentContext::placeInPathContext called for incorrect type of context";
0043 }
0044 return parent_.placeInPath;
0045 }
0046
0047 StreamContext const* ParentContext::streamContext() const noexcept(false) {
0048 if (type_ != Type::kStream) {
0049 throw Exception(errors::LogicError) << "ParentContext::streamContext called for incorrect type of context";
0050 }
0051 return parent_.stream;
0052 }
0053
0054 GlobalContext const* ParentContext::globalContext() const noexcept(false) {
0055 if (type_ != Type::kGlobal) {
0056 throw Exception(errors::LogicError) << "ParentContext::globalContext called for incorrect type of context";
0057 }
0058 return parent_.global;
0059 }
0060
0061 InternalContext const* ParentContext::internalContext() const noexcept(false) {
0062 if (type_ != Type::kInternal) {
0063 throw Exception(errors::LogicError) << "ParentContext::internalContext called for incorrect type of context";
0064 }
0065 return parent_.internal;
0066 }
0067
0068 bool ParentContext::isAtEndTransition() const noexcept {
0069 switch (type_) {
0070 case Type::kGlobal: {
0071 return parent_.global->isAtEndTransition();
0072 }
0073 case Type::kModule: {
0074 return parent_.module->parent().isAtEndTransition();
0075 }
0076 case Type::kStream: {
0077 return parent_.stream->isAtEndTransition();
0078 }
0079 case Type::kPlaceInPath: {
0080 return parent_.placeInPath->pathContext()->streamContext()->isAtEndTransition();
0081 }
0082 default:
0083 break;
0084 }
0085 return false;
0086 }
0087
0088 std::ostream& operator<<(std::ostream& os, ParentContext const& pc) {
0089 if (pc.type() == ParentContext::Type::kGlobal && pc.globalContext()) {
0090 os << *pc.globalContext();
0091 } else if (pc.type() == ParentContext::Type::kInternal && pc.internalContext()) {
0092 os << *pc.internalContext();
0093 } else if (pc.type() == ParentContext::Type::kModule && pc.moduleCallingContext()) {
0094 os << *pc.moduleCallingContext();
0095 } else if (pc.type() == ParentContext::Type::kPlaceInPath && pc.placeInPathContext()) {
0096 os << *pc.placeInPathContext();
0097 } else if (pc.type() == ParentContext::Type::kStream && pc.streamContext()) {
0098 os << *pc.streamContext();
0099 } else if (pc.type() == ParentContext::Type::kInvalid) {
0100 os << "ParentContext invalid\n";
0101 }
0102 return os;
0103 }
0104 }