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 } 00041 00042 virtual const std::string& baseType() const { 00043 return T::baseType(); 00044 } 00045 00046 private: 00047 ParameterSetDescriptionFiller(const ParameterSetDescriptionFiller&); // stop default 00048 const ParameterSetDescriptionFiller& operator=(const ParameterSetDescriptionFiller&); // stop default 00049 }; 00050 00051 // We need a special version of this class for Services because there is 00052 // no common base class for all Service classes. This means we cannot define 00053 // the baseType and fillDescriptions functions for all Service classes without 00054 // great difficulty. 00055 00056 // First, some template metaprogramming to determining if the class T has 00057 // a fillDescriptions function. 00058 00059 namespace fillDetails { 00060 00061 typedef char (& no_tag)[1]; // type indicating FALSE 00062 typedef char (& yes_tag)[2]; // type indicating TRUE 00063 00064 template <typename T, void (*)(ConfigurationDescriptions &)> struct fillDescriptions_function; 00065 template <typename T> no_tag has_fillDescriptions_helper(...); 00066 template <typename T> yes_tag has_fillDescriptions_helper(fillDescriptions_function<T, &T::fillDescriptions> * dummy); 00067 00068 template<typename T> 00069 struct has_fillDescriptions_function { 00070 static bool const value = 00071 sizeof(has_fillDescriptions_helper<T>(0)) == sizeof(yes_tag); 00072 }; 00073 00074 template <typename T> 00075 struct DoFillDescriptions { 00076 void operator()(ConfigurationDescriptions & descriptions) { 00077 T::fillDescriptions(descriptions); 00078 } 00079 }; 00080 00081 template <typename T> 00082 struct DoFillAsUnknown { 00083 void operator()(ConfigurationDescriptions & descriptions) { 00084 ParameterSetDescription desc; 00085 desc.setUnknown(); 00086 descriptions.addDefault(desc); 00087 } 00088 }; 00089 } 00090 00091 template< typename T> 00092 class DescriptionFillerForServices : public ParameterSetDescriptionFillerBase 00093 { 00094 public: 00095 DescriptionFillerForServices() {} 00096 00097 // If T has a fillDescriptions function then just call that, otherwise 00098 // put in an "unknown description" as a default. 00099 virtual void fill(ConfigurationDescriptions & descriptions) const { 00100 typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value, 00101 edm::fillDetails::DoFillDescriptions<T>, 00102 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions; 00103 fill_descriptions(descriptions); 00104 } 00105 00106 virtual const std::string& baseType() const { 00107 return kBaseForService; 00108 } 00109 00110 private: 00111 DescriptionFillerForServices(const DescriptionFillerForServices&); // stop default 00112 const DescriptionFillerForServices& operator=(const DescriptionFillerForServices&); // stop default 00113 }; 00114 00115 template<typename T> 00116 class DescriptionFillerForESSources : public ParameterSetDescriptionFillerBase 00117 { 00118 public: 00119 DescriptionFillerForESSources() {} 00120 00121 // If T has a fillDescriptions function then just call that, otherwise 00122 // put in an "unknown description" as a default. 00123 virtual void fill(ConfigurationDescriptions & descriptions) const { 00124 typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value, 00125 edm::fillDetails::DoFillDescriptions<T>, 00126 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions; 00127 fill_descriptions(descriptions); 00128 } 00129 00130 virtual const std::string& baseType() const { 00131 return kBaseForESSource; 00132 } 00133 00134 private: 00135 DescriptionFillerForESSources(const DescriptionFillerForESSources&); // stop default 00136 const DescriptionFillerForESSources& operator=(const DescriptionFillerForESSources&); // stop default 00137 }; 00138 00139 template<typename T> 00140 class DescriptionFillerForESProducers : public ParameterSetDescriptionFillerBase 00141 { 00142 public: 00143 DescriptionFillerForESProducers() {} 00144 00145 // If T has a fillDescriptions function then just call that, otherwise 00146 // put in an "unknown description" as a default. 00147 virtual void fill(ConfigurationDescriptions & descriptions) const { 00148 typename boost::mpl::if_c<edm::fillDetails::has_fillDescriptions_function<T>::value, 00149 edm::fillDetails::DoFillDescriptions<T>, 00150 edm::fillDetails::DoFillAsUnknown<T> >::type fill_descriptions; 00151 fill_descriptions(descriptions); 00152 } 00153 00154 virtual const std::string& baseType() const { 00155 return kBaseForESProducer; 00156 } 00157 00158 private: 00159 DescriptionFillerForESProducers(const DescriptionFillerForESProducers&); // stop default 00160 const DescriptionFillerForESProducers& operator=(const DescriptionFillerForESProducers&); // stop default 00161 }; 00162 } 00163 #endif