CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/FWCore/ParameterSet/interface/ParameterSetDescriptionFiller.h

Go to the documentation of this file.
00001 #ifndef FWCore_ParameterSet_ParameterSetDescriptionFiller_h
00002 #define FWCore_ParameterSet_ParameterSetDescriptionFiller_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     ParameterSet
00006 // Class  :     ParameterSetDescriptionFiller
00007 // 
00020 //
00021 // Original Author:  Chris Jones
00022 //         Created:  Wed Aug  1 16:46:56 EDT 2007
00023 //
00024 
00025 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerBase.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00027 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00028 #include "boost/mpl/if.hpp"
00029 #include <string>
00030 
00031 namespace edm {
00032   template< typename T>
00033   class ParameterSetDescriptionFiller : public ParameterSetDescriptionFillerBase
00034   {
00035   public:
00036     ParameterSetDescriptionFiller() {}
00037 
00038     virtual void fill(ConfigurationDescriptions & descriptions) const {
00039       T::fillDescriptions(descriptions);
00040       T::prevalidate(descriptions);
00041     }
00042 
00043     virtual const std::string& baseType() const {
00044       return T::baseType();
00045     }
00046 
00047   private:
00048     ParameterSetDescriptionFiller(const ParameterSetDescriptionFiller&); // stop default
00049     const ParameterSetDescriptionFiller& operator=(const ParameterSetDescriptionFiller&); // stop default
00050   };
00051 
00052   // We need a special version of this class for Services because there is
00053   // no common base class for all Service classes.  This means we cannot define
00054   // the baseType and fillDescriptions functions for all Service classes without
00055   // great difficulty.
00056 
00057   // First, some template metaprogramming to determining if the class T has
00058   // a fillDescriptions function.
00059 
00060   namespace fillDetails {
00061 
00062     typedef char (& no_tag)[1]; // type indicating FALSE
00063     typedef char (& yes_tag)[2]; // type indicating TRUE
00064 
00065     template <typename T, void (*)(ConfigurationDescriptions &)>  struct fillDescriptions_function;
00066     template <typename T> no_tag  has_fillDescriptions_helper(...);
00067     template <typename T> yes_tag has_fillDescriptions_helper(fillDescriptions_function<T, &T::fillDescriptions> * dummy);
00068 
00069     template<typename T>
00070     struct has_fillDescriptions_function {
00071       static bool const value =
00072         sizeof(has_fillDescriptions_helper<T>(0)) == sizeof(yes_tag);
00073     };
00074 
00075     template <typename T>
00076     struct DoFillDescriptions {
00077       void operator()(ConfigurationDescriptions & descriptions) {
00078         T::fillDescriptions(descriptions);
00079       }
00080     };
00081 
00082     template <typename T>
00083     struct DoFillAsUnknown {
00084       void operator()(ConfigurationDescriptions & descriptions) {
00085         ParameterSetDescription desc;
00086         desc.setUnknown();
00087         descriptions.addDefault(desc);
00088       }
00089     };
00090     
00091     template <typename T, void (*)(ConfigurationDescriptions &)>  struct prevalidate_function;
00092     template <typename T> no_tag  has_prevalidate_helper(...);
00093     template <typename T> yes_tag has_prevalidate_helper(fillDescriptions_function<T, &T::prevalidate> * dummy);
00094     
00095     template<typename T>
00096     struct has_prevalidate_function {
00097       static bool const value =
00098       sizeof(has_prevalidate_helper<T>(0)) == sizeof(yes_tag);
00099     };
00100     
00101     template <typename T>
00102     struct DoPrevalidate {
00103       void operator()(ConfigurationDescriptions & descriptions) {
00104         T::prevalidate(descriptions);
00105       }
00106     };
00107     
00108     template <typename T>
00109     struct DoNothing {
00110       void operator()(ConfigurationDescriptions & descriptions) {
00111       }
00112     };
00113 
00114   }
00115 
00116   // Not needed at the moment
00117   //void prevalidateService(ConfigurationDescriptions &);
00118   
00119   template< typename T>
00120   class DescriptionFillerForServices : public ParameterSetDescriptionFillerBase
00121   {
00122   public:
00123     DescriptionFillerForServices() {}
00124 
00125     // If T has a fillDescriptions function then just call that, otherwise
00126     // put in an "unknown description" as a default.
00127     virtual void fill(ConfigurationDescriptions & descriptions) const {
00128       typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value,
00129                                 edm::fillDetails::DoFillDescriptions<T>,
00130                                 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions;
00131       fill_descriptions(descriptions);
00132       //we don't have a need for prevalidation of services at the moment, so this is a placeholder
00133       // Probably the best package to declare this in would be FWCore/ServiceRegistry
00134       //prevalidateService(descriptions);
00135     }
00136 
00137     virtual const std::string& baseType() const {
00138       return kBaseForService;
00139     }
00140 
00141   private:
00142     void prevalidate(ConfigurationDescriptions & descriptions);
00143     DescriptionFillerForServices(const DescriptionFillerForServices&); // stop default
00144     const DescriptionFillerForServices& operator=(const DescriptionFillerForServices&); // stop default
00145   };
00146 
00147   template<typename T>
00148   class DescriptionFillerForESSources : public ParameterSetDescriptionFillerBase
00149   {
00150   public:
00151     DescriptionFillerForESSources() {}
00152 
00153     // If T has a fillDescriptions function then just call that, otherwise
00154     // put in an "unknown description" as a default.
00155     virtual void fill(ConfigurationDescriptions & descriptions) const {
00156       typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value,
00157                                 edm::fillDetails::DoFillDescriptions<T>,
00158                                 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions;
00159       fill_descriptions(descriptions);
00160       
00161       typename boost::mpl::if_c<edm::fillDetails::has_prevalidate_function<T>::value,
00162       edm::fillDetails::DoPrevalidate<T>,
00163       edm::fillDetails::DoNothing<T> >::type prevalidate;
00164       prevalidate(descriptions);
00165     }
00166 
00167     virtual const std::string& baseType() const {
00168       return kBaseForESSource;
00169     }
00170 
00171   private:
00172     DescriptionFillerForESSources(const DescriptionFillerForESSources&); // stop default
00173     const DescriptionFillerForESSources& operator=(const DescriptionFillerForESSources&); // stop default
00174   };
00175 
00176   template<typename T>
00177   class DescriptionFillerForESProducers : public ParameterSetDescriptionFillerBase
00178   {
00179   public:
00180     DescriptionFillerForESProducers() {}
00181 
00182     // If T has a fillDescriptions function then just call that, otherwise
00183     // put in an "unknown description" as a default.
00184     virtual void fill(ConfigurationDescriptions & descriptions) const {
00185       typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value,
00186                                 edm::fillDetails::DoFillDescriptions<T>,
00187                                 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions;
00188       fill_descriptions(descriptions);
00189       
00190       typename boost::mpl::if_c<edm::fillDetails::has_prevalidate_function<T>::value,
00191       edm::fillDetails::DoPrevalidate<T>,
00192       edm::fillDetails::DoNothing<T> >::type prevalidate;
00193       prevalidate(descriptions);
00194     }
00195 
00196     virtual const std::string& baseType() const {
00197       return kBaseForESProducer;
00198     }
00199 
00200   private:
00201     DescriptionFillerForESProducers(const DescriptionFillerForESProducers&); // stop default
00202     const DescriptionFillerForESProducers& operator=(const DescriptionFillerForESProducers&); // stop default
00203   };
00204 }
00205 #endif