Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-23 03:13:14

0001 
0002 #include "FWCore/ParameterSet/interface/ParameterDescription.h"
0003 
0004 #include "DataFormats/Provenance/interface/EventID.h"
0005 #include "DataFormats/Provenance/interface/EventRange.h"
0006 #include "DataFormats/Provenance/interface/LuminosityBlockID.h"
0007 #include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
0008 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0009 #include "FWCore/Utilities/interface/FileInPath.h"
0010 #include "FWCore/ParameterSet/src/FillDescriptionFromPSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
0013 #include "FWCore/Utilities/interface/Algorithms.h"
0014 #include "FWCore/Utilities/interface/EDMException.h"
0015 #include "FWCore/Utilities/interface/InputTag.h"
0016 #include "FWCore/Utilities/interface/ESInputTag.h"
0017 
0018 #include <cassert>
0019 #include <cstdlib>
0020 #include <iomanip>
0021 #include <ostream>
0022 #include <sstream>
0023 
0024 namespace edm {
0025 
0026   // =================================================================
0027 
0028   ParameterDescription<ParameterSetDescription>::ParameterDescription(std::string const& iLabel,
0029                                                                       ParameterSetDescription const& value,
0030                                                                       bool isTracked,
0031                                                                       Comment const& iComment)
0032       : ParameterDescriptionBase(iLabel, k_PSet, isTracked, true, iComment),
0033         psetDesc_(new ParameterSetDescription(value)) {}
0034 
0035   ParameterDescription<ParameterSetDescription>::ParameterDescription(char const* iLabel,
0036                                                                       ParameterSetDescription const& value,
0037                                                                       bool isTracked,
0038                                                                       Comment const& iComment)
0039       : ParameterDescriptionBase(iLabel, k_PSet, isTracked, true, iComment),
0040         psetDesc_(new ParameterSetDescription(value)) {}
0041 
0042   ParameterDescription<ParameterSetDescription>::~ParameterDescription() {}
0043 
0044   void ParameterDescription<ParameterSetDescription>::validate_(ParameterSet& pset,
0045                                                                 std::set<std::string>& validatedLabels,
0046                                                                 bool optional) const {
0047     bool exists = pset.existsAs<ParameterSet>(label(), isTracked());
0048 
0049     if (exists) {
0050       validatedLabels.insert(label());
0051     } else if (pset.existsAs<ParameterSet>(label(), !isTracked())) {
0052       throwParameterWrongTrackiness();
0053     } else if (pset.exists(label())) {
0054       throwParameterWrongType();
0055     }
0056 
0057     if (!optional && !exists) {
0058       if (isTracked()) {
0059         pset.addParameter(label(), ParameterSet());
0060       } else {
0061         pset.addUntrackedParameter(label(), ParameterSet());
0062       }
0063       validatedLabels.insert(label());
0064     }
0065 
0066     exists = pset.existsAs<ParameterSet>(label(), isTracked());
0067 
0068     if (exists) {
0069       if (pset.isRegistered()) {
0070         pset.invalidateRegistration("");
0071       }
0072       ParameterSet* containedPSet = pset.getPSetForUpdate(label());
0073       psetDesc_->validate(*containedPSet);
0074     }
0075   }
0076 
0077   void ParameterDescription<ParameterSetDescription>::printDefault_(std::ostream& os,
0078                                                                     bool writeToCfi,
0079                                                                     DocFormatHelper& dfh) const {
0080     os << "see Section " << dfh.section() << "." << dfh.counter();
0081     if (!writeToCfi)
0082       os << " (do not write to cfi)";
0083     os << "\n";
0084   }
0085 
0086   bool ParameterDescription<ParameterSetDescription>::hasNestedContent_() const { return true; }
0087 
0088   void ParameterDescription<ParameterSetDescription>::printNestedContent_(std::ostream& os,
0089                                                                           bool /*optional*/,
0090                                                                           DocFormatHelper& dfh) const {
0091     int indentation = dfh.indentation();
0092     if (dfh.parent() != DocFormatHelper::TOP) {
0093       indentation -= DocFormatHelper::offsetSectionContent();
0094     }
0095 
0096     std::stringstream ss;
0097     ss << dfh.section() << "." << dfh.counter();
0098     std::string newSection = ss.str();
0099 
0100     printSpaces(os, indentation);
0101     os << "Section " << newSection << " " << label() << " PSet description:\n";
0102     if (!dfh.brief())
0103       os << "\n";
0104 
0105     DocFormatHelper new_dfh(dfh);
0106     new_dfh.init();
0107     new_dfh.setSection(newSection);
0108     if (dfh.parent() == DocFormatHelper::TOP) {
0109       new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0110     }
0111     psetDesc_->print(os, new_dfh);
0112   }
0113 
0114   bool ParameterDescription<ParameterSetDescription>::exists_(ParameterSet const& pset) const {
0115     return pset.existsAs<ParameterSet>(label(), isTracked());
0116   }
0117 
0118   ParameterSetDescription const* ParameterDescription<ParameterSetDescription>::parameterSetDescription() const {
0119     return psetDesc_.operator->();
0120   }
0121 
0122   ParameterSetDescription* ParameterDescription<ParameterSetDescription>::parameterSetDescription() {
0123     return psetDesc_.operator->();
0124   }
0125 
0126   void ParameterDescription<ParameterSetDescription>::writeCfi_(std::ostream& os,
0127                                                                 int indentation,
0128                                                                 CfiOptions& options) const {
0129     bool startWithComma = false;
0130     indentation += 2;
0131     psetDesc_->writeCfi(os, startWithComma, indentation, options);
0132   }
0133 
0134   void ParameterDescription<ParameterSetDescription>::writeDoc_(std::ostream&, int /*indentation*/) const {}
0135 
0136   // These next two should not be needed for this specialization
0137   bool ParameterDescription<ParameterSetDescription>::exists_(ParameterSet const&, bool /*isTracked*/) const {
0138     throw Exception(errors::LogicError);
0139     return true;
0140   }
0141 
0142   void ParameterDescription<ParameterSetDescription>::insertDefault_(ParameterSet&) const {
0143     throw Exception(errors::LogicError);
0144     return;
0145   }
0146 
0147   // =================================================================
0148 
0149   ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(std::string const& iLabel,
0150                                                                          ParameterSetDescription const& psetDesc,
0151                                                                          bool isTracked,
0152                                                                          std::vector<ParameterSet> const& vPset,
0153                                                                          Comment const& iComment)
0154       : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, true, iComment),
0155         psetDesc_(new ParameterSetDescription(psetDesc)),
0156         vPset_(vPset),
0157         partOfDefaultOfVPSet_(false) {}
0158 
0159   ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(char const* iLabel,
0160                                                                          ParameterSetDescription const& psetDesc,
0161                                                                          bool isTracked,
0162                                                                          std::vector<ParameterSet> const& vPset,
0163                                                                          Comment const& iComment)
0164       : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, true, iComment),
0165         psetDesc_(new ParameterSetDescription(psetDesc)),
0166         vPset_(vPset),
0167         partOfDefaultOfVPSet_(false) {}
0168 
0169   ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(std::string const& iLabel,
0170                                                                          ParameterSetDescription const& psetDesc,
0171                                                                          bool isTracked,
0172                                                                          Comment const& iComment)
0173       : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, false, iComment),
0174         psetDesc_(new ParameterSetDescription(psetDesc)),
0175         vPset_(),
0176         partOfDefaultOfVPSet_(false) {}
0177 
0178   ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(char const* iLabel,
0179                                                                          ParameterSetDescription const& psetDesc,
0180                                                                          bool isTracked,
0181                                                                          Comment const& iComment)
0182       : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, false, iComment),
0183         psetDesc_(new ParameterSetDescription(psetDesc)),
0184         vPset_(),
0185         partOfDefaultOfVPSet_(false) {}
0186 
0187   ParameterDescription<std::vector<ParameterSet> >::~ParameterDescription() {}
0188 
0189   ParameterSetDescription const* ParameterDescription<std::vector<ParameterSet> >::parameterSetDescription() const {
0190     return psetDesc_.operator->();
0191   }
0192 
0193   ParameterSetDescription* ParameterDescription<std::vector<ParameterSet> >::parameterSetDescription() {
0194     return psetDesc_.operator->();
0195   }
0196 
0197   void ParameterDescription<std::vector<ParameterSet> >::validate_(ParameterSet& pset,
0198                                                                    std::set<std::string>& validatedLabels,
0199                                                                    bool optional) const {
0200     bool exists = pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());
0201 
0202     if (exists) {
0203       validatedLabels.insert(label());
0204     } else if (pset.existsAs<std::vector<ParameterSet> >(label(), !isTracked())) {
0205       throwParameterWrongTrackiness();
0206     } else if (pset.exists(label())) {
0207       throwParameterWrongType();
0208     }
0209 
0210     if (!exists && !optional) {
0211       if (hasDefault()) {
0212         if (isTracked()) {
0213           pset.addParameter(label(), vPset_);
0214         } else {
0215           pset.addUntrackedParameter(label(), vPset_);
0216         }
0217         validatedLabels.insert(label());
0218       } else {
0219         throwMissingRequiredNoDefault();
0220       }
0221     }
0222 
0223     exists = pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());
0224     if (exists) {
0225       VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(label());
0226       assert(vpsetEntry);
0227 
0228       for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
0229         psetDesc_->validate(vpsetEntry->psetInVector(i));
0230       }
0231     }
0232   }
0233 
0234   void ParameterDescription<std::vector<ParameterSet> >::printDefault_(std::ostream& os,
0235                                                                        bool writeToCfi,
0236                                                                        DocFormatHelper& dfh) const {
0237     os << "see Section " << dfh.section() << "." << dfh.counter();
0238     if (!writeToCfi)
0239       os << " (do not write to cfi)";
0240     os << "\n";
0241   }
0242 
0243   bool ParameterDescription<std::vector<ParameterSet> >::hasNestedContent_() const { return true; }
0244 
0245   void ParameterDescription<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
0246                                                                              bool /*optional*/,
0247                                                                              DocFormatHelper& dfh) const {
0248     int indentation = dfh.indentation();
0249     if (dfh.parent() != DocFormatHelper::TOP) {
0250       indentation -= DocFormatHelper::offsetSectionContent();
0251     }
0252 
0253     if (!partOfDefaultOfVPSet_) {
0254       printSpaces(os, indentation);
0255       os << "Section " << dfh.section() << "." << dfh.counter() << " " << label() << " VPSet description:\n";
0256 
0257       printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
0258       os << "All elements will be validated using the PSet description in Section " << dfh.section() << "."
0259          << dfh.counter() << ".1.\n";
0260     } else {
0261       printSpaces(os, indentation);
0262       os << "Section " << dfh.section() << "." << dfh.counter() << " "
0263          << " VPSet description for VPSet that is part of the default of a containing VPSet:\n";
0264     }
0265 
0266     printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
0267 
0268     unsigned subsectionOffset = 2;
0269     if (partOfDefaultOfVPSet_)
0270       subsectionOffset = 1;
0271 
0272     if (hasDefault()) {
0273       if (vPset_.empty())
0274         os << "The default VPSet is empty.\n";
0275       else if (vPset_.size() == 1U)
0276         os << "The default VPSet has 1 element.\n";
0277       else
0278         os << "The default VPSet has " << vPset_.size() << " elements.\n";
0279 
0280       if (!vPset_.empty()) {
0281         for (unsigned i = 0; i < vPset_.size(); ++i) {
0282           printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
0283           os << "[" << (i) << "]: see Section " << dfh.section() << "." << dfh.counter() << "."
0284              << (i + subsectionOffset) << "\n";
0285         }
0286       }
0287     } else {
0288       os << "Does not have a default VPSet.\n";
0289     }
0290 
0291     if (!dfh.brief())
0292       os << "\n";
0293 
0294     if (!partOfDefaultOfVPSet_) {
0295       std::stringstream ss;
0296       ss << dfh.section() << "." << dfh.counter() << ".1";
0297       std::string newSection = ss.str();
0298 
0299       printSpaces(os, indentation);
0300       os << "Section " << newSection << " description of PSet used to validate elements of VPSet:\n";
0301       if (!dfh.brief())
0302         os << "\n";
0303 
0304       DocFormatHelper new_dfh(dfh);
0305       new_dfh.init();
0306       new_dfh.setSection(newSection);
0307       if (dfh.parent() == DocFormatHelper::TOP) {
0308         new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0309       }
0310       psetDesc_->print(os, new_dfh);
0311     }
0312 
0313     if (hasDefault()) {
0314       for (unsigned i = 0; i < vPset_.size(); ++i) {
0315         std::stringstream ss;
0316         ss << dfh.section() << "." << dfh.counter() << "." << (i + subsectionOffset);
0317         std::string newSection = ss.str();
0318 
0319         printSpaces(os, indentation);
0320         os << "Section " << newSection << " PSet description of "
0321            << "default VPSet element [" << i << "]\n";
0322         if (!dfh.brief())
0323           os << "\n";
0324 
0325         DocFormatHelper new_dfh(dfh);
0326         new_dfh.init();
0327         new_dfh.setSection(newSection);
0328         if (dfh.parent() == DocFormatHelper::TOP) {
0329           new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
0330         }
0331 
0332         ParameterSetDescription defaultDescription;
0333         fillDescriptionFromPSet(vPset_[i], defaultDescription);
0334         defaultDescription.print(os, new_dfh);
0335       }
0336     }
0337   }
0338 
0339   bool ParameterDescription<std::vector<ParameterSet> >::exists_(ParameterSet const& pset) const {
0340     return pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());
0341   }
0342 
0343   void ParameterDescription<std::vector<ParameterSet> >::writeOneElementToCfi(
0344       ParameterSet const& pset, std::ostream& os, int indentation, CfiOptions& options, bool& nextOneStartsWithAComma) {
0345     if (nextOneStartsWithAComma)
0346       os << ",";
0347     nextOneStartsWithAComma = true;
0348     os << "\n";
0349     printSpaces(os, indentation + 2);
0350 
0351     os << "cms.PSet(";
0352 
0353     bool startWithComma = false;
0354     int indent = indentation + 4;
0355 
0356     ParameterSetDescription psetDesc;
0357     fillDescriptionFromPSet(pset, psetDesc);
0358     CfiOptions ops = cfi::Typed{};
0359     psetDesc.writeCfi(os, startWithComma, indent, ops);
0360 
0361     os << ")";
0362   }
0363 
0364   void ParameterDescription<std::vector<ParameterSet> >::writeCfi_(std::ostream& os,
0365                                                                    int indentation,
0366                                                                    CfiOptions& options) const {
0367     bool nextOneStartsWithAComma = false;
0368     for_all(vPset_,
0369             std::bind(&writeOneElementToCfi,
0370                       std::placeholders::_1,
0371                       std::ref(os),
0372                       indentation,
0373                       options,
0374                       std::ref(nextOneStartsWithAComma)));
0375     os << "\n";
0376     printSpaces(os, indentation);
0377   }
0378 
0379   void ParameterDescription<std::vector<ParameterSet> >::writeDoc_(std::ostream&, int /*indentation*/) const {}
0380 
0381   // These next two should not be needed for this specialization
0382   bool ParameterDescription<std::vector<ParameterSet> >::exists_(ParameterSet const&, bool /*isTracked*/) const {
0383     throw Exception(errors::LogicError);
0384     return true;
0385   }
0386 
0387   void ParameterDescription<std::vector<ParameterSet> >::insertDefault_(ParameterSet&) const {
0388     throw Exception(errors::LogicError);
0389     return;
0390   }
0391 
0392   // =================================================================
0393 
0394   namespace writeParameterValue {
0395 
0396     template <typename T>
0397     void writeSingleValue(std::ostream& os, T const& value, ValueFormat) {
0398       os << value;
0399     }
0400 
0401     // Specialize this for cases where the operator<< does not give
0402     // the proper formatting for a configuration file.
0403 
0404     // Formatting the doubles is a little tricky.  It is a requirement
0405     // that when a value of ***type double*** is added to a ParameterSetDescription
0406     // the EXACT same value of type double will be created and passed to the
0407     // ParameterSet after the cfi files have been read.  The tricky part
0408     // is these values usually appear in the C++ code and cfi file as text
0409     // strings (in decimal form).  We do our best to force the text
0410     // string in the C++ code to be the same as the text string in the
0411     // cfi file by judiciously rounding to smaller precision when possible.
0412     // But it is not always possible to force the text strings to be the
0413     // same.  Generally, there are differences when the text string in the
0414     // C++ code has many digits (probably more than a human will ever type).
0415     // Even in cases where the text strings differ, the values stored in
0416     // memory in variables of type double will be exactly the same.
0417     // The alternative to the approach here is to store the values as strings,
0418     // but that approach was rejected because it would require the
0419     // ParameterSetDescription to know how to parse the strings.
0420     void formatDouble(double value, std::string& result) {
0421       {
0422         std::stringstream ss;
0423         ss << std::setprecision(17) << value;
0424         result = ss.str();
0425       }
0426       if (result.size() > 15 && std::string::npos != result.find('.')) {
0427         std::stringstream ss;
0428         ss << std::setprecision(15) << value;
0429         std::string resultLessPrecision = ss.str();
0430 
0431         if (resultLessPrecision.size() < result.size() - 2) {
0432           double test = std::strtod(resultLessPrecision.c_str(), nullptr);
0433           if (test == value) {
0434             result = resultLessPrecision;
0435           }
0436         }
0437       }
0438     }
0439 
0440     template <>
0441     void writeSingleValue<double>(std::ostream& os, double const& value, ValueFormat) {
0442       std::string sValue;
0443       formatDouble(value, sValue);
0444       os << sValue;
0445     }
0446 
0447     template <>
0448     void writeSingleValue<bool>(std::ostream& os, bool const& value, ValueFormat) {
0449       value ? os << "True" : os << "False";
0450     }
0451 
0452     template <>
0453     void writeSingleValue<std::string>(std::ostream& os, std::string const& value, ValueFormat) {
0454       os << "'" << value << "'";
0455     }
0456 
0457     template <>
0458     void writeSingleValue<EventID>(std::ostream& os, EventID const& value, ValueFormat format) {
0459       if (format == CFI) {
0460         os << value.run() << ", " << value.luminosityBlock() << ", " << value.event();
0461       } else {
0462         if (value.luminosityBlock() == 0U) {
0463           os << value.run() << ":" << value.event();
0464         } else {
0465           os << value.run() << ":" << value.luminosityBlock() << ":" << value.event();
0466         }
0467       }
0468     }
0469 
0470     template <>
0471     void writeSingleValue<LuminosityBlockID>(std::ostream& os, LuminosityBlockID const& value, ValueFormat format) {
0472       if (format == CFI)
0473         os << value.run() << ", " << value.luminosityBlock();
0474       else
0475         os << value.run() << ":" << value.luminosityBlock();
0476     }
0477 
0478     template <>
0479     void writeSingleValue<EventRange>(std::ostream& os, EventRange const& value, ValueFormat format) {
0480       if (value.startLumi() == 0U) {
0481         if (format == CFI)
0482           os << "'" << value.startRun() << ":" << value.startEvent() << "-" << value.endRun() << ":" << value.endEvent()
0483              << "'";
0484         else
0485           os << value.startRun() << ":" << value.startEvent() << "-" << value.endRun() << ":" << value.endEvent();
0486       } else {
0487         if (format == CFI)
0488           os << "'" << value.startRun() << ":" << value.startLumi() << ":" << value.startEvent() << "-"
0489              << value.endRun() << ":" << value.endLumi() << ":" << value.endEvent() << "'";
0490         else
0491           os << value.startRun() << ":" << value.startLumi() << ":" << value.startEvent() << "-" << value.endRun()
0492              << ":" << value.endLumi() << ":" << value.endEvent();
0493       }
0494     }
0495 
0496     template <>
0497     void writeSingleValue<LuminosityBlockRange>(std::ostream& os,
0498                                                 LuminosityBlockRange const& value,
0499                                                 ValueFormat format) {
0500       if (format == CFI)
0501         os << "'" << value.startRun() << ":" << value.startLumi() << "-" << value.endRun() << ":" << value.endLumi()
0502            << "'";
0503       else
0504         os << value.startRun() << ":" << value.startLumi() << "-" << value.endRun() << ":" << value.endLumi();
0505     }
0506 
0507     template <>
0508     void writeSingleValue<InputTag>(std::ostream& os, InputTag const& value, ValueFormat format) {
0509       if (format == CFI) {
0510         os << "'" << value.label() << "'";
0511         if (!value.instance().empty() || !value.process().empty()) {
0512           os << ", '" << value.instance() << "'";
0513         }
0514         if (!value.process().empty()) {
0515           os << ", '" << value.process() << "'";
0516         }
0517       } else {
0518         os << "'" << value.label();
0519         if (!value.instance().empty() || !value.process().empty()) {
0520           os << ":" << value.instance();
0521         }
0522         if (!value.process().empty()) {
0523           os << ":" << value.process();
0524         }
0525         os << "'";
0526       }
0527     }
0528 
0529     template <>
0530     void writeSingleValue<ESInputTag>(std::ostream& os, ESInputTag const& value, ValueFormat format) {
0531       if (format == CFI) {
0532         os << "'" << value.module() << "', '" << value.data() << "'";
0533       } else {
0534         os << "'" << value.module() << ":" << value.data() << "'";
0535       }
0536     }
0537 
0538     template <>
0539     void writeSingleValue<FileInPath>(std::ostream& os, FileInPath const& value, ValueFormat) {
0540       os << "'" << value.relativePath() << "'";
0541     }
0542 
0543     template <typename T>
0544     void writeValue(std::ostream& os, T const& value_, ValueFormat format) {
0545       std::ios_base::fmtflags ff = os.flags(std::ios_base::dec);
0546       os.width(0);
0547       writeSingleValue<T>(os, value_, format);
0548       os.flags(ff);
0549     }
0550 
0551     template <typename T>
0552     void writeValueInVector(std::ostream& os, T const& value, ValueFormat format) {
0553       writeSingleValue<T>(os, value, format);
0554     }
0555 
0556     // Specializations for cases where we write the single values into
0557     // vectors differently than when there is only one not in a vector.
0558     template <>
0559     void writeValueInVector<EventID>(std::ostream& os, EventID const& value, ValueFormat format) {
0560       if (value.luminosityBlock() == 0U) {
0561         if (format == CFI)
0562           os << "'" << value.run() << ":" << value.event() << "'";
0563         else
0564           os << value.run() << ":" << value.event();
0565       } else {
0566         if (format == CFI)
0567           os << "'" << value.run() << ":" << value.luminosityBlock() << ":" << value.event() << "'";
0568         else
0569           os << value.run() << ":" << value.luminosityBlock() << ":" << value.event();
0570       }
0571     }
0572 
0573     template <>
0574     void writeValueInVector<LuminosityBlockID>(std::ostream& os, LuminosityBlockID const& value, ValueFormat format) {
0575       if (format == CFI)
0576         os << "'" << value.run() << ":" << value.luminosityBlock() << "'";
0577       else
0578         os << value.run() << ":" << value.luminosityBlock();
0579     }
0580 
0581     template <>
0582     void writeValueInVector<InputTag>(std::ostream& os, InputTag const& value, ValueFormat) {
0583       os << "'" << value.label();
0584       if (!value.instance().empty() || !value.process().empty()) {
0585         os << ":" << value.instance();
0586       }
0587       if (!value.process().empty()) {
0588         os << ":" << value.process();
0589       }
0590       os << "'";
0591     }
0592 
0593     template <>
0594     void writeValueInVector<ESInputTag>(std::ostream& os, ESInputTag const& value, ValueFormat) {
0595       os << "'" << value.module() << ":" << value.data() << "'";
0596     }
0597 
0598     template <typename T>
0599     void writeValueInVectorWithSpace(
0600         T const& value, std::ostream& os, int indentation, bool& startWithComma, ValueFormat format, int& i) {
0601       if (startWithComma && format == CFI)
0602         os << ",";
0603       startWithComma = true;
0604       os << "\n" << std::setw(indentation) << "";
0605       if (format == DOC)
0606         os << "[" << i << "]: ";
0607       writeValueInVector<T>(os, value, format);
0608       ++i;
0609     }
0610 
0611     template <typename T>
0612     void writeVector(std::ostream& os, int indentation, std::vector<T> const& value_, ValueFormat format) {
0613       std::ios_base::fmtflags ff = os.flags(std::ios_base::dec);
0614       char oldFill = os.fill();
0615       os.width(0);
0616       if (value_.empty() && format == DOC) {
0617         os << "empty";
0618       } else if (value_.size() == 1U && format == CFI) {
0619         writeValueInVector<T>(os, value_[0], format);
0620       } else if (!value_.empty()) {
0621         if (format == DOC)
0622           os << "(vector size = " << value_.size() << ")";
0623         if (format == CFI and value_.size() > 255U)
0624           os << " *(";
0625         os.fill(' ');
0626         bool startWithComma = false;
0627         int i = 0;
0628         for_all(value_,
0629                 std::bind(&writeValueInVectorWithSpace<T>,
0630                           std::placeholders::_1,
0631                           std::ref(os),
0632                           indentation + 2,
0633                           std::ref(startWithComma),
0634                           format,
0635                           std::ref(i)));
0636         if (format == CFI)
0637           os << "\n" << std::setw(indentation) << "";
0638         if (format == CFI and value_.size() > 255U)
0639           os << ") ";
0640       }
0641       os.flags(ff);
0642       os.fill(oldFill);
0643     }
0644 
0645     void writeValue(std::ostream& os, int, int const& value_, ValueFormat format) {
0646       writeValue<int>(os, value_, format);
0647     }
0648 
0649     void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format) {
0650       writeVector<int>(os, indentation, value_, format);
0651     }
0652 
0653     void writeValue(std::ostream& os, int, unsigned const& value_, ValueFormat format) {
0654       writeValue<unsigned>(os, value_, format);
0655     }
0656 
0657     void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format) {
0658       writeVector<unsigned>(os, indentation, value_, format);
0659     }
0660 
0661     void writeValue(std::ostream& os, int, long long const& value_, ValueFormat format) {
0662       writeValue<long long>(os, value_, format);
0663     }
0664 
0665     void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format) {
0666       writeVector<long long>(os, indentation, value_, format);
0667     }
0668 
0669     void writeValue(std::ostream& os, int, unsigned long long const& value_, ValueFormat format) {
0670       writeValue<unsigned long long>(os, value_, format);
0671     }
0672 
0673     void writeValue(std::ostream& os,
0674                     int indentation,
0675                     std::vector<unsigned long long> const& value_,
0676                     ValueFormat format) {
0677       writeVector<unsigned long long>(os, indentation, value_, format);
0678     }
0679 
0680     void writeValue(std::ostream& os, int, double const& value_, ValueFormat format) {
0681       writeValue<double>(os, value_, format);
0682     }
0683 
0684     void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format) {
0685       writeVector<double>(os, indentation, value_, format);
0686     }
0687 
0688     void writeValue(std::ostream& os, int, bool const& value_, ValueFormat format) {
0689       writeValue<bool>(os, value_, format);
0690     }
0691 
0692     void writeValue(std::ostream& os, int, std::string const& value_, ValueFormat format) {
0693       writeValue<std::string>(os, value_, format);
0694     }
0695 
0696     void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format) {
0697       writeVector<std::string>(os, indentation, value_, format);
0698     }
0699 
0700     void writeValue(std::ostream& os, int, EventID const& value_, ValueFormat format) {
0701       writeValue<EventID>(os, value_, format);
0702     }
0703 
0704     void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format) {
0705       writeVector<EventID>(os, indentation, value_, format);
0706     }
0707 
0708     void writeValue(std::ostream& os, int, LuminosityBlockID const& value_, ValueFormat format) {
0709       writeValue<LuminosityBlockID>(os, value_, format);
0710     }
0711 
0712     void writeValue(std::ostream& os,
0713                     int indentation,
0714                     std::vector<LuminosityBlockID> const& value_,
0715                     ValueFormat format) {
0716       writeVector<LuminosityBlockID>(os, indentation, value_, format);
0717     }
0718 
0719     void writeValue(std::ostream& os, int, LuminosityBlockRange const& value_, ValueFormat format) {
0720       writeValue<LuminosityBlockRange>(os, value_, format);
0721     }
0722 
0723     void writeValue(std::ostream& os,
0724                     int indentation,
0725                     std::vector<LuminosityBlockRange> const& value_,
0726                     ValueFormat format) {
0727       writeVector<LuminosityBlockRange>(os, indentation, value_, format);
0728     }
0729 
0730     void writeValue(std::ostream& os, int, EventRange const& value_, ValueFormat format) {
0731       writeValue<EventRange>(os, value_, format);
0732     }
0733 
0734     void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format) {
0735       writeVector<EventRange>(os, indentation, value_, format);
0736     }
0737 
0738     void writeValue(std::ostream& os, int, InputTag const& value_, ValueFormat format) {
0739       writeValue<InputTag>(os, value_, format);
0740     }
0741 
0742     void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format) {
0743       writeVector<InputTag>(os, indentation, value_, format);
0744     }
0745 
0746     void writeValue(std::ostream& os, int, ESInputTag const& value_, ValueFormat format) {
0747       writeValue<ESInputTag>(os, value_, format);
0748     }
0749 
0750     void writeValue(std::ostream& os, int indentation, std::vector<ESInputTag> const& value_, ValueFormat format) {
0751       writeVector<ESInputTag>(os, indentation, value_, format);
0752     }
0753 
0754     void writeValue(std::ostream& os, int, FileInPath const& value_, ValueFormat format) {
0755       writeValue<FileInPath>(os, value_, format);
0756     }
0757 
0758     bool hasNestedContent(int const&) { return false; }
0759     bool hasNestedContent(std::vector<int> const& value) { return value.size() > 5U; }
0760     bool hasNestedContent(unsigned const&) { return false; }
0761     bool hasNestedContent(std::vector<unsigned> const& value) { return value.size() > 5U; }
0762     bool hasNestedContent(long long const&) { return false; }
0763     bool hasNestedContent(std::vector<long long> const& value) { return value.size() > 5U; }
0764     bool hasNestedContent(unsigned long long const&) { return false; }
0765     bool hasNestedContent(std::vector<unsigned long long> const& value) { return value.size() > 5U; }
0766     bool hasNestedContent(double const&) { return false; }
0767     bool hasNestedContent(std::vector<double> const& value) { return value.size() > 5U; }
0768     bool hasNestedContent(bool const&) { return false; }
0769     bool hasNestedContent(std::string const&) { return false; }
0770     bool hasNestedContent(std::vector<std::string> const& value) { return value.size() > 5U; }
0771     bool hasNestedContent(EventID const&) { return false; }
0772     bool hasNestedContent(std::vector<EventID> const& value) { return value.size() > 5U; }
0773     bool hasNestedContent(LuminosityBlockID const&) { return false; }
0774     bool hasNestedContent(std::vector<LuminosityBlockID> const& value) { return value.size() > 5U; }
0775     bool hasNestedContent(LuminosityBlockRange const&) { return false; }
0776     bool hasNestedContent(std::vector<LuminosityBlockRange> const& value) { return value.size() > 5U; }
0777     bool hasNestedContent(EventRange const&) { return false; }
0778     bool hasNestedContent(std::vector<EventRange> const& value) { return value.size() > 5U; }
0779     bool hasNestedContent(InputTag const&) { return false; }
0780     bool hasNestedContent(std::vector<InputTag> const& value) { return value.size() > 5U; }
0781     bool hasNestedContent(ESInputTag const&) { return false; }
0782     bool hasNestedContent(std::vector<ESInputTag> const& value) { return value.size() > 5U; }
0783     bool hasNestedContent(FileInPath const&) { return false; }
0784   }  // namespace writeParameterValue
0785 }  // namespace edm