CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FWCore/Framework/interface/ComponentMaker.h

Go to the documentation of this file.
00001 #ifndef Framework_ComponentMaker_h
00002 #define Framework_ComponentMaker_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     ComponentMaker
00007 // 
00016 //
00017 // Author:      Chris Jones
00018 // Created:     Wed May 25 16:56:05 EDT 2005
00019 //
00020 
00021 // system include files
00022 #include <string>
00023 #include "boost/shared_ptr.hpp"
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/ComponentDescription.h"
00027 #include "FWCore/Framework/interface/DataProxyProvider.h"
00028 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00029 
00030 // forward declarations
00031 
00032 namespace edm {
00033    namespace eventsetup {
00034       class EventSetupProvider;
00035       class EventSetupsController;
00036       class DataProxyProvider;
00037     
00038       class ComponentMakerBaseHelper
00039       {
00040       public:
00041         virtual ~ComponentMakerBaseHelper() {}
00042       protected:
00043         ComponentDescription createComponentDescription(ParameterSet const& iConfiguration) const;
00044       };
00045  
00046       template <class T>
00047       class ComponentMakerBase : public ComponentMakerBaseHelper {
00048       public:
00049          typedef typename T::base_type base_type;
00050          virtual boost::shared_ptr<base_type> addTo(EventSetupsController& esController,
00051                                                     EventSetupProvider& iProvider,
00052                                                     ParameterSet const& iConfiguration,
00053                                                     bool replaceExisting) const = 0;
00054       };
00055       
00056    template <class T, class TComponent>
00057    class ComponentMaker : public ComponentMakerBase<T>
00058    {
00059 
00060    public:
00061    ComponentMaker() {}
00062       //virtual ~ComponentMaker();
00063    typedef typename T::base_type base_type;
00064 
00065       // ---------- const member functions ---------------------
00066    virtual boost::shared_ptr<base_type> addTo(EventSetupsController& esController,
00067                                               EventSetupProvider& iProvider,
00068                                               ParameterSet const& iConfiguration,
00069                                               bool replaceExisting) const;
00070    
00071       // ---------- static member functions --------------------
00072 
00073       // ---------- member functions ---------------------------
00074    private:
00075       ComponentMaker(const ComponentMaker&); // stop default
00076 
00077       const ComponentMaker& operator=(const ComponentMaker&); // stop default
00078 
00079       void setDescription(DataProxyProvider* iProv, const ComponentDescription& iDesc) const {
00080         iProv->setDescription(iDesc);
00081       }
00082       void setDescriptionForFinder(EventSetupRecordIntervalFinder* iFinder, const ComponentDescription& iDesc) const {
00083         iFinder->setDescriptionForFinder(iDesc);
00084       }
00085       void setPostConstruction(DataProxyProvider* iProv, const edm::ParameterSet& iPSet) const {
00086         //The 'appendToDataLabel' parameter was added very late in the development cycle and since
00087         // the ParameterSet is not sent to the base class we must set the value after construction
00088         iProv->setAppendToDataLabel(iPSet);
00089       }
00090       void setDescription(void*, const ComponentDescription&) const {
00091       }
00092       void setDescriptionForFinder(void*, const ComponentDescription&) const {
00093       }
00094       void setPostConstruction(void*, const edm::ParameterSet&) const {
00095       }
00096       // ---------- member data --------------------------------
00097 
00098 };
00099 
00100 template< class T, class TComponent>
00101 boost::shared_ptr<typename ComponentMaker<T,TComponent>::base_type>
00102 ComponentMaker<T,TComponent>::addTo(EventSetupsController& esController,
00103                                     EventSetupProvider& iProvider,
00104                                     ParameterSet const& iConfiguration,
00105                                     bool replaceExisting) const
00106 {
00107    // This adds components to the EventSetupProvider for the process. It might
00108    // make a new component then add it or reuse a component from an earlier
00109    // SubProcess or the top level process and add that.
00110 
00111    if (!replaceExisting) {
00112       boost::shared_ptr<typename T::base_type> alreadyMadeComponent = T::getComponentAndRegisterProcess(esController, iConfiguration);
00113 
00114       if (alreadyMadeComponent) {
00115          // This is for the case when a component is shared between
00116          // a SubProcess and a previous SubProcess or the top level process
00117          // because the component has an identical configuration to a component
00118          // from the top level process or earlier SubProcess.
00119          boost::shared_ptr<TComponent> component(boost::static_pointer_cast<TComponent, typename T::base_type>(alreadyMadeComponent));
00120          T::addTo(iProvider, component, iConfiguration, true);
00121          return component;
00122       }
00123    }
00124 
00125    boost::shared_ptr<TComponent> component(new TComponent(iConfiguration));
00126    ComponentDescription description =
00127       this->createComponentDescription(iConfiguration);
00128 
00129    this->setDescription(component.get(),description);
00130    this->setDescriptionForFinder(component.get(),description);
00131    this->setPostConstruction(component.get(),iConfiguration);
00132 
00133    if (replaceExisting) {
00134       // This case is for ESProducers where in the first pass
00135       // the algorithm thought the component could be shared
00136       // across SubProcess's because there was an ESProducer
00137       // from a previous process with an identical configuration.
00138       // But in a later check it was determined that sharing was not
00139       // possible because other components associated with the
00140       // same record or records that record depends on had
00141       // differing configurations.
00142       T::replaceExisting(iProvider, component);
00143    } else {
00144       // This is for the case when a new component is being constructed.
00145       // All components for the top level process fall in this category.
00146       // Or it could be a SubProcess where neither the top level process
00147       // nor any prior SubProcess had a component with exactly the same configuration.
00148       T::addTo(iProvider, component, iConfiguration, false);
00149       T::putComponent(esController, iConfiguration, component);
00150    }
00151    return component;
00152 }
00153    }
00154 }
00155 #endif