Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803

#include "FWCore/ParameterSet/interface/ParameterDescription.h"

#include "DataFormats/Provenance/interface/EventID.h"
#include "DataFormats/Provenance/interface/EventRange.h"
#include "DataFormats/Provenance/interface/LuminosityBlockID.h"
#include "DataFormats/Provenance/interface/LuminosityBlockRange.h"
#include "FWCore/ParameterSet/interface/DocFormatHelper.h"
#include "FWCore/Utilities/interface/FileInPath.h"
#include "FWCore/ParameterSet/src/FillDescriptionFromPSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/ParameterSet/interface/VParameterSetEntry.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/Algorithms.h"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/ESInputTag.h"

#include <cassert>
#include <cstdlib>
#include <iomanip>
#include <ostream>
#include <sstream>

namespace edm {

  // =================================================================

  ParameterDescription<ParameterSetDescription>::ParameterDescription(std::string const& iLabel,
                                                                      ParameterSetDescription const& value,
                                                                      bool isTracked,
                                                                      Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_PSet, isTracked, true, iComment),
        psetDesc_(new ParameterSetDescription(value)) {}

  ParameterDescription<ParameterSetDescription>::ParameterDescription(char const* iLabel,
                                                                      ParameterSetDescription const& value,
                                                                      bool isTracked,
                                                                      Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_PSet, isTracked, true, iComment),
        psetDesc_(new ParameterSetDescription(value)) {}

  ParameterDescription<ParameterSetDescription>::~ParameterDescription() {}

  void ParameterDescription<ParameterSetDescription>::validate_(ParameterSet& pset,
                                                                std::set<std::string>& validatedLabels,
                                                                Modifier modifier) const {
    bool exists = pset.existsAs<ParameterSet>(label(), isTracked());

    if (exists) {
      validatedLabels.insert(label());
    } else if (pset.existsAs<ParameterSet>(label(), !isTracked())) {
      throwParameterWrongTrackiness();
    } else if (pset.exists(label())) {
      throwParameterWrongType();
    }

    if (modifier == Modifier::kNone && !exists) {
      if (isTracked()) {
        pset.addParameter(label(), ParameterSet());
      } else {
        pset.addUntrackedParameter(label(), ParameterSet());
      }
      validatedLabels.insert(label());
    }

    exists = pset.existsAs<ParameterSet>(label(), isTracked());

    if (exists) {
      if (modifier == Modifier::kObsolete) {
        edm::LogWarning("Configuration") << "ignoring obsolete parameter '" << label() << "'";
        return;
      }
      if (pset.isRegistered()) {
        pset.invalidateRegistration("");
      }
      ParameterSet* containedPSet = pset.getPSetForUpdate(label());
      psetDesc_->validate(*containedPSet);
    }
  }

  void ParameterDescription<ParameterSetDescription>::printDefault_(std::ostream& os,
                                                                    bool writeToCfi,
                                                                    DocFormatHelper& dfh) const {
    os << "see Section " << dfh.section() << "." << dfh.counter();
    if (!writeToCfi)
      os << " (do not write to cfi)";
    os << "\n";
  }

  bool ParameterDescription<ParameterSetDescription>::hasNestedContent_() const { return true; }

  void ParameterDescription<ParameterSetDescription>::printNestedContent_(std::ostream& os,
                                                                          bool /*optional*/,
                                                                          DocFormatHelper& dfh) const {
    int indentation = dfh.indentation();
    if (dfh.parent() != DocFormatHelper::TOP) {
      indentation -= DocFormatHelper::offsetSectionContent();
    }

    std::stringstream ss;
    ss << dfh.section() << "." << dfh.counter();
    std::string newSection = ss.str();

    printSpaces(os, indentation);
    os << "Section " << newSection << " " << label() << " PSet description:\n";
    if (!dfh.brief())
      os << "\n";

    DocFormatHelper new_dfh(dfh);
    new_dfh.init();
    new_dfh.setSection(newSection);
    if (dfh.parent() == DocFormatHelper::TOP) {
      new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
    }
    psetDesc_->print(os, new_dfh);
  }

