Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:53

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     ESProxyFactoryProducer
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Author:      Chris Jones
0010 // Created:     Thu Apr  7 21:36:15 CDT 2005
0011 //
0012 
0013 // system include files
0014 #include <algorithm>
0015 #include <cassert>
0016 
0017 // user include files
0018 #include "FWCore/Framework/interface/ESProxyFactoryProducer.h"
0019 #include "FWCore/Framework/interface/ProxyFactoryBase.h"
0020 
0021 #include "FWCore/Framework/interface/DataProxy.h"
0022 
0023 #include "FWCore/Utilities/interface/Exception.h"
0024 
0025 using namespace edm::eventsetup;
0026 namespace edm {
0027 
0028   using Record2Factories = std::multimap<EventSetupRecordKey, FactoryInfo>;
0029 
0030   ESProxyFactoryProducer::ESProxyFactoryProducer() : record2Factories_() {}
0031 
0032   ESProxyFactoryProducer::~ESProxyFactoryProducer() noexcept(false) {}
0033 
0034   DataProxyProvider::KeyedProxiesVector ESProxyFactoryProducer::registerProxies(const EventSetupRecordKey& iRecord,
0035                                                                                 unsigned int iovIndex) {
0036     KeyedProxiesVector keyedProxiesVector;
0037     using Iterator = Record2Factories::iterator;
0038     std::pair<Iterator, Iterator> range = record2Factories_.equal_range(iRecord);
0039     for (Iterator it = range.first; it != range.second; ++it) {
0040       std::shared_ptr<DataProxy> proxy(it->second.factory_->makeProxy(iovIndex).release());
0041       if (nullptr != proxy.get()) {
0042         keyedProxiesVector.emplace_back((*it).second.key_, proxy);
0043       }
0044     }
0045     return keyedProxiesVector;
0046   }
0047 
0048   void ESProxyFactoryProducer::registerFactoryWithKey(const EventSetupRecordKey& iRecord,
0049                                                       std::unique_ptr<ProxyFactoryBase> iFactory,
0050                                                       const std::string& iLabel) {
0051     if (nullptr == iFactory.get()) {
0052       assert(false && "Factor pointer was null");
0053       ::exit(1);
0054     }
0055 
0056     usingRecordWithKey(iRecord);
0057 
0058     std::shared_ptr<ProxyFactoryBase> temp(iFactory.release());
0059     FactoryInfo info(temp->makeKey(iLabel), temp);
0060 
0061     //has this already been registered?
0062     std::pair<Record2Factories::const_iterator, Record2Factories::const_iterator> range =
0063         record2Factories_.equal_range(iRecord);
0064     if (range.second !=
0065         std::find_if(range.first, range.second, [&info](const auto& r2f) { return r2f.second.key_ == info.key_; })) {
0066       throw cms::Exception("IdenticalProducts")
0067           << "Producer has been asked to produce " << info.key_.type().name() << " \"" << info.key_.name().value()
0068           << "\" multiple times.\n Please modify the code.";
0069     }
0070 
0071     record2Factories_.insert(Record2Factories::value_type(iRecord, std::move(info)));
0072   }
0073 
0074 }  // namespace edm