00001
00002 #include "FWCore/ParameterSet/interface/AllowedLabelsDescription.h"
00003 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
00004 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00005
00006 #include <cassert>
00007
00008 namespace edm {
00009
00010 AllowedLabelsDescription<ParameterSetDescription>::
00011 AllowedLabelsDescription(std::string const& label,
00012 bool isTracked) :
00013 AllowedLabelsDescriptionBase(label, k_PSet, isTracked),
00014 psetDesc_()
00015 {
00016 }
00017
00018 AllowedLabelsDescription<ParameterSetDescription>::
00019 AllowedLabelsDescription(char const* label,
00020 bool isTracked) :
00021 AllowedLabelsDescriptionBase(label, k_PSet, isTracked),
00022 psetDesc_()
00023 {
00024 }
00025
00026 AllowedLabelsDescription<ParameterSetDescription>::
00027 AllowedLabelsDescription(std::string const& label,
00028 ParameterSetDescription const& value,
00029 bool isTracked) :
00030 AllowedLabelsDescriptionBase(label, k_PSet, isTracked),
00031 psetDesc_(new ParameterSetDescription(value))
00032 {
00033 }
00034
00035 AllowedLabelsDescription<ParameterSetDescription>::
00036 AllowedLabelsDescription(char const* label,
00037 ParameterSetDescription const& value,
00038 bool isTracked) :
00039 AllowedLabelsDescriptionBase(label, k_PSet, isTracked),
00040 psetDesc_(new ParameterSetDescription(value))
00041 {
00042 }
00043
00044 ParameterDescriptionNode*
00045 AllowedLabelsDescription<ParameterSetDescription>::
00046 clone() const {
00047 return new AllowedLabelsDescription(*this);
00048 }
00049
00050 void
00051 AllowedLabelsDescription<ParameterSetDescription>::
00052 printNestedContent_(std::ostream & os,
00053 bool optional,
00054 DocFormatHelper & dfh) {
00055
00056 printNestedContentBase_(os, optional, dfh);
00057
00058 int indentation = dfh.indentation();
00059 if (dfh.parent() != DocFormatHelper::TOP) {
00060 indentation -= DocFormatHelper::offsetSectionContent();
00061 }
00062
00063 std::stringstream ss;
00064 ss << dfh.section() << "." << dfh.counter() << ".1";
00065 std::string newSection = ss.str();
00066
00067 if (dfh.brief()) {
00068 printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
00069 }
00070 else {
00071 dfh.indent2(os);
00072 }
00073 os << "see Section " << newSection << "\n";
00074 if (!dfh.brief()) os << "\n";
00075
00076 printSpaces(os, indentation);
00077 os << "Section " << newSection
00078 << " PSet description:\n";
00079 if (!dfh.brief()) os << "\n";
00080
00081 DocFormatHelper new_dfh(dfh);
00082 new_dfh.setSection(newSection);
00083 new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
00084 new_dfh.setParent(DocFormatHelper::OTHER);
00085
00086 psetDesc_->print(os, new_dfh);
00087 }
00088
00089 void
00090 AllowedLabelsDescription<ParameterSetDescription>::
00091 validateAllowedLabel_(std::string const& allowedLabel,
00092 ParameterSet & pset,
00093 std::set<std::string> & validatedLabels) const {
00094 if (pset.existsAs<ParameterSet>(allowedLabel, isTracked())) {
00095 validatedLabels.insert(allowedLabel);
00096 if (psetDesc_) {
00097 ParameterSet * containedPSet = pset.getPSetForUpdate(allowedLabel);
00098 psetDesc_->validate(*containedPSet);
00099 }
00100 }
00101 }
00102
00103
00104
00105 AllowedLabelsDescription<std::vector<ParameterSet> >::
00106 AllowedLabelsDescription(std::string const& label,
00107 bool isTracked) :
00108 AllowedLabelsDescriptionBase(label, k_VPSet, isTracked),
00109 psetDesc_()
00110 {
00111 }
00112
00113 AllowedLabelsDescription<std::vector<ParameterSet> >::
00114 AllowedLabelsDescription(char const* label,
00115 bool isTracked) :
00116 AllowedLabelsDescriptionBase(label, k_VPSet, isTracked),
00117 psetDesc_()
00118 {
00119 }
00120
00121 AllowedLabelsDescription<std::vector<ParameterSet> >::
00122 AllowedLabelsDescription(std::string const& label,
00123 ParameterSetDescription const& value,
00124 bool isTracked) :
00125 AllowedLabelsDescriptionBase(label, k_VPSet, isTracked),
00126 psetDesc_(new ParameterSetDescription(value))
00127 {
00128 }
00129
00130 AllowedLabelsDescription<std::vector<ParameterSet> >::
00131 AllowedLabelsDescription(char const* label,
00132 ParameterSetDescription const& value,
00133 bool isTracked) :
00134 AllowedLabelsDescriptionBase(label, k_VPSet, isTracked),
00135 psetDesc_(new ParameterSetDescription(value))
00136 {
00137 }
00138
00139 ParameterDescriptionNode*
00140 AllowedLabelsDescription<std::vector<ParameterSet> >::
00141 clone() const {
00142 return new AllowedLabelsDescription(*this);
00143 }
00144
00145 void
00146 AllowedLabelsDescription<std::vector<ParameterSet> >::
00147 printNestedContent_(std::ostream & os,
00148 bool optional,
00149 DocFormatHelper & dfh) {
00150
00151 printNestedContentBase_(os, optional, dfh);
00152
00153 int indentation = dfh.indentation();
00154 if (dfh.parent() != DocFormatHelper::TOP) {
00155 indentation -= DocFormatHelper::offsetSectionContent();
00156 }
00157
00158 std::stringstream ss;
00159 ss << dfh.section() << "." << dfh.counter() << ".1";
00160 std::string newSection = ss.str();
00161
00162 if (dfh.brief()) {
00163 printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
00164 }
00165 else {
00166 dfh.indent2(os);
00167 }
00168 os << "see Section " << newSection << "\n";
00169 if (!dfh.brief()) os << "\n";
00170
00171 printSpaces(os, indentation);
00172 os << "Section " << newSection
00173 << " PSet description used to validate all elements of VPSet's:\n";
00174 if (!dfh.brief()) os << "\n";
00175
00176 DocFormatHelper new_dfh(dfh);
00177 new_dfh.setSection(newSection);
00178 new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
00179 new_dfh.setParent(DocFormatHelper::OTHER);
00180
00181 psetDesc_->print(os, new_dfh);
00182 }
00183
00184 void
00185 AllowedLabelsDescription<std::vector<ParameterSet> >::
00186 validateAllowedLabel_(std::string const& allowedLabel,
00187 ParameterSet & pset,
00188 std::set<std::string> & validatedLabels) const {
00189 if (pset.existsAs<std::vector<ParameterSet> >(allowedLabel, isTracked())) {
00190 validatedLabels.insert(allowedLabel);
00191
00192 if (psetDesc_) {
00193 VParameterSetEntry * vpsetEntry = pset.getPSetVectorForUpdate(allowedLabel);
00194 assert(vpsetEntry);
00195 for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
00196 psetDesc_->validate(vpsetEntry->psetInVector(i));
00197 }
00198 }
00199 }
00200 }
00201 }