  bool ParameterDescription<ParameterSetDescription>::exists_(ParameterSet const& pset) const {
    return pset.existsAs<ParameterSet>(label(), isTracked());
  }

  ParameterSetDescription const* ParameterDescription<ParameterSetDescription>::parameterSetDescription() const {
    return psetDesc_.operator->();
  }

  ParameterSetDescription* ParameterDescription<ParameterSetDescription>::parameterSetDescription() {
    return psetDesc_.operator->();
  }

  void ParameterDescription<ParameterSetDescription>::writeCfi_(std::ostream& os,
                                                                int indentation,
                                                                CfiOptions& options) const {
    bool startWithComma = false;
    indentation += 2;
    psetDesc_->writeCfi(os, startWithComma, indentation, options);
  }

  void ParameterDescription<ParameterSetDescription>::writeDoc_(std::ostream&, int /*indentation*/) const {}

  // These next two should not be needed for this specialization
  bool ParameterDescription<ParameterSetDescription>::exists_(ParameterSet const&, bool /*isTracked*/) const {
    throw Exception(errors::LogicError);
    return true;
  }

  void ParameterDescription<ParameterSetDescription>::insertDefault_(ParameterSet&) const {
    throw Exception(errors::LogicError);
    return;
  }

  // =================================================================

  ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(std::string const& iLabel,
                                                                         ParameterSetDescription const& psetDesc,
                                                                         bool isTracked,
                                                                         std::vector<ParameterSet> const& vPset,
                                                                         Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, true, iComment),
        psetDesc_(new ParameterSetDescription(psetDesc)),
        vPset_(vPset),
        partOfDefaultOfVPSet_(false) {}

  ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(char const* iLabel,
                                                                         ParameterSetDescription const& psetDesc,
                                                                         bool isTracked,
                                                                         std::vector<ParameterSet> const& vPset,
                                                                         Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, true, iComment),
        psetDesc_(new ParameterSetDescription(psetDesc)),
        vPset_(vPset),
        partOfDefaultOfVPSet_(false) {}

  ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(std::string const& iLabel,
                                                                         ParameterSetDescription const& psetDesc,
                                                                         bool isTracked,
                                                                         Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, false, iComment),
        psetDesc_(new ParameterSetDescription(psetDesc)),
        vPset_(),
        partOfDefaultOfVPSet_(false) {}

  ParameterDescription<std::vector<ParameterSet> >::ParameterDescription(char const* iLabel,
                                                                         ParameterSetDescription const& psetDesc,
                                                                         bool isTracked,
                                                                         Comment const& iComment)
      : ParameterDescriptionBase(iLabel, k_VPSet, isTracked, false, iComment),
        psetDesc_(new ParameterSetDescription(psetDesc)),
        vPset_(),
        partOfDefaultOfVPSet_(false) {}

  ParameterDescription<std::vector<ParameterSet> >::~ParameterDescription() {}

  ParameterSetDescription const* ParameterDescription<std::vector<ParameterSet> >::parameterSetDescription() const {
    return psetDesc_.operator->();
  }

  ParameterSetDescription* ParameterDescription<std::vector<ParameterSet> >::parameterSetDescription() {
    return psetDesc_.operator->();
  }

  void ParameterDescription<std::vector<ParameterSet> >::validate_(ParameterSet& pset,
                                                                   std::set<std::string>& validatedLabels,
                                                                   Modifier modifier) const {
    bool exists = pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());

    if (exists) {
      validatedLabels.insert(label());
    } else if (pset.existsAs<std::vector<ParameterSet> >(label(), !isTracked())) {
      throwParameterWrongTrackiness();
    } else if (pset.exists(label())) {
      throwParameterWrongType();
    }

    if (!exists && modifier == Modifier::kNone) {
      if (hasDefault()) {
        if (isTracked()) {
          pset.addParameter(label(), vPset_);
        } else {
          pset.addUntrackedParameter(label(), vPset_);
        }
        validatedLabels.insert(label());
      } else {
        throwMissingRequiredNoDefault();
      }
    }

