CMS 3D CMS Logo

ParameterSwitch.h
Go to the documentation of this file.
1 #ifndef FWCore_ParameterSet_ParameterSwitch_h
2 #define FWCore_ParameterSet_ParameterSwitch_h
3 
12 
13 #include <map>
14 #include <memory>
15 #include <set>
16 #include <string>
17 #include <utility>
18 #include <sstream>
19 #include <ostream>
20 #include <iomanip>
21 
22 namespace edm {
23 
24  template <class T>
26  public:
27  typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > CaseMap;
28  typedef typename std::map<T, edm::value_ptr<ParameterDescriptionNode> >::const_iterator CaseMapConstIter;
29 
30  ParameterSwitch(ParameterDescription<T> const& switchParameter,
32  : switch_(switchParameter), cases_(*cases->caseMap()) {
33  if (cases->duplicateCaseValues()) {
34  throwDuplicateCaseValues(switchParameter.label());
35  }
36  }
37 
38  ParameterDescriptionNode* clone() const override { return new ParameterSwitch(*this); }
39 
40  private:
41  void checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
42  std::set<ParameterTypes>& parameterTypes,
43  std::set<ParameterTypes>& wildcardTypes) const override {
44  std::set<std::string> caseLabels;
45  std::set<ParameterTypes> caseParameterTypes;
46  std::set<ParameterTypes> caseWildcardTypes;
49  std::placeholders::_1,
50  std::ref(caseLabels),
51  std::ref(caseParameterTypes),
52  std::ref(caseWildcardTypes)));
53 
54  insertAndCheckLabels(switch_.label(), usedLabels, caseLabels);
55 
56  insertAndCheckTypes(switch_.type(), caseParameterTypes, caseWildcardTypes, parameterTypes, wildcardTypes);
57 
58  if (cases_.find(switch_.getDefaultValue()) == cases_.end()) {
60  }
61  }
62 
63  void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, bool optional) const override {
64  switch_.validate(pset, validatedLabels, optional);
65  if (switch_.exists(pset)) {
66  T switchValue;
67  if (switch_.isTracked()) {
68  switchValue = pset.getParameter<T>(switch_.label());
69  } else {
70  switchValue = pset.getUntrackedParameter<T>(switch_.label());
71  }
72  typename CaseMap::const_iterator selectedCase = cases_.find(switchValue);
73  if (selectedCase != cases_.end()) {
74  selectedCase->second->validate(pset, validatedLabels, false);
75  } else {
76  std::stringstream ss;
77  ss << "The switch parameter with label \"" << switch_.label() << "\" has been assigned an illegal value.\n"
78  << "The value from the configuration is \"" << switchValue << "\".\n"
79  << "The allowed values are:\n";
80 
81  for (CaseMapConstIter iter = cases_.begin(), iEnd = cases_.end(); iter != iEnd; ++iter) {
82  ss << " " << iter->first << "\n";
83  }
85  }
86  }
87  }
88 
89  void writeCfi_(
90  std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const override {
91  switch_.writeCfi(os, optional, startWithComma, indentation, wroteSomething);
92 
93  typename CaseMap::const_iterator selectedCase = cases_.find(switch_.getDefaultValue());
94  if (selectedCase != cases_.end()) {
95  selectedCase->second->writeCfi(os, optional, startWithComma, indentation, wroteSomething);
96  }
97  }
98 
99  void print_(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const override {
100  printBase(os,
101  optional,
102  writeToCfi,
103  dfh,
104  switch_.label(),
105  switch_.isTracked(),
107  }
108 
109  void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override {
110  DocFormatHelper new_dfh(dfh);
111  printNestedContentBase(os, dfh, new_dfh, switch_.label());
112 
113  switch_.print(os, optional, true, new_dfh);
114  for_all(cases_,
115  std::bind(&ParameterSwitchBase::printCaseT<T>,
116  std::placeholders::_1,
117  std::ref(os),
118  optional,
119  std::ref(new_dfh),
120  std::cref(switch_.label())));
121 
122  new_dfh.setPass(1);
123  new_dfh.setCounter(0);
124 
125  new_dfh.indent(os);
126  os << "switch:\n";
127  switch_.print(os, optional, true, new_dfh);
128  for_all(cases_,
129  std::bind(&ParameterSwitchBase::printCaseT<T>,
130  std::placeholders::_1,
131  std::ref(os),
132  optional,
133  std::ref(new_dfh),
134  std::cref(switch_.label())));
135 
136  new_dfh.setPass(2);
137  new_dfh.setCounter(0);
138 
139  switch_.printNestedContent(os, optional, new_dfh);
140  for_all(cases_,
141  std::bind(&ParameterSwitchBase::printCaseT<T>,
142  std::placeholders::_1,
143  std::ref(os),
144  optional,
145  std::ref(new_dfh),
146  std::cref(switch_.label())));
147  }
148 
149  bool exists_(ParameterSet const& pset) const override { return switch_.exists(pset); }
150 
151  static void checkCaseLabels(std::pair<T, edm::value_ptr<ParameterDescriptionNode> > const& thePair,
152  std::set<std::string>& labels,
153  std::set<ParameterTypes>& parameterTypes,
154  std::set<ParameterTypes>& wildcardTypes) {
155  thePair.second->checkAndGetLabelsAndTypes(labels, parameterTypes, wildcardTypes);
156  }
157 
160  };
161 } // namespace edm
162 #endif
edm::ParameterSwitchBase::throwNoCaseForSwitchValue
void throwNoCaseForSwitchValue(std::string const &message) const
Definition: ParameterSwitchBase.cc:57
SummaryClient_cfi.labels
labels
Definition: SummaryClient_cfi.py:61
edm::ParameterSwitch::CaseMap
std::map< T, edm::value_ptr< ParameterDescriptionNode > > CaseMap
Definition: ParameterSwitch.h:27
edm::DocFormatHelper::setCounter
void setCounter(int value)
Definition: DocFormatHelper.h:67
edm::ParameterSwitch::CaseMapConstIter
std::map< T, edm::value_ptr< ParameterDescriptionNode > >::const_iterator CaseMapConstIter
Definition: ParameterSwitch.h:28
edm::ParameterSwitch::cases_
CaseMap cases_
Definition: ParameterSwitch.h:159
edm::ParameterDescriptionBase::label
std::string const & label() const
Definition: ParameterDescriptionBase.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSwitch::switch_
ParameterDescription< T > switch_
Definition: ParameterSwitch.h:158
Types.optional
optional
Definition: Types.py:167
Algorithms.h
edm::ParameterSwitch::checkAndGetLabelsAndTypes_
void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
Definition: ParameterSwitch.h:41
edm::parameterTypeEnumToString
std::string parameterTypeEnumToString(ParameterTypes iType)
Definition: ParameterDescriptionNode.cc:64
edm::ParameterSwitch::printNestedContent_
void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh) const override
Definition: ParameterSwitch.h:109
edm::ParameterSwitch::clone
ParameterDescriptionNode * clone() const override
Definition: ParameterSwitch.h:38
edm::for_all
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:14
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::DocFormatHelper
Definition: DocFormatHelper.h:15
edm::ParameterSwitch::exists_
bool exists_(ParameterSet const &pset) const override
Definition: ParameterSwitch.h:149
edm::ParameterDescriptionCases
Definition: ParameterDescriptionCases.h:35
ParameterDescriptionNode.h
edm::ParameterSwitch::ParameterSwitch
ParameterSwitch(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
Definition: ParameterSwitch.h:30
edm::ParameterSwitchBase::printNestedContentBase
void printNestedContentBase(std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:138
edm::ParameterSwitch::print_
void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
Definition: ParameterSwitch.h:99
value_ptr.h
edm::ParameterSwitchBase::insertAndCheckLabels
void insertAndCheckLabels(std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
Definition: ParameterSwitchBase.cc:21
edm::ParameterSet
Definition: ParameterSet.h:36
edm::value_ptr
Definition: value_ptr.h:63
edm::ParameterSwitchBase::throwDuplicateCaseValues
void throwDuplicateCaseValues(std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:15
edm::ParameterSwitch::checkCaseLabels
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)
Definition: ParameterSwitch.h:151
edm::ParameterSwitchBase::insertAndCheckTypes
void insertAndCheckTypes(ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
Definition: ParameterSwitchBase.cc:34
edm::ParameterSwitch::writeCfi_
void writeCfi_(std::ostream &os, bool optional, bool &startWithComma, int indentation, bool &wroteSomething) const override
Definition: ParameterSwitch.h:89
edm::ParameterSwitchBase::printBase
void printBase(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
Definition: ParameterSwitchBase.cc:61
edm::DocFormatHelper::indent
void indent(std::ostream &os) const
Definition: DocFormatHelper.cc:133
edm::ParameterSwitch
Definition: ParameterSwitch.h:25
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
edm::ParameterSwitchBase
Definition: ParameterSwitchBase.h:16
ParameterSwitchBase.h
DocFormatHelper.h
T
long double T
Definition: Basic3DVectorLD.h:48
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
edm::DocFormatHelper::setPass
void setPass(int value)
Definition: DocFormatHelper.h:47
edm::ParameterSwitchBase::throwNoCaseForDefault
void throwNoCaseForDefault(std::string const &switchLabel) const
Definition: ParameterSwitchBase.cc:50
ParameterDescription.h
ParameterSet.h
ParameterDescriptionCases.h
edm::ParameterDescriptionNode
Definition: ParameterDescriptionNode.h:82
edm::ParameterDescription
Definition: ParameterDescription.h:110
edm::ParameterSwitch::validate_
void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
Definition: ParameterSwitch.h:63
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27