00001 #ifndef Framework_ESProducer_h
00002 #define Framework_ESProducer_h
00003
00004
00005
00006
00007
00066
00067
00068
00069
00070
00071
00072 #include <memory>
00073 #include <string>
00074
00075
00076 #include "FWCore/Framework/interface/ESProxyFactoryProducer.h"
00077 #include "FWCore/Framework/interface/ProxyArgumentFactoryTemplate.h"
00078
00079 #include "FWCore/Framework/interface/CallbackProxy.h"
00080 #include "FWCore/Framework/interface/Callback.h"
00081 #include "FWCore/Framework/interface/produce_helpers.h"
00082 #include "FWCore/Framework/interface/eventsetup_dependsOn.h"
00083 #include "FWCore/Framework/interface/es_Label.h"
00084
00085
00086 namespace edm {
00087 namespace eventsetup {
00088
00089
00090
00091
00092 template< typename T, typename TRecord, typename TDecorator >
00093 inline const TDecorator& createDecoratorFrom(T*, const TRecord*, const TDecorator& iDec) {
00094 return iDec;
00095 }
00096 }
00097 class ESProducer : public ESProxyFactoryProducer
00098 {
00099
00100 public:
00101 ESProducer();
00102 virtual ~ESProducer();
00103
00104
00105
00106
00107
00108
00109 protected:
00114 template<typename T>
00115 void setWhatProduced(T* iThis, const es::Label& iLabel = es::Label()) {
00116
00117 setWhatProduced(iThis , &T::produce, iLabel);
00118 }
00119
00120 template<typename T>
00121 void setWhatProduced(T* iThis, const char* iLabel) {
00122
00123 setWhatProduced(iThis , es::Label(iLabel));
00124 }
00125 template<typename T>
00126 void setWhatProduced(T* iThis, const std::string& iLabel) {
00127
00128 setWhatProduced(iThis , es::Label(iLabel));
00129 }
00130
00131 template<typename T, typename TDecorator >
00132 void setWhatProduced(T* iThis, const TDecorator& iDec, const es::Label& iLabel = es::Label()) {
00133
00134 setWhatProduced(iThis , &T::produce, iDec, iLabel);
00135 }
00141 template<typename T, typename TReturn, typename TRecord>
00142 void setWhatProduced(T* iThis,
00143 TReturn (T ::* iMethod)(const TRecord&),
00144 const es::Label& iLabel = es::Label()) {
00145 setWhatProduced(iThis, iMethod, eventsetup::CallbackSimpleDecorator<TRecord>(),iLabel);
00146 }
00153 template<typename T, typename TReturn, typename TRecord, typename TArg>
00154 void setWhatProduced(T* iThis,
00155 TReturn (T ::* iMethod)(const TRecord&),
00156 const TArg& iDec,
00157 const es::Label& iLabel = es::Label()) {
00158 boost::shared_ptr<eventsetup::Callback<T,TReturn,TRecord, typename eventsetup::DecoratorFromArg<T, TRecord, TArg>::Decorator_t > >
00159 callback(new eventsetup::Callback<T,
00160 TReturn,
00161 TRecord,
00162 typename eventsetup::DecoratorFromArg<T,TRecord,TArg>::Decorator_t>(
00163 iThis,
00164 iMethod,
00165 createDecoratorFrom(iThis,
00166 static_cast<const TRecord*>(0),
00167 iDec)));
00168 registerProducts(callback,
00169 static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(0),
00170 static_cast<const TRecord*>(0),
00171 iLabel);
00172
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 private:
00184 ESProducer(const ESProducer&);
00185
00186 ESProducer const& operator=(const ESProducer&);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 template<typename CallbackT, typename TList, typename TRecord>
00197 void registerProducts(boost::shared_ptr<CallbackT> iCallback, const TList*, const TRecord* iRecord,
00198 const es::Label& iLabel) {
00199 registerProduct(iCallback, static_cast<const typename TList::tail_type*>(0), iRecord, iLabel);
00200 registerProducts(iCallback, static_cast<const typename TList::head_type*>(0), iRecord, iLabel);
00201 }
00202 template<typename T, typename TRecord>
00203 void registerProducts(boost::shared_ptr<T>, const eventsetup::produce::Null*, const TRecord*,const es::Label&) {
00204
00205 }
00206
00207
00208 template<typename T, typename TProduct, typename TRecord>
00209 void registerProduct(boost::shared_ptr<T> iCallback, const TProduct*, const TRecord*,const es::Label& iLabel) {
00210 typedef eventsetup::CallbackProxy<T, TRecord, TProduct> ProxyType;
00211 typedef eventsetup::ProxyArgumentFactoryTemplate<ProxyType, boost::shared_ptr<T> > FactoryType;
00212 registerFactory(std::auto_ptr<FactoryType>(new FactoryType(iCallback)), iLabel.default_);
00213 }
00214
00215 template<typename T, typename TProduct, typename TRecord, int IIndex>
00216 void registerProduct(boost::shared_ptr<T> iCallback, const es::L<TProduct,IIndex>*, const TRecord*,const es::Label& iLabel) {
00217 if(iLabel.labels_.size() <= IIndex ||
00218 iLabel.labels_[IIndex] == es::Label::def()) {
00219 Exception::throwThis(errors::Configuration,
00220 "Unnamed Label\nthe index ",
00221 IIndex,
00222 " was never assigned a name in the 'setWhatProduced' method");
00223 }
00224 typedef eventsetup::CallbackProxy<T, TRecord, es::L<TProduct, IIndex> > ProxyType;
00225 typedef eventsetup::ProxyArgumentFactoryTemplate<ProxyType, boost::shared_ptr<T> > FactoryType;
00226 registerFactory(std::auto_ptr<FactoryType>(new FactoryType(iCallback)), iLabel.labels_[IIndex]);
00227 }
00228
00229
00230
00231
00232
00233 };
00234 }
00235 #endif