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 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
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,
00069 bool replaceExisting) const;
00070
00071
00072
00073
00074 private:
00075 ComponentMaker(const ComponentMaker&);
00076
00077 const ComponentMaker& operator=(const ComponentMaker&);
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
00087
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
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
00108
00109
00110
00111 if (!replaceExisting) {
00112 boost::shared_ptr<typename T::base_type> alreadyMadeComponent = T::getComponentAndRegisterProcess(esController, iConfiguration);
00113
00114 if (alreadyMadeComponent) {
00115
00116
00117
00118
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
00135
00136
00137
00138
00139
00140
00141
00142 T::replaceExisting(iProvider, component);
00143 } else {
00144
00145
00146
00147
00148 T::addTo(iProvider, component, iConfiguration, false);
00149 T::putComponent(esController, iConfiguration, component);
00150 }
00151 return component;
00152 }
00153 }
00154 }
00155 #endif