Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-12 04:16:28

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     ESProducer
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Author:      Chris Jones
0010 // Created:     Sat Apr 16 10:19:37 EDT 2005
0011 //
0012 
0013 #include "FWCore/Framework/interface/ESProducer.h"
0014 #include "FWCore/Framework/interface/ESRecordsToProductResolverIndices.h"
0015 #include "FWCore/Framework/interface/SharedResourcesRegistry.h"
0016 #include "FWCore/Utilities/interface/ESIndices.h"
0017 
0018 namespace edm {
0019 
0020   ESProducer::ESProducer() : consumesInfos_{}, acquirer_{{{std::make_shared<SerialTaskQueue>()}}} {}
0021 
0022   ESProducer::~ESProducer() noexcept(false) {}
0023 
0024   void ESProducer::updateLookup(eventsetup::ESRecordsToProductResolverIndices const& iResolverToIndices) {
0025     if (sharedResourceNames_) {
0026       auto instance = SharedResourcesRegistry::instance();
0027       acquirer_ = instance->createAcquirer(*sharedResourceNames_);
0028       sharedResourceNames_.reset();
0029     }
0030 
0031     itemsToGetFromRecords_.reserve(consumesInfos_.size());
0032     recordsUsedDuringGet_.reserve(consumesInfos_.size());
0033 
0034     if (itemsToGetFromRecords_.size() == consumesInfos_.size()) {
0035       return;
0036     }
0037 
0038     for (auto& info : consumesInfos_) {
0039       auto& items = itemsToGetFromRecords_.emplace_back();
0040       items.reserve(info->size());
0041       auto& records = recordsUsedDuringGet_.emplace_back();
0042       records.reserve(info->size());
0043       for (auto& resolverInfo : *info) {
0044         //check for mayConsumes
0045         if (auto chooser = resolverInfo.chooser_.get()) {
0046           hasMayConsumes_ = true;
0047           auto tagGetter = iResolverToIndices.makeTagGetter(chooser->recordKey(), chooser->productType());
0048           if (not tagGetter.hasNothingToGet()) {
0049             records.push_back(iResolverToIndices.recordIndexFor(chooser->recordKey()));
0050           } else {
0051             //The record is not actually missing but the resolver is
0052             records.emplace_back(eventsetup::ESRecordsToProductResolverIndices::missingRecordIndex());
0053           }
0054           chooser->setTagGetter(std::move(tagGetter));
0055           // This value will get overwritten before being used
0056           items.push_back(ESResolverIndex::noResolverConfigured());
0057         } else {
0058           auto index = iResolverToIndices.indexInRecord(resolverInfo.recordKey_, resolverInfo.productKey_);
0059           if (index != ESResolverIndex::noResolverConfigured()) {
0060             if (not resolverInfo.moduleLabel_.empty()) {
0061               auto component = iResolverToIndices.component(resolverInfo.recordKey_, resolverInfo.productKey_);
0062               if (nullptr == component) {
0063                 index = ESResolverIndex::moduleLabelDoesNotMatch();
0064               } else {
0065                 if (component->label_.empty()) {
0066                   if (component->type_ != resolverInfo.moduleLabel_) {
0067                     index = ESResolverIndex::moduleLabelDoesNotMatch();
0068                   }
0069                 } else if (component->label_ != resolverInfo.moduleLabel_) {
0070                   index = ESResolverIndex::moduleLabelDoesNotMatch();
0071                 }
0072               }
0073             }
0074           }
0075           items.push_back(index);
0076           if (index != ESResolverIndex::noResolverConfigured() && index != ESResolverIndex::moduleLabelDoesNotMatch()) {
0077             records.push_back(iResolverToIndices.recordIndexFor(resolverInfo.recordKey_));
0078           } else {
0079             //The record is not actually missing but the resolver is
0080             records.emplace_back(eventsetup::ESRecordsToProductResolverIndices::missingRecordIndex());
0081           }
0082           assert(items.size() == records.size());
0083         }
0084       }
0085     }
0086   }
0087 
0088   void ESProducer::usesResources(std::vector<std::string> const& iResourceNames) {
0089     auto instance = SharedResourcesRegistry::instance();
0090     if (not sharedResourceNames_ and !iResourceNames.empty()) {
0091       sharedResourceNames_ = std::make_unique<std::vector<std::string>>(iResourceNames);
0092     }
0093 
0094     for (auto const& r : iResourceNames) {
0095       instance->registerSharedResource(r);
0096     }
0097     //Must defer setting acquirer_ until all resources have been registered
0098     // by all modules in the job
0099   }
0100 
0101 }  // namespace edm