CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AllowedLabelsDescriptionBase.cc
Go to the documentation of this file.
1 
7 
8 #include "boost/bind.hpp"
9 
10 #include <iomanip>
11 #include <ostream>
12 
13 namespace edm {
14 
16 
18  AllowedLabelsDescriptionBase(std::string const& label, ParameterTypes iType, bool isTracked):
19  parameterHoldingLabels_(label, std::vector<std::string>(), isTracked),
20  type_(iType),
21  isTracked_(isTracked) {
22  }
23 
25  AllowedLabelsDescriptionBase(char const* label, ParameterTypes iType, bool isTracked):
26  parameterHoldingLabels_(label, std::vector<std::string>(), isTracked),
27  type_(iType),
28  isTracked_(isTracked) {
29  }
30 
31 
32  void
34  checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
35  std::set<ParameterTypes> & parameterTypes,
36  std::set<ParameterTypes> & wildcardTypes) const {
37 
38  parameterHoldingLabels_.checkAndGetLabelsAndTypes(usedLabels, parameterTypes, wildcardTypes);
39  }
40 
41  void
44  std::set<std::string> & validatedLabels,
45  bool optional) const {
46 
47  parameterHoldingLabels_.validate(pset, validatedLabels, optional);
48  if (parameterHoldingLabels_.exists(pset)) {
49  std::vector<std::string> allowedLabels;
50  if (isTracked()) {
51  allowedLabels = pset.getParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
52  }
53  else {
54  allowedLabels = pset.getUntrackedParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
55  }
57  boost::cref(this),
58  _1,
59  boost::ref(pset),
60  boost::ref(validatedLabels)));
61  }
62  }
63 
64  void
66  writeCfi_(std::ostream & os,
67  bool & startWithComma,
68  int indentation,
69  bool & wroteSomething) const {
70  parameterHoldingLabels_.writeCfi(os, startWithComma, indentation, wroteSomething);
71  }
72 
73  void
75  print_(std::ostream & os,
76  bool optional,
77  bool writeToCfi,
78  DocFormatHelper & dfh)
79  {
80  if (dfh.pass() == 1) {
81 
82  dfh.indent(os);
83  os << parameterHoldingLabels_.label() << " (list of allowed labels)";
84 
85  if (dfh.brief()) {
86 
87  if (optional) os << " optional";
88 
89  if (!writeToCfi) os << " (do not write to cfi)";
90 
91  os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
92  }
93  // not brief
94  else {
95 
96  os << "\n";
97  dfh.indent2(os);
98 
99  if (optional) os << "optional";
100  if (!writeToCfi) os << " (do not write to cfi)";
101  if (optional || !writeToCfi) {
102  os << "\n";
103  dfh.indent2(os);
104  }
105 
106  os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
107 
108  if (!comment().empty()) {
110  comment(),
111  dfh.startColumn2(),
112  dfh.commentWidth());
113  }
114  os << "\n";
115  }
116  }
117  }
118 
119  bool
122  return true;
123  }
124 
125 
126  void
128  printNestedContent_(std::ostream & os,
129  bool optional,
130  DocFormatHelper & dfh) {
131  printNestedContentBase_(os, optional, dfh);
132  if (!dfh.brief()) os << "\n";
133  }
134 
135  void
137  printNestedContentBase_(std::ostream & os,
138  bool optional,
139  DocFormatHelper & dfh) {
140 
141  int indentation = dfh.indentation();
142  if (dfh.parent() != DocFormatHelper::TOP) {
143  indentation -= DocFormatHelper::offsetSectionContent();
144  }
145 
146  printSpaces(os, indentation);
147  os << "Section " << dfh.section() << "." << dfh.counter()
148  << " " << parameterHoldingLabels_.label()
149  << " - allowed labels description\n";
150  printSpaces(os, indentation);
151  os << "The following parameter contains a list of parameter labels\n";
152  printSpaces(os, indentation);
153  os << "which are allowed to be in the PSet\n";
154  if (!dfh.brief()) os << "\n";
155 
156  DocFormatHelper new_dfh(dfh);
157  new_dfh.init();
158  new_dfh.setPass(1);
159  parameterHoldingLabels_.print(os, optional, true, new_dfh);
160  dfh.indent(os);
161  os << "type of allowed parameters:";
162  if (dfh.brief()) os << " ";
163  else {
164  os << "\n";
165  dfh.indent2(os);
166  }
167  if (!isTracked()) os << "untracked ";
168  os << parameterTypeEnumToString(type()) << "\n";
169  }
170 
171  bool
173  exists_(ParameterSet const& pset) const {
174  return parameterHoldingLabels_.exists(pset);
175  }
176 
177  bool
179  partiallyExists_(ParameterSet const& pset) const {
180  return exists(pset);
181  }
182 
183  int
186  return exists(pset) ? 1 : 0;
187  }
188 }
void printNestedContentBase_(std::ostream &os, bool optional, DocFormatHelper &dfh)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void validate(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
static void wrapAndPrintText(std::ostream &os, std::string const &text, size_t indent, size_t suggestedWidth)
virtual bool partiallyExists_(ParameterSet const &pset) const
int startColumn2() const
std::string parameterTypeEnumToString(ParameterTypes iType)
AllowedLabelsDescriptionBase(std::string const &label, ParameterTypes iType, bool isTracked)
DescriptionParent parent() const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
int indentation() const
virtual void checkAndGetLabelsAndTypes_(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
std::string const & comment() const
virtual void validateAllowedLabel_(std::string const &allowedLabel, ParameterSet &pset, std::set< std::string > &validatedLabels) const =0
static int offsetSectionContent()
void indent2(std::ostream &os) const
virtual bool exists_(ParameterSet const &pset) const
void setPass(int value)
static void printSpaces(std::ostream &os, int n)
bool exists(ParameterSet const &pset) const
void print(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
ParameterDescription< std::vector< std::string > > parameterHoldingLabels_
virtual void writeCfi_(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
void checkAndGetLabelsAndTypes(std::set< std::string > &usedLabels, std::set< ParameterTypes > &parameterTypes, std::set< ParameterTypes > &wildcardTypes) const
void indent(std::ostream &os) const
virtual void printNestedContent_(std::ostream &os, bool optional, DocFormatHelper &dfh)
void writeCfi(std::ostream &os, bool &startWithComma, int indentation, bool &wroteSomething) const
size_t commentWidth() const
virtual void print_(std::ostream &os, bool optional, bool writeToCfi, DocFormatHelper &dfh)
virtual int howManyXORSubNodesExist_(ParameterSet const &pset) const
std::string const & label() const
std::string const & section() const