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";
44 : baseType_(baseType), pluginName_(pluginName), defaultDescDefined_(
false) {}
54 add(labelString, psetDescription);
59 if (0 != strcmp(label.c_str(),
k_source)) {
61 "ConfigurationDescriptions::add, when adding a ParameterSetDescription for a source the " 62 "label must be \"source\"\n");
67 "ConfigurationDescriptions::add, for a source only 1 ParameterSetDescription may be added\n");
73 "ConfigurationDescriptions::add, for a service only 1 ParameterSetDescription may be added\n");
79 std::pair<std::string, ParameterSetDescription> pairWithEmptyDescription;
81 std::pair<std::string, ParameterSetDescription>& pair =
descriptions_.back();
84 pair.second = psetDescription;
96 add(label, psetDescription);
103 "ConfigurationDescriptions::addDefault, for a source or service only 1 " 104 "ParameterSetDescription may be added\n");
125 for_all(
descriptions_, std::bind(&matchLabel, std::placeholders::_1, std::cref(moduleLabel), std::ref(psetDesc)));
128 if (psetDesc !=
nullptr) {
146 std::placeholders::_1,
149 std::ref(usedCfiFileNames)));
155 std::set<std::string>& usedCfiFileNames) {
156 if (0 == strcmp(baseType.c_str(),
kService) && labelAndDesc.first != pluginName) {
158 "ConfigurationDescriptions::writeCfiForLabel\nFor a service the label and the plugin name " 159 "must be the same.\n")
160 <<
"This error is probably caused by an incorrect label being passed\nto the ConfigurationDescriptions::add " 161 "function earlier.\n" 162 <<
"plugin name = \"" << pluginName <<
"\" label name = \"" << labelAndDesc.first <<
"\"\n";
166 if (0 == strcmp(baseType.c_str(),
kSource)) {
167 cfi_filename = pluginName +
"_cfi.py";
169 cfi_filename = labelAndDesc.first +
"_cfi.py";
171 if (!usedCfiFileNames.insert(cfi_filename).second) {
173 "Two cfi files are being generated with the same name in the same directory.\n");
174 ex <<
"The cfi file name is '" << cfi_filename <<
"' and\n" 175 <<
"the module label is \'" << labelAndDesc.first <<
"\'.\n" 176 <<
"This error is probably caused by an error in one or more fillDescriptions functions\n" 177 <<
"where duplicate module labels are being passed to the ConfigurationDescriptions::add\n" 178 <<
"function. All such module labels must be unique within a package.\n" 179 <<
"If you do not want the generated cfi file and do not need more than one\n" 180 <<
"description for a plugin, then a way to fix this is to use the addDefault\n" 181 <<
"function instead of the add function.\n" 182 <<
"There are 3 common ways this problem can happen.\n" 183 <<
"1. This can happen when a module label is explicitly duplicated in one or more\n" 184 <<
"fillDescriptions functions. Fix these by changing the module labels to be unique.\n" 185 <<
"2. This can also happen when a module class is a template class and plugins are\n" 186 <<
"defined by instantiations with differing template parameters and these plugins\n" 187 <<
"share the same fillDescriptions function. Fix these by specializing the fillDescriptions\n" 188 <<
"function for each template instantiation.\n" 189 <<
"3. This can also happen when there is an inheritance heirarchy and multiple plugin modules\n" 190 <<
"are defined using derived classes and the base class which share the same fillDescriptions\n" 191 <<
"function. Fix these by redefining the fillDescriptions function in each derived class.\n";
192 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
195 std::ofstream
outFile(cfi_filename.c_str());
198 ex <<
"Opening a file '" << cfi_filename <<
"' for module '" << labelAndDesc.first <<
"' failed.\n";
199 ex <<
"Error code from errno " << errno <<
": " << std::strerror(errno) <<
"\n";
201 ex.
addContext(
"Executing function ConfigurationDescriptions::writeCfiForLabel");
205 outFile <<
"import FWCore.ParameterSet.Config as cms\n\n";
206 outFile << labelAndDesc.first <<
" = cms." << baseType <<
"('" << pluginName <<
"'";
208 bool startWithComma =
true;
210 labelAndDesc.second.writeCfi(
outFile, startWithComma, indentation);
216 if (0 == strcmp(baseType.c_str(),
kSource)) {
226 bool printOnlyLabels,
238 char oldFill = os.fill();
240 os << std::setfill(
' ') << std::setw(indentation) <<
"";
241 os <<
"There are no PSet descriptions defined for this plugin.\n";
242 os << std::setfill(
' ') << std::setw(indentation) <<
"";
243 os <<
"PSets will not be validated and no cfi files will be generated.\n";
244 os << std::setfill(oldFill);
252 char oldFill = os.fill();
253 os << std::setfill(
' ') << std::setw(indentation) <<
"";
254 os <<
"This plugin has not implemented the function which defines its\n";
255 os << std::setfill(
' ') << std::setw(indentation) <<
"";
256 os <<
"configuration descriptions yet. No descriptions are available.\n";
257 os << std::setfill(
' ') << std::setw(indentation) <<
"";
258 os <<
"Its PSets will not be validated, and no cfi files will be generated.\n";
259 os << std::setfill(oldFill);
266 std::stringstream ss;
269 ss <<
"This plugin has only one PSet description. " 270 <<
"This description is always used to validate configurations. " 271 <<
"Because this configuration has no label, no cfi files will be generated.";
273 ss <<
"This plugin has " << (
descriptions_.size() + 1
U) <<
" PSet descriptions. " 274 <<
"The description used to validate a configuration is selected by " 275 <<
"matching the module labels. If none match, then the last description, " 276 <<
"which has no label, is selected. " 277 <<
"A cfi file will be generated for each configuration with a module label.";
281 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet description. " 282 <<
"This description is always used to validate configurations. " 283 <<
"The label below is used when generating the cfi file.";
285 ss <<
"This plugin has " <<
descriptions_.size() <<
" PSet descriptions. " 286 <<
"The description used to validate a configuration is selected by " 287 <<
"matching the module labels. If none match the first description below is used. " 288 <<
"The module labels below are also used when generating the cfi files.";
303 printForLabel(
d, os, moduleLabel, brief, printOnlyLabels, lineWidth, indentation, counter);
323 bool printOnlyLabels,
343 bool printOnlyLabels,
348 if (!moduleLabel.empty() && label != moduleLabel)
352 std::stringstream ss;
356 char oldFill = os.fill();
357 os << std::setfill(
' ') << std::setw(indentation) <<
"" << std::setfill(oldFill);
358 os << section <<
" ";
360 os <<
"description without a module label\n";
366 os <<
"module label: ";
373 if (!description.
comment().empty()) {
388 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