CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
edm::ParameterSwitch< T > Class Template Reference

#include <ParameterSwitch.h>

Inheritance diagram for edm::ParameterSwitch< T >:
edm::ParameterSwitchBase edm::ParameterDescriptionNode

Public Types

typedef std::map< T, edm::value_ptr< ParameterDescriptionNode > > CaseMap
 
typedef std::map< T, edm::value_ptr< ParameterDescriptionNode > >::const_iterator CaseMapConstIter
 

Public Member Functions

ParameterDescriptionNodeclone () const override
 
 ParameterSwitch (ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
 
- Public Member Functions inherited from edm::ParameterSwitchBase
 ~ParameterSwitchBase () override
 
- Public Member Functions inherited from edm::ParameterDescriptionNode
void checkAndGetLabelsAndTypes (std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
 
std::string const & comment () const
 
bool exists (ParameterSet const &pset) const
 
bool hasNestedContent () const
 
int howManyXORSubNodesExist (ParameterSet const &pset) const
 
 ParameterDescriptionNode ()
 
 ParameterDescriptionNode (Comment const &iComment)
 
bool partiallyExists (ParameterSet const &pset) const
 
void print (std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const
 
void printNestedContent (std::ostream &os, bool optional, DocFormatHelper &dfh) const
 
void setComment (std::string const &value)
 
void setComment (char const *value)
 
void validate (ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
 
void writeCfi (std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
 
virtual ~ParameterDescriptionNode ()
 

Private Member Functions

void checkAndGetLabelsAndTypes_ (std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const override
 
bool exists_ (ParameterSet const &pset) const override
 
void print_ (std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh) const override
 
void printNestedContent_ (std::ostream &os, bool optional, DocFormatHelper &dfh) const override
 
void validate_ (ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const override
 
void writeCfi_ (std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const override
 

Static Private Member Functions

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)
 

Private Attributes

CaseMap cases_
 
ParameterDescription< Tswitch_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::ParameterDescriptionNode
static void printSpaces (std::ostream &os, int n)
 
- Protected Member Functions inherited from edm::ParameterSwitchBase
bool hasNestedContent_ () const override
 
void insertAndCheckLabels (std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
 
void insertAndCheckTypes (ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
 
void printBase (std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
 
void printNestedContentBase (std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel) const
 
void throwDuplicateCaseValues (std::string const &switchLabel) const
 
void throwNoCaseForDefault (std::string const &switchLabel) const
 
void throwNoCaseForSwitchValue (std::string const &message) const
 
- Static Protected Member Functions inherited from edm::ParameterSwitchBase
template<typename T >
static void printCaseT (std::pair< T, edm::value_ptr< ParameterDescriptionNode > > const &p, std::ostream &os, bool optional, DocFormatHelper &dfh, std::string const &switchLabel)
 
- Protected Attributes inherited from edm::ParameterDescriptionNode
std::string comment_
 

Detailed Description

template<class T>
class edm::ParameterSwitch< T >

Definition at line 25 of file ParameterSwitch.h.

Member Typedef Documentation

template<class T >
typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> > edm::ParameterSwitch< T >::CaseMap

Definition at line 28 of file ParameterSwitch.h.

template<class T >
typedef std::map<T, edm::value_ptr<ParameterDescriptionNode> >::const_iterator edm::ParameterSwitch< T >::CaseMapConstIter

Definition at line 29 of file ParameterSwitch.h.

Constructor & Destructor Documentation

template<class T >
edm::ParameterSwitch< T >::ParameterSwitch ( ParameterDescription< T > const &  switchParameter,
std::unique_ptr< ParameterDescriptionCases< T > >  cases 
)
inline

Definition at line 31 of file ParameterSwitch.h.

References edm::ParameterDescriptionBase::label(), and edm::ParameterSwitchBase::throwDuplicateCaseValues().

Referenced by edm::ParameterSwitch< T >::clone().

32  :
33  switch_(switchParameter),
34  cases_(*cases->caseMap())
35  {
36  if (cases->duplicateCaseValues()) {
37  throwDuplicateCaseValues(switchParameter.label());
38  }
39  }
void throwDuplicateCaseValues(std::string const &switchLabel) const
ParameterDescription< T > switch_

Member Function Documentation

template<class T >
void edm::ParameterSwitch< T >::checkAndGetLabelsAndTypes_ ( std::set< std::string > &  usedLabels,
std::set< ParameterTypes > &  parameterTypes,
std::set< ParameterTypes > &  wildcardTypes 
) const
inlineoverrideprivatevirtual

Implements edm::ParameterDescriptionNode.

Definition at line 47 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::cases_, edm::ParameterSwitch< T >::checkCaseLabels(), edm::for_all(), edm::ParameterSwitchBase::insertAndCheckLabels(), edm::ParameterSwitchBase::insertAndCheckTypes(), edm::ParameterSwitch< T >::switch_, and edm::ParameterSwitchBase::throwNoCaseForDefault().

49  {
50 
51  std::set<std::string> caseLabels;
52  std::set<ParameterTypes> caseParameterTypes;
53  std::set<ParameterTypes> caseWildcardTypes;
55  std::placeholders::_1,
56  std::ref(caseLabels),
57  std::ref(caseParameterTypes),
58  std::ref(caseWildcardTypes)));
59 
61  usedLabels,
62  caseLabels);
63 
65  caseParameterTypes,
66  caseWildcardTypes,
67  parameterTypes,
68  wildcardTypes);
69 
70  if (cases_.find(switch_.getDefaultValue()) == cases_.end()) {
72  }
73  }
void insertAndCheckTypes(ParameterTypes switchType, std::set< ParameterTypes > const &caseParameterTypes, std::set< ParameterTypes > const &caseWildcardTypes, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
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)
void insertAndCheckLabels(std::string const &switchLabel, std::set< std::string > &usedLabels, std::set< std::string > &labels) const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
void throwNoCaseForDefault(std::string const &switchLabel) const
ParameterDescription< T > switch_
template<class T >
static void edm::ParameterSwitch< T >::checkCaseLabels ( std::pair< T, edm::value_ptr< ParameterDescriptionNode > > const &  thePair,
std::set< std::string > &  labels,
std::set< ParameterTypes > &  parameterTypes,
std::set< ParameterTypes > &  wildcardTypes 
)
inlinestaticprivate

Definition at line 173 of file ParameterSwitch.h.

Referenced by edm::ParameterSwitch< T >::checkAndGetLabelsAndTypes_().

176  {
177  thePair.second->checkAndGetLabelsAndTypes(labels, parameterTypes, wildcardTypes);
178  }
template<class T >
ParameterDescriptionNode* edm::ParameterSwitch< T >::clone ( void  ) const
inlineoverridevirtual

Implements edm::ParameterDescriptionNode.

Definition at line 41 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::ParameterSwitch().

41  {
42  return new ParameterSwitch(*this);
43  }
ParameterSwitch(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T > > cases)
template<class T >
bool edm::ParameterSwitch< T >::exists_ ( ParameterSet const &  pset) const
inlineoverrideprivatevirtual

Implements edm::ParameterDescriptionNode.

Definition at line 171 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::switch_.

171 { return switch_.exists(pset); }
ParameterDescription< T > switch_
template<class T >
void edm::ParameterSwitch< T >::print_ ( std::ostream &  os,
bool  optional,
bool  writeToCfi,
DocFormatHelper dfh 
) const
inlineoverrideprivatevirtual

Reimplemented from edm::ParameterDescriptionNode.

Definition at line 124 of file ParameterSwitch.h.

References edm::parameterTypeEnumToString(), edm::ParameterSwitchBase::printBase(), and edm::ParameterSwitch< T >::switch_.

127  {
128  printBase(os, optional, writeToCfi, dfh, switch_.label(), switch_.isTracked(), parameterTypeEnumToString(switch_.type()));
129  }
std::string parameterTypeEnumToString(ParameterTypes iType)
void printBase(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh, std::string const &switchLabel, bool isTracked, std::string const &typeString) const
ParameterDescription< T > switch_
template<class T >
void edm::ParameterSwitch< T >::printNestedContent_ ( std::ostream &  os,
bool  optional,
DocFormatHelper dfh 
) const
inlineoverrideprivatevirtual

Reimplemented from edm::ParameterDescriptionNode.

Definition at line 131 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::cases_, edm::for_all(), edm::DocFormatHelper::indent(), edm::ParameterSwitchBase::printNestedContentBase(), edm::DocFormatHelper::setCounter(), edm::DocFormatHelper::setPass(), and edm::ParameterSwitch< T >::switch_.

133  {
134 
135  DocFormatHelper new_dfh(dfh);
136  printNestedContentBase(os, dfh, new_dfh, switch_.label());
137 
138  switch_.print(os, optional, true, new_dfh);
139  for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>,
140  std::placeholders::_1,
141  std::ref(os),
142  optional,
143  std::ref(new_dfh),
144  std::cref(switch_.label())));
145 
146  new_dfh.setPass(1);
147  new_dfh.setCounter(0);
148 
149  new_dfh.indent(os);
150  os << "switch:\n";
151  switch_.print(os, optional, true, new_dfh);
152  for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>,
153  std::placeholders::_1,
154  std::ref(os),
155  optional,
156  std::ref(new_dfh),
157  std::cref(switch_.label())));
158 
159  new_dfh.setPass(2);
160  new_dfh.setCounter(0);
161 
162  switch_.printNestedContent(os, optional, new_dfh);
163  for_all(cases_, std::bind(&ParameterSwitchBase::printCaseT<T>,
164  std::placeholders::_1,
165  std::ref(os),
166  optional,
167  std::ref(new_dfh),
168  std::cref(switch_.label())));
169  }
void printNestedContentBase(std::ostream &os, DocFormatHelper &dfh, DocFormatHelper &new_dfh, std::string const &switchLabel) const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
ParameterDescription< T > switch_
template<class T >
void edm::ParameterSwitch< T >::validate_ ( ParameterSet pset,
std::set< std::string > &  validatedLabels,
bool  optional 
) const
inlineoverrideprivatevirtual

Implements edm::ParameterDescriptionNode.

Definition at line 75 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::cases_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), edm::ParameterSwitch< T >::switch_, and edm::ParameterSwitchBase::throwNoCaseForSwitchValue().

77  {
78 
79  switch_.validate(pset, validatedLabels, optional);
80  if (switch_.exists(pset)) {
81  T switchValue;
82  if (switch_.isTracked()) {
83  switchValue = pset.getParameter<T>(switch_.label());
84  }
85  else {
86  switchValue = pset.getUntrackedParameter<T>(switch_.label());
87  }
88  typename CaseMap::const_iterator selectedCase = cases_.find(switchValue);
89  if (selectedCase != cases_.end()) {
90  selectedCase->second->validate(pset, validatedLabels, false);
91  }
92  else {
93  std::stringstream ss;
94  ss << "The switch parameter with label \""
95  << switch_.label()
96  << "\" has been assigned an illegal value.\n"
97  << "The value from the configuration is \""
98  << switchValue
99  << "\".\n"
100  << "The allowed values are:\n";
101 
102  for (CaseMapConstIter iter = cases_.begin(), iEnd = cases_.end();
103  iter != iEnd;
104  ++iter) {
105  ss << " " << iter->first << "\n";
106  }
107  throwNoCaseForSwitchValue(ss.str());
108  }
109  }
110  }
std::map< T, edm::value_ptr< ParameterDescriptionNode > >::const_iterator CaseMapConstIter
void throwNoCaseForSwitchValue(std::string const &message) const
ParameterDescription< T > switch_
long double T
template<class T >
void edm::ParameterSwitch< T >::writeCfi_ ( std::ostream &  os,
bool &  startWithComma,
int  indentation,
bool &  wroteSomething 
) const
inlineoverrideprivatevirtual

Implements edm::ParameterDescriptionNode.

Definition at line 112 of file ParameterSwitch.h.

References edm::ParameterSwitch< T >::cases_, and edm::ParameterSwitch< T >::switch_.

115  {
116  switch_.writeCfi(os, startWithComma, indentation, wroteSomething);
117 
118  typename CaseMap::const_iterator selectedCase = cases_.find(switch_.getDefaultValue());
119  if (selectedCase != cases_.end()) {
120  selectedCase->second->writeCfi(os, startWithComma, indentation, wroteSomething);
121  }
122  }
ParameterDescription< T > switch_

Member Data Documentation

template<class T >
CaseMap edm::ParameterSwitch< T >::cases_
private
template<class T >
ParameterDescription<T> edm::ParameterSwitch< T >::switch_
private