Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:56

0001 
0002 #include "FWCore/ParameterSet/src/FillDescriptionFromPSet.h"
0003 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/Entry.h"
0007 
0008 #include <string>
0009 #include <map>
0010 #include <vector>
0011 
0012 namespace edm {
0013   class EventID;
0014   class LuminosityBlockID;
0015   class LuminosityBlockRange;
0016   class EventRange;
0017   class InputTag;
0018   class FileInPath;
0019 }  // namespace edm
0020 
0021 typedef void (*FillDescriptionFromParameter)(edm::ParameterSet const&,
0022                                              std::string const&,
0023                                              bool,
0024                                              edm::ParameterSetDescription&);
0025 
0026 static std::map<edm::ParameterTypes, FillDescriptionFromParameter> s_findTheRightFunction;
0027 
0028 namespace {
0029 
0030   template <typename T>
0031   void fillDescriptionFromParameter(edm::ParameterSet const& pset,
0032                                     std::string const& name,
0033                                     bool isTracked,
0034                                     edm::ParameterSetDescription& desc) {
0035     if (isTracked) {
0036       desc.add<T>(name, pset.getParameter<T>(name));
0037     } else {
0038       desc.addUntracked<T>(name, pset.getUntrackedParameter<T>(name));
0039     }
0040   }
0041 
0042   void initMap() {
0043     s_findTheRightFunction[static_cast<edm::ParameterTypes>('I')] = &fillDescriptionFromParameter<int>;
0044     s_findTheRightFunction[static_cast<edm::ParameterTypes>('i')] = &fillDescriptionFromParameter<std::vector<int>>;
0045     s_findTheRightFunction[static_cast<edm::ParameterTypes>('U')] = &fillDescriptionFromParameter<unsigned>;
0046     s_findTheRightFunction[static_cast<edm::ParameterTypes>('u')] =
0047         &fillDescriptionFromParameter<std::vector<unsigned>>;
0048     s_findTheRightFunction[static_cast<edm::ParameterTypes>('L')] = &fillDescriptionFromParameter<long long>;
0049     s_findTheRightFunction[static_cast<edm::ParameterTypes>('l')] =
0050         &fillDescriptionFromParameter<std::vector<long long>>;
0051     s_findTheRightFunction[static_cast<edm::ParameterTypes>('X')] = &fillDescriptionFromParameter<unsigned long long>;
0052     s_findTheRightFunction[static_cast<edm::ParameterTypes>('x')] =
0053         &fillDescriptionFromParameter<std::vector<unsigned long long>>;
0054     s_findTheRightFunction[static_cast<edm::ParameterTypes>('D')] = &fillDescriptionFromParameter<double>;
0055     s_findTheRightFunction[static_cast<edm::ParameterTypes>('d')] = &fillDescriptionFromParameter<std::vector<double>>;
0056     s_findTheRightFunction[static_cast<edm::ParameterTypes>('B')] = &fillDescriptionFromParameter<bool>;
0057     s_findTheRightFunction[static_cast<edm::ParameterTypes>('S')] = &fillDescriptionFromParameter<std::string>;
0058     s_findTheRightFunction[static_cast<edm::ParameterTypes>('s')] =
0059         &fillDescriptionFromParameter<std::vector<std::string>>;
0060     s_findTheRightFunction[static_cast<edm::ParameterTypes>('E')] = &fillDescriptionFromParameter<edm::EventID>;
0061     s_findTheRightFunction[static_cast<edm::ParameterTypes>('e')] =
0062         &fillDescriptionFromParameter<std::vector<edm::EventID>>;
0063     s_findTheRightFunction[static_cast<edm::ParameterTypes>('M')] =
0064         &fillDescriptionFromParameter<edm::LuminosityBlockID>;
0065     s_findTheRightFunction[static_cast<edm::ParameterTypes>('m')] =
0066         &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockID>>;
0067     s_findTheRightFunction[static_cast<edm::ParameterTypes>('t')] = &fillDescriptionFromParameter<edm::InputTag>;
0068     s_findTheRightFunction[static_cast<edm::ParameterTypes>('v')] =
0069         &fillDescriptionFromParameter<std::vector<edm::InputTag>>;
0070     s_findTheRightFunction[static_cast<edm::ParameterTypes>('F')] = &fillDescriptionFromParameter<edm::FileInPath>;
0071     s_findTheRightFunction[static_cast<edm::ParameterTypes>('A')] =
0072         &fillDescriptionFromParameter<edm::LuminosityBlockRange>;
0073     s_findTheRightFunction[static_cast<edm::ParameterTypes>('a')] =
0074         &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockRange>>;
0075     s_findTheRightFunction[static_cast<edm::ParameterTypes>('R')] = &fillDescriptionFromParameter<edm::EventRange>;
0076     s_findTheRightFunction[static_cast<edm::ParameterTypes>('r')] =
0077         &fillDescriptionFromParameter<std::vector<edm::EventRange>>;
0078   }
0079 
0080   std::map<edm::ParameterTypes, FillDescriptionFromParameter>& findTheRightFunction() {
0081     if (s_findTheRightFunction.empty())
0082       initMap();
0083     return s_findTheRightFunction;
0084   }
0085 }  // namespace
0086 
0087 namespace edm {
0088 
0089   // Note that the description this fills is used for purposes
0090   // of printing documentation from edmPluginHelp and writing
0091   // cfi files.  In general, it will not be useful for validation
0092   // purposes.  First of all, if the ParameterSet contains a
0093   // vector of ParameterSets, then the description of that vector
0094   // of ParameterSets will have an empty ParameterSetDescription
0095   // (so if you try to validate with such a description, it will
0096   // always fail).  Also, the ParameterSet has no concept of "optional"
0097   // or the logical relationships between parameters in the
0098   // description (like "and", "xor", "switches", ...), so there is
0099   // no way a description generated from a ParameterSet can properly
0100   // express those concepts.
0101 
0102   void fillDescriptionFromPSet(ParameterSet const& pset, ParameterSetDescription& desc) {
0103     ParameterSet::table const& entries = pset.tbl();
0104     for (ParameterSet::table::const_iterator entry = entries.begin(), endEntries = entries.end(); entry != endEntries;
0105          ++entry) {
0106       std::map<edm::ParameterTypes, FillDescriptionFromParameter>::iterator iter =
0107           findTheRightFunction().find(static_cast<edm::ParameterTypes>(entry->second.typeCode()));
0108       if (iter != findTheRightFunction().end()) {
0109         iter->second(pset, entry->first, entry->second.isTracked(), desc);
0110       }
0111     }
0112 
0113     ParameterSet::psettable const& pset_entries = pset.psetTable();
0114     for (ParameterSet::psettable::const_iterator pset_entry = pset_entries.begin(), endEntries = pset_entries.end();
0115          pset_entry != endEntries;
0116          ++pset_entry) {
0117       edm::ParameterSet nestedPset;
0118       if (pset_entry->second.isTracked()) {
0119         nestedPset = pset.getParameterSet(pset_entry->first);
0120       } else {
0121         nestedPset = pset.getUntrackedParameterSet(pset_entry->first);
0122       }
0123       ParameterSetDescription nestedDescription;
0124       fillDescriptionFromPSet(nestedPset, nestedDescription);
0125       if (pset_entry->second.isTracked()) {
0126         desc.add<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
0127       } else {
0128         desc.addUntracked<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
0129       }
0130     }
0131 
0132     ParameterSet::vpsettable const& vpset_entries = pset.vpsetTable();
0133     for (ParameterSet::vpsettable::const_iterator vpset_entry = vpset_entries.begin(), endEntries = vpset_entries.end();
0134          vpset_entry != endEntries;
0135          ++vpset_entry) {
0136       std::vector<edm::ParameterSet> nestedVPset;
0137       if (vpset_entry->second.isTracked()) {
0138         nestedVPset = pset.getParameterSetVector(vpset_entry->first);
0139       } else {
0140         nestedVPset = pset.getUntrackedParameterSetVector(vpset_entry->first);
0141       }
0142       ParameterSetDescription emptyDescription;
0143 
0144       auto pd = std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(
0145           vpset_entry->first, emptyDescription, vpset_entry->second.isTracked(), nestedVPset);
0146 
0147       pd->setPartOfDefaultOfVPSet(true);
0148       std::unique_ptr<ParameterDescriptionNode> node(std::move(pd));
0149       desc.addNode(std::move(node));
0150     }
0151   }
0152 }  // namespace edm