Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef Framework_ComponentMaker_h
0002 #define Framework_ComponentMaker_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     ComponentMaker
0007 //
0008 /**\class ComponentMaker ComponentMaker.h FWCore/Framework/interface/ComponentMaker.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Author:      Chris Jones
0018 // Created:     Wed May 25 16:56:05 EDT 2005
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <string>
0024 
0025 // user include files
0026 #include "FWCore/Framework/interface/ComponentDescription.h"
0027 #include "FWCore/Framework/interface/DataProxyProvider.h"
0028 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
0029 
0030 // forward declarations
0031 
0032 namespace edm {
0033   namespace eventsetup {
0034     class EventSetupProvider;
0035     class EventSetupsController;
0036     class DataProxyProvider;
0037 
0038     class ComponentMakerBaseHelper {
0039     public:
0040       virtual ~ComponentMakerBaseHelper() {}
0041 
0042     protected:
0043       ComponentDescription createComponentDescription(ParameterSet const& iConfiguration) const;
0044     };
0045 
0046     template <class T>
0047     class ComponentMakerBase : public ComponentMakerBaseHelper {
0048     public:
0049       typedef typename T::base_type base_type;
0050       virtual std::shared_ptr<base_type> addTo(EventSetupsController& esController,
0051                                                EventSetupProvider& iProvider,
0052                                                ParameterSet const& iConfiguration,
0053                                                bool replaceExisting) const = 0;
0054     };
0055 
0056     template <class T, class TComponent>
0057     class ComponentMaker : public ComponentMakerBase<T> {
0058     public:
0059       ComponentMaker() {}
0060       ComponentMaker(const ComponentMaker&) = delete;                   // stop default
0061       const ComponentMaker& operator=(const ComponentMaker&) = delete;  // stop default
0062       typedef typename T::base_type base_type;
0063 
0064       // ---------- const member functions ---------------------
0065       std::shared_ptr<base_type> addTo(EventSetupsController& esController,
0066                                        EventSetupProvider& iProvider,
0067                                        ParameterSet const& iConfiguration,
0068                                        bool replaceExisting) const override;
0069 
0070       // ---------- static member functions --------------------
0071 
0072       // ---------- member functions ---------------------------
0073     private:
0074       void setDescription(DataProxyProvider* iProv, const ComponentDescription& iDesc) const {
0075         iProv->setDescription(iDesc);
0076       }
0077       void setDescriptionForFinder(EventSetupRecordIntervalFinder* iFinder, const ComponentDescription& iDesc) const {
0078         iFinder->setDescriptionForFinder(iDesc);
0079       }
0080       void setPostConstruction(DataProxyProvider* iProv, const edm::ParameterSet& iPSet) const {
0081         //The 'appendToDataLabel' parameter was added very late in the development cycle and since
0082         // the ParameterSet is not sent to the base class we must set the value after construction
0083         iProv->setAppendToDataLabel(iPSet);
0084       }
0085       void setDescription(void*, const ComponentDescription&) const {}
0086       void setDescriptionForFinder(void*, const ComponentDescription&) const {}
0087       void setPostConstruction(void*, const edm::ParameterSet&) const {}
0088       // ---------- member data --------------------------------
0089     };
0090 
0091     template <class T, class TComponent>
0092     std::shared_ptr<typename ComponentMaker<T, TComponent>::base_type> ComponentMaker<T, TComponent>::addTo(
0093         EventSetupsController& esController,
0094         EventSetupProvider& iProvider,
0095         ParameterSet const& iConfiguration,
0096         bool replaceExisting) const {
0097       // This adds components to the EventSetupProvider for the process. It might
0098       // make a new component then add it or reuse a component from an earlier
0099       // SubProcess or the top level process and add that.
0100 
0101       if (!replaceExisting) {
0102         std::shared_ptr<typename T::base_type> alreadyMadeComponent =
0103             T::getComponentAndRegisterProcess(esController, iConfiguration);
0104 
0105         if (alreadyMadeComponent) {
0106           // This is for the case when a component is shared between
0107           // a SubProcess and a previous SubProcess or the top level process
0108           // because the component has an identical configuration to a component
0109           // from the top level process or earlier SubProcess.
0110           std::shared_ptr<TComponent> component(
0111               std::static_pointer_cast<TComponent, typename T::base_type>(alreadyMadeComponent));
0112           T::addTo(iProvider, component, iConfiguration, true);
0113           return component;
0114         }
0115       }
0116 
0117       std::shared_ptr<TComponent> component = std::make_shared<TComponent>(iConfiguration);
0118       ComponentDescription description = this->createComponentDescription(iConfiguration);
0119 
0120       this->setDescription(component.get(), description);
0121       this->setDescriptionForFinder(component.get(), description);
0122       this->setPostConstruction(component.get(), iConfiguration);
0123 
0124       if (replaceExisting) {
0125         // This case is for ESProducers where in the first pass
0126         // the algorithm thought the component could be shared
0127         // across SubProcess's because there was an ESProducer
0128         // from a previous process with an identical configuration.
0129         // But in a later check it was determined that sharing was not
0130         // possible because other components associated with the
0131         // same record or records that record depends on had
0132         // differing configurations.
0133         T::replaceExisting(iProvider, component);
0134       } else {
0135         // This is for the case when a new component is being constructed.
0136         // All components for the top level process fall in this category.
0137         // Or it could be a SubProcess where neither the top level process
0138         // nor any prior SubProcess had a component with exactly the same configuration.
0139         T::addTo(iProvider, component, iConfiguration, false);
0140         T::putComponent(esController, iConfiguration, component);
0141       }
0142       return component;
0143     }
0144   }  // namespace eventsetup
0145 }  // namespace edm
0146 #endif