    exists = pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());
    if (exists) {
      if (modifier == Modifier::kObsolete) {
        edm::LogWarning("Configuration") << "ignoring obsolete parameter '" << label() << "'";
        return;
      }
      VParameterSetEntry* vpsetEntry = pset.getPSetVectorForUpdate(label());
      assert(vpsetEntry);

      for (unsigned i = 0; i < vpsetEntry->size(); ++i) {
        psetDesc_->validate(vpsetEntry->psetInVector(i));
      }
    }
  }

  void ParameterDescription<std::vector<ParameterSet> >::printDefault_(std::ostream& os,
                                                                       bool writeToCfi,
                                                                       DocFormatHelper& dfh) const {
    os << "see Section " << dfh.section() << "." << dfh.counter();
    if (!writeToCfi)
      os << " (do not write to cfi)";
    os << "\n";
  }

  bool ParameterDescription<std::vector<ParameterSet> >::hasNestedContent_() const { return true; }

  void ParameterDescription<std::vector<ParameterSet> >::printNestedContent_(std::ostream& os,
                                                                             bool /*optional*/,
                                                                             DocFormatHelper& dfh) const {
    int indentation = dfh.indentation();
    if (dfh.parent() != DocFormatHelper::TOP) {
      indentation -= DocFormatHelper::offsetSectionContent();
    }

    if (!partOfDefaultOfVPSet_) {
      printSpaces(os, indentation);
      os << "Section " << dfh.section() << "." << dfh.counter() << " " << label() << " VPSet description:\n";

      printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
      os << "All elements will be validated using the PSet description in Section " << dfh.section() << "."
         << dfh.counter() << ".1.\n";
    } else {
      printSpaces(os, indentation);
      os << "Section " << dfh.section() << "." << dfh.counter() << " "
         << " VPSet description for VPSet that is part of the default of a containing VPSet:\n";
    }

    printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());

    unsigned subsectionOffset = 2;
    if (partOfDefaultOfVPSet_)
      subsectionOffset = 1;

    if (hasDefault()) {
      if (vPset_.empty())
        os << "The default VPSet is empty.\n";
      else if (vPset_.size() == 1U)
        os << "The default VPSet has 1 element.\n";
      else
        os << "The default VPSet has " << vPset_.size() << " elements.\n";

      if (!vPset_.empty()) {
        for (unsigned i = 0; i < vPset_.size(); ++i) {
          printSpaces(os, indentation + DocFormatHelper::offsetSectionContent());
          os << "[" << (i) << "]: see Section " << dfh.section() << "." << dfh.counter() << "."
             << (i + subsectionOffset) << "\n";
        }
      }
    } else {
      os << "Does not have a default VPSet.\n";
    }

    if (!dfh.brief())
      os << "\n";

    if (!partOfDefaultOfVPSet_) {
      std::stringstream ss;
      ss << dfh.section() << "." << dfh.counter() << ".1";
      std::string newSection = ss.str();

      printSpaces(os, indentation);
      os << "Section " << newSection << " description of PSet used to validate elements of VPSet:\n";
      if (!dfh.brief())
        os << "\n";

      DocFormatHelper new_dfh(dfh);
      new_dfh.init();
      new_dfh.setSection(newSection);
      if (dfh.parent() == DocFormatHelper::TOP) {
        new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
      }
      psetDesc_->print(os, new_dfh);
    }

    if (hasDefault()) {
      for (unsigned i = 0; i < vPset_.size(); ++i) {
        std::stringstream ss;
        ss << dfh.section() << "." << dfh.counter() << "." << (i + subsectionOffset);
        std::string newSection = ss.str();

        printSpaces(os, indentation);
        os << "Section " << newSection << " PSet description of "
           << "default VPSet element [" << i << "]\n";
        if (!dfh.brief())
          os << "\n";

        DocFormatHelper new_dfh(dfh);
        new_dfh.init();
        new_dfh.setSection(newSection);
        if (dfh.parent() == DocFormatHelper::TOP) {
          new_dfh.setIndentation(indentation + DocFormatHelper::offsetSectionContent());
        }

        ParameterSetDescription defaultDescription;
        fillDescriptionFromPSet(vPset_[i], defaultDescription);
        defaultDescription.print(os, new_dfh);
      }
    }
  }

  bool ParameterDescription<std::vector<ParameterSet> >::exists_(ParameterSet const& pset) const {
    return pset.existsAs<std::vector<ParameterSet> >(label(), isTracked());
  }

  void ParameterDescription<std::vector<ParameterSet> >::writeOneElementToCfi(
      ParameterSet const& pset, std::ostream& os, int indentation, CfiOptions& options, bool& nextOneStartsWithAComma) {
    if (nextOneStartsWithAComma)
      os << ",";
    nextOneStartsWithAComma = true;
    os << "\n";
    printSpaces(os, indentation + 2);

    os << "cms.PSet(";

    bool startWithComma = false;
    int indent = indentation + 4;

    ParameterSetDescription psetDesc;
    fillDescriptionFromPSet(pset, psetDesc);
    CfiOptions ops = cfi::Typed{};
    psetDesc.writeCfi(os, startWithComma, indent, ops);

    os << ")";
  }

  void ParameterDescription<std::vector<ParameterSet> >::writeCfi_(std::ostream& os,
                                                                   int indentation,
                                                                   CfiOptions& options) const {
    bool nextOneStartsWithAComma = false;
    for (auto const& p : vPset_) {
      writeOneElementToCfi(p, os, indentation, options, nextOneStartsWithAComma);
    }
    if (cfi::shouldWriteUntyped(options) or psetDesc_->empty() or psetDesc_->anythingAllowed() or
        psetDesc_->isUnknown()) {
      os << "\n";
    } else {
      if (not vPset_.empty()) {
        os << ",";
      }
      os << "\n";
      printSpaces(os, indentation + 2);
      CfiOptions fullOp = cfi::Typed{};
      os << "template = cms.PSetTemplate(";
      psetDesc_->writeCfi(os, false, indentation + 4, fullOp);
      os << ")\n";
    }
    printSpaces(os, indentation);
  }

  void ParameterDescription<std::vector<ParameterSet> >::writeDoc_(std::ostream&, int /*indentation*/) const {}

  // These next two should not be needed for this specialization
  bool ParameterDescription<std::vector<ParameterSet> >::exists_(ParameterSet const&, bool /*isTracked*/) const {
    throw Exception(errors::LogicError);
    return true;
  }

  void ParameterDescription<std::vector<ParameterSet> >::insertDefault_(ParameterSet&) const {
    throw Exception(errors::LogicError);
    return;
  }

  // =================================================================

  namespace writeParameterValue {

    template <typename T>
    void writeSingleValue(std::ostream& os, T const& value, ValueFormat) {
      os << value;
    }

    // Specialize this for cases where the operator<< does not give
    // the proper formatting for a configuration file.

    // Formatting the doubles is a little tricky.  It is a requirement
    // that when a value of ***type double*** is added to a ParameterSetDescription
    // the EXACT same value of type double will be created and passed to the
    // ParameterSet after the cfi files have been read.  The tricky part
    // is these values usually appear in the C++ code and cfi file as text
    // strings (in decimal form).  We do our best to force the text
    // string in the C++ code to be the same as the text string in the
    // cfi file by judiciously rounding to smaller precision when possible.
    // But it is not always possible to force the text strings to be the
    // same.  Generally, there are differences when the text string in the
    // C++ code has many digits (probably more than a human will ever type).
    // Even in cases where the text strings differ, the values stored in
    // memory in variables of type double will be exactly the same.
    // The alternative to the approach here is to store the values as strings,
    // but that approach was rejected because it would require the
    // ParameterSetDescription to know how to parse the strings.
    void formatDouble(double value, std::string& result) {
      {
        std::stringstream ss;
        ss << std::setprecision(17) << value;
        result = ss.str();
      }
      if (result.size() > 15 && std::string::npos != result.find('.')) {
        std::stringstream ss;
        ss << std::setprecision(15) << value;
        std::string resultLessPrecision = ss.str();

        if (resultLessPrecision.size() < result.size() - 2) {
          double test = std::strtod(resultLessPrecision.c_str(), nullptr);
          if (test == value) {
            result = resultLessPrecision;
          }
        }
      }
    }

    template <>
    void writeSingleValue<double>(std::ostream& os, double const& value, ValueFormat) {
      std::string sValue;
      formatDouble(value, sValue);
      os << sValue;
    }

    template <>
    void writeSingleValue<bool>(std::ostream& os, bool const& value, ValueFormat) {
      value ? os << "True" : os << "False";
    }

    template <>
    void writeSingleValue<std::string>(std::ostream& os, std::string const& value, ValueFormat) {
      os << "'" << value << "'";
    }

    template <>
    void writeSingleValue<EventID>(std::ostream& os, EventID const& value, ValueFormat format) {
      if (format == CFI) {
        os << value.run() << ", " << value.luminosityBlock() << ", " << value.event();
      } else {
        if (value.luminosityBlock() == 0U) {
          os << value.run() << ":" << value.event();
        } else {
          os << value.run() << ":" << value.luminosityBlock() << ":" << value.event();
        }
      }
    }

    template <>
    void writeSingleValue<LuminosityBlockID>(std::ostream& os, LuminosityBlockID const& value, ValueFormat format) {
      if (format == CFI)
        os << value.run() << ", " << value.luminosityBlock();
      else
        os << value.run() << ":" << value.luminosityBlock();
    }

    template <>
    void writeSingleValue<EventRange>(std::ostream& os, EventRange const& value, ValueFormat format) {
      if (value.startLumi() == 0U) {
        if (format == CFI)
          os << "'" << value.startRun() << ":" << value.startEvent() << "-" << value.endRun() << ":" << value.endEvent()
             << "'";
        else
          os << value.startRun() << ":" << value.startEvent() << "-" << value.endRun() << ":" << value.endEvent();
      } else {
        if (format == CFI)
          os << "'" << value.startRun() << ":" << value.startLumi() << ":" << value.startEvent() << "-"
             << value.endRun() << ":" << value.endLumi() << ":" << value.endEvent() << "'";
        else
          os << value.startRun() << ":" << value.startLumi() << ":" << value.startEvent() << "-" << value.endRun()
             << ":" << value.endLumi() << ":" << value.endEvent();
      }
    }

    template <>
    void writeSingleValue<LuminosityBlockRange>(std::ostream& os,
                                                LuminosityBlockRange const& value,
                                                ValueFormat format) {
      if (format == CFI)
        os << "'" << value.startRun() << ":" << value.startLumi() << "-" << value.endRun() << ":" << value.endLumi()
           << "'";
      else
        os << value.startRun() << ":" << value.startLumi() << "-" << value.endRun() << ":" << value.endLumi();
    }

    template <>
    void writeSingleValue<InputTag>(std::ostream& os, InputTag const& value, ValueFormat format) {
      if (format == CFI) {
        os << "'" << value.label() << "'";
        if (!value.instance().empty() || !value.process().empty()) {
          os << ", '" << value.instance() << "'";
        }
        if (!value.process().empty()) {
          os << ", '" << value.process() << "'";
        }
      } else {
        os << "'" << value.label();
        if (!value.instance().empty() || !value.process().empty()) {
          os << ":" << value.instance();
        }
        if (!value.process().empty()) {
          os << ":" << value.process();
        }
        os << "'";
      }
    }

    template <>
    void writeSingleValue<ESInputTag>(std::ostream& os, ESInputTag const& value, ValueFormat format) {
      if (format == CFI) {
        os << "'" << value.module() << "', '" << value.data() << "'";
      } else {
        os << "'" << value.module() << ":" << value.data() << "'";
      }
    }

    template <>
    void writeSingleValue<FileInPath>(std::ostream& os, FileInPath const& value, ValueFormat) {
      os << "'" << value.relativePath() << "'";
    }

    template <typename T>
    void writeValue(std::ostream& os, T const& value_, ValueFormat format) {
      std::ios_base::fmtflags ff = os.flags(std::ios_base::dec);
      os.width(0);
      writeSingleValue<T>(os, value_, format);
      os.flags(ff);
    }

    template <typename T>
    void writeValueInVector(std::ostream& os, T const& value, ValueFormat format) {
      writeSingleValue<T>(os, value, format);
    }

    // Specializations for cases where we write the single values into
    // vectors differently than when there is only one not in a vector.
    template <>
    void writeValueInVector<EventID>(std::ostream& os, EventID const& value, ValueFormat format) {
      if (value.luminosityBlock() == 0U) {
        if (format == CFI)
          os << "'" << value.run() << ":" << value.event() << "'";
        else
          os << value.run() << ":" << value.event();
      } else {
        if (format == CFI)
          os << "'" << value.run() << ":" << value.luminosityBlock() << ":" << value.event() << "'";
        else
          os << value.run() << ":" << value.luminosityBlock() << ":" << value.event();
      }
    }

    template <>
    void writeValueInVector<LuminosityBlockID>(std::ostream& os, LuminosityBlockID const& value, ValueFormat format) {
      if (format == CFI)
        os << "'" << value.run() << ":" << value.luminosityBlock() << "'";
      else
        os << value.run() << ":" << value.luminosityBlock();
    }

    template <>
    void writeValueInVector<InputTag>(std::ostream& os, InputTag const& value, ValueFormat) {
      os << "'" << value.label();
      if (!value.instance().empty() || !value.process().empty()) {
        os << ":" << value.instance();
      }
      if (!value.process().empty()) {
        os << ":" << value.process();
      }
      os << "'";
    }

    template <>
    void writeValueInVector<ESInputTag>(std::ostream& os, ESInputTag const& value, ValueFormat) {
      os << "'" << value.module() << ":" << value.data() << "'";
    }

    template <typename T>
    void writeValueInVectorWithSpace(
        T const& value, std::ostream& os, int indentation, bool& startWithComma, ValueFormat format, int& i) {
      if (startWithComma && format == CFI)
        os << ",";
      startWithComma = true;
      os << "\n" << std::setw(indentation) << "";
      if (format == DOC)
        os << "[" << i << "]: ";
      writeValueInVector<T>(os, value, format);
      ++i;
    }

    template <typename T>
    void writeVector(std::ostream& os, int indentation, std::vector<T> const& value_, ValueFormat format) {
      std::ios_base::fmtflags ff = os.flags(std::ios_base::dec);
      char oldFill = os.fill();
      os.width(0);
      if (value_.empty() && format == DOC) {
        os << "empty";
      } else if (value_.size() == 1U && format == CFI) {
        writeValueInVector<T>(os, value_[0], format);
      } else if (!value_.empty()) {
        if (format == DOC)
          os << "(vector size = " << value_.size() << ")";
        if (format == CFI and value_.size() > 255U)
          os << " *(";
        os.fill(' ');
        bool startWithComma = false;
        int i = 0;
        for_all(value_,
                std::bind(&writeValueInVectorWithSpace<T>,
                          std::placeholders::_1,
                          std::ref(os),
                          indentation + 2,
                          std::ref(startWithComma),
                          format,
                          std::ref(i)));
        if (format == CFI)
          os << "\n" << std::setw(indentation) << "";
        if (format == CFI and value_.size() > 255U)
          os << ") ";
      }
      os.flags(ff);
      os.fill(oldFill);
    }

    void writeValue(std::ostream& os, int, int const& value_, ValueFormat format) {
      writeValue<int>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format) {
      writeVector<int>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, unsigned const& value_, ValueFormat format) {
      writeValue<unsigned>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format) {
      writeVector<unsigned>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, long long const& value_, ValueFormat format) {
      writeValue<long long>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format) {
      writeVector<long long>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, unsigned long long const& value_, ValueFormat format) {
      writeValue<unsigned long long>(os, value_, format);
    }

    void writeValue(std::ostream& os,
                    int indentation,
                    std::vector<unsigned long long> const& value_,
                    ValueFormat format) {
      writeVector<unsigned long long>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, double const& value_, ValueFormat format) {
      writeValue<double>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format) {
      writeVector<double>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, bool const& value_, ValueFormat format) {
      writeValue<bool>(os, value_, format);
    }

    void writeValue(std::ostream& os, int, std::string const& value_, ValueFormat format) {
      writeValue<std::string>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format) {
      writeVector<std::string>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, EventID const& value_, ValueFormat format) {
      writeValue<EventID>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format) {
      writeVector<EventID>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, LuminosityBlockID const& value_, ValueFormat format) {
      writeValue<LuminosityBlockID>(os, value_, format);
    }

    void writeValue(std::ostream& os,
                    int indentation,
                    std::vector<LuminosityBlockID> const& value_,
                    ValueFormat format) {
      writeVector<LuminosityBlockID>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, LuminosityBlockRange const& value_, ValueFormat format) {
      writeValue<LuminosityBlockRange>(os, value_, format);
    }

    void writeValue(std::ostream& os,
                    int indentation,
                    std::vector<LuminosityBlockRange> const& value_,
                    ValueFormat format) {
      writeVector<LuminosityBlockRange>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, EventRange const& value_, ValueFormat format) {
      writeValue<EventRange>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format) {
      writeVector<EventRange>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, InputTag const& value_, ValueFormat format) {
      writeValue<InputTag>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format) {
      writeVector<InputTag>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, ESInputTag const& value_, ValueFormat format) {
      writeValue<ESInputTag>(os, value_, format);
    }

    void writeValue(std::ostream& os, int indentation, std::vector<ESInputTag> const& value_, ValueFormat format) {
      writeVector<ESInputTag>(os, indentation, value_, format);
    }

    void writeValue(std::ostream& os, int, FileInPath const& value_, ValueFormat format) {
      writeValue<FileInPath>(os, value_, format);
    }

    bool hasNestedContent(int const&) { return false; }
    bool hasNestedContent(std::vector<int> const& value) { return value.size() > 5U; }
    bool hasNestedContent(unsigned const&) { return false; }
    bool hasNestedContent(std::vector<unsigned> const& value) { return value.size() > 5U; }
    bool hasNestedContent(long long const&) { return false; }
    bool hasNestedContent(std::vector<long long> const& value) { return value.size() > 5U; }
    bool hasNestedContent(unsigned long long const&) { return false; }
    bool hasNestedContent(std::vector<unsigned long long> const& value) { return value.size() > 5U; }
    bool hasNestedContent(double const&) { return false; }
    bool hasNestedContent(std::vector<double> const& value) { return value.size() > 5U; }
    bool hasNestedContent(bool const&) { return false; }
    bool hasNestedContent(std::string const&) { return false; }
    bool hasNestedContent(std::vector<std::string> const& value) { return value.size() > 5U; }
    bool hasNestedContent(EventID const&) { return false; }
    bool hasNestedContent(std::vector<EventID> const& value) { return value.size() > 5U; }
    bool hasNestedContent(LuminosityBlockID const&) { return false; }
    bool hasNestedContent(std::vector<LuminosityBlockID> const& value) { return value.size() > 5U; }
    bool hasNestedContent(LuminosityBlockRange const&) { return false; }
    bool hasNestedContent(std::vector<LuminosityBlockRange> const& value) { return value.size() > 5U; }
    bool hasNestedContent(EventRange const&) { return false; }
    bool hasNestedContent(std::vector<EventRange> const& value) { return value.size() > 5U; }
    bool hasNestedContent(InputTag const&) { return false; }
    bool hasNestedContent(std::vector<InputTag> const& value) { return value.size() > 5U; }
    bool hasNestedContent(ESInputTag const&) { return false; }
    bool hasNestedContent(std::vector<ESInputTag> const& value) { return value.size() > 5U; }
    bool hasNestedContent(FileInPath const&) { return false; }
  }  // namespace writeParameterValue
}  // namespace edm