/
githubmirror
/
cmssw
Обзор
Документация
Войти
/
githubmirror
/
cmssw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
FWCore/ParameterSet/interface/ParameterSwitch.h
195 строк
8 KB
Chris Jones
Added `trackiness` function to parameter description code
07 фев 2026, 00:26
07 фев 2026, 00:26
0583fb2
Код
Авторство
О чём код?
#ifndef FWCore_ParameterSet_ParameterSwitch_h #define FWCore_ParameterSet_ParameterSwitch_h #include "FWCore/ParameterSet/interface/ParameterSwitchBase.h" #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h" #include "FWCore/Utilities/interface/value_ptr.h" #include "FWCore/ParameterSet/interface/ParameterDescription.h" #include "FWCore/ParameterSet/interface/ParameterDescriptionCases.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/Algorithms.h" #include "FWCore/ParameterSet/interface/DocFormatHelper.h" #include <map> #include <memory> #include <set> #include <string> #include <utility> #include <sstream> #include <ostream> #include <iomanip> namespace edm { template <class T> class ParameterSwitch : public ParameterSwitchBase { public: typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > CaseMap; typedef typename std::map<T, edm::value_ptr<ParameterDescriptionNode> >::const_iterator CaseMapConstIter; ParameterSwitch(ParameterDescription<T> const& switchParameter, std::unique_ptr<ParameterDescriptionCases<T> > cases) : switch_(switchParameter), cases_(*cases->caseMap()) { if (cases->duplicateCaseValues()) { throwDuplicateCaseValues(switchParameter.label()); } } ParameterDescriptionNode* clone() const override { return new ParameterSwitch(*this); } private: void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels, std::set<ParameterTypes>& parameterTypes, std::set<ParameterTypes>& wildcardTypes) const override { std::set<std::string> caseLabels; std::set<ParameterTypes> caseParameterTypes; std::set<ParameterTypes> caseWildcardTypes; for_all(cases_, std::bind(&ParameterSwitch::checkCaseLabels, std::placeholders::_1, std::ref(caseLabels), std::ref(caseParameterTypes), std::ref(caseWildcardTypes))); insertAndCheckLabels(switch_.label(), usedLabels, caseLabels); insertAndCheckTypes(switch_.type(), caseParameterTypes, caseWildcardTypes, parameterTypes, wildcardTypes); if (cases_.find(switch_.getDefaultValue()) == cases_.end()) { throwNoCaseForDefault(switch_.label()); } } void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, Modifier modifier) const override { switch_.validate(pset, validatedLabels, modifier); if (switch_.exists(pset)) { T switchValue; if (switch_.isTracked()) { switchValue = pset.getParameter<T>(switch_.label()); } else { switchValue = pset.getUntrackedParameter<T>(switch_.label()); } typename CaseMap::const_iterator selectedCase = cases_.find(switchValue); if (selectedCase != cases_.end()) { selectedCase->second->validate(pset, validatedLabels, Modifier::kNone); } else { std::stringstream ss; ss << "The switch parameter with label \"" << switch_.label() << "\" has been assigned an illegal value.\n" << "The value from the configuration is \"" << switchValue << "\".\n" << "The allowed values are:\n"; for (CaseMapConstIter iter = cases_.begin(), iEnd = cases_.end(); iter != iEnd; ++iter) { ss << " " << iter->first << "\n"; } throwNoCaseForSwitchValue(ss.str()); } } } void writeCfi_(std::ostream& os, Modifier modifier, bool& startWithComma, int indentation, CfiOptions& options, bool& wroteSomething) const override { switch_.writeCfi(os, modifier, startWithComma, indentation, options, wroteSomething); if (std::holds_alternative<cfi::ClassFile>(options)) { std::set<std::string> labels; std::set<ParameterTypes> parameterTypes; std::set<ParameterTypes> wildcardTypes; for (auto const& n : cases_) { n.second->checkAndGetLabelsAndTypes(labels, parameterTypes, wildcardTypes); } for (auto const& l : labels) { cfi::parameterMustBeTyped(options, l); } } typename CaseMap::const_iterator selectedCase = cases_.find(switch_.getDefaultValue()); if (selectedCase != cases_.end()) { selectedCase->second->writeCfi(os, modifier, startWithComma, indentation, options, wroteSomething); } } void print_(std::ostream& os, Modifier modifier, bool writeToCfi, DocFormatHelper& dfh) const override { printBase(os, modifier, writeToCfi, dfh, switch_.label(), switch_.isTracked(), parameterTypeEnumToString(switch_.type())); } cfi::Trackiness trackiness_(std::string_view path) const override { cfi::Trackiness switchTrackiness = switch_.trackiness(path); if (switchTrackiness != cfi::Trackiness::kNotAllowed) { return switchTrackiness; } // If we reach here, the path is not for the switch parameter itself. // We need to check all cases to see if any of them match the path. for (auto const& casePair : cases_) { cfi::Trackiness caseTrackiness = casePair.second->trackiness(path); if (caseTrackiness != cfi::Trackiness::kNotAllowed) { return caseTrackiness; } } return cfi::Trackiness::kNotAllowed; } void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override { DocFormatHelper new_dfh(dfh); printNestedContentBase(os, dfh, new_dfh, switch_.label()); switch_.print(os, modifierIsOptional(optional), true, new_dfh); for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>, std::placeholders::_1, std::ref(os), optional, std::ref(new_dfh), std::cref(switch_.label()))); new_dfh.setPass(1); new_dfh.setCounter(0); new_dfh.indent(os); os << "switch:\n"; switch_.print(os, modifierIsOptional(optional), true, new_dfh); for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>, std::placeholders::_1, std::ref(os), optional, std::ref(new_dfh), std::cref(switch_.label()))); new_dfh.setPass(2); new_dfh.setCounter(0); switch_.printNestedContent(os, optional, new_dfh); for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>, std::placeholders::_1, std::ref(os), optional, std::ref(new_dfh), std::cref(switch_.label()))); } bool exists_(ParameterSet const& pset) const override { return switch_.exists(pset); } static void checkCaseLabels(std::pair<T, edm::value_ptr<ParameterDescriptionNode> > const& thePair, std::set<std::string>& labels, std::set<ParameterTypes>& parameterTypes, std::set<ParameterTypes>& wildcardTypes) { thePair.second->checkAndGetLabelsAndTypes(labels, parameterTypes, wildcardTypes); } ParameterDescription<T> switch_; CaseMap cases_; }; } // namespace edm #endif