Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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 ESProductResolverProvider;
0039     class EventSetupsController;
0040 
0041     namespace looper {
0042       template <class T>
0043       void addProviderTo(EventSetupProvider& iProvider,
0044                          std::shared_ptr<T> iComponent,
0045                          const ESProductResolverProvider*) {
0046         std::shared_ptr<ESProductResolverProvider> pProvider(iComponent);
0047         ComponentDescription description = pProvider->description();
0048         description.isSource_ = true;
0049         description.isLooper_ = true;
0050         if (description.label_ == "@main_looper") {
0051           //remove the 'hidden' label so that es_prefer statements will work
0052           description.label_ = "";
0053         }
0054         pProvider->setDescription(description);
0055         iProvider.add(pProvider);
0056       }
0057       template <class T>
0058       void addProviderTo(EventSetupProvider& /* iProvider */, std::shared_ptr<T> /*iComponent*/, const void*) {
0059         //do nothing
0060       }
0061 
0062       template <class T>
0063       void addFinderTo(EventSetupProvider& iProvider,
0064                        std::shared_ptr<T> iComponent,
0065                        const EventSetupRecordIntervalFinder*) {
0066         std::shared_ptr<EventSetupRecordIntervalFinder> pFinder(iComponent);
0067 
0068         ComponentDescription description = pFinder->descriptionForFinder();
0069         description.isSource_ = true;
0070         description.isLooper_ = true;
0071         if (description.label_ == "@main_looper") {
0072           //remove the 'hidden' label so that es_prefer statements will work
0073           description.label_ = "";
0074         }
0075         pFinder->setDescriptionForFinder(description);
0076 
0077         iProvider.add(pFinder);
0078       }
0079       template <class T>
0080       void addFinderTo(EventSetupProvider& /* iProvider */, std::shared_ptr<T> /*iComponent*/, const void*) {
0081         //do nothing
0082       }
0083     }  // namespace looper
0084     struct LooperMakerTraits {
0085       typedef EDLooperBase base_type;
0086       static std::string name();
0087       static std::string const& baseType();
0088       template <class T>
0089       static void addTo(EventSetupProvider& iProvider, std::shared_ptr<T> iComponent, ParameterSet const&, bool) {
0090         //a looper does not always have to be a provider or a finder
0091         looper::addProviderTo(iProvider, iComponent, static_cast<const T*>(nullptr));
0092         looper::addFinderTo(iProvider, iComponent, static_cast<const T*>(nullptr));
0093       }
0094 
0095       static void replaceExisting(EventSetupProvider& iProvider, std::shared_ptr<EDLooperBase> iComponent);
0096 
0097       static std::shared_ptr<base_type> getComponentAndRegisterProcess(EventSetupsController& esController,
0098                                                                        ParameterSet const& iConfiguration);
0099       static void putComponent(EventSetupsController& esController,
0100                                ParameterSet const& iConfiguration,
0101                                std::shared_ptr<base_type> const& component);
0102     };
0103     template <class TType>
0104     struct LooperMaker : public ComponentMaker<edm::eventsetup::LooperMakerTraits, TType> {};
0105     typedef ComponentFactory<LooperMakerTraits> LooperFactory;
0106 
0107     typedef edmplugin::PluginFactory<edm::eventsetup::ComponentMakerBase<LooperMakerTraits>*()> LooperPluginFactory;
0108   }  // namespace eventsetup
0109 }  // namespace edm
0110 
0111 #define DEFINE_FWK_LOOPER(type)                                                                       \
0112   DEFINE_EDM_PLUGIN(edm::eventsetup::LooperPluginFactory, edm::eventsetup::LooperMaker<type>, #type); \
0113   DEFINE_DESC_FILLER_FOR_EDLOOPERS(type)
0114 
0115 #endif