Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-10-10 03:58:40

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, void (*)(ConfigurationDescriptions&)>
0078     struct prevalidate_function;
0079     template <typename T>
0080     no_tag has_prevalidate_helper(...);
0081     template <typename T>
0082     yes_tag has_prevalidate_helper(fillDescriptions_function<T, &T::prevalidate>* dummy);
0083 
0084     template <typename T>
0085     struct has_prevalidate_function {
0086       static constexpr bool value = std::is_same<decltype(has_prevalidate_helper<T>(nullptr)), yes_tag>::value;
0087     };
0088 
0089     template <typename T>
0090     void fillIfExists(ConfigurationDescriptions& descriptions) {
0091       if constexpr (has_fillDescriptions_function<T>::value) {
0092         T::fillDescriptions(descriptions);
0093       } else {
0094         ParameterSetDescription desc;
0095         desc.setUnknown();
0096         descriptions.addDefault(desc);
0097       }
0098     }
0099 
0100     template <typename T>
0101     void prevalidateIfExists(ConfigurationDescriptions& descriptions) {
0102       if constexpr (has_prevalidate_function<T>::value) {
0103         T::prevalidate(descriptions);
0104       }
0105     }
0106 
0107   }  // namespace fillDetails
0108 
0109   // Not needed at the moment
0110   //void prevalidateService(ConfigurationDescriptions &);
0111 
0112   template <typename T>
0113   class DescriptionFillerForServices : public ParameterSetDescriptionFillerBase {
0114   public:
0115     DescriptionFillerForServices() {}
0116 
0117     // If T has a fillDescriptions function then just call that, otherwise
0118     // put in an "unknown description" as a default.
0119     void fill(ConfigurationDescriptions& descriptions) const override {
0120       fillDetails::fillIfExists<T>(descriptions);
0121       //we don't have a need for prevalidation of services at the moment, so this is a placeholder
0122       // Probably the best package to declare this in would be FWCore/ServiceRegistry
0123       //prevalidateService(descriptions);
0124     }
0125 
0126     const std::string& baseType() const override { return kBaseForService; }
0127 
0128     const std::string& extendedBaseType() const override { return kEmpty; }
0129 
0130   private:
0131     void prevalidate(ConfigurationDescriptions& descriptions);
0132     DescriptionFillerForServices(const DescriptionFillerForServices&);                   // stop default
0133     const DescriptionFillerForServices& operator=(const DescriptionFillerForServices&);  // stop default
0134   };
0135 
0136   template <typename T>
0137   class DescriptionFillerForESSources : public ParameterSetDescriptionFillerBase {
0138   public:
0139     DescriptionFillerForESSources() {}
0140     DescriptionFillerForESSources(const DescriptionFillerForESSources&) = delete;                   // stop default
0141     const DescriptionFillerForESSources& operator=(const DescriptionFillerForESSources&) = delete;  // stop default
0142 
0143     // If T has a fillDescriptions function then just call that, otherwise
0144     // put in an "unknown description" as a default.
0145     void fill(ConfigurationDescriptions& descriptions) const override {
0146       fillDetails::fillIfExists<T>(descriptions);
0147       fillDetails::prevalidateIfExists<T>(descriptions);
0148     }
0149 
0150     const std::string& baseType() const override { return kBaseForESSource; }
0151 
0152     const std::string& extendedBaseType() const override { return kEmpty; }
0153   };
0154 
0155   template <typename T>
0156   class DescriptionFillerForESProducers : public ParameterSetDescriptionFillerBase {
0157   public:
0158     DescriptionFillerForESProducers() {}
0159     DescriptionFillerForESProducers(const DescriptionFillerForESProducers&) = delete;                   // stop default
0160     const DescriptionFillerForESProducers& operator=(const DescriptionFillerForESProducers&) = delete;  // stop default
0161 
0162     // If T has a fillDescriptions function then just call that, otherwise
0163     // put in an "unknown description" as a default.
0164     void fill(ConfigurationDescriptions& descriptions) const override {
0165       fillDetails::fillIfExists<T>(descriptions);
0166       fillDetails::prevalidateIfExists<T>(descriptions);
0167     }
0168 
0169     const std::string& baseType() const override { return kBaseForESProducer; }
0170 
0171     const std::string& extendedBaseType() const override { return kEmpty; }
0172   };
0173 
0174   template <typename T>
0175   class DescriptionFillerForEDLoopers : public ParameterSetDescriptionFillerBase {
0176   public:
0177     DescriptionFillerForEDLoopers() {}
0178     DescriptionFillerForEDLoopers(const DescriptionFillerForEDLoopers&) = delete;                   // stop default
0179     const DescriptionFillerForEDLoopers& operator=(const DescriptionFillerForEDLoopers&) = 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       fillDetails::fillIfExists<T>(descriptions);
0185       fillDetails::prevalidateIfExists<T>(descriptions);
0186     }
0187 
0188     const std::string& baseType() const override { return kBaseForEDLooper; }
0189 
0190     const std::string& extendedBaseType() const override { return kEmpty; }
0191   };
0192 }  // namespace edm
0193 #endif