Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:45:08

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