File indexing completed on 2023-03-17 11:03:29
0001 #include "FWCore/ParameterSet/interface/ParameterWildcardWithSpecifics.h"
0002
0003 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
0006 #include "FWCore/Utilities/interface/Algorithms.h"
0007
0008 #include <cassert>
0009 #include <iomanip>
0010 #include <ostream>
0011
0012 namespace edm {
0013
0014 ParameterWildcardWithSpecifics::ParameterWildcardWithSpecifics(
0015 std::string_view pattern,
0016 WildcardValidationCriteria criteria,
0017 bool isTracked,
0018 ParameterSetDescription const& desc,
0019 std::map<std::string, ParameterSetDescription> exceptions)
0020 : ParameterWildcardBase(k_PSet, isTracked, criteria), wildcardDesc_(desc), exceptions_(std::move(exceptions)) {
0021 throwIfInvalidPattern(std::string(pattern));
0022 }
0023
0024 ParameterDescriptionNode* ParameterWildcardWithSpecifics::clone() const {
0025 return new ParameterWildcardWithSpecifics(*this);
0026 }
0027
0028 void ParameterWildcardWithSpecifics::validate_(ParameterSet& pset,
0029 std::set<std::string>& validatedLabels,
0030 bool optional) const {
0031 std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
0032 validateMatchingNames(parameterNames, validatedLabels, optional);
0033
0034 for (auto const& name : parameterNames) {
0035 validateDescription(name, pset);
0036 }
0037
0038 for (auto const& v : exceptions_) {
0039 if (std::find(parameterNames.begin(), parameterNames.end(), v.first) == parameterNames.end()) {
0040 if (isTracked()) {
0041 pset.addParameter<edm::ParameterSet>(v.first, edm::ParameterSet());
0042 } else {
0043 pset.addUntrackedParameter<edm::ParameterSet>(v.first, edm::ParameterSet());
0044 }
0045 validatedLabels.insert(v.first);
0046 validateDescription(v.first, pset);
0047 }
0048 }
0049 }
0050
0051 void ParameterWildcardWithSpecifics::validateDescription(std::string const& parameterName, ParameterSet& pset) const {
0052 ParameterSet* containedPSet = pset.getPSetForUpdate(parameterName);
0053 auto itFound = exceptions_.find(parameterName);
0054 if (itFound != exceptions_.end()) {
0055 itFound->second.validate(*containedPSet);
0056 } else {
0057 wildcardDesc_.validate(*containedPSet);
0058 }
0059 }
0060
0061 bool ParameterWildcardWithSpecifics::hasNestedContent_() const { return true; }
0062
0063 void ParameterWildcardWithSpecifics::printNestedContent_(std::ostream& os,
0064 bool ,
0065 DocFormatHelper& dfh) const {
0066 int indentation = dfh.indentation();
0067 if (dfh.parent() != DocFormatHelper::TOP) {
0068 indentation -= DocFormatHelper::offsetSectionContent();
0069 }
0070
0071 printSpaces(os, indentation);
0072 os << "Section " << dfh.section() << "." << dfh.counter() << " description of PSet matching wildcard:";
0073 os << "\n";
0074 if (!dfh.brief())
0075 os << "\n";
0076
0077 std::stringstream ss;
0078 ss << dfh.section() << "." << dfh.counter();
0079 std::string newSection = ss.str();
0080
0081 DocFormatHelper new_dfh(dfh);
0082 new_dfh.setSection(newSection);
0083 new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0084 new_dfh.setParent(DocFormatHelper::OTHER);
0085
0086 wildcardDesc_.print(os, new_dfh);
0087
0088 }
0089
0090 bool ParameterWildcardWithSpecifics::exists_(ParameterSet const& pset) const {
0091 if (criteria() == RequireZeroOrMore)
0092 return true;
0093
0094 std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
0095
0096 if (criteria() == RequireAtLeastOne)
0097 return !parameterNames.empty();
0098 return parameterNames.size() == 1U;
0099 }
0100
0101 }