Go to the documentation of this file.00001 #ifndef Framework_ComponentMaker_h
00002 #define Framework_ComponentMaker_h
00003
00004
00005
00006
00007
00016
00017
00018
00019
00020
00021
00022 #include <string>
00023 #include "boost/shared_ptr.hpp"
00024
00025
00026 #include "FWCore/Framework/interface/ComponentDescription.h"
00027 #include "FWCore/Framework/interface/DataProxyProvider.h"
00028 #include "FWCore/Framework/interface/EventSetupRecordIntervalFinder.h"
00029
00030
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 void logInfoWhenSharing(ParameterSet const& iConfiguration) const;
00044 ComponentDescription createComponentDescription(ParameterSet const& iConfiguration) const;
00045 };
00046
00047 template <class T>
00048 class ComponentMakerBase : public ComponentMakerBaseHelper {
00049 public:
00050 typedef typename T::base_type base_type;
00051 virtual boost::shared_ptr<base_type> addTo(EventSetupsController& esController,
00052 EventSetupProvider& iProvider,
00053 ParameterSet const& iConfiguration) const = 0;
00054 };
00055
00056 template <class T, class TComponent>
00057 class ComponentMaker : public ComponentMakerBase<T>
00058 {
00059
00060 public:
00061 ComponentMaker() {}
00062
00063 typedef typename T::base_type base_type;
00064
00065
00066 virtual boost::shared_ptr<base_type> addTo(EventSetupsController& esController,
00067 EventSetupProvider& iProvider,
00068 ParameterSet const& iConfiguration) const;
00069
00070
00071
00072
00073 private:
00074 ComponentMaker(const ComponentMaker&);
00075
00076 const ComponentMaker& operator=(const ComponentMaker&);
00077
00078 void setDescription(DataProxyProvider* iProv, const ComponentDescription& iDesc) const {
00079 iProv->setDescription(iDesc);
00080 }
00081 void setDescriptionForFinder(EventSetupRecordIntervalFinder* iFinder, const ComponentDescription& iDesc) const {
00082 iFinder->setDescriptionForFinder(iDesc);
00083 }
00084 void setPostConstruction(DataProxyProvider* iProv, const edm::ParameterSet& iPSet) const {
00085
00086
00087 iProv->setAppendToDataLabel(iPSet);
00088 }
00089 void setDescription(void*, const ComponentDescription&) const {
00090 }
00091 void setDescriptionForFinder(void*, const ComponentDescription&) const {
00092 }
00093 void setPostConstruction(void*, const edm::ParameterSet&) const {
00094 }
00095
00096
00097 };
00098
00099 template< class T, class TComponent>
00100 boost::shared_ptr<typename ComponentMaker<T,TComponent>::base_type>
00101 ComponentMaker<T,TComponent>::addTo(EventSetupsController& esController,
00102 EventSetupProvider& iProvider,
00103 ParameterSet const& iConfiguration) const
00104 {
00105 boost::shared_ptr<typename T::base_type> const* alreadyMadeComponent = T::getAlreadyMadeComponent(esController, iConfiguration);
00106
00107 if (alreadyMadeComponent) {
00108 this->logInfoWhenSharing(iConfiguration);
00109 boost::shared_ptr<TComponent> component(boost::static_pointer_cast<TComponent, typename T::base_type>(*alreadyMadeComponent));
00110 T::addTo(iProvider, component);
00111 return component;
00112 }
00113
00114 boost::shared_ptr<TComponent> component(new TComponent(iConfiguration));
00115 ComponentDescription description =
00116 this->createComponentDescription(iConfiguration);
00117
00118 this->setDescription(component.get(),description);
00119 this->setDescriptionForFinder(component.get(),description);
00120 this->setPostConstruction(component.get(),iConfiguration);
00121 T::addTo(iProvider, component);
00122 T::putComponent(esController, iConfiguration, component);
00123
00124 return component;
00125 }
00126 }
00127 }
00128 #endif