CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Framework/interface/ESProducer.h

Go to the documentation of this file.
00001 #ifndef Framework_ESProducer_h
00002 #define Framework_ESProducer_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     ESProducer
00007 // 
00066 //
00067 // Author:      Chris Jones
00068 // Created:     Thu Apr  7 17:08:14 CDT 2005
00069 //
00070 
00071 // system include files
00072 #include <memory>
00073 #include <string>
00074 
00075 // user include files
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 // forward declarations
00086 namespace edm {
00087    namespace eventsetup {      
00088       
00089       //used by ESProducer to create the proper Decorator based on the
00090       //  argument type passed.  The default it to just 'pass through'
00091       //  the argument as the decorator itself
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       // ---------- const member functions ---------------------
00105 
00106       // ---------- static member functions --------------------
00107 
00108       // ---------- member functions ---------------------------
00109    protected:
00114       template<typename T>
00115          void setWhatProduced(T* iThis, const es::Label& iLabel = es::Label()) {
00116             //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
00117             setWhatProduced(iThis , &T::produce, iLabel);
00118          }
00119 
00120       template<typename T>
00121          void setWhatProduced(T* iThis, const char* iLabel) {
00122             //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
00123             setWhatProduced(iThis , es::Label(iLabel));
00124          }
00125       template<typename T>
00126          void setWhatProduced(T* iThis, const std::string& iLabel) {
00127             //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
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             //BOOST_STATIC_ASSERT((typename boost::is_base_and_derived<ED, T>::type));
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             //BOOST_STATIC_ASSERT((boost::is_base_and_derived<ED, T>::type));
00173          }
00174 
00175       /*
00176       template<typename T, typename TReturn, typename TArg>
00177          void setWhatProduced(T* iThis, TReturn (T ::* iMethod)(const TArg&)) {
00178             registerProducts(iThis, static_cast<const typename produce::product_traits<TReturn>::type *>(0));
00179             registerGet(iThis, static_cast<const TArg*>(0));
00180             //BOOST_STATIC_ASSERT((boost::is_base_and_derived<ED, T>::type));
00181          }
00182       */
00183    private:
00184       ESProducer(const ESProducer&); // stop default
00185 
00186       ESProducer const& operator=(const ESProducer&); // stop default
00187 
00188       /*
00189       template<typename T, typename TProduct>
00190          void registerGet(T* i, const TProduct* iProd) {
00191             std::cout <<"registered 'get' for product type "
00192             << test::name(iProd) <<
00193             std::endl;
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             //do nothing
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       // ---------- member data --------------------------------
00230       // NOTE: the factories share ownership of the callback
00231       //std::vector<boost::shared_ptr<CallbackBase> > callbacks_;
00232       
00233 };
00234 }
00235 #endif