25 void matchLabel(std::pair<std::string, edm::ParameterSetDescription>
const& thePair,
28 if (thePair.first == moduleLabel) {
29 psetDesc = &thePair.second;
34 static const char*
const kSource =
"Source";
42 defaultDescDefined_(
false)
59 add(labelString, psetDescription);
67 if (0!=strcmp(label.c_str(),
k_source)) {
69 "ConfigurationDescriptions::add, when adding a ParameterSetDescription for a source the label must be \"source\"\n");
74 "ConfigurationDescriptions::add, for a source only 1 ParameterSetDescription may be added\n");
81 "ConfigurationDescriptions::add, for a service only 1 ParameterSetDescription may be added\n");
87 std::pair<std::string, ParameterSetDescription> pairWithEmptyDescription;
89 std::pair<std::string, ParameterSetDescription> & pair =
descriptions_.back();
92 pair.second = psetDescription;
103 "ConfigurationDescriptions::addDefault, for a source or service only 1 ParameterSetDescription may be added\n");
133 std::placeholders::_1,
134 std::cref(moduleLabel),
135 std::ref(psetDesc)));
156 std::set<std::string>& usedCfiFileNames)
const {
159 std::placeholders::_1,
161 std::cref(pluginName),
162 std::ref(usedCfiFileNames)));
170 std::set<std::string>& usedCfiFileNames)
172 if (0 == strcmp(baseType.c_str(),
kService) && labelAndDesc.first != pluginName) {
174 "ConfigurationDescriptions::writeCfiForLabel\nFor a service the label and the plugin name must be the same.\n")
175 <<
"This error is probably caused by an incorrect label being passed\nto the ConfigurationDescriptions::add function earlier.\n" 176 <<
"plugin name = \"" << pluginName <<
"\" label name = \"" << labelAndDesc.first <<
"\"\n";
180 if (0 == strcmp(baseType.c_str(),
kSource)) {
181 cfi_filename = pluginName +
"_cfi.py";
184 cfi_filename = labelAndDesc.first +
"_cfi.py";
186 if (!usedCfiFileNames.insert(cfi_filename).second) {
188 "Two cfi files are being generated with the same name in the same directory.\n");
189 ex <<
"The cfi file name is '" << cfi_filename <<
"' and\n" 190 <<
"the module label is \'" << labelAndDesc.first <<
"\'.\n" 191 <<
"This error is probably caused by an error in one or more fillDescriptions functions\n" 192 <<
"where duplicate module labels are being passed to the ConfigurationDescriptions::add\n" 193 <<
"function. All such module labels must be unique within a package.\n" 194 <<
"If you do not want the generated cfi file and do not need more than one\n" 195 <<
"description for a plugin, then a way to fix this is to use the addDefault\n" 196 <<
"function instead of the add function.\n" 197 <<
"There are 3 common ways this problem can happen.\n" 198 <<
"1. This can happen when a module label is explicitly duplicated in one or more\n" 199 <<
"fillDescriptions functions. Fix these by changing the module labels to be unique.\n" 200 <<
"2. This can also happen when a module class is a template class and plugins are\n" 201 <<
"defined by instantiations with differing template parameters and these plugins\n" 202 <<
"share the same fillDescriptions function. Fix these by specializing the fillDescriptions\n" 203 <<
"function for each template instantiation.\n" 204 <<
"3. This can also happen when there is an inheritance heirarchy and multiple plugin modules\n" 205 <<
"are defined using derived classes and the base class which share the same fillDescriptions\n" 206 <<
"function. Fix these by redefining the fillDescriptions function in each derived class.\n";
207 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
210 std::ofstream
outFile(cfi_filename.c_str());
212 outFile <<
"import FWCore.ParameterSet.Config as cms\n\n";
213 outFile << labelAndDesc.first <<
" = cms." << baseType <<
"('" << pluginName <<
"'";
215 bool startWithComma =
true;
217 labelAndDesc.second.writeCfi(outFile, startWithComma, indentation);
223 if (0 == strcmp(baseType.c_str(),
kSource)) {
234 bool printOnlyLabels,
246 char oldFill = os.fill();
248 os << std::setfill(
' ') << std::setw(indentation) <<
"";
249 os <<
"There are no PSet descriptions defined for this plugin.\n";
250 os << std::setfill(
' ') << std::setw(indentation) <<
"";
251 os <<
"PSets will not be validated and no cfi files will be generated.\n";
252 os << std::setfill(oldFill);
253 if (!brief) os <<
"\n";
259 char oldFill = os.fill();
260 os << std::setfill(
' ') << std::setw(indentation) <<
"";
261 os <<
"This plugin has not implemented the function which defines its\n";
262 os << std::setfill(
' ') << std::setw(indentation) <<
"";
263 os <<
"configuration descriptions yet. No descriptions are available.\n";
264 os << std::setfill(
' ') << std::setw(indentation) <<
"";
265 os <<
"Its PSets will not be validated, and no cfi files will be generated.\n";
266 os << std::setfill(oldFill);
267 if (!brief) os <<
"\n";
272 std::stringstream ss;
275 ss <<
"This plugin has only one PSet description. " 276 <<
"This description is always used to validate configurations. " 277 <<
"Because this configuration has no label, no cfi files will be generated.";
280 ss <<
"This plugin has " << (
descriptions_.size() + 1
U) <<
" PSet descriptions. " 281 <<
"The description used to validate a configuration is selected by " 282 <<
"matching the module labels. If none match, then the last description, " 283 <<
"which has no label, is selected. " 284 <<
"A cfi file will be generated for each configuration with a module label.";
289 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet description. " 290 <<
"This description is always used to validate configurations. " 291 <<
"The label below is used when generating the cfi file.";
294 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet descriptions. " 295 <<
"The description used to validate a configuration is selected by " 296 <<
"matching the module labels. If none match the first description below is used. " 297 <<
"The module labels below are also used when generating the cfi files.";
312 printForLabel(
d,os, moduleLabel,brief, printOnlyLabels,lineWidth,indentation, counter);
333 bool printOnlyLabels,
355 bool printOnlyLabels,
361 if (!moduleLabel.empty() && label != moduleLabel)
return;
364 std::stringstream ss;
368 char oldFill = os.fill();
369 os << std::setfill(
' ') << std::setw(indentation) <<
"" << std::setfill(oldFill);
370 os << section <<
" ";
372 os <<
"description without a module label\n";
380 os <<
"module label: ";
387 if (!description.
comment().empty()) {
392 if (printOnlyLabels)
return;
401 description.
print(os, dfh);
static void writeCfiForLabel(std::pair< std::string, ParameterSetDescription > const &labelAndDesc, std::string const &baseType, std::string const &pluginName, std::set< std::string > &usedCfiFileNames)
~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
static const char *const kService
void validate(ParameterSet &pset) const
ParameterSetDescription * defaultDescription()
Returns 0 if no default has been assigned.
static const char *const kSource
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
void writeCfis(std::string const &baseType, std::string const &pluginName, std::set< std::string > &usedCfiFileNames) const
void setComment(std::string const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void addContext(std::string const &context)
static std::atomic< unsigned int > counter
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
static const char *const k_source
std::vector< std::pair< std::string, ParameterSetDescription > >::iterator iterator
ParameterSetDescription defaultDesc_