Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:01

0001 #ifndef FWCore_Framework_ESProductResolverArgumentFactoryTemplate_h
0002 #define FWCore_Framework_ESProductResolverArgumentFactoryTemplate_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ESProductResolverArgumentFactoryTemplate
0007 //
0008 /**\class edm::eventsetup::ESProductResolverArgumentFactoryTemplate
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Mon Apr 11 16:20:52 CDT 2005
0019 //
0020 
0021 // system include files
0022 #include <cassert>
0023 #include <memory>
0024 #include <string>
0025 #include <vector>
0026 
0027 // user include files
0028 #include "FWCore/Framework/interface/ESProductResolverFactoryBase.h"
0029 #include "FWCore/Framework/interface/DataKey.h"
0030 
0031 namespace edm {
0032   namespace eventsetup {
0033 
0034     class ESProductResolver;
0035 
0036     template <class ResolverType, class CallbackType>
0037     class ESProductResolverArgumentFactoryTemplate : public ESProductResolverFactoryBase {
0038     public:
0039       using RecordType = typename ResolverType::RecordType;
0040 
0041       ESProductResolverArgumentFactoryTemplate(
0042           std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackType>>> callback)
0043           : callback_(std::move(callback)) {}
0044 
0045       ESProductResolverArgumentFactoryTemplate(const ESProductResolverArgumentFactoryTemplate&) = delete;
0046       const ESProductResolverArgumentFactoryTemplate& operator=(const ESProductResolverArgumentFactoryTemplate&) =
0047           delete;
0048 
0049       std::unique_ptr<ESProductResolver> makeResolver(unsigned int iovIndex) override {
0050         if (iovIndex != callback_->first) {
0051           // We are using the fact that we know all the factories related
0052           // to one iovIndex are dealt with before makeResolver is called with
0053           // a different iovIndex and that these calls are made in an
0054           // order such that the iovIndex increments by 1 when it changes.
0055           // We must clone, because we need a different callback object
0056           // for each iovIndex.
0057           assert(iovIndex == callback_->first + 1);
0058           callback_->first = callback_->first + 1;
0059           callback_->second = std::shared_ptr<CallbackType>(callback_->second->clone());
0060         }
0061         return std::make_unique<ResolverType>(callback_->second);
0062       }
0063 
0064       DataKey makeKey(const std::string& iName) const override {
0065         return DataKey(DataKey::makeTypeTag<typename ResolverType::ValueType>(), iName.c_str());
0066       }
0067 
0068     private:
0069       std::shared_ptr<std::pair<unsigned int, std::shared_ptr<CallbackType>>> callback_;
0070     };
0071   }  // namespace eventsetup
0072 }  // namespace edm
0073 #endif