Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:46:56

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 
0017 namespace edm {
0018 
0019   ESProducer::ESProducer() : consumesInfos_{}, acquirer_{{{std::make_shared<SerialTaskQueue>()}}} {}
0020 
0021   ESProducer::~ESProducer() noexcept(false) {}
0022 
0023   void ESProducer::updateLookup(eventsetup::ESRecordsToProductResolverIndices const& iResolverToIndices) {
0024     if (sharedResourceNames_) {
0025       auto instance = SharedResourcesRegistry::instance();
0026       acquirer_ = instance->createAcquirer(*sharedResourceNames_);
0027       sharedResourceNames_.reset();
0028     }
0029 
0030     itemsToGetFromRecords_.reserve(consumesInfos_.size());
0031     recordsUsedDuringGet_.reserve(consumesInfos_.size());
0032 
0033     if (itemsToGetFromRecords_.size() == consumesInfos_.size()) {
0034       return;
0035     }
0036 
0037     for (auto& info : consumesInfos_) {
0038       auto& items = itemsToGetFromRecords_.emplace_back();
0039       items.reserve(info->size());
0040       auto& records = recordsUsedDuringGet_.emplace_back();
0041       records.reserve(info->size());
0042       for (auto& resolverInfo : *info) {
0043         //check for mayConsumes
0044         if (auto chooser = resolverInfo.chooser_.get()) {
0045           hasMayConsumes_ = true;
0046           auto tagGetter = iResolverToIndices.makeTagGetter(chooser->recordKey(), chooser->productType());
0047           if (not tagGetter.hasNothingToGet()) {
0048             records.push_back(iResolverToIndices.recordIndexFor(chooser->recordKey()));
0049           } else {
0050             //The record is not actually missing but the resolver is
0051             records.emplace_back(eventsetup::ESRecordsToProductResolverIndices::missingRecordIndex());
0052           }
0053           chooser->setTagGetter(std::move(tagGetter));
0054           items.push_back(eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex());
0055         } else {
0056           auto index = iResolverToIndices.indexInRecord(resolverInfo.recordKey_, resolverInfo.productKey_);
0057           if (index != eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex()) {
0058             if (not resolverInfo.moduleLabel_.empty()) {
0059               auto component = iResolverToIndices.component(resolverInfo.recordKey_, resolverInfo.productKey_);
0060               if (nullptr == component) {
0061                 index = eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex();
0062               } else {
0063                 if (component->label_.empty()) {
0064                   if (component->type_ != resolverInfo.moduleLabel_) {
0065                     index = eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex();
0066                   }
0067                 } else if (component->label_ != resolverInfo.moduleLabel_) {
0068                   index = eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex();
0069                 }
0070               }
0071             }
0072           }
0073           items.push_back(index);
0074           if (index != eventsetup::ESRecordsToProductResolverIndices::missingResolverIndex()) {
0075             records.push_back(iResolverToIndices.recordIndexFor(resolverInfo.recordKey_));
0076           } else {
0077             //The record is not actually missing but the resolver is
0078             records.emplace_back(eventsetup::ESRecordsToProductResolverIndices::missingRecordIndex());
0079           }
0080           assert(items.size() == records.size());
0081         }
0082       }
0083     }
0084   }
0085 
0086   void ESProducer::usesResources(std::vector<std::string> const& iResourceNames) {
0087     auto instance = SharedResourcesRegistry::instance();
0088     if (not sharedResourceNames_ and !iResourceNames.empty()) {
0089       sharedResourceNames_ = std::make_unique<std::vector<std::string>>(iResourceNames);
0090     }
0091 
0092     for (auto const& r : iResourceNames) {
0093       instance->registerSharedResource(r);
0094     }
0095     //Must defer setting acquirer_ until all resources have been registered
0096     // by all modules in the job
0097   }
0098 
0099 }  // namespace edm