26 void matchLabel(std::pair<std::string, edm::ParameterSetDescription>
const& thePair,
29 if (thePair.first == moduleLabel) {
30 psetDesc = &thePair.second;
35 static const char*
const kSource =
"Source";
43 pluginName_(pluginName),
44 defaultDescDefined_(
false)
61 add(labelString, psetDescription);
69 if (0!=strcmp(label.c_str(),
k_source)) {
71 "ConfigurationDescriptions::add, when adding a ParameterSetDescription for a source the label must be \"source\"\n");
76 "ConfigurationDescriptions::add, for a source only 1 ParameterSetDescription may be added\n");
83 "ConfigurationDescriptions::add, for a service only 1 ParameterSetDescription may be added\n");
89 std::pair<std::string, ParameterSetDescription> pairWithEmptyDescription;
91 std::pair<std::string, ParameterSetDescription> & pair =
descriptions_.back();
94 pair.second = psetDescription;
110 add(label, psetDescription);
120 "ConfigurationDescriptions::addDefault, for a source or service only 1 ParameterSetDescription may be added\n");
150 std::placeholders::_1,
151 std::cref(moduleLabel),
152 std::ref(psetDesc)));
155 if (psetDesc !=
nullptr) {
174 std::placeholders::_1,
177 std::ref(usedCfiFileNames)));
185 std::set<std::string>& usedCfiFileNames)
187 if (0 == strcmp(baseType.c_str(),
kService) && labelAndDesc.first != pluginName) {
189 "ConfigurationDescriptions::writeCfiForLabel\nFor a service the label and the plugin name must be the same.\n")
190 <<
"This error is probably caused by an incorrect label being passed\nto the ConfigurationDescriptions::add function earlier.\n" 191 <<
"plugin name = \"" << pluginName <<
"\" label name = \"" << labelAndDesc.first <<
"\"\n";
195 if (0 == strcmp(baseType.c_str(),
kSource)) {
196 cfi_filename = pluginName +
"_cfi.py";
199 cfi_filename = labelAndDesc.first +
"_cfi.py";
201 if (!usedCfiFileNames.insert(cfi_filename).second) {
203 "Two cfi files are being generated with the same name in the same directory.\n");
204 ex <<
"The cfi file name is '" << cfi_filename <<
"' and\n" 205 <<
"the module label is \'" << labelAndDesc.first <<
"\'.\n" 206 <<
"This error is probably caused by an error in one or more fillDescriptions functions\n" 207 <<
"where duplicate module labels are being passed to the ConfigurationDescriptions::add\n" 208 <<
"function. All such module labels must be unique within a package.\n" 209 <<
"If you do not want the generated cfi file and do not need more than one\n" 210 <<
"description for a plugin, then a way to fix this is to use the addDefault\n" 211 <<
"function instead of the add function.\n" 212 <<
"There are 3 common ways this problem can happen.\n" 213 <<
"1. This can happen when a module label is explicitly duplicated in one or more\n" 214 <<
"fillDescriptions functions. Fix these by changing the module labels to be unique.\n" 215 <<
"2. This can also happen when a module class is a template class and plugins are\n" 216 <<
"defined by instantiations with differing template parameters and these plugins\n" 217 <<
"share the same fillDescriptions function. Fix these by specializing the fillDescriptions\n" 218 <<
"function for each template instantiation.\n" 219 <<
"3. This can also happen when there is an inheritance heirarchy and multiple plugin modules\n" 220 <<
"are defined using derived classes and the base class which share the same fillDescriptions\n" 221 <<
"function. Fix these by redefining the fillDescriptions function in each derived class.\n";
222 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
225 std::ofstream
outFile(cfi_filename.c_str());
227 outFile <<
"import FWCore.ParameterSet.Config as cms\n\n";
228 outFile << labelAndDesc.first <<
" = cms." << baseType <<
"('" << pluginName <<
"'";
230 bool startWithComma =
true;
232 labelAndDesc.second.writeCfi(outFile, startWithComma, indentation);
238 if (0 == strcmp(baseType.c_str(),
kSource)) {
249 bool printOnlyLabels,
261 char oldFill = os.fill();
263 os << std::setfill(
' ') << std::setw(indentation) <<
"";
264 os <<
"There are no PSet descriptions defined for this plugin.\n";
265 os << std::setfill(
' ') << std::setw(indentation) <<
"";
266 os <<
"PSets will not be validated and no cfi files will be generated.\n";
267 os << std::setfill(oldFill);
268 if (!brief) os <<
"\n";
274 char oldFill = os.fill();
275 os << std::setfill(
' ') << std::setw(indentation) <<
"";
276 os <<
"This plugin has not implemented the function which defines its\n";
277 os << std::setfill(
' ') << std::setw(indentation) <<
"";
278 os <<
"configuration descriptions yet. No descriptions are available.\n";
279 os << std::setfill(
' ') << std::setw(indentation) <<
"";
280 os <<
"Its PSets will not be validated, and no cfi files will be generated.\n";
281 os << std::setfill(oldFill);
282 if (!brief) os <<
"\n";
287 std::stringstream ss;
290 ss <<
"This plugin has only one PSet description. " 291 <<
"This description is always used to validate configurations. " 292 <<
"Because this configuration has no label, no cfi files will be generated.";
295 ss <<
"This plugin has " << (
descriptions_.size() + 1
U) <<
" PSet descriptions. " 296 <<
"The description used to validate a configuration is selected by " 297 <<
"matching the module labels. If none match, then the last description, " 298 <<
"which has no label, is selected. " 299 <<
"A cfi file will be generated for each configuration with a module label.";
304 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet description. " 305 <<
"This description is always used to validate configurations. " 306 <<
"The label below is used when generating the cfi file.";
309 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet descriptions. " 310 <<
"The description used to validate a configuration is selected by " 311 <<
"matching the module labels. If none match the first description below is used. " 312 <<
"The module labels below are also used when generating the cfi files.";
327 printForLabel(
d,os, moduleLabel,brief, printOnlyLabels,lineWidth,indentation, counter);
348 bool printOnlyLabels,
370 bool printOnlyLabels,
376 if (!moduleLabel.empty() && label != moduleLabel)
return;
379 std::stringstream ss;
383 char oldFill = os.fill();
384 os << std::setfill(
' ') << std::setw(indentation) <<
"" << std::setfill(oldFill);
385 os << section <<
" ";
387 os <<
"description without a module label\n";
395 os <<
"module label: ";
402 if (!description.
comment().empty()) {
407 if (printOnlyLabels)
return;
416 description.
print(os, dfh);
ConfigurationDescriptions(std::string const &baseType, std::string const &pluginName)
static void writeCfiForLabel(std::pair< std::string, ParameterSetDescription > const &labelAndDesc, std::string const &baseType, std::string const &pluginName, std::set< std::string > &usedCfiFileNames)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
~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
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
std::string defaultModuleLabel(std::string label)
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_
void writeCfis(std::set< std::string > &usedCfiFileNames) const