Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:47:43

0001 
0002 #include "FWCore/ParameterSet/interface/AllowedLabelsDescription.h"
0003 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0005 
0006 #include <cassert>
0007 
0008 namespace edm {
0009 
0010   AllowedLabelsDescription<ParameterSetDescription>::AllowedLabelsDescription(std::string const& label, bool isTracked)
0011       : AllowedLabelsDescriptionBase(label, k_PSet, isTracked), psetDesc_() {}
0012 
0013   AllowedLabelsDescription<ParameterSetDescription>::AllowedLabelsDescription(char const* label, bool isTracked)
0014       : AllowedLabelsDescriptionBase(label, k_PSet, isTracked), psetDesc_() {}
0015 
0016   AllowedLabelsDescription<ParameterSetDescription>::AllowedLabelsDescription(std::string const& label,
0017                                                                               ParameterSetDescription const& value,
0018                                                                               bool isTracked)
0019       : AllowedLabelsDescriptionBase(label, k_PSet, isTracked), psetDesc_(new ParameterSetDescription(value)) {}
0020 
0021   AllowedLabelsDescription<ParameterSetDescription>::AllowedLabelsDescription(char const* label,
0022                                                                               ParameterSetDescription const& value,
0023                                                                               bool isTracked)
0024       : AllowedLabelsDescriptionBase(label, k_PSet, isTracked), psetDesc_(new ParameterSetDescription(value)) {}
0025 
0026   AllowedLabelsDescription<ParameterSetDescription>::~AllowedLabelsDescription() {}
0027 
0028   ParameterDescriptionNode* AllowedLabelsDescription<ParameterSetDescription>::clone() const {
0029     return new AllowedLabelsDescription(*this);
0030   }
0031 
0032   void AllowedLabelsDescription<ParameterSetDescription>::printNestedContent_(std::ostream& os,
0033                                                                               bool optional,
0034                                                                               DocFormatHelper& dfh) const {
0035     printNestedContentBase_(os, optional, dfh);
0036 
0037     int indentation = dfh.indentation();
0038     if (dfh.parent() != DocFormatHelper::TOP) {
0039       indentation -= DocFormatHelper::offsetSectionContent();
0040     }
0041 
0042     std::stringstream ss;
0043     ss << dfh.section() << "." << dfh.counter() << ".1";
0044     std::string newSection = ss.str();
0045 
0046     if (dfh.brief()) {
0047       printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
0048     } else {
0049       dfh.indent2(os);
0050     }
0051     os << "see Section " << newSection << "\n";
0052     if (!dfh.brief())
0053       os << "\n";
0054 
0055     printSpaces(os, indentation);
0056     os << "Section " << newSection << " PSet description:\n";
0057     if (!dfh.brief())
0058       os << "\n";
0059 
0060     DocFormatHelper new_dfh(dfh);
0061     new_dfh.setSection(newSection);
0062     new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0063     new_dfh.setParent(DocFormatHelper::OTHER);
0064 
0065     psetDesc_->print(os, new_dfh);
0066   }
0067 
0068   void AllowedLabelsDescription<ParameterSetDescription>::validateAllowedLabel_(
0069       std::string const& allowedLabel, ParameterSet& pset, std::set<std::string>& validatedLabels) const {
0070     if (pset.existsAs<ParameterSet>(allowedLabel, isTracked())) {
0071       validatedLabels.insert(allowedLabel);
0072       if (psetDesc_) {
0073         ParameterSet* containedPSet = pset.getPSetForUpdate(allowedLabel);
0074         psetDesc_->validate(*containedPSet);
0075       }
0076     }
0077   }
0078 
0079   // -----------------------------------------------------------------------
0080 
0081   AllowedLabelsDescription<std::vector<ParameterSet> >::AllowedLabelsDescription(std::string const& label,
0082                                                                                  bool isTracked)
0083       : AllowedLabelsDescriptionBase(label, k_VPSet, isTracked), psetDesc_() {}
0084 
0085   AllowedLabelsDescription<std::vector<ParameterSet> >::AllowedLabelsDescription(char const* label, bool isTracked)
0086       : AllowedLabelsDescriptionBase(label, k_VPSet, isTracked), psetDesc_() {}
0087 
0088   AllowedLabelsDescription<std::vector<ParameterSet> >::AllowedLabelsDescription(std::string const& label,
0089                                                                                  ParameterSetDescription const& value,
0090                                                                                  bool isTracked)
0091       : AllowedLabelsDescriptionBase(label, k_VPSet, isTracked), psetDesc_(new ParameterSetDescription(value)) {}
0092 
0093   AllowedLabelsDescription<std::vector<ParameterSet> >::AllowedLabelsDescription(char const* label,
0094                                                                                  ParameterSetDescription const& value,
0095                                                                                  bool isTracked)
0096       : AllowedLabelsDescriptionBase(label, k_VPSet, isTracked), psetDesc_(new ParameterSetDescription(value)) {}
0097 
0098   AllowedLabelsDescription<std::vector<ParameterSet> >::~AllowedLabelsDescription() {}
0099 
0100   ParameterDescriptionNode* AllowedLabelsDescription<std::vector<ParameterSet> >::clone() const {
0101     return new AllowedLabelsDescription(*this);
0102   }
0103 
0104   void AllowedLabelsDescription<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
0105                                                                                  bool optional,
0106                                                                                  DocFormatHelper& dfh) const {
0107     printNestedContentBase_(os, optional, dfh);
0108 
0109     int indentation = dfh.indentation();
0110     if (dfh.parent() != DocFormatHelper::TOP) {
0111       indentation -= DocFormatHelper::offsetSectionContent();
0112     }
0113 
0114     std::stringstream ss;
0115     ss << dfh.section() << "." << dfh.counter() << ".1";
0116     std::string newSection = ss.str();
0117 
0118     if (dfh.brief()) {
0119       printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
0120     } else {
0121       dfh.indent2(os);
0122     }
0123     os << "see Section " << newSection << "\n";
0124     if (!dfh.brief())
0125       os << "\n";
0126 
0127     printSpaces(os, indentation);
0128     os << "Section " << newSection << " PSet description used to validate all elements of VPSet's:\n";
0129     if (!dfh.brief())
0130       os << "\n";
0131 
0132     DocFormatHelper new_dfh(dfh);
0133     new_dfh.setSection(newSection);
0134     new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0135     new_dfh.setParent(DocFormatHelper::OTHER);
0136 
0137     psetDesc_->print(os, new_dfh);
0138   }
0139 
0140   void AllowedLabelsDescription<std::vector<ParameterSet> >::validateAllowedLabel_(
0141       std::string const& allowedLabel, ParameterSet& pset, std::set<std::string>& validatedLabels) const {
0142     if (pset.existsAs<std::vector<ParameterSet> >(allowedLabel, isTracked())) {
0143       validatedLabels.insert(allowedLabel);
0144 
0145       if (psetDesc_) {
0146         VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(allowedLabel);
0147         assert(vpsetEntry);
0148         for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
0149           psetDesc_->validate(vpsetEntry->psetInVector(i));
0150         }
0151       }
0152     }
0153   }
0154 }  // namespace edm