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 // Module:      EventSetup
0005 //
0006 // Description: <one line class summary>
0007 //
0008 // Implementation:
0009 //     <Notes on implementation>
0010 //
0011 // Author:      Chris Jones
0012 // Created:     Thu Mar 24 16:27:10 EST 2005
0013 //
0014 
0015 // system include files
0016 #include <algorithm>
0017 
0018 // user include files
0019 #include "FWCore/Framework/interface/EventSetupImpl.h"
0020 #include "FWCore/Framework/interface/EventSetupRecord.h"
0021 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0022 #include "FWCore/Utilities/interface/Exception.h"
0023 
0024 namespace edm {
0025 
0026   EventSetupImpl::EventSetupImpl() {}
0027 
0028   EventSetupImpl::~EventSetupImpl() {}
0029 
0030   void EventSetupImpl::insertRecordImpl(const eventsetup::EventSetupRecordKey& iKey,
0031                                         const eventsetup::EventSetupRecordImpl* iRecord) {
0032     auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
0033     if (lb == keysEnd_ || iKey != *lb) {
0034       throw cms::Exception("LogicError") << "EventSetupImpl::insert Could not find key\n"
0035                                          << "Should be impossible. Please contact Framework developer.\n";
0036     }
0037     auto index = std::distance(keysBegin_, lb);
0038     recordImpls_[index] = iRecord;
0039   }
0040 
0041   void EventSetupImpl::addRecordImpl(const eventsetup::EventSetupRecordImpl& iRecord) {
0042     insertRecordImpl(iRecord.key(), &iRecord);
0043   }
0044 
0045   std::optional<eventsetup::EventSetupRecordGeneric> EventSetupImpl::find(const eventsetup::EventSetupRecordKey& iKey,
0046                                                                           unsigned int iTransitionID,
0047                                                                           ESResolverIndex const* getTokenIndices,
0048                                                                           ESParentContext const& iParent) const {
0049     auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
0050     if (lb == keysEnd_ || iKey != *lb) {
0051       return std::nullopt;
0052     }
0053     auto index = std::distance(keysBegin_, lb);
0054     if (recordImpls_[index] == nullptr) {
0055       return std::nullopt;
0056     }
0057     return eventsetup::EventSetupRecordGeneric(recordImpls_[index], iTransitionID, getTokenIndices, this, &iParent);
0058   }
0059 
0060   eventsetup::EventSetupRecordImpl const* EventSetupImpl::findImpl(const eventsetup::EventSetupRecordKey& iKey) const {
0061     auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
0062     if (lb == keysEnd_ || iKey != *lb) {
0063       return nullptr;
0064     }
0065     auto index = std::distance(keysBegin_, lb);
0066     return recordImpls_[index];
0067   }
0068 
0069   eventsetup::EventSetupRecordImpl const* EventSetupImpl::findImpl(ESRecordIndex iKey) const {
0070     if UNLIKELY (iKey.value() == ESRecordIndex::invalidValue()) {
0071       return nullptr;
0072     }
0073     return recordImpls_[iKey.value()];
0074   }
0075 
0076   void EventSetupImpl::fillAvailableRecordKeys(std::vector<eventsetup::EventSetupRecordKey>& oToFill) const {
0077     oToFill.clear();
0078     oToFill.reserve(recordImpls_.size());
0079 
0080     for (auto const& recordImpl : recordImpls_) {
0081       if (recordImpl != nullptr) {
0082         oToFill.push_back(recordImpl->key());
0083       }
0084     }
0085   }
0086 
0087   bool EventSetupImpl::recordIsProvidedByAModule(eventsetup::EventSetupRecordKey const& iKey) const {
0088     auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
0089     return lb != keysEnd_ && iKey == *lb;
0090   }
0091 
0092   bool EventSetupImpl::validRecord(eventsetup::EventSetupRecordKey const& iKey) const {
0093     auto lb = std::lower_bound(keysBegin_, keysEnd_, iKey);
0094     if (lb != keysEnd_ && iKey == *lb) {
0095       auto index = std::distance(keysBegin_, lb);
0096       return recordImpls_[index] != nullptr;
0097     }
0098     return false;
0099   }
0100 
0101   void EventSetupImpl::setKeyIters(std::vector<eventsetup::EventSetupRecordKey>::const_iterator const& keysBegin,
0102                                    std::vector<eventsetup::EventSetupRecordKey>::const_iterator const& keysEnd) {
0103     keysBegin_ = keysBegin;
0104     keysEnd_ = keysEnd;
0105     recordImpls_.resize(keysEnd_ - keysBegin_, nullptr);
0106   }
0107 
0108 }  // namespace edm