Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-27 02:13:25

0001 #ifndef FWCore_Framework_LooperFactory_h
0002 #define FWCore_Framework_LooperFactory_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     LooperFactory
0007 //
0008 /**\class LooperFactory LooperFactory.h FWCore/Framework/interface/LooperFactory.h
0009 
0010  Description: PluginManager factory for creating EDLoopers
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Wed May 25 18:01:38 EDT 2005
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <string>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/ComponentFactory.h"
0027 #include "FWCore/Framework/interface/EventSetupProvider.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerPluginFactory.h"
0029 
0030 // forward declarations
0031 namespace edm {
0032   class EDLooperBase;
0033   class EventSetupRecordIntervalFinder;
0034   class ParameterSet;
0035 
0036   namespace eventsetup {
0037 
0038     class DataProxyProvider;
0039     class EventSetupsController;
0040 
0041     namespace looper {
0042       template <class T>
0043       void addProviderTo(EventSetupProvider& iProvider, std::shared_ptr<T> iComponent, const DataProxyProvider*) {
0044         std::shared_ptr<DataProxyProvider> pProvider(iComponent);
0045         ComponentDescription description = pProvider->description();
0046         description.isSource_ = true;
0047         description.isLooper_ = true;
0048         if (description.label_ == "@main_looper") {
0049           //remove the 'hidden' label so that es_prefer statements will work
0050           description.label_ = "";
0051         }
0052         pProvider->setDescription(description);
0053         iProvider.add(pProvider);
0054       }
0055       template <class T>
0056       void addProviderTo(EventSetupProvider& /* iProvider */, std::shared_ptr<T> /*iComponent*/, const void*) {
0057         //do nothing
0058       }
0059 
0060       template <class T>
0061       void addFinderTo(EventSetupProvider& iProvider,
0062                        std::shared_ptr<T> iComponent,
0063                        const EventSetupRecordIntervalFinder*) {
0064         std::shared_ptr<EventSetupRecordIntervalFinder> pFinder(iComponent);
0065 
0066         ComponentDescription description = pFinder->descriptionForFinder();
0067         description.isSource_ = true;
0068         description.isLooper_ = true;
0069         if (description.label_ == "@main_looper") {
0070           //remove the 'hidden' label so that es_prefer statements will work
0071           description.label_ = "";
0072         }
0073         pFinder->setDescriptionForFinder(description);
0074 
0075         iProvider.add(pFinder);
0076       }
0077       template <class T>
0078       void addFinderTo(EventSetupProvider& /* iProvider */, std::shared_ptr<T> /*iComponent*/, const void*) {
0079         //do nothing
0080       }
0081     }  // namespace looper
0082     struct LooperMakerTraits {
0083       typedef EDLooperBase base_type;
0084       static std::string name();
0085       template <class T>
0086       static void addTo(EventSetupProvider& iProvider, std::shared_ptr<T> iComponent, ParameterSet const&, bool) {
0087         //a looper does not always have to be a provider or a finder
0088         looper::addProviderTo(iProvider, iComponent, static_cast<const T*>(nullptr));
0089         looper::addFinderTo(iProvider, iComponent, static_cast<const T*>(nullptr));
0090       }
0091 
0092       static void replaceExisting(EventSetupProvider& iProvider, std::shared_ptr<EDLooperBase> iComponent);
0093 
0094       static std::shared_ptr<base_type> getComponentAndRegisterProcess(EventSetupsController& esController,
0095                                                                        ParameterSet const& iConfiguration);
0096       static void putComponent(EventSetupsController& esController,
0097                                ParameterSet const& iConfiguration,
0098                                std::shared_ptr<base_type> const& component);
0099     };
0100     template <class TType>
0101     struct LooperMaker : public ComponentMaker<edm::eventsetup::LooperMakerTraits, TType> {};
0102     typedef ComponentFactory<LooperMakerTraits> LooperFactory;
0103 
0104     typedef edmplugin::PluginFactory<edm::eventsetup::ComponentMakerBase<LooperMakerTraits>*()> LooperPluginFactory;
0105   }  // namespace eventsetup
0106 }  // namespace edm
0107 
0108 #define DEFINE_FWK_LOOPER(type)                                                                       \
0109   DEFINE_EDM_PLUGIN(edm::eventsetup::LooperPluginFactory, edm::eventsetup::LooperMaker<type>, #type); \
0110   DEFINE_DESC_FILLER_FOR_EDLOOPERS(type)
0111 
0112 #endif