Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-03-26 01:51:13

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                                                Modifier modifier) const {
0032     parameterHoldingLabels_.validate(pset, validatedLabels, modifier);
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_(std::ostream& os,
0050                                                Modifier modifier,
0051                                                bool& startWithComma,
0052                                                int indentation,
0053                                                CfiOptions& options,
0054                                                bool& wroteSomething) const {
0055     parameterHoldingLabels_.writeCfi(os, modifier, startWithComma, indentation, options, wroteSomething);
0056   }
0057 
0058   void AllowedLabelsDescriptionBase::print_(std::ostream& os,
0059                                             Modifier modifier,
0060                                             bool writeToCfi,
0061                                             DocFormatHelper& dfh) const {
0062     if (dfh.pass() == 1) {
0063       dfh.indent(os);
0064       os << parameterHoldingLabels_.label() << " (list of allowed labels)";
0065 
0066       if (dfh.brief()) {
0067         if (modifier == Modifier::kOptional)
0068           os << " optional";
0069 
0070         if (modifier == Modifier::kObsolete)
0071           os << " obsolete";
0072 
0073         if (!writeToCfi)
0074           os << " (do not write to cfi)";
0075 
0076         os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
0077       }
0078       // not brief
0079       else {
0080         os << "\n";
0081         dfh.indent2(os);
0082 
0083         if (modifier == Modifier::kOptional)
0084           os << "optional";
0085         if (modifier == Modifier::kObsolete)
0086           os << "obsolete";
0087         if (!writeToCfi)
0088           os << " (do not write to cfi)";
0089         if (modifier == Modifier::kOptional || !writeToCfi) {
0090           os << "\n";
0091           dfh.indent2(os);
0092         }
0093 
0094         os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
0095 
0096         if (!comment().empty()) {
0097           DocFormatHelper::wrapAndPrintText(os, comment(), dfh.startColumn2(), dfh.commentWidth());
0098         }
0099         os << "\n";
0100       }
0101     }
0102   }
0103 
0104   bool AllowedLabelsDescriptionBase::hasNestedContent_() const { return true; }
0105 
0106   void AllowedLabelsDescriptionBase::printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
0107     printNestedContentBase_(os, optional, dfh);
0108     if (!dfh.brief())
0109       os << "\n";
0110   }
0111 
0112   void AllowedLabelsDescriptionBase::printNestedContentBase_(std::ostream& os,
0113                                                              bool optional,
0114                                                              DocFormatHelper& dfh) const {
0115     int indentation = dfh.indentation();
0116     if (dfh.parent() != DocFormatHelper::TOP) {
0117       indentation -= DocFormatHelper::offsetSectionContent();
0118     }
0119 
0120     printSpaces(os, indentation);
0121     os << "Section " << dfh.section() << "." << dfh.counter() << " " << parameterHoldingLabels_.label()
0122        << " - allowed labels description\n";
0123     printSpaces(os, indentation);
0124     os << "The following parameter contains a list of parameter labels\n";
0125     printSpaces(os, indentation);
0126     os << "which are allowed to be in the PSet\n";
0127     if (!dfh.brief())
0128       os << "\n";
0129 
0130     DocFormatHelper new_dfh(dfh);
0131     new_dfh.init();
0132     new_dfh.setPass(1);
0133     parameterHoldingLabels_.print(os, modifierIsOptional(optional), true, new_dfh);
0134     dfh.indent(os);
0135     os << "type of allowed parameters:";
0136     if (dfh.brief())
0137       os << " ";
0138     else {
0139       os << "\n";
0140       dfh.indent2(os);
0141     }
0142     if (!isTracked())
0143       os << "untracked ";
0144     os << parameterTypeEnumToString(type()) << "\n";
0145   }
0146 
0147   bool AllowedLabelsDescriptionBase::exists_(ParameterSet const& pset) const {
0148     return parameterHoldingLabels_.exists(pset);
0149   }
0150 
0151   bool AllowedLabelsDescriptionBase::partiallyExists_(ParameterSet const& pset) const { return exists(pset); }
0152 
0153   int AllowedLabelsDescriptionBase::howManyXORSubNodesExist_(ParameterSet const& pset) const {
0154     return exists(pset) ? 1 : 0;
0155   }
0156 }  // namespace edm