28 void matchLabel(std::pair<std::string, edm::ParameterSetDescription>
const& thePair,
31 if (thePair.first == moduleLabel) {
32 psetDesc = &thePair.second;
37 static const char*
const kSource =
"Source";
45 pluginName_(pluginName),
46 defaultDescDefined_(
false)
63 add(labelString, psetDescription);
71 if (0!=strcmp(label.c_str(),
k_source)) {
73 "ConfigurationDescriptions::add, when adding a ParameterSetDescription for a source the label must be \"source\"\n");
78 "ConfigurationDescriptions::add, for a source only 1 ParameterSetDescription may be added\n");
85 "ConfigurationDescriptions::add, for a service only 1 ParameterSetDescription may be added\n");
91 std::pair<std::string, ParameterSetDescription> pairWithEmptyDescription;
93 std::pair<std::string, ParameterSetDescription> & pair =
descriptions_.back();
96 pair.second = psetDescription;
112 add(label, psetDescription);
122 "ConfigurationDescriptions::addDefault, for a source or service only 1 ParameterSetDescription may be added\n");
152 std::placeholders::_1,
153 std::cref(moduleLabel),
154 std::ref(psetDesc)));
157 if (psetDesc !=
nullptr) {
176 std::placeholders::_1,
179 std::ref(usedCfiFileNames)));
187 std::set<std::string>& usedCfiFileNames)
189 if (0 == strcmp(baseType.c_str(),
kService) && labelAndDesc.first != pluginName) {
191 "ConfigurationDescriptions::writeCfiForLabel\nFor a service the label and the plugin name must be the same.\n")
192 <<
"This error is probably caused by an incorrect label being passed\nto the ConfigurationDescriptions::add function earlier.\n" 193 <<
"plugin name = \"" << pluginName <<
"\" label name = \"" << labelAndDesc.first <<
"\"\n";
197 if (0 == strcmp(baseType.c_str(),
kSource)) {
198 cfi_filename = pluginName +
"_cfi.py";
201 cfi_filename = labelAndDesc.first +
"_cfi.py";
203 if (!usedCfiFileNames.insert(cfi_filename).second) {
205 "Two cfi files are being generated with the same name in the same directory.\n");
206 ex <<
"The cfi file name is '" << cfi_filename <<
"' and\n" 207 <<
"the module label is \'" << labelAndDesc.first <<
"\'.\n" 208 <<
"This error is probably caused by an error in one or more fillDescriptions functions\n" 209 <<
"where duplicate module labels are being passed to the ConfigurationDescriptions::add\n" 210 <<
"function. All such module labels must be unique within a package.\n" 211 <<
"If you do not want the generated cfi file and do not need more than one\n" 212 <<
"description for a plugin, then a way to fix this is to use the addDefault\n" 213 <<
"function instead of the add function.\n" 214 <<
"There are 3 common ways this problem can happen.\n" 215 <<
"1. This can happen when a module label is explicitly duplicated in one or more\n" 216 <<
"fillDescriptions functions. Fix these by changing the module labels to be unique.\n" 217 <<
"2. This can also happen when a module class is a template class and plugins are\n" 218 <<
"defined by instantiations with differing template parameters and these plugins\n" 219 <<
"share the same fillDescriptions function. Fix these by specializing the fillDescriptions\n" 220 <<
"function for each template instantiation.\n" 221 <<
"3. This can also happen when there is an inheritance heirarchy and multiple plugin modules\n" 222 <<
"are defined using derived classes and the base class which share the same fillDescriptions\n" 223 <<
"function. Fix these by redefining the fillDescriptions function in each derived class.\n";
224 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
227 std::ofstream
outFile(cfi_filename.c_str());
230 "Creating cfi file failed.\n");
231 ex <<
"Opening a file '" << cfi_filename <<
"' for module '" << labelAndDesc.first <<
"' failed.\n";
232 ex <<
"Error code from errno " << errno <<
": " << std::strerror(errno) <<
"\n";
234 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
238 outFile <<
"import FWCore.ParameterSet.Config as cms\n\n";
239 outFile << labelAndDesc.first <<
" = cms." << baseType <<
"('" << pluginName <<
"'";
241 bool startWithComma =
true;
243 labelAndDesc.second.writeCfi(
outFile, startWithComma, indentation);
249 if (0 == strcmp(baseType.c_str(),
kSource)) {
260 bool printOnlyLabels,
272 char oldFill = os.fill();
274 os << std::setfill(
' ') << std::setw(indentation) <<
"";
275 os <<
"There are no PSet descriptions defined for this plugin.\n";
276 os << std::setfill(
' ') << std::setw(indentation) <<
"";
277 os <<
"PSets will not be validated and no cfi files will be generated.\n";
278 os << std::setfill(oldFill);
279 if (!brief) os <<
"\n";
285 char oldFill = os.fill();
286 os << std::setfill(
' ') << std::setw(indentation) <<
"";
287 os <<
"This plugin has not implemented the function which defines its\n";
288 os << std::setfill(
' ') << std::setw(indentation) <<
"";
289 os <<
"configuration descriptions yet. No descriptions are available.\n";
290 os << std::setfill(
' ') << std::setw(indentation) <<
"";
291 os <<
"Its PSets will not be validated, and no cfi files will be generated.\n";
292 os << std::setfill(oldFill);
293 if (!brief) os <<
"\n";
298 std::stringstream ss;
301 ss <<
"This plugin has only one PSet description. " 302 <<
"This description is always used to validate configurations. " 303 <<
"Because this configuration has no label, no cfi files will be generated.";
306 ss <<
"This plugin has " << (
descriptions_.size() + 1
U) <<
" PSet descriptions. " 307 <<
"The description used to validate a configuration is selected by " 308 <<
"matching the module labels. If none match, then the last description, " 309 <<
"which has no label, is selected. " 310 <<
"A cfi file will be generated for each configuration with a module label.";
315 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet description. " 316 <<
"This description is always used to validate configurations. " 317 <<
"The label below is used when generating the cfi file.";
320 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet descriptions. " 321 <<
"The description used to validate a configuration is selected by " 322 <<
"matching the module labels. If none match the first description below is used. " 323 <<
"The module labels below are also used when generating the cfi files.";
338 printForLabel(
d,os, moduleLabel,brief, printOnlyLabels,lineWidth,indentation, counter);
359 bool printOnlyLabels,
381 bool printOnlyLabels,
387 if (!moduleLabel.empty() && label != moduleLabel)
return;
390 std::stringstream ss;
394 char oldFill = os.fill();
395 os << std::setfill(
' ') << std::setw(indentation) <<
"" << std::setfill(oldFill);
396 os << section <<
" ";
398 os <<
"description without a module label\n";
406 os <<
"module label: ";
413 if (!description.
comment().empty()) {
418 if (printOnlyLabels)
return;
427 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