ParameterDescription

ParameterDescription

ParameterDescription

ValueFormat

Macros

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
#ifndef FWCore_ParameterSet_ParameterDescription_h
#define FWCore_ParameterSet_ParameterDescription_h
// -*- C++ -*-
//
// Package:     ParameterSet
// Class  :     ParameterDescription
//
/**\class ParameterDescription ParameterDescription.h FWCore/ParameterSet/interface/ParameterDescription.h

 Description: <one line class summary>

 Usage:
    <usage>

*/
//
// Original Author:  Chris Jones
//         Created:  Thu Aug  2 15:33:51 EDT 2007
//

#include "FWCore/ParameterSet/interface/ParameterDescriptionBase.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescriptionTraits.h"
#include "FWCore/Utilities/interface/value_ptr.h"

#include <string>
#include <vector>
#include <iosfwd>
#include <set>

namespace edm {

  class ParameterSetDescription;

  class EventID;
  class LuminosityBlockID;
  class LuminosityBlockRange;
  class EventRange;
  class InputTag;
  class ESInputTag;
  class FileInPath;
  class DocFormatHelper;

  namespace writeParameterValue {

    enum ValueFormat { CFI, DOC };

    void writeValue(std::ostream& os, int indentation, int const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, unsigned const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, long long const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, unsigned long long const& value_, ValueFormat format);
    void writeValue(std::ostream& os,
                    int indentation,
                    std::vector<unsigned long long> const& value_,
                    ValueFormat format);
    void writeValue(std::ostream& os, int indentation, double const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, bool const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::string const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, EventID const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, LuminosityBlockID const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockID> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, LuminosityBlockRange const& value_, ValueFormat format);
    void writeValue(std::ostream& os,
                    int indentation,
                    std::vector<LuminosityBlockRange> const& value_,
                    ValueFormat format);
    void writeValue(std::ostream& os, int indentation, EventRange const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, InputTag const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, ESInputTag const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, std::vector<ESInputTag> const& value_, ValueFormat format);
    void writeValue(std::ostream& os, int indentation, FileInPath const& value_, ValueFormat format);

    bool hasNestedContent(int const& value);
    bool hasNestedContent(std::vector<int> const& value);
    bool hasNestedContent(unsigned const& value);
    bool hasNestedContent(std::vector<unsigned> const& value);
    bool hasNestedContent(long long const& value);
    bool hasNestedContent(std::vector<long long> const& value);
    bool hasNestedContent(unsigned long long const& value);
    bool hasNestedContent(std::vector<unsigned long long> const& value);
    bool hasNestedContent(double const& value);
    bool hasNestedContent(std::vector<double> const& value);
    bool hasNestedContent(bool const& value);
    bool hasNestedContent(std::string const& value);
    bool hasNestedContent(std::vector<std::string> const& value);
    bool hasNestedContent(EventID const& value);
    bool hasNestedContent(std::vector<EventID> const& value);
    bool hasNestedContent(LuminosityBlockID const& value);
    bool hasNestedContent(std::vector<LuminosityBlockID> const& value);
    bool hasNestedContent(LuminosityBlockRange const& value);
    bool hasNestedContent(std::vector<LuminosityBlockRange> const& value);
    bool hasNestedContent(EventRange const& value);
    bool hasNestedContent(std::vector<EventRange> const& value);
    bool hasNestedContent(InputTag const& value);
    bool hasNestedContent(std::vector<InputTag> const& value);
    bool hasNestedContent(ESInputTag const& value);
    bool hasNestedContent(std::vector<ESInputTag> const& value);
    bool hasNestedContent(FileInPath const& value);
  }  // namespace writeParameterValue

  template <typename T>
  class ParameterDescription : public ParameterDescriptionBase {
  public:
    ParameterDescription(std::string const& iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
        :  // WARNING: the toEnum function is intentionally undefined if the template
          // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
          // are handled by full template specializations below.  In the first case.
          // ParameterSetDescription should be used instead of ParameterSet.
          // In the second case the function arguments are completely different.
          // Note that this template parameter is most often passed through from
          // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
          // use the addVPSet* versions of those functions.
          ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
          value_(value) {}

    ParameterDescription(char const* iLabel, T const& value, bool isTracked, Comment const& iComment = Comment())
        :  // WARNING: the toEnum function is intentionally undefined if the template
          // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
          // are handled by full template specializations below.  In the first case.
          // ParameterSetDescription should be used instead of ParameterSet.
          // In the second case the function arguments are completely different.
          // Note that this template parameter is most often passed through from
          // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
          // use the addVPSet* versions of those functions.
          ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true, iComment),
          value_(value) {}

