CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/ParameterSet/src/AllowedLabelsDescriptionBase.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/AllowedLabelsDescriptionBase.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 #include "FWCore/Utilities/interface/Algorithms.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00006 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
00007 
00008 #include "boost/bind.hpp"
00009 
00010 #include <iomanip>
00011 #include <ostream>
00012 
00013 namespace edm {
00014 
00015   AllowedLabelsDescriptionBase::~AllowedLabelsDescriptionBase() { }
00016 
00017   AllowedLabelsDescriptionBase::
00018   AllowedLabelsDescriptionBase(std::string const& label, ParameterTypes iType, bool isTracked):
00019     parameterHoldingLabels_(label, std::vector<std::string>(), isTracked),
00020     type_(iType),
00021     isTracked_(isTracked) {
00022   }
00023 
00024   AllowedLabelsDescriptionBase::
00025   AllowedLabelsDescriptionBase(char const* label, ParameterTypes iType, bool isTracked):
00026     parameterHoldingLabels_(label, std::vector<std::string>(), isTracked),
00027     type_(iType),
00028     isTracked_(isTracked) {
00029   }
00030 
00031 
00032   void
00033   AllowedLabelsDescriptionBase::
00034   checkAndGetLabelsAndTypes_(std::set<std::string> & usedLabels,
00035                              std::set<ParameterTypes> & parameterTypes,
00036                              std::set<ParameterTypes> & wildcardTypes) const {
00037 
00038     parameterHoldingLabels_.checkAndGetLabelsAndTypes(usedLabels, parameterTypes, wildcardTypes);
00039   }
00040 
00041   void
00042   AllowedLabelsDescriptionBase::
00043   validate_(ParameterSet & pset,
00044             std::set<std::string> & validatedLabels,
00045             bool optional) const {
00046 
00047     parameterHoldingLabels_.validate(pset, validatedLabels, optional);
00048     if (parameterHoldingLabels_.exists(pset)) {
00049       std::vector<std::string> allowedLabels;
00050       if (isTracked()) {
00051         allowedLabels = pset.getParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
00052       }
00053       else {
00054         allowedLabels = pset.getUntrackedParameter<std::vector<std::string> >(parameterHoldingLabels_.label());
00055       }
00056       for_all(allowedLabels, boost::bind(&AllowedLabelsDescriptionBase::validateAllowedLabel_,
00057                                          boost::cref(this),
00058                                          _1,
00059                                          boost::ref(pset),
00060                                          boost::ref(validatedLabels)));
00061     }
00062   }
00063 
00064   void
00065   AllowedLabelsDescriptionBase::
00066   writeCfi_(std::ostream & os,
00067             bool & startWithComma,
00068             int indentation,
00069             bool & wroteSomething) const {
00070     parameterHoldingLabels_.writeCfi(os, startWithComma, indentation, wroteSomething);
00071   }
00072 
00073   void
00074   AllowedLabelsDescriptionBase::
00075   print_(std::ostream & os,
00076          bool optional,
00077          bool writeToCfi,
00078          DocFormatHelper & dfh)
00079   {
00080     if (dfh.pass() == 1) {
00081 
00082       dfh.indent(os);
00083       os << parameterHoldingLabels_.label() << " (list of allowed labels)";
00084 
00085       if (dfh.brief()) {
00086 
00087         if (optional)  os << " optional";
00088 
00089         if (!writeToCfi) os << " (do not write to cfi)";
00090 
00091         os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
00092       }
00093       // not brief
00094       else {
00095 
00096         os << "\n";
00097         dfh.indent2(os);
00098 
00099         if (optional)  os << "optional";
00100         if (!writeToCfi) os << " (do not write to cfi)";
00101         if (optional || !writeToCfi) {
00102           os << "\n";
00103           dfh.indent2(os);
00104         }
00105 
00106         os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
00107 
00108         if (!comment().empty()) {
00109           DocFormatHelper::wrapAndPrintText(os,
00110                                             comment(),
00111                                             dfh.startColumn2(),
00112                                             dfh.commentWidth());
00113         }
00114         os << "\n";
00115       }
00116     }
00117   }
00118 
00119   bool
00120   AllowedLabelsDescriptionBase::
00121   hasNestedContent_() {
00122     return true;
00123   }
00124 
00125 
00126   void
00127   AllowedLabelsDescriptionBase::
00128   printNestedContent_(std::ostream & os,
00129                       bool optional,
00130                       DocFormatHelper & dfh) {
00131     printNestedContentBase_(os, optional, dfh);
00132     if (!dfh.brief()) os << "\n";
00133   }
00134 
00135   void
00136   AllowedLabelsDescriptionBase::
00137   printNestedContentBase_(std::ostream & os,
00138                           bool optional,
00139                           DocFormatHelper & dfh) {
00140 
00141     int indentation = dfh.indentation();
00142     if (dfh.parent() != DocFormatHelper::TOP) {
00143       indentation -= DocFormatHelper::offsetSectionContent();
00144     }
00145 
00146     printSpaces(os, indentation);
00147     os << "Section " << dfh.section() << "." << dfh.counter()
00148        << " " << parameterHoldingLabels_.label()
00149        << " - allowed labels description\n";
00150     printSpaces(os, indentation);
00151     os << "The following parameter contains a list of parameter labels\n";
00152     printSpaces(os, indentation);
00153     os << "which are allowed to be in the PSet\n";
00154     if (!dfh.brief()) os << "\n";
00155 
00156     DocFormatHelper new_dfh(dfh);
00157     new_dfh.init();
00158     new_dfh.setPass(1);
00159     parameterHoldingLabels_.print(os, optional, true, new_dfh);
00160     dfh.indent(os);
00161     os << "type of allowed parameters:";
00162     if (dfh.brief()) os << " ";
00163     else {
00164       os << "\n";
00165       dfh.indent2(os);
00166     } 
00167     if (!isTracked()) os << "untracked ";
00168     os << parameterTypeEnumToString(type()) << "\n";
00169   }
00170 
00171   bool
00172   AllowedLabelsDescriptionBase::
00173   exists_(ParameterSet const& pset) const {
00174     return parameterHoldingLabels_.exists(pset);
00175   }
00176 
00177   bool
00178   AllowedLabelsDescriptionBase::
00179   partiallyExists_(ParameterSet const& pset) const {
00180     return exists(pset);
00181   }
00182 
00183   int
00184   AllowedLabelsDescriptionBase::
00185   howManyXORSubNodesExist_(ParameterSet const& pset) const {
00186     return exists(pset) ? 1 : 0;
00187   }
00188 }