Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:10

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/DataKeyTags.h"
0018 #include "FWCore/Framework/interface/EventSetupRecord.h"
0019 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0020 #include "FWCore/Framework/interface/ComponentDescription.h"
0021 
0022 #include "FWCore/Utilities/interface/Exception.h"
0023 #include "FWCore/Utilities/interface/TypeIDBase.h"
0024 
0025 namespace {
0026   void throwWrongRecordType(const edm::TypeIDBase& aFromToken, const edm::eventsetup::EventSetupRecordKey& aRecord) {
0027     throw cms::Exception("WrongRecordType") << "A ESGetTokenGeneric token using the record " << aFromToken.name()
0028                                             << " was passed to record " << aRecord.type().name();
0029   }
0030 }  // namespace
0031 
0032 namespace edm {
0033   namespace eventsetup {
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 resolverIndex = getTokenIndices_[aToken.index().value()];
0047       if UNLIKELY (resolverIndex.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_->getFromResolverAfterPrefetch(resolverIndex, 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::addTraceInfoToCmsException(cms::Exception& iException,
0063                                                       const char* iName,
0064                                                       const ComponentDescription* iDescription,
0065                                                       const DataKey& iKey) const {
0066       std::ostringstream ost;
0067       ost << "Using EventSetup component " << iDescription->type_ << "/'" << iDescription->label_ << "' to make data "
0068           << iKey.type().name() << "/'" << iName << "' in record " << this->key().type().name();
0069       iException.addContext(ost.str());
0070     }
0071 
0072     std::exception_ptr EventSetupRecord::makeUninitializedTokenException(EventSetupRecordKey const& iRecordKey,
0073                                                                          TypeTag const& iDataKey) {
0074       cms::Exception ex("InvalidESGetToken");
0075       ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
0076          << iRecordKey.name()
0077          << ">.\n"
0078             "Please call consumes to properly initialize the token.";
0079       return std::make_exception_ptr(ex);
0080     }
0081 
0082     std::exception_ptr EventSetupRecord::makeInvalidTokenException(EventSetupRecordKey const& iRecordKey,
0083                                                                    TypeTag const& iDataKey,
0084                                                                    unsigned int iTransitionID) {
0085       cms::Exception ex("InvalidESGetToken");
0086       ex << "Attempted to get data using an invalid token of type ESGetToken<" << iDataKey.name() << ","
0087          << iRecordKey.name() << "> that had transition ID set (" << iTransitionID
0088          << ") but not the index.\n"
0089             "This should not happen, please contact core framework developers.";
0090       return std::make_exception_ptr(ex);
0091     }
0092 
0093     void EventSetupRecord::throwWrongTransitionID() const {
0094       cms::Exception ex("ESGetTokenWrongTransition");
0095       ex << "The transition ID stored in the ESGetToken does not match the\n"
0096          << "transition where the token is being used. The associated record\n"
0097          << "type is: " << key().type().name() << "\n"
0098          << "For producers, filters and analyzers this transition ID is\n"
0099          << "set as a template parameter to the call to the esConsumes\n"
0100          << "function that creates the token. Event is the default transition.\n"
0101          << "Other possibilities are BeginRun, EndRun, BeginLuminosityBlock,\n"
0102          << "or EndLuminosityBlock. You may need multiple tokens if you want to\n"
0103          << "get the same data in multiple transitions. The transition ID has a\n"
0104          << "different meaning in ESProducers. For ESProducers, the transition\n"
0105          << "ID identifies the function that produces the EventSetup data (often\n"
0106          << "there is one function named produce but there can be multiple\n"
0107          << "functions with different names). For ESProducers, the ESGetToken\n"
0108          << "must be used in the function associated with the ESConsumesCollector\n"
0109          << "returned by the setWhatProduced function.";
0110       throw ex;
0111     }
0112 
0113   }  // namespace eventsetup
0114 }  // namespace edm