Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:25

0001 
0002 #include "FWCore/ParameterSet/interface/AllowedLabelsDescriptionBase.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Utilities/interface/Algorithms.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0007 
0008 #include <iomanip>
0009 #include <ostream>
0010 
0011 namespace edm {
0012 
0013   AllowedLabelsDescriptionBase::~AllowedLabelsDescriptionBase() {}
0014 
0015   AllowedLabelsDescriptionBase::AllowedLabelsDescriptionBase(std::string const& label,
0016                                                              ParameterTypes iType,
0017                                                              bool isTracked)
0018       : parameterHoldingLabels_(label, std::vector<std::string>(), isTracked), type_(iType), isTracked_(isTracked) {}
0019 
0020   AllowedLabelsDescriptionBase::AllowedLabelsDescriptionBase(char const* label, ParameterTypes iType, bool isTracked)
0021       : parameterHoldingLabels_(label, std::vector<std::string>(), isTracked), type_(iType), isTracked_(isTracked) {}
0022 
0023   void AllowedLabelsDescriptionBase::checkAndGetLabelsAndTypes_(std::set<std::string>& usedLabels,
0024                                                                 std::set<ParameterTypes>& parameterTypes,
0025                                                                 std::set<ParameterTypes>& wildcardTypes) const {
0026     parameterHoldingLabels_.checkAndGetLabelsAndTypes(usedLabels, parameterTypes, wildcardTypes);
0027   }
0028 
0029   void AllowedLabelsDescriptionBase::validate_(ParameterSet& pset,
0030                                                std::set<std::string>& validatedLabels,
0031                                                bool optional) const {
0032     parameterHoldingLabels_.validate(pset, validatedLabels, optional);
0033     if (parameterHoldingLabels_.exists(pset)) {
0034       std::vector<std::string> allowedLabels;
0035       if (isTracked()) {
0036         allowedLabels = pset.getParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
0037       } else {
0038         allowedLabels = pset.getUntrackedParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
0039       }
0040       for_all(allowedLabels,
0041               std::bind(&AllowedLabelsDescriptionBase::validateAllowedLabel_,
0042                         this,
0043                         std::placeholders::_1,
0044                         std::ref(pset),
0045                         std::ref(validatedLabels)));
0046     }
0047   }
0048 
0049   void AllowedLabelsDescriptionBase::writeCfi_(
0050       std::ostream& os, bool optional, bool& startWithComma, int indentation, bool& wroteSomething) const {
0051     parameterHoldingLabels_.writeCfi(os, optional, startWithComma, indentation, wroteSomething);
0052   }
0053 
0054   void AllowedLabelsDescriptionBase::print_(std::ostream& os,
0055                                             bool optional,
0056                                             bool writeToCfi,
0057                                             DocFormatHelper& dfh) const {
0058     if (dfh.pass() == 1) {
0059       dfh.indent(os);
0060       os << parameterHoldingLabels_.label() << " (list of allowed labels)";
0061 
0062       if (dfh.brief()) {
0063         if (optional)
0064           os << " optional";
0065 
0066         if (!writeToCfi)
0067           os << " (do not write to cfi)";
0068 
0069         os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
0070       }
0071       // not brief
0072       else {
0073         os << "\n";
0074         dfh.indent2(os);
0075 
0076         if (optional)
0077           os << "optional";
0078         if (!writeToCfi)
0079           os << " (do not write to cfi)";
0080         if (optional || !writeToCfi) {
0081           os << "\n";
0082           dfh.indent2(os);
0083         }
0084 
0085         os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
0086 
0087         if (!comment().empty()) {
0088           DocFormatHelper::wrapAndPrintText(os, comment(), dfh.startColumn2(), dfh.commentWidth());
0089         }
0090         os << "\n";
0091       }
0092     }
0093   }
0094 
0095   bool AllowedLabelsDescriptionBase::hasNestedContent_() const { return true; }
0096 
0097   void AllowedLabelsDescriptionBase::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
0098     printNestedContentBase_(os, optional, dfh);
0099     if (!dfh.brief())
0100       os << "\n";
0101   }
0102 
0103   void AllowedLabelsDescriptionBase::printNestedContentBase_(std::ostream& os,
0104                                                              bool optional,
0105                                                              DocFormatHelper& dfh) const {
0106     int indentation = dfh.indentation();
0107     if (dfh.parent() != DocFormatHelper::TOP) {
0108       indentation -= DocFormatHelper::offsetSectionContent();
0109     }
0110 
0111     printSpaces(os, indentation);
0112     os << "Section " << dfh.section() << "." << dfh.counter() << " " << parameterHoldingLabels_.label()
0113        << " - allowed labels description\n";
0114     printSpaces(os, indentation);
0115     os << "The following parameter contains a list of parameter labels\n";
0116     printSpaces(os, indentation);
0117     os << "which are allowed to be in the PSet\n";
0118     if (!dfh.brief())
0119       os << "\n";
0120 
0121     DocFormatHelper new_dfh(dfh);
0122     new_dfh.init();
0123     new_dfh.setPass(1);
0124     parameterHoldingLabels_.print(os, optional, true, new_dfh);
0125     dfh.indent(os);
0126     os << "type of allowed parameters:";
0127     if (dfh.brief())
0128       os << " ";
0129     else {
0130       os << "\n";
0131       dfh.indent2(os);
0132     }
0133     if (!isTracked())
0134       os << "untracked ";
0135     os << parameterTypeEnumToString(type()) << "\n";
0136   }
0137 
0138   bool AllowedLabelsDescriptionBase::exists_(ParameterSet const& pset) const {
0139     return parameterHoldingLabels_.exists(pset);
0140   }
0141 
0142   bool AllowedLabelsDescriptionBase::partiallyExists_(ParameterSet const& pset) const { return exists(pset); }
0143 
0144   int AllowedLabelsDescriptionBase::howManyXORSubNodesExist_(ParameterSet const& pset) const {
0145     return exists(pset) ? 1 : 0;
0146   }
0147 }  // namespace edm