Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-18 22:30:18

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 // system include files
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/ESProducer.h"
0017 #include "FWCore/Framework/interface/ESRecordsToProxyIndices.h"
0018 #include "FWCore/Framework/interface/SharedResourcesRegistry.h"
0019 //
0020 // constants, enums and typedefs
0021 //
0022 namespace edm {
0023   //
0024   // static data member definitions
0025   //
0026 
0027   //
0028   // constructors and destructor
0029   //
0030   ESProducer::ESProducer() : consumesInfos_{}, acquirer_{{{std::make_shared<SerialTaskQueue>()}}} {}
0031 
0032   // ESProducer::ESProducer(const ESProducer& rhs)
0033   // {
0034   //    // do actual copying here;
0035   // }
0036 
0037   ESProducer::~ESProducer() noexcept(false) {}
0038 
0039   //
0040   // assignment operators
0041   //
0042   // const ESProducer& ESProducer::operator=(const ESProducer& rhs)
0043   // {
0044   //   //An exception safe implementation is
0045   //   ESProducer temp(rhs);
0046   //   swap(rhs);
0047   //
0048   //   return *this;
0049   // }
0050 
0051   //
0052   // member functions
0053   //
0054   void ESProducer::updateLookup(eventsetup::ESRecordsToProxyIndices const& iProxyToIndices) {
0055     if (sharedResourceNames_) {
0056       auto instance = SharedResourcesRegistry::instance();
0057       acquirer_ = instance->createAcquirer(*sharedResourceNames_);
0058       sharedResourceNames_.reset();
0059     }
0060 
0061     itemsToGetFromRecords_.reserve(consumesInfos_.size());
0062     recordsUsedDuringGet_.reserve(consumesInfos_.size());
0063 
0064     if (itemsToGetFromRecords_.size() == consumesInfos_.size()) {
0065       return;
0066     }
0067 
0068     for (auto& info : consumesInfos_) {
0069       auto& items = itemsToGetFromRecords_.emplace_back();
0070       items.reserve(info->size());
0071       auto& records = recordsUsedDuringGet_.emplace_back();
0072       records.reserve(info->size());
0073       for (auto& proxyInfo : *info) {
0074         //check for mayConsumes
0075         if (auto chooser = proxyInfo.chooser_.get()) {
0076           hasMayConsumes_ = true;
0077           auto tagGetter = iProxyToIndices.makeTagGetter(chooser->recordKey(), chooser->productType());
0078           if (not tagGetter.hasNothingToGet()) {
0079             records.push_back(iProxyToIndices.recordIndexFor(chooser->recordKey()));
0080           } else {
0081             //The record is not actually missing but the proxy is
0082             records.emplace_back(eventsetup::ESRecordsToProxyIndices::missingRecordIndex());
0083           }
0084           chooser->setTagGetter(std::move(tagGetter));
0085           items.push_back(eventsetup::ESRecordsToProxyIndices::missingProxyIndex());
0086         } else {
0087           auto index = iProxyToIndices.indexInRecord(proxyInfo.recordKey_, proxyInfo.productKey_);
0088           if (index != eventsetup::ESRecordsToProxyIndices::missingProxyIndex()) {
0089             if (not proxyInfo.moduleLabel_.empty()) {
0090               auto component = iProxyToIndices.component(proxyInfo.recordKey_, proxyInfo.productKey_);
0091               if (nullptr == component) {
0092                 index = eventsetup::ESRecordsToProxyIndices::missingProxyIndex();
0093               } else {
0094                 if (component->label_.empty()) {
0095                   if (component->type_ != proxyInfo.moduleLabel_) {
0096                     index = eventsetup::ESRecordsToProxyIndices::missingProxyIndex();
0097                   }
0098                 } else if (component->label_ != proxyInfo.moduleLabel_) {
0099                   index = eventsetup::ESRecordsToProxyIndices::missingProxyIndex();
0100                 }
0101               }
0102             }
0103           }
0104           items.push_back(index);
0105           if (index != eventsetup::ESRecordsToProxyIndices::missingProxyIndex()) {
0106             records.push_back(iProxyToIndices.recordIndexFor(proxyInfo.recordKey_));
0107           } else {
0108             //The record is not actually missing but the proxy is
0109             records.emplace_back(eventsetup::ESRecordsToProxyIndices::missingRecordIndex());
0110           }
0111           assert(items.size() == records.size());
0112         }
0113       }
0114     }
0115   }
0116 
0117   void ESProducer::usesResources(std::vector<std::string> const& iResourceNames) {
0118     auto instance = SharedResourcesRegistry::instance();
0119     if (not sharedResourceNames_ and !iResourceNames.empty()) {
0120       sharedResourceNames_ = std::make_unique<std::vector<std::string>>(iResourceNames);
0121     }
0122 
0123     for (auto const& r : iResourceNames) {
0124       instance->registerSharedResource(r);
0125     }
0126     //Must defer setting acquirer_ until all resources have been registered
0127     // by all modules in the job
0128   }
0129 
0130   //
0131   // const member functions
0132   //
0133 
0134   //
0135   // static member functions
0136   //
0137 }  // namespace edm