CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ParameterWildcard.cc
Go to the documentation of this file.
2 
7 
8 #include <cassert>
9 #include <iomanip>
10 #include <ostream>
11 
12 namespace edm {
13 
16  ParameterWildcardBase(k_PSet, isTracked, criteria),
17  psetDesc_() {
18  throwIfInvalidPattern(pattern);
19  }
20 
22  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
23  ParameterWildcardBase(k_PSet, isTracked, criteria),
24  psetDesc_() {
25  throwIfInvalidPattern(pattern);
26  }
27 
30  ParameterWildcardBase(k_PSet, isTracked, criteria),
31  psetDesc_(new ParameterSetDescription(desc)) {
32  throwIfInvalidPattern(pattern);
33  }
34 
35 
37  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
38  ParameterWildcardBase(k_PSet, isTracked, criteria),
39  psetDesc_(new ParameterSetDescription(desc)) {
40  throwIfInvalidPattern(pattern);
41  }
42 
43 
46 
49  clone() const {
50  return new ParameterWildcard(*this);
51  }
52 
53  void
56  std::set<std::string>& validatedLabels,
57  bool optional) const {
58 
59  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
60  validateMatchingNames(parameterNames, validatedLabels, optional);
61 
62  if(psetDesc_) {
63  for_all(parameterNames,
65  this,
66  std::placeholders::_1,
67  std::ref(pset)));
68  }
69  }
70 
71  void
73  validateDescription(std::string const& parameterName,
74  ParameterSet& pset) const {
75  ParameterSet* containedPSet = pset.getPSetForUpdate(parameterName);
76  psetDesc_->validate(*containedPSet);
77  }
78 
79  bool
82  if(psetDesc_) return true;
83  return false;
84  }
85 
86  void
88  printNestedContent_(std::ostream& os,
89  bool /*optional*/,
90  DocFormatHelper& dfh) {
91 
92  int indentation = dfh.indentation();
93  if(dfh.parent() != DocFormatHelper::TOP) {
95  }
96 
97  printSpaces(os, indentation);
98  os << "Section " << dfh.section() << "." << dfh.counter()
99  << " description of PSet matching wildcard:";
100  os << "\n";
101  if(!dfh.brief()) os << "\n";
102 
103  std::stringstream ss;
104  ss << dfh.section() << "." << dfh.counter();
105  std::string newSection = ss.str();
106 
107  DocFormatHelper new_dfh(dfh);
108  new_dfh.setSection(newSection);
109  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
111 
112  psetDesc_->print(os, new_dfh);
113  }
114 
115  bool
117  exists_(ParameterSet const& pset) const {
118 
119  if(criteria() == RequireZeroOrMore) return true;
120 
121  std::vector<std::string> parameterNames = pset.getParameterNamesForType<ParameterSet>(isTracked());
122 
123  if(criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
124  return parameterNames.size() == 1U;
125  }
126 
127 // -------------------------------------------------------------------------
128 
131  ParameterWildcardBase(k_VPSet, isTracked, criteria),
132  psetDesc_() {
133  throwIfInvalidPattern(pattern);
134  }
135 
137  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
138  ParameterWildcardBase(k_VPSet, isTracked, criteria),
139  psetDesc_() {
140  throwIfInvalidPattern(pattern);
141  }
142 
145  ParameterSetDescription const& desc) :
146  ParameterWildcardBase(k_VPSet, isTracked, criteria),
147  psetDesc_(new ParameterSetDescription(desc)) {
148  throwIfInvalidPattern(pattern);
149  }
150 
151 
153  ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
154  ParameterSetDescription const& desc) :
155  ParameterWildcardBase(k_VPSet, isTracked, criteria),
156  psetDesc_(new ParameterSetDescription(desc)) {
157  throwIfInvalidPattern(pattern);
158  }
159 
160 
162  ~ParameterWildcard() { }
163 
166  clone() const {
167  return new ParameterWildcard(*this);
168  }
169 
170  void
172  validate_(ParameterSet& pset,
173  std::set<std::string>& validatedLabels,
174  bool optional) const {
175 
176  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
177  validateMatchingNames(parameterNames, validatedLabels, optional);
178 
179  if(psetDesc_) {
180  for_all(parameterNames,
181  std::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
182  this,
183  std::placeholders::_1,
184  std::ref(pset)));
185  }
186  }
187 
188  void
190  validatePSetVector(std::string const& parameterName, ParameterSet& pset) const {
191  VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
192  assert(vpsetEntry);
193  for(unsigned i = 0; i < vpsetEntry->size(); ++i) {
194  psetDesc_->validate(vpsetEntry->psetInVector(i));
195  }
196  }
197 
198  bool
200  hasNestedContent_() {
201  if(psetDesc_) return true;
202  return false;
203  }
204 
205  void
207  printNestedContent_(std::ostream& os,
208  bool /*optional*/,
209  DocFormatHelper& dfh) {
210 
211  int indentation = dfh.indentation();
212  if(dfh.parent() != DocFormatHelper::TOP) {
213  indentation -= DocFormatHelper::offsetSectionContent();
214  }
215 
216  printSpaces(os, indentation);
217  os << "Section " << dfh.section() << "." << dfh.counter()
218  << " description used to validate all PSets which are in the VPSet matching the wildcard:";
219  os << "\n";
220  if(!dfh.brief()) os << "\n";
221 
222  std::stringstream ss;
223  ss << dfh.section() << "." << dfh.counter();
224  std::string newSection = ss.str();
225 
226  DocFormatHelper new_dfh(dfh);
227  new_dfh.setSection(newSection);
228  new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
230 
231  psetDesc_->print(os, new_dfh);
232  }
233 
234  bool
236  exists_(ParameterSet const& pset) const {
237 
238  if(criteria() == RequireZeroOrMore) return true;
239 
240  std::vector<std::string> parameterNames = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
241 
242  if(criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
243  return parameterNames.size() == 1U;
244  }
245 }
WildcardValidationCriteria
virtual bool exists_(ParameterSet const &pset) const
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
virtual void validate_(ParameterSet &pset, std::set< std::string > &validatedLabels, bool optional) const
virtual void printNestedContent_(std::ostream &, bool, DocFormatHelper &)
virtual ParameterDescriptionNode * clone() const
DescriptionParent parent() const
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
Definition: Algorithms.h:16
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
int indentation() const
VParameterSetEntry * getPSetVectorForUpdate(std::string const &name)
static int offsetSectionContent()
static void printSpaces(std::ostream &os, int n)
WildcardValidationCriteria criteria() const
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void throwIfInvalidPattern(char const *pattern) const
std::vector< ParameterSet >::size_type size() const
ParameterWildcard(std::string const &pattern, WildcardValidationCriteria criteria, bool isTracked)
ParameterSet & psetInVector(int i)
void validateMatchingNames(std::vector< std::string > const &matchingNames, std::set< std::string > &validatedLabels, bool optional) const
void setSection(std::string const &value)
void setParent(DescriptionParent value)
void setIndentation(int value)
ParameterSet * getPSetForUpdate(std::string const &name, bool &isTracked)
std::string const & section() const