File indexing completed on 2023-01-15 23:49:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <sstream>
0015
0016
0017 #include "FWCore/Framework/interface/EventSetupRecord.h"
0018 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0019 #include "FWCore/Framework/interface/ComponentDescription.h"
0020
0021 #include "FWCore/Utilities/interface/ESInputTag.h"
0022 #include "FWCore/Utilities/interface/Exception.h"
0023
0024 namespace {
0025 void throwWrongRecordType(const edm::TypeIDBase& aFromToken, const edm::eventsetup::EventSetupRecordKey& aRecord) {
0026 throw cms::Exception("WrongRecordType") << "A ESGetTokenGeneric token using the record " << aFromToken.name()
0027 << " was passed to record " << aRecord.type().name();
0028 }
0029 }
0030
0031 namespace edm {
0032 namespace eventsetup {
0033
0034 typedef std::map<DataKey, const DataProxy*> Proxies;
0035
0036 EventSetupRecord::EventSetupRecord() {}
0037
0038 EventSetupRecord::~EventSetupRecord() {}
0039
0040 bool EventSetupRecord::doGet(const ESGetTokenGeneric& aToken, bool aGetTransiently) const {
0041 if UNLIKELY (aToken.transitionID() != transitionID()) {
0042 throwWrongTransitionID();
0043 }
0044 if UNLIKELY (aToken.recordType() != key().type()) {
0045 throwWrongRecordType(aToken.recordType(), key());
0046 }
0047 auto proxyIndex = getTokenIndices_[aToken.index().value()];
0048 if UNLIKELY (proxyIndex.value() == std::numeric_limits<int>::max()) {
0049 return false;
0050 }
0051
0052 const ComponentDescription* cd = nullptr;
0053 DataKey const* dk = nullptr;
0054 return nullptr != impl_->getFromProxyAfterPrefetch(proxyIndex, aGetTransiently, cd, dk);
0055 }
0056
0057 bool EventSetupRecord::wasGotten(const DataKey& aKey) const { return impl_->wasGotten(aKey); }
0058
0059 edm::eventsetup::ComponentDescription const* EventSetupRecord::providerDescription(const DataKey& aKey) const {
0060 return impl_->providerDescription(aKey);
0061 }
0062
0063 void EventSetupRecord::validate(const ComponentDescription* iDesc, const ESInputTag& iTag) const {
0064 if (iDesc && !iTag.module().empty()) {
0065 bool matched = false;
0066 if (iDesc->label_.empty()) {
0067 matched = iDesc->type_ == iTag.module();
0068 } else {
0069 matched = iDesc->label_ == iTag.module();
0070 }
0071 if (!matched) {
0072 throw cms::Exception("EventSetupWrongModule")
0073 << "EventSetup data was retrieved using an ESInputTag with the values\n"
0074 << " moduleLabel = '" << iTag.module() << "'\n"
0075 << " dataLabel = '" << iTag.data() << "'\n"
0076 << "but the data matching the C++ class type and dataLabel comes from module type=" << iDesc->type_
0077 << " label='" << iDesc->label_ << "'.\n Please either change the ESInputTag's 'module' label to be "
0078 << (iDesc->label_.empty() ? iDesc->type_ : iDesc->label_) << "\n or add the EventSetup module "
0079 << iTag.module() << " to the configuration.";
0080 }
0081 }
0082 }
0083
0084 void EventSetupRecord::addTraceInfoToCmsException(cms::Exception& iException,
0085 const char* iName,
0086 const ComponentDescription* iDescription,
0087 const DataKey& iKey) const {
0088 std::ostringstream ost;
0089 ost << "Using EventSetup component " << iDescription->type_ << "/'" << iDescription->label_ << "' to make data "
0090 << iKey.type().name() << "/'" << iName << "' in record " << this->key().type().name();
0091 iException.addContext(ost.str());
0092 }
0093
0094 std::exception_ptr EventSetupRecord::makeUninitializedTokenException(EventSetupRecordKey const& iRecordKey,
0095 TypeTag const& iDataKey) {
0096 cms::Exception ex("InvalidESGetToken");
0097 ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
0098 << iRecordKey.name()
0099 << ">.\n"
0100 "Please call consumes to properly initialize the token.";
0101 return std::make_exception_ptr(ex);
0102 }
0103
0104 std::exception_ptr EventSetupRecord::makeInvalidTokenException(EventSetupRecordKey const& iRecordKey,
0105 TypeTag const& iDataKey,
0106 unsigned int iTransitionID) {
0107 cms::Exception ex("InvalidESGetToken");
0108 ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
0109 << iRecordKey.name() << "> that had transition ID set (" << iTransitionID
0110 << ") but not the index.\n"
0111 "This should not happen, please contact core framework developers.";
0112 return std::make_exception_ptr(ex);
0113 }
0114
0115 void EventSetupRecord::throwWrongTransitionID() const {
0116 cms::Exception ex("ESGetTokenWrongTransition");
0117 ex << "The transition ID stored in the ESGetToken does not match the\n"
0118 << "transition where the token is being used. The associated record\n"
0119 << "type is: " << key().type().name() << "\n"
0120 << "For producers, filters and analyzers this transition ID is\n"
0121 << "set as a template parameter to the call to the esConsumes\n"
0122 << "function that creates the token. Event is the default transition.\n"
0123 << "Other possibilities are BeginRun, EndRun, BeginLuminosityBlock,\n"
0124 << "or EndLuminosityBlock. You may need multiple tokens if you want to\n"
0125 << "get the same data in multiple transitions. The transition ID has a\n"
0126 << "different meaning in ESProducers. For ESProducers, the transition\n"
0127 << "ID identifies the function that produces the EventSetup data (often\n"
0128 << "there is one function named produce but there can be multiple\n"
0129 << "functions with different names). For ESProducers, the ESGetToken\n"
0130 << "must be used in the function associated with the ESConsumesCollector\n"
0131 << "returned by the setWhatProduced function.";
0132 throw ex;
0133 }
0134
0135 }
0136 }