CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/FWCore/ParameterSet/src/ParameterWildcard.cc

Go to the documentation of this file.
00001 #include "FWCore/ParameterSet/interface/ParameterWildcard.h"
00002 #include "FWCore/Utilities/interface/Algorithms.h"
00003 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00005 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
00006 
00007 #include "boost/bind.hpp"
00008 
00009 #include <cassert>
00010 #include <ostream>
00011 #include <iomanip>
00012 
00013 namespace edm {
00014 
00015   ParameterWildcard<ParameterSetDescription>::
00016   ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked) :
00017     ParameterWildcardBase(k_PSet, isTracked, criteria),
00018     psetDesc_()
00019   {
00020     throwIfInvalidPattern(pattern);
00021   }
00022 
00023   ParameterWildcard<ParameterSetDescription>::
00024   ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
00025     ParameterWildcardBase(k_PSet, isTracked, criteria),
00026     psetDesc_()
00027   {
00028     throwIfInvalidPattern(pattern);
00029   }
00030 
00031   ParameterWildcard<ParameterSetDescription>::
00032   ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
00033     ParameterWildcardBase(k_PSet, isTracked, criteria),
00034     psetDesc_(new ParameterSetDescription(desc))
00035   {
00036     throwIfInvalidPattern(pattern);
00037   }
00038 
00039 
00040   ParameterWildcard<ParameterSetDescription>::
00041   ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked, ParameterSetDescription const& desc) :
00042     ParameterWildcardBase(k_PSet, isTracked, criteria),
00043     psetDesc_(new ParameterSetDescription(desc))
00044   {
00045     throwIfInvalidPattern(pattern);
00046   }
00047 
00048 
00049   ParameterWildcard<ParameterSetDescription>::
00050   ~ParameterWildcard() { }
00051 
00052   ParameterDescriptionNode*
00053   ParameterWildcard<ParameterSetDescription>::
00054   clone() const {
00055     return new ParameterWildcard(*this);
00056   }
00057 
00058   void
00059   ParameterWildcard<ParameterSetDescription>::
00060   validate_(ParameterSet & pset,
00061             std::set<std::string> & validatedLabels,
00062             bool optional) const {
00063 
00064     std::vector<std::string> parameterNames  = pset.getParameterNamesForType<ParameterSet>(isTracked());
00065     validateMatchingNames(parameterNames, validatedLabels, optional);
00066 
00067     if (psetDesc_) {
00068       for_all(parameterNames,
00069               boost::bind(&ParameterWildcard<ParameterSetDescription>::validateDescription,
00070                           boost::cref(this),
00071                           _1,
00072                           boost::ref(pset)));
00073     }
00074   }
00075 
00076   void
00077   ParameterWildcard<ParameterSetDescription>::
00078   validateDescription(std::string const& parameterName,
00079                       ParameterSet & pset) const {
00080     ParameterSet * containedPSet = pset.getPSetForUpdate(parameterName);
00081     psetDesc_->validate(*containedPSet);
00082   }
00083 
00084   bool
00085   ParameterWildcard<ParameterSetDescription>::
00086   hasNestedContent_() {
00087     if (psetDesc_) return true;
00088     return false;
00089   }
00090 
00091   void
00092   ParameterWildcard<ParameterSetDescription>::
00093   printNestedContent_(std::ostream & os,
00094                       bool optional,
00095                       DocFormatHelper & dfh) {
00096 
00097     int indentation = dfh.indentation();
00098     if (dfh.parent() != DocFormatHelper::TOP) {
00099       indentation -= DocFormatHelper::offsetSectionContent();
00100     }
00101 
00102     printSpaces(os, indentation);
00103     os << "Section " << dfh.section() << "." << dfh.counter()
00104        << " description of PSet matching wildcard:";
00105     os << "\n";
00106     if (!dfh.brief()) os << "\n";
00107 
00108     std::stringstream ss;
00109     ss << dfh.section() << "." << dfh.counter();
00110     std::string newSection = ss.str();
00111 
00112     DocFormatHelper new_dfh(dfh);
00113     new_dfh.setSection(newSection);
00114     new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
00115     new_dfh.setParent(DocFormatHelper::OTHER);
00116 
00117     psetDesc_->print(os, new_dfh);
00118   }
00119 
00120   bool
00121   ParameterWildcard<ParameterSetDescription>::
00122   exists_(ParameterSet const& pset) const {
00123 
00124     if (criteria() == RequireZeroOrMore) return true;
00125 
00126     std::vector<std::string> parameterNames  = pset.getParameterNamesForType<ParameterSet>(isTracked());
00127 
00128     if (criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
00129     return parameterNames.size() == 1U;
00130   }
00131 
00132 // -------------------------------------------------------------------------
00133 
00134   ParameterWildcard<std::vector<ParameterSet> >::
00135   ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked) :
00136     ParameterWildcardBase(k_VPSet, isTracked, criteria),
00137     psetDesc_()
00138   {
00139     throwIfInvalidPattern(pattern);
00140   }
00141 
00142   ParameterWildcard<std::vector<ParameterSet> >::
00143   ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked) :
00144     ParameterWildcardBase(k_VPSet, isTracked, criteria),
00145     psetDesc_()
00146   {
00147     throwIfInvalidPattern(pattern);
00148   }
00149 
00150   ParameterWildcard<std::vector<ParameterSet> >::
00151   ParameterWildcard(std::string const& pattern, WildcardValidationCriteria criteria, bool isTracked,
00152                     ParameterSetDescription const& desc) :
00153     ParameterWildcardBase(k_VPSet, isTracked, criteria),
00154     psetDesc_(new ParameterSetDescription(desc))
00155   {
00156     throwIfInvalidPattern(pattern);
00157   }
00158 
00159 
00160   ParameterWildcard<std::vector<ParameterSet> >::
00161   ParameterWildcard(char const* pattern, WildcardValidationCriteria criteria, bool isTracked,
00162                     ParameterSetDescription const& desc) :
00163     ParameterWildcardBase(k_VPSet, isTracked, criteria),
00164     psetDesc_(new ParameterSetDescription(desc))
00165   {
00166     throwIfInvalidPattern(pattern);
00167   }
00168 
00169 
00170   ParameterWildcard<std::vector<ParameterSet> >::
00171   ~ParameterWildcard() { }
00172 
00173   ParameterDescriptionNode*
00174   ParameterWildcard<std::vector<ParameterSet> >::
00175   clone() const {
00176     return new ParameterWildcard(*this);
00177   }
00178 
00179   void
00180   ParameterWildcard<std::vector<ParameterSet> >::
00181   validate_(ParameterSet & pset,
00182             std::set<std::string> & validatedLabels,
00183             bool optional) const {
00184 
00185     std::vector<std::string> parameterNames  = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
00186     validateMatchingNames(parameterNames, validatedLabels, optional);
00187 
00188     if (psetDesc_) {
00189       for_all(parameterNames,
00190               boost::bind(&ParameterWildcard<std::vector<ParameterSet> >::validatePSetVector,
00191                           boost::cref(this),
00192                           _1,
00193                           boost::ref(pset)));
00194     }
00195   }
00196 
00197   void
00198   ParameterWildcard<std::vector<ParameterSet> >::
00199   validatePSetVector(std::string const& parameterName, ParameterSet & pset) const {
00200     VParameterSetEntry * vpsetEntry = pset.getPSetVectorForUpdate(parameterName);
00201     assert(vpsetEntry);
00202     for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
00203       psetDesc_->validate(vpsetEntry->psetInVector(i));
00204     }
00205   }
00206 
00207   bool
00208   ParameterWildcard<std::vector<ParameterSet> >::
00209   hasNestedContent_() {
00210     if (psetDesc_) return true;
00211     return false;
00212   }
00213 
00214   void
00215   ParameterWildcard<std::vector<ParameterSet> >::
00216   printNestedContent_(std::ostream & os,
00217                       bool optional,
00218                       DocFormatHelper & dfh) {
00219 
00220     int indentation = dfh.indentation();
00221     if (dfh.parent() != DocFormatHelper::TOP) {
00222       indentation -= DocFormatHelper::offsetSectionContent();
00223     }
00224 
00225     printSpaces(os, indentation);
00226     os << "Section " << dfh.section() << "." << dfh.counter()
00227        << " description used to validate all PSets which are in the VPSet matching the wildcard:";
00228     os << "\n";
00229     if (!dfh.brief()) os << "\n";
00230 
00231     std::stringstream ss;
00232     ss << dfh.section() << "." << dfh.counter();
00233     std::string newSection = ss.str();
00234 
00235     DocFormatHelper new_dfh(dfh);
00236     new_dfh.setSection(newSection);
00237     new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
00238     new_dfh.setParent(DocFormatHelper::OTHER);
00239 
00240     psetDesc_->print(os, new_dfh);
00241   }
00242 
00243   bool
00244   ParameterWildcard<std::vector<ParameterSet> >::
00245   exists_(ParameterSet const& pset) const {
00246 
00247     if (criteria() == RequireZeroOrMore) return true;
00248 
00249     std::vector<std::string> parameterNames  = pset.getParameterNamesForType<std::vector<ParameterSet> >(isTracked());
00250 
00251     if (criteria() == RequireAtLeastOne) return parameterNames.size() >= 1U;
00252     return parameterNames.size() == 1U;
00253   }
00254 }