Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-27 02:13:27

0001 #ifndef FWCore_ParameterSet_ParameterSetDescriptionFiller_h
0002 #define FWCore_ParameterSet_ParameterSetDescriptionFiller_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     ParameterSet
0006 // Class  :     ParameterSetDescriptionFiller
0007 //
0008 /**\class ParameterSetDescriptionFiller ParameterSetDescriptionFiller.h FWCore/ParameterSet/interface/ParameterSetDescriptionFiller.h
0009 
0010  Description: A concrete ParameterSetDescription filler which calls a static function of the template argument
0011 
0012  Usage:
0013     This is an ParameterSetDescription filler adapter class which calls the
0014 
0015 void fillDescription(edm::ParameterSetDescription&)
0016 
0017 method of the templated argument.  This allows the ParameterSetDescriptionFillerPluginFactory to communicate with existing plugins.
0018 
0019 */
0020 //
0021 // Original Author:  Chris Jones
0022 //         Created:  Wed Aug  1 16:46:56 EDT 2007
0023 //
0024 
0025 #include <type_traits>
0026 #include <string>
0027 #include "FWCore/ParameterSet/interface/ParameterSetDescriptionFillerBase.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0029 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0030 
0031 namespace edm {
0032   template <typename T>
0033   class ParameterSetDescriptionFiller : public ParameterSetDescriptionFillerBase {
0034   public:
0035     ParameterSetDescriptionFiller() {}
0036     ParameterSetDescriptionFiller(const ParameterSetDescriptionFiller&) = delete;                   // stop default
0037     const ParameterSetDescriptionFiller& operator=(const ParameterSetDescriptionFiller&) = delete;  // stop default
0038 
0039     void fill(ConfigurationDescriptions& descriptions) const override {
0040       T::fillDescriptions(descriptions);
0041       T::prevalidate(descriptions);
0042     }
0043 
0044     const std::string& baseType() const override { return T::baseType(); }
0045 
0046     const std::string& extendedBaseType() const override {
0047       const T* type = nullptr;
0048       return ParameterSetDescriptionFillerBase::extendedBaseType(type);
0049     }
0050   };
0051 
0052   // We need a special version of this class for Services because there is
0053   // no common base class for all Service classes.  This means we cannot define
0054   // the baseType and fillDescriptions functions for all Service classes without
0055   // great difficulty.
0056 
0057   // First, some template metaprogramming to determining if the class T has
0058   // a fillDescriptions function.
0059 
0060   namespace fillDetails {
0061 
0062     using no_tag = std::false_type;  // type indicating FALSE
0063     using yes_tag = std::true_type;  // type indicating TRUE
0064 
0065     template <typename T, void (*)(ConfigurationDescriptions&)>
0066     struct fillDescriptions_function;
0067     template <typename T>
0068     no_tag has_fillDescriptions_helper(...);
0069     template <typename T>
0070     yes_tag has_fillDescriptions_helper(fillDescriptions_function<T, &T::fillDescriptions>* dummy);
0071 
0072     template <typename T>
0073     struct has_fillDescriptions_function {
0074       static constexpr bool value = std::is_same<decltype(has_fillDescriptions_helper<T>(nullptr)), yes_tag>::value;
0075     };
0076 
0077     template <typename T>
0078     struct DoFillDescriptions {
0079       void operator()(ConfigurationDescriptions& descriptions) { T::fillDescriptions(descriptions); }
0080     };
0081 
0082     template <typename T>
0083     struct DoFillAsUnknown {
0084       void operator()(ConfigurationDescriptions& descriptions) {
0085         ParameterSetDescription desc;
0086         desc.setUnknown();
0087         descriptions.addDefault(desc);
0088       }
0089     };
0090 
0091     template <typename T, void (*)(ConfigurationDescriptions&)>
0092     struct prevalidate_function;
0093     template <typename T>
0094     no_tag has_prevalidate_helper(...);
0095     template <typename T>
0096     yes_tag has_prevalidate_helper(fillDescriptions_function<T, &T::prevalidate>* dummy);
0097 
0098     template <typename T>
0099     struct has_prevalidate_function {
0100       static constexpr bool value = std::is_same<decltype(has_prevalidate_helper<T>(nullptr)), yes_tag>::value;
0101     };
0102 
0103     template <typename T>
0104     struct DoPrevalidate {
0105       void operator()(ConfigurationDescriptions& descriptions) { T::prevalidate(descriptions); }
0106     };
0107 
0108     template <typename T>
0109     struct DoNothing {
0110       void operator()(ConfigurationDescriptions& descriptions) {}
0111     };
0112 
0113   }  // namespace fillDetails
0114 
0115   // Not needed at the moment
0116   //void prevalidateService(ConfigurationDescriptions &);
0117 
0118   template <typename T>
0119   class DescriptionFillerForServices : public ParameterSetDescriptionFillerBase {
0120   public:
0121     DescriptionFillerForServices() {}
0122 
0123     // If T has a fillDescriptions function then just call that, otherwise
0124     // put in an "unknown description" as a default.
0125     void fill(ConfigurationDescriptions& descriptions) const override {
0126       std::conditional_t<edm::fillDetails::has_fillDescriptions_function<T>::value,
0127                          edm::fillDetails::DoFillDescriptions<T>,
0128                          edm::fillDetails::DoFillAsUnknown<T>>
0129           fill_descriptions;
0130       fill_descriptions(descriptions);
0131       //we don't have a need for prevalidation of services at the moment, so this is a placeholder
0132       // Probably the best package to declare this in would be FWCore/ServiceRegistry
0133       //prevalidateService(descriptions);
0134     }
0135 
0136     const std::string& baseType() const override { return kBaseForService; }
0137 
0138     const std::string& extendedBaseType() const override { return kEmpty; }
0139 
0140   private:
0141     void prevalidate(ConfigurationDescriptions& descriptions);
0142     DescriptionFillerForServices(const DescriptionFillerForServices&);                   // stop default
0143     const DescriptionFillerForServices& operator=(const DescriptionFillerForServices&);  // stop default
0144   };
0145 
0146   template <typename T>
0147   class DescriptionFillerForESSources : public ParameterSetDescriptionFillerBase {
0148   public:
0149     DescriptionFillerForESSources() {}
0150     DescriptionFillerForESSources(const DescriptionFillerForESSources&) = delete;                   // stop default
0151     const DescriptionFillerForESSources& operator=(const DescriptionFillerForESSources&) = delete;  // stop default
0152 
0153     // If T has a fillDescriptions function then just call that, otherwise
0154     // put in an "unknown description" as a default.
0155     void fill(ConfigurationDescriptions& descriptions) const override {
0156       std::conditional_t<edm::fillDetails::has_fillDescriptions_function<T>::value,
0157                          edm::fillDetails::DoFillDescriptions<T>,
0158                          edm::fillDetails::DoFillAsUnknown<T>>
0159           fill_descriptions;
0160       fill_descriptions(descriptions);
0161 
0162       std::conditional_t<edm::fillDetails::has_prevalidate_function<T>::value,
0163                          edm::fillDetails::DoPrevalidate<T>,
0164                          edm::fillDetails::DoNothing<T>>
0165           prevalidate;
0166       prevalidate(descriptions);
0167     }
0168 
0169     const std::string& baseType() const override { return kBaseForESSource; }
0170 
0171     const std::string& extendedBaseType() const override { return kEmpty; }
0172   };
0173 
0174   template <typename T>
0175   class DescriptionFillerForESProducers : public ParameterSetDescriptionFillerBase {
0176   public:
0177     DescriptionFillerForESProducers() {}
0178     DescriptionFillerForESProducers(const DescriptionFillerForESProducers&) = delete;                   // stop default
0179     const DescriptionFillerForESProducers& operator=(const DescriptionFillerForESProducers&) = delete;  // stop default
0180 
0181     // If T has a fillDescriptions function then just call that, otherwise
0182     // put in an "unknown description" as a default.
0183     void fill(ConfigurationDescriptions& descriptions) const override {
0184       std::conditional_t<edm::fillDetails::has_fillDescriptions_function<T>::value,
0185                          edm::fillDetails::DoFillDescriptions<T>,
0186                          edm::fillDetails::DoFillAsUnknown<T>>
0187           fill_descriptions;
0188       fill_descriptions(descriptions);
0189 
0190       std::conditional_t<edm::fillDetails::has_prevalidate_function<T>::value,
0191                          edm::fillDetails::DoPrevalidate<T>,
0192                          edm::fillDetails::DoNothing<T>>
0193           prevalidate;
0194       prevalidate(descriptions);
0195     }
0196 
0197     const std::string& baseType() const override { return kBaseForESProducer; }
0198 
0199     const std::string& extendedBaseType() const override { return kEmpty; }
0200   };
0201 
0202   template <typename T>
0203   class DescriptionFillerForEDLoopers : public ParameterSetDescriptionFillerBase {
0204   public:
0205     DescriptionFillerForEDLoopers() {}
0206     DescriptionFillerForEDLoopers(const DescriptionFillerForEDLoopers&) = delete;                   // stop default
0207     const DescriptionFillerForEDLoopers& operator=(const DescriptionFillerForEDLoopers&) = delete;  // stop default
0208 
0209     // If T has a fillDescriptions function then just call that, otherwise
0210     // put in an "unknown description" as a default.
0211     void fill(ConfigurationDescriptions& descriptions) const override {
0212       std::conditional_t<edm::fillDetails::has_fillDescriptions_function<T>::value,
0213                          edm::fillDetails::DoFillDescriptions<T>,
0214                          edm::fillDetails::DoFillAsUnknown<T>>
0215           fill_descriptions;
0216       fill_descriptions(descriptions);
0217 
0218       std::conditional_t<edm::fillDetails::has_prevalidate_function<T>::value,
0219                          edm::fillDetails::DoPrevalidate<T>,
0220                          edm::fillDetails::DoNothing<T>>
0221           prevalidate;
0222       prevalidate(descriptions);
0223     }
0224 
0225     const std::string& baseType() const override { return kBaseForEDLooper; }
0226 
0227     const std::string& extendedBaseType() const override { return kEmpty; }
0228   };
0229 }  // namespace edm
0230 #endif