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