File indexing completed on 2024-04-06 12:12:55
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 ESInputTag;
0019 class FileInPath;
0020 }
0021
0022 typedef void (*FillDescriptionFromParameter)(edm::ParameterSet const&,
0023 std::string const&,
0024 bool,
0025 edm::ParameterSetDescription&);
0026
0027 static std::map<edm::ParameterTypes, FillDescriptionFromParameter> s_findTheRightFunction;
0028
0029 namespace {
0030
0031 template <typename T>
0032 void fillDescriptionFromParameter(edm::ParameterSet const& pset,
0033 std::string const& name,
0034 bool isTracked,
0035 edm::ParameterSetDescription& desc) {
0036 if (isTracked) {
0037 desc.add<T>(name, pset.getParameter<T>(name));
0038 } else {
0039 desc.addUntracked<T>(name, pset.getUntrackedParameter<T>(name));
0040 }
0041 }
0042
0043 void initMap() {
0044 s_findTheRightFunction[edm::k_int32] = &fillDescriptionFromParameter<int>;
0045 s_findTheRightFunction[edm::k_vint32] = &fillDescriptionFromParameter<std::vector<int>>;
0046 s_findTheRightFunction[edm::k_uint32] = &fillDescriptionFromParameter<unsigned>;
0047 s_findTheRightFunction[edm::k_vuint32] = &fillDescriptionFromParameter<std::vector<unsigned>>;
0048 s_findTheRightFunction[edm::k_int64] = &fillDescriptionFromParameter<long long>;
0049 s_findTheRightFunction[edm::k_vint64] = &fillDescriptionFromParameter<std::vector<long long>>;
0050 s_findTheRightFunction[edm::k_uint64] = &fillDescriptionFromParameter<unsigned long long>;
0051 s_findTheRightFunction[edm::k_vuint64] = &fillDescriptionFromParameter<std::vector<unsigned long long>>;
0052 s_findTheRightFunction[edm::k_double] = &fillDescriptionFromParameter<double>;
0053 s_findTheRightFunction[edm::k_vdouble] = &fillDescriptionFromParameter<std::vector<double>>;
0054 s_findTheRightFunction[edm::k_bool] = &fillDescriptionFromParameter<bool>;
0055 s_findTheRightFunction[edm::k_stringRaw] = &fillDescriptionFromParameter<std::string>;
0056 s_findTheRightFunction[edm::k_vstringRaw] = &fillDescriptionFromParameter<std::vector<std::string>>;
0057 s_findTheRightFunction[edm::k_EventID] = &fillDescriptionFromParameter<edm::EventID>;
0058 s_findTheRightFunction[edm::k_VEventID] = &fillDescriptionFromParameter<std::vector<edm::EventID>>;
0059 s_findTheRightFunction[edm::k_LuminosityBlockID] = &fillDescriptionFromParameter<edm::LuminosityBlockID>;
0060 s_findTheRightFunction[edm::k_VLuminosityBlockID] =
0061 &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockID>>;
0062 s_findTheRightFunction[edm::k_InputTag] = &fillDescriptionFromParameter<edm::InputTag>;
0063 s_findTheRightFunction[edm::k_VInputTag] = &fillDescriptionFromParameter<std::vector<edm::InputTag>>;
0064 s_findTheRightFunction[edm::k_ESInputTag] = &fillDescriptionFromParameter<edm::ESInputTag>;
0065 s_findTheRightFunction[edm::k_VESInputTag] = &fillDescriptionFromParameter<std::vector<edm::ESInputTag>>;
0066 s_findTheRightFunction[edm::k_FileInPath] = &fillDescriptionFromParameter<edm::FileInPath>;
0067 s_findTheRightFunction[edm::k_LuminosityBlockRange] = &fillDescriptionFromParameter<edm::LuminosityBlockRange>;
0068 s_findTheRightFunction[edm::k_VLuminosityBlockRange] =
0069 &fillDescriptionFromParameter<std::vector<edm::LuminosityBlockRange>>;
0070 s_findTheRightFunction[edm::k_EventRange] = &fillDescriptionFromParameter<edm::EventRange>;
0071 s_findTheRightFunction[edm::k_VEventRange] = &fillDescriptionFromParameter<std::vector<edm::EventRange>>;
0072 }
0073
0074 std::map<edm::ParameterTypes, FillDescriptionFromParameter>& findTheRightFunction() {
0075 if (s_findTheRightFunction.empty())
0076 initMap();
0077 return s_findTheRightFunction;
0078 }
0079 }
0080
0081 namespace edm {
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 void fillDescriptionFromPSet(ParameterSet const& pset, ParameterSetDescription& desc) {
0097 ParameterSet::table const& entries = pset.tbl();
0098 for (ParameterSet::table::const_iterator entry = entries.begin(), endEntries = entries.end(); entry != endEntries;
0099 ++entry) {
0100 std::map<edm::ParameterTypes, FillDescriptionFromParameter>::iterator iter =
0101 findTheRightFunction().find(static_cast<edm::ParameterTypes>(entry->second.typeCode()));
0102 if (iter != findTheRightFunction().end()) {
0103 iter->second(pset, entry->first, entry->second.isTracked(), desc);
0104 }
0105 }
0106
0107 ParameterSet::psettable const& pset_entries = pset.psetTable();
0108 for (ParameterSet::psettable::const_iterator pset_entry = pset_entries.begin(), endEntries = pset_entries.end();
0109 pset_entry != endEntries;
0110 ++pset_entry) {
0111 edm::ParameterSet nestedPset;
0112 if (pset_entry->second.isTracked()) {
0113 nestedPset = pset.getParameterSet(pset_entry->first);
0114 } else {
0115 nestedPset = pset.getUntrackedParameterSet(pset_entry->first);
0116 }
0117 ParameterSetDescription nestedDescription;
0118 fillDescriptionFromPSet(nestedPset, nestedDescription);
0119 if (pset_entry->second.isTracked()) {
0120 desc.add<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
0121 } else {
0122 desc.addUntracked<edm::ParameterSetDescription>(pset_entry->first, nestedDescription);
0123 }
0124 }
0125
0126 ParameterSet::vpsettable const& vpset_entries = pset.vpsetTable();
0127 for (ParameterSet::vpsettable::const_iterator vpset_entry = vpset_entries.begin(), endEntries = vpset_entries.end();
0128 vpset_entry != endEntries;
0129 ++vpset_entry) {
0130 std::vector<edm::ParameterSet> nestedVPset;
0131 if (vpset_entry->second.isTracked()) {
0132 nestedVPset = pset.getParameterSetVector(vpset_entry->first);
0133 } else {
0134 nestedVPset = pset.getUntrackedParameterSetVector(vpset_entry->first);
0135 }
0136 ParameterSetDescription emptyDescription;
0137
0138 auto pd = std::make_unique<ParameterDescription<std::vector<ParameterSet>>>(
0139 vpset_entry->first, emptyDescription, vpset_entry->second.isTracked(), nestedVPset);
0140
0141 pd->setPartOfDefaultOfVPSet(true);
0142 std::unique_ptr<ParameterDescriptionNode> node(std::move(pd));
0143 desc.addNode(std::move(node));
0144 }
0145 }
0146 }