18 #include "boost/bind.hpp"
26 void matchLabel(std::pair<std::string, edm::ParameterSetDescription>
const& thePair,
29 if (thePair.first == moduleLabel) {
30 psetDesc = &thePair.second;
39 defaultDescDefined_(
false)
55 std::string labelString(label);
56 add(labelString, psetDescription);
64 if (label != std::string(
"source")) {
66 "ConfigurationDescriptions::add, when adding a ParameterSetDescription for a source the label must be \"source\"\n");
71 "ConfigurationDescriptions::add, for a source only 1 ParameterSetDescription may be added\n");
74 else if (
baseType_ == std::string(
"Service")) {
78 "ConfigurationDescriptions::add, for a service only 1 ParameterSetDescription may be added\n");
84 std::pair<std::string, ParameterSetDescription> pairWithEmptyDescription;
86 std::pair<std::string, ParameterSetDescription> & pair =
descriptions_.back();
89 pair.second = psetDescription;
92 std::string
name(
"appendToDataLabel");
93 if (pair.second.isLabelUnused(name)) {
94 pair.second.add<std::string>(
name, std::string(
""));
106 "ConfigurationDescriptions::addDefault, for a source or service only 1 ParameterSetDescription may be added\n");
114 std::string
name(
"appendToDataLabel");
128 boost::cref(moduleLabel),
129 boost::ref(psetDesc)));
149 std::string
const& pluginName)
const {
153 boost::cref(baseType),
154 boost::cref(pluginName)));
160 std::string
const& baseType,
161 std::string
const& pluginName)
163 if (baseType == std::string(
"Service") && labelAndDesc.first != pluginName) {
165 "ConfigurationDescriptions::writeCfiForLabel\nFor a service the label and the plugin name must be the same.\n")
166 <<
"This error probably is caused by an incorrect label being passed\nto the ConfigurationDescriptions::add function earlier.\n"
167 <<
"plugin name = \"" << pluginName <<
"\" label name = \"" << labelAndDesc.first <<
"\"\n";
170 std::string cfi_filename;
171 if (baseType == std::string(
"Source")) {
172 cfi_filename = pluginName +
"_cfi.py";
175 cfi_filename = labelAndDesc.first +
"_cfi.py";
177 std::ofstream outFile(cfi_filename.c_str());
180 outFile <<
"import FWCore.ParameterSet.Config as cms\n\n";
181 outFile << labelAndDesc.first <<
" = cms." << baseType <<
"('" << pluginName <<
"'";
183 bool startWithComma =
true;
185 labelAndDesc.second.writeCfi(outFile, startWithComma, indentation);
191 if (baseType == std::string(
"Source")) {
202 bool printOnlyLabels,
213 char oldFill = os.fill();
216 os << std::setfill(
' ') << std::setw(indentation) <<
"";
217 os <<
"There are no PSet descriptions defined for this plugin.\n";
218 os << std::setfill(
' ') << std::setw(indentation) <<
"";
219 os <<
"PSets will not be validated and no cfi files will be generated.\n";
220 if (!brief) os <<
"\n";
227 os << std::setfill(
' ') << std::setw(indentation) <<
"";
228 os <<
"This plugin has not implemented the function which defines its\n";
229 os << std::setfill(
' ') << std::setw(indentation) <<
"";
230 os <<
"configuration descriptions yet. No descriptions are available.\n";
231 os << std::setfill(
' ') << std::setw(indentation) <<
"";
232 os <<
"Its PSets will not be validated, and no cfi files will be generated.\n";
233 if (!brief) os <<
"\n";
239 std::stringstream ss;
242 ss <<
"This plugin has only one PSet description. "
243 <<
"This description is always used to validate configurations. "
244 <<
"Because this configuration has no label, no cfi files will be generated.";
247 ss <<
"This plugin has " << (
descriptions_.size() + 1U) <<
" PSet descriptions. "
248 <<
"The description used to validate a configuration is selected by "
249 <<
"matching the module labels. If none match, then the last description, "
250 <<
"which has no label, is selected. "
251 <<
"A cfi file will be generated for each configuration with a module label.";
256 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet description. "
257 <<
"This description is always used to validate configurations. "
258 <<
"The label below is used when generating the cfi file.";
261 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet descriptions. "
262 <<
"The description used to validate a configuration is selected by "
263 <<
"matching the module labels. If none match the first description below is used. "
264 <<
"The module labels below are also used when generating the cfi files.";
282 boost::cref(moduleLabel),
287 boost::ref(counter)));
291 std::string(
"@default"),
307 bool printOnlyLabels,
325 std::string
const&
label,
329 bool printOnlyLabels,
335 if (!moduleLabel.empty() && label !=
moduleLabel)
return;
338 std::stringstream ss;
340 std::string section = ss.str();
342 char oldFill = os.fill();
343 os << std::setfill(
' ') << std::setw(indentation) <<
"";
345 os << section <<
" ";
346 if (label == std::string(
"@default")) {
347 os <<
"description without a module label\n";
355 os <<
"module label: ";
362 if (!description.
comment().empty()) {
367 if (printOnlyLabels)
return;
376 description.
print(os, dfh);
void writeCfis(std::string const &baseType, std::string const &pluginName) const
~ConfigurationDescriptions()
void printForLabel(std::pair< std::string, ParameterSetDescription > const &labelAndDesc, std::ostream &os, std::string const &moduleLabel, bool brief, bool printOnlyLabels, size_t lineWidth, int indentationn, DescriptionCounter &counter) const
void validate(ParameterSet &pset) const
static void writeCfiForLabel(std::pair< std::string, ParameterSetDescription > const &labelAndDesc, std::string const &baseType, std::string const &pluginName)
ConfigurationDescriptions(std::string const &baseType)
Func for_all(ForwardSequence &s, Func f)
wrapper for std::for_each
void addDefault(ParameterSetDescription const &psetDescription)
std::vector< std::pair< std::string, ParameterSetDescription > > descriptions_
void print(std::ostream &os, DocFormatHelper &dfh) const
bool isLabelUnused(std::string const &label) const
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void print(std::ostream &os, std::string const &moduleLabel, bool brief, bool printOnlyLabels, size_t lineWidth, int indentation, int iPlugin) const
void validate(ParameterSet &pset, std::string const &moduleLabel) const
std::string const & comment() const
std::string const & comment() const
ParameterSetDescription defaultDesc_
const std::string * moduleLabel() const