CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/ParameterSet/src/ParameterSwitchBase.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/ParameterSet/interface/ParameterSwitchBase.h"
00003 #include "FWCore/Utilities/interface/EDMException.h"
00004 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
00005 
00006 #include <ostream>
00007 #include <iomanip>
00008 #include <sstream>
00009 
00010 namespace edm {
00011 
00012   ParameterSwitchBase::~ParameterSwitchBase() { }
00013 
00014   void
00015   ParameterSwitchBase::
00016   throwDuplicateCaseValues(std::string const& switchLabel) const {
00017     throw edm::Exception(errors::LogicError)
00018       << "When adding a ParameterSwitch to a ParameterSetDescription the values\n"
00019       << "associated with the different cases must be unique.  Duplicate\n"
00020       << "values were found for the switch with label: \"" << switchLabel 
00021       << "\"\n";
00022   }
00023 
00024   void
00025   ParameterSwitchBase::
00026   insertAndCheckLabels(std::string const& switchLabel,
00027                        std::set<std::string> & usedLabels,
00028                        std::set<std::string> & labels) const {
00029         
00030     std::pair<std::set<std::string>::iterator,bool> status = labels.insert(switchLabel);
00031     if (status.second == false) {
00032       throw edm::Exception(errors::LogicError)
00033         << "The label used for the switch parameter in a ParameterSetDescription\n"
00034         << "must be different from the labels used in the associated cases.  The following\n"
00035         << "duplicate label was found: \"" << switchLabel << "\"\n";
00036     }
00037     usedLabels.insert(labels.begin(), labels.end());
00038   }
00039 
00040 
00041   void
00042   ParameterSwitchBase::
00043   insertAndCheckTypes(ParameterTypes switchType,
00044                       std::set<ParameterTypes> const& caseParameterTypes,
00045                       std::set<ParameterTypes> const& caseWildcardTypes,
00046                       std::set<ParameterTypes> & parameterTypes,
00047                       std::set<ParameterTypes> & wildcardTypes) const {
00048     
00049     if (caseWildcardTypes.find(switchType) != caseWildcardTypes.end()) {
00050       throw edm::Exception(errors::LogicError)
00051         << "The type used for the switch parameter in a ParameterSetDescription\n"
00052         << "must be different from the types used for wildcards in the associated cases.  The following\n"
00053         << "duplicate type was found: \"" << parameterTypeEnumToString(switchType) << "\"\n";
00054     }
00055     parameterTypes.insert(switchType);
00056     parameterTypes.insert(caseParameterTypes.begin(), caseParameterTypes.end());
00057     wildcardTypes.insert(caseWildcardTypes.begin(), caseWildcardTypes.end());
00058   }
00059 
00060   void
00061   ParameterSwitchBase::
00062   throwNoCaseForDefault(std::string const& switchLabel) const {
00063     throw edm::Exception(errors::LogicError)
00064       << "The default value used for the switch parameter in a ParameterSetDescription\n"
00065       << "must match the value used to select one of the associated cases.  This is not\n"
00066       << "true for the switch named \"" << switchLabel << "\"\n";
00067   }
00068 
00069   void
00070   ParameterSwitchBase::
00071   throwNoCaseForSwitchValue(std::string const& message) const {
00072     throw edm::Exception(errors::Configuration)
00073       << message;
00074   }
00075 
00076   void
00077   ParameterSwitchBase::
00078   printBase(std::ostream & os,
00079             bool optional,
00080             bool writeToCfi,
00081             DocFormatHelper & dfh,
00082             std::string const& switchLabel,
00083             bool isTracked,
00084             std::string const& typeString) const {
00085 
00086     if (dfh.pass() == 0) {
00087       dfh.setAtLeast1(switchLabel.size() + 9U);
00088       if (isTracked) {
00089         dfh.setAtLeast2(typeString.size());
00090       }
00091       else {
00092         dfh.setAtLeast2(typeString.size() + 10U);
00093       }
00094       dfh.setAtLeast3(8U);
00095     }
00096     if (dfh.pass() == 1) {
00097 
00098       dfh.indent(os);
00099 
00100       if (dfh.brief()) {
00101 
00102         std::stringstream ss;
00103         ss << switchLabel << " (switch)"; 
00104         std::ios::fmtflags oldFlags = os.flags();
00105         os << std::left << std::setw(dfh.column1()) << ss.str();
00106         os << " ";
00107 
00108         os << std::setw(dfh.column2());
00109         if (isTracked) {
00110           os << typeString;
00111         }
00112         else {
00113           std::stringstream ss1;
00114           ss1 << "untracked " << typeString;
00115           os << ss1.str();
00116         }
00117 
00118         os << " " << std::setw(dfh.column3());
00119         if (optional)  os << "optional";
00120         else  os << "";
00121 
00122         if (!writeToCfi) os << " (do not write to cfi)";
00123 
00124         os << " see Section " << dfh.section() << "." << dfh.counter() << "\n";
00125         os.flags(oldFlags);
00126       }
00127       // not brief
00128       else {
00129 
00130         os << switchLabel << " (switch)\n";
00131 
00132         dfh.indent2(os);
00133         os << "type: ";
00134         if (!isTracked) os << "untracked ";
00135         os << typeString << " ";
00136 
00137         if (optional)  os << "optional";
00138 
00139         if (!writeToCfi) os << " (do not write to cfi)";
00140         os << "\n";
00141 
00142         dfh.indent2(os);
00143         os << "see Section " << dfh.section() << "." << dfh.counter() << "\n";
00144 
00145         if (!comment().empty()) {
00146           DocFormatHelper::wrapAndPrintText(os,
00147                                             comment(),
00148                                             dfh.startColumn2(),
00149                                             dfh.commentWidth());
00150         }
00151         os << "\n";
00152       }
00153     }
00154   }
00155 
00156   bool
00157   ParameterSwitchBase::
00158   hasNestedContent_() {
00159     return true;
00160   }
00161 
00162   void
00163   ParameterSwitchBase::
00164   printNestedContentBase(std::ostream & os,
00165                          DocFormatHelper & dfh,
00166                          DocFormatHelper & new_dfh,
00167                          std::string const& switchLabel) {
00168 
00169     int indentation = dfh.indentation();
00170     if (dfh.parent() != DocFormatHelper::TOP) {
00171       indentation -= DocFormatHelper::offsetSectionContent();
00172     }
00173 
00174     std::stringstream ss;
00175     ss << dfh.section() << "." << dfh.counter();
00176     std::string newSection = ss.str();
00177 
00178     printSpaces(os, indentation);
00179     os << "Section " << newSection
00180        << " " << switchLabel << " (switch):\n";
00181     
00182     if (!dfh.brief()) {
00183       printSpaces(os, indentation);
00184       os << "The value of \"" << switchLabel << "\" controls which other parameters\n";
00185       printSpaces(os, indentation);
00186       os << "are required or allowed to be in the PSet.\n";
00187     }
00188     if (!dfh.brief()) os << "\n";
00189 
00190     new_dfh.init();
00191     new_dfh.setSection(newSection);
00192     new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
00193     new_dfh.setParent(DocFormatHelper::OTHER);
00194   }
00195 
00196 
00197   void
00198   ParameterSwitchBase::
00199   printCase(std::pair<bool, edm::value_ptr<ParameterDescriptionNode> > const& p,
00200             std::ostream & os,
00201             bool optional,
00202             DocFormatHelper & dfh,
00203             std::string const& switchLabel) {
00204     if (dfh.pass() == 0) {
00205       p.second->print(os, false, true, dfh);
00206     }
00207     if (dfh.pass() == 1) {
00208       dfh.indent(os);
00209       os << "if " << switchLabel << " = ";
00210       if (p.first) os << "True";
00211       else os << "False";
00212       os << "\n";
00213       p.second->print(os, false, true, dfh);
00214     }
00215     if (dfh.pass() == 2) {
00216       p.second->printNestedContent(os, false, dfh);
00217     }
00218   }
00219 
00220   void
00221   ParameterSwitchBase::
00222   printCase(std::pair<int, edm::value_ptr<ParameterDescriptionNode> > const& p,
00223             std::ostream & os,
00224             bool optional,
00225             DocFormatHelper & dfh,
00226             std::string const& switchLabel) {
00227     if (dfh.pass() == 0) {
00228       p.second->print(os, false, true, dfh);
00229     }
00230     if (dfh.pass() == 1) {
00231       dfh.indent(os);
00232       os << "if " << switchLabel << " = " << p.first << "\n";
00233       p.second->print(os, false, true, dfh);
00234     }
00235     if (dfh.pass() == 2) {
00236       p.second->printNestedContent(os, false, dfh);
00237     }
00238   }
00239 
00240   void
00241   ParameterSwitchBase::
00242   printCase(std::pair<std::string, edm::value_ptr<ParameterDescriptionNode> > const& p,
00243             std::ostream & os,
00244             bool optional,
00245             DocFormatHelper & dfh,
00246             std::string const& switchLabel) {
00247     if (dfh.pass() == 0) {
00248       p.second->print(os, false, true, dfh);
00249     }
00250     if (dfh.pass() == 1) {
00251       dfh.indent(os);
00252       os << "if " << switchLabel << " = \"" << p.first << "\"\n";
00253       p.second->print(os, false, true, dfh);
00254     }
00255     if (dfh.pass() == 2) {
00256       p.second->printNestedContent(os, false, dfh);
00257     }
00258   }
00259 
00260   bool
00261   ParameterSwitchBase::
00262   partiallyExists_(ParameterSet const& pset) const {
00263     return exists(pset);
00264   }
00265 
00266   int
00267   ParameterSwitchBase::
00268   howManyXORSubNodesExist_(ParameterSet const& pset) const {
00269     return exists(pset) ? 1 : 0; 
00270   }
00271 }