    ParameterDescription(std::string const& iLabel, bool isTracked, Comment const& iComment = Comment())
        :  // WARNING: the toEnum function is intentionally undefined if the template
          // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
          // are handled by full template specializations below.  In the first case.
          // ParameterSetDescription should be used instead of ParameterSet.
          // In the second case the function arguments are completely different.
          // Note that this template parameter is most often passed through from
          // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
          // use the addVPSet* versions of those functions.
          ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
          value_() {}

    ParameterDescription(char const* iLabel, bool isTracked, Comment const& iComment = Comment())
        :  // WARNING: the toEnum function is intentionally undefined if the template
          // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
          // are handled by full template specializations below.  In the first case.
          // ParameterSetDescription should be used instead of ParameterSet.
          // In the second case the function arguments are completely different.
          // Note that this template parameter is most often passed through from
          // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
          // use the addVPSet* versions of those functions.
          ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false, iComment),
          value_() {}

    ~ParameterDescription() override {}

    ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }

    T getDefaultValue() const { return value_; }

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

    bool hasNestedContent_() const override {
      if (!hasDefault())
        return false;
      return writeParameterValue::hasNestedContent(value_);
    }

    using ParameterDescriptionNode::writeCfi_;
    void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override {
      writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::CFI);
    }

    void writeDoc_(std::ostream& os, int indentation) const override {
      writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::DOC);
    }

    bool exists_(ParameterSet const& pset, bool isTracked) const override {
      return pset.existsAs<T>(label(), isTracked);
    }

    void insertDefault_(ParameterSet& pset) const override {
      if (isTracked()) {
        pset.addParameter(label(), value_);
      } else {
        pset.addUntrackedParameter(label(), value_);
      }
    }

    T value_;
  };

  template <>
  class ParameterDescription<ParameterSetDescription> : public ParameterDescriptionBase {
  public:
    ParameterDescription(std::string const& iLabel,
                         ParameterSetDescription const& value,
                         bool isTracked,
                         Comment const& iComment = Comment());

    ParameterDescription(char const* iLabel,
                         ParameterSetDescription const& value,
                         bool isTracked,
                         Comment const& iComment = Comment());

    ~ParameterDescription() override;

    ParameterSetDescription const* parameterSetDescription() const override;
    ParameterSetDescription* parameterSetDescription() override;

    ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }

  private:
    void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, Modifier modifier) const override;

    void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;

    bool hasNestedContent_() const override;

    void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;

    bool exists_(ParameterSet const& pset) const override;

    using ParameterDescriptionNode::writeCfi_;
    void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;

    void writeDoc_(std::ostream& os, int indentation) const override;

    bool exists_(ParameterSet const& pset, bool isTracked) const override;

    void insertDefault_(ParameterSet& pset) const override;

    value_ptr<ParameterSetDescription> psetDesc_;
  };

  template <>
  class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
  public:
    ParameterDescription(std::string const& iLabel,
                         ParameterSetDescription const& psetDesc,
                         bool isTracked,
                         std::vector<ParameterSet> const& vPset,
                         Comment const& iComment = Comment());

    ParameterDescription(char const* iLabel,
                         ParameterSetDescription const& psetDesc,
                         bool isTracked,
                         std::vector<ParameterSet> const& vPset,
                         Comment const& iComment = Comment());

    ParameterDescription(std::string const& iLabel,
                         ParameterSetDescription const& psetDesc,
                         bool isTracked,
                         Comment const& iComment = Comment());

    ParameterDescription(char const* iLabel,
                         ParameterSetDescription const& psetDesc,
                         bool isTracked,
                         Comment const& iComment = Comment());

    ~ParameterDescription() override;

    ParameterSetDescription const* parameterSetDescription() const override;
    ParameterSetDescription* parameterSetDescription() override;

    ParameterDescriptionNode* clone() const override { return new ParameterDescription(*this); }

    void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }

  private:
    void validate_(ParameterSet& pset, std::set<std::string>& validatedLabels, Modifier modifier) const override;

    void printDefault_(std::ostream& os, bool writeToCfi, DocFormatHelper& dfh) const override;

    bool hasNestedContent_() const override;

    void printNestedContent_(std::ostream& os, bool optional, DocFormatHelper& dfh) const override;

    bool exists_(ParameterSet const& pset) const override;

    using ParameterDescriptionNode::writeCfi_;
    void writeCfi_(std::ostream& os, int indentation, CfiOptions&) const override;

    void writeDoc_(std::ostream& os, int indentation) const override;

    bool exists_(ParameterSet const& pset, bool isTracked) const override;

    void insertDefault_(ParameterSet& pset) const override;

    static void writeOneElementToCfi(
        ParameterSet const& pset, std::ostream& os, int indentation, CfiOptions&, bool& nextOneStartsWithAComma);

    value_ptr<ParameterSetDescription> psetDesc_;
    std::vector<ParameterSet> vPset_;
    bool partOfDefaultOfVPSet_;
  };
}  // namespace edm
#endif