CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/FWCore/ParameterSet/interface/ParameterDescription.h

Go to the documentation of this file.
00001 #ifndef FWCore_ParameterSet_ParameterDescription_h
00002 #define FWCore_ParameterSet_ParameterDescription_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     ParameterSet
00006 // Class  :     ParameterDescription
00007 //
00016 //
00017 // Original Author:  Chris Jones
00018 //         Created:  Thu Aug  2 15:33:51 EDT 2007
00019 //
00020 
00021 #include "FWCore/ParameterSet/interface/ParameterDescriptionBase.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Utilities/interface/value_ptr.h"
00024 
00025 #include <string>
00026 #include <vector>
00027 #include <iosfwd>
00028 #include <set>
00029 
00030 namespace edm {
00031 
00032   class ParameterSetDescription;
00033 
00034   class EventID;
00035   class LuminosityBlockID;
00036   class LuminosityBlockRange;
00037   class EventRange;
00038   class InputTag;
00039   class FileInPath;
00040   class DocFormatHelper;
00041 
00042   namespace writeParameterValue {
00043 
00044     enum ValueFormat { CFI, DOC };
00045 
00046     void writeValue(std::ostream& os, int indentation, int const& value_, ValueFormat format);
00047     void writeValue(std::ostream& os, int indentation, std::vector<int> const& value_, ValueFormat format);
00048     void writeValue(std::ostream& os, int indentation, unsigned const& value_, ValueFormat format);
00049     void writeValue(std::ostream& os, int indentation, std::vector<unsigned> const& value_, ValueFormat format);
00050     void writeValue(std::ostream& os, int indentation, long long const& value_, ValueFormat format);
00051     void writeValue(std::ostream& os, int indentation, std::vector<long long> const& value_, ValueFormat format);
00052     void writeValue(std::ostream& os, int indentation, unsigned long long const& value_, ValueFormat format);
00053     void writeValue(std::ostream& os, int indentation, std::vector<unsigned long long> const& value_, ValueFormat format);
00054     void writeValue(std::ostream& os, int indentation, double const& value_, ValueFormat format);
00055     void writeValue(std::ostream& os, int indentation, std::vector<double> const& value_, ValueFormat format);
00056     void writeValue(std::ostream& os, int indentation, bool const& value_, ValueFormat format);
00057     void writeValue(std::ostream& os, int indentation, std::string const& value_, ValueFormat format);
00058     void writeValue(std::ostream& os, int indentation, std::vector<std::string> const& value_, ValueFormat format);
00059     void writeValue(std::ostream& os, int indentation, EventID const& value_, ValueFormat format);
00060     void writeValue(std::ostream& os, int indentation, std::vector<EventID> const& value_, ValueFormat format);
00061     void writeValue(std::ostream& os, int indentation, LuminosityBlockID const& value_, ValueFormat format);
00062     void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockID> const& value_, ValueFormat format);
00063     void writeValue(std::ostream& os, int indentation, LuminosityBlockRange const& value_, ValueFormat format);
00064     void writeValue(std::ostream& os, int indentation, std::vector<LuminosityBlockRange> const& value_, ValueFormat format);
00065     void writeValue(std::ostream& os, int indentation, EventRange const& value_, ValueFormat format);
00066     void writeValue(std::ostream& os, int indentation, std::vector<EventRange> const& value_, ValueFormat format);
00067     void writeValue(std::ostream& os, int indentation, InputTag const& value_, ValueFormat format);
00068     void writeValue(std::ostream& os, int indentation, std::vector<InputTag> const& value_, ValueFormat format);
00069     void writeValue(std::ostream& os, int indentation, FileInPath const& value_, ValueFormat format);
00070 
00071     bool hasNestedContent(int const& value);
00072     bool hasNestedContent(std::vector<int> const& value);
00073     bool hasNestedContent(unsigned const& value);
00074     bool hasNestedContent(std::vector<unsigned> const& value);
00075     bool hasNestedContent(long long const& value);
00076     bool hasNestedContent(std::vector<long long> const& value);
00077     bool hasNestedContent(unsigned long long const& value);
00078     bool hasNestedContent(std::vector<unsigned long long> const& value);
00079     bool hasNestedContent(double const& value);
00080     bool hasNestedContent(std::vector<double> const& value);
00081     bool hasNestedContent(bool const& value);
00082     bool hasNestedContent(std::string const& value);
00083     bool hasNestedContent(std::vector<std::string> const& value);
00084     bool hasNestedContent(EventID const& value);
00085     bool hasNestedContent(std::vector<EventID> const& value);
00086     bool hasNestedContent(LuminosityBlockID const& value);
00087     bool hasNestedContent(std::vector<LuminosityBlockID> const& value);
00088     bool hasNestedContent(LuminosityBlockRange const& value);
00089     bool hasNestedContent(std::vector<LuminosityBlockRange> const& value);
00090     bool hasNestedContent(EventRange const& value);
00091     bool hasNestedContent(std::vector<EventRange> const& value);
00092     bool hasNestedContent(InputTag const& value);
00093     bool hasNestedContent(std::vector<InputTag> const& value);
00094     bool hasNestedContent(FileInPath const& value);
00095   }
00096 
00097   template<typename T>
00098   class ParameterDescription : public ParameterDescriptionBase {
00099   public:
00100 
00101     ParameterDescription(std::string const& iLabel,
00102                          T const& value,
00103                          bool isTracked) :
00104       // WARNING: the toEnum function is intentionally undefined if the template
00105       // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
00106       // are handled by full template specializations below.  In the first case.
00107       // ParameterSetDescription should be used instead of ParameterSet.
00108       // In the second case the function arguments are completely different.
00109       // Note that this template parameter is most often passed through from
00110       // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
00111       // use the addVPSet* versions of those functions.
00112       ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true),
00113       value_(value) {
00114     }
00115 
00116     ParameterDescription(char const* iLabel,
00117                          T const& value,
00118                          bool isTracked) :
00119       // WARNING: the toEnum function is intentionally undefined if the template
00120       // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
00121       // are handled by full template specializations below.  In the first case.
00122       // ParameterSetDescription should be used instead of ParameterSet.
00123       // In the second case the function arguments are completely different.
00124       // Note that this template parameter is most often passed through from
00125       // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
00126       // use the addVPSet* versions of those functions.
00127       ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, true),
00128       value_(value) {
00129     }
00130 
00131     ParameterDescription(std::string const& iLabel,
00132                          bool isTracked) :
00133       // WARNING: the toEnum function is intentionally undefined if the template
00134       // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
00135       // are handled by full template specializations below.  In the first case.
00136       // ParameterSetDescription should be used instead of ParameterSet.
00137       // In the second case the function arguments are completely different.
00138       // Note that this template parameter is most often passed through from
00139       // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
00140       // use the addVPSet* versions of those functions.
00141       ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false),
00142       value_() {
00143     }
00144 
00145     ParameterDescription(char const* iLabel,
00146                          bool isTracked) :
00147       // WARNING: the toEnum function is intentionally undefined if the template
00148       // parameter is ParameterSet or vector<ParameterSet>.  Both of these cases
00149       // are handled by full template specializations below.  In the first case.
00150       // ParameterSetDescription should be used instead of ParameterSet.
00151       // In the second case the function arguments are completely different.
00152       // Note that this template parameter is most often passed through from
00153       // an add*<T> function of class ParameterSetDescription. For vector<ParameterSet>
00154       // use the addVPSet* versions of those functions.
00155       ParameterDescriptionBase(iLabel, ParameterTypeToEnum::toEnum<T>(), isTracked, false),
00156       value_() {
00157     }
00158 
00159     virtual ~ParameterDescription() { }
00160 
00161     virtual ParameterDescriptionNode* clone() const {
00162       return new ParameterDescription(*this);
00163     }
00164 
00165     T getDefaultValue() const { return value_; }
00166 
00167   private:
00168 
00169     virtual bool exists_(ParameterSet const& pset) const {
00170       return pset.existsAs<T>(label(), isTracked());
00171     }
00172 
00173     virtual bool hasNestedContent_() {
00174       if (!hasDefault()) return false;
00175       return writeParameterValue::hasNestedContent(value_);
00176     }
00177 
00178     virtual void writeCfi_(std::ostream& os, int indentation) const {
00179       writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::CFI);
00180     }
00181 
00182     virtual void writeDoc_(std::ostream& os, int indentation) const {
00183       writeParameterValue::writeValue(os, indentation, value_, writeParameterValue::DOC);
00184     }
00185 
00186     virtual bool exists_(ParameterSet const& pset, bool isTracked) const {
00187       return pset.existsAs<T>(label(), isTracked);
00188     }
00189 
00190     virtual void insertDefault_(ParameterSet& pset) const {
00191       if (isTracked()) {
00192         pset.addParameter(label(), value_);
00193       }
00194       else {
00195         pset.addUntrackedParameter(label(), value_);
00196       }
00197     }
00198 
00199     T value_;
00200   };
00201 
00202   template<>
00203   class ParameterDescription<ParameterSetDescription> : public ParameterDescriptionBase {
00204 
00205   public:
00206 
00207     ParameterDescription(std::string const& iLabel,
00208                          ParameterSetDescription const& value,
00209                          bool isTracked);
00210 
00211     ParameterDescription(char const* iLabel,
00212                          ParameterSetDescription const& value,
00213                          bool isTracked);
00214 
00215     virtual ~ParameterDescription();
00216 
00217     virtual ParameterSetDescription const* parameterSetDescription() const;
00218     virtual ParameterSetDescription * parameterSetDescription();
00219 
00220     virtual ParameterDescriptionNode* clone() const {
00221       return new ParameterDescription(*this);
00222     }
00223 
00224   private:
00225 
00226     virtual void validate_(ParameterSet& pset,
00227                            std::set<std::string>& validatedLabels,
00228                            bool optional) const;
00229 
00230     virtual void printDefault_(std::ostream& os,
00231                                  bool writeToCfi,
00232                                  DocFormatHelper& dfh);
00233 
00234     virtual bool hasNestedContent_();
00235 
00236     virtual void printNestedContent_(std::ostream& os,
00237                                      bool optional,
00238                                      DocFormatHelper& dfh);
00239 
00240     virtual bool exists_(ParameterSet const& pset) const;
00241 
00242     virtual void writeCfi_(std::ostream& os, int indentation) const;
00243 
00244     virtual void writeDoc_(std::ostream& os, int indentation) const;
00245 
00246     virtual bool exists_(ParameterSet const& pset, bool isTracked) const;
00247 
00248     virtual void insertDefault_(ParameterSet& pset) const;
00249 
00250     value_ptr<ParameterSetDescription> psetDesc_;
00251   };
00252 
00253   template<>
00254   class ParameterDescription<std::vector<ParameterSet> > : public ParameterDescriptionBase {
00255 
00256   public:
00257 
00258     ParameterDescription(std::string const& iLabel,
00259                          ParameterSetDescription const& psetDesc,
00260                          bool isTracked,
00261                          std::vector<ParameterSet> const& vPset);
00262 
00263     ParameterDescription(char const* iLabel,
00264                          ParameterSetDescription const& psetDesc,
00265                          bool isTracked,
00266                          std::vector<ParameterSet> const& vPset);
00267 
00268     ParameterDescription(std::string const& iLabel,
00269                          ParameterSetDescription const& psetDesc,
00270                          bool isTracked);
00271 
00272     ParameterDescription(char const* iLabel,
00273                          ParameterSetDescription const& psetDesc,
00274                          bool isTracked);
00275 
00276     virtual ~ParameterDescription();
00277 
00278     virtual ParameterSetDescription const* parameterSetDescription() const;
00279     virtual ParameterSetDescription * parameterSetDescription();
00280 
00281     virtual ParameterDescriptionNode* clone() const {
00282       return new ParameterDescription(*this);
00283     }
00284 
00285     void setPartOfDefaultOfVPSet(bool value) { partOfDefaultOfVPSet_ = value; }
00286 
00287   private:
00288 
00289     virtual void validate_(ParameterSet& pset,
00290                            std::set<std::string>& validatedLabels,
00291                            bool optional) const;
00292 
00293     virtual void printDefault_(std::ostream& os,
00294                                bool writeToCfi,
00295                                DocFormatHelper& dfh);
00296 
00297     virtual bool hasNestedContent_();
00298 
00299     virtual void printNestedContent_(std::ostream& os,
00300                                      bool optional,
00301                                      DocFormatHelper& dfh);
00302 
00303     virtual bool exists_(ParameterSet const& pset) const;
00304 
00305     virtual void writeCfi_(std::ostream& os, int indentation) const;
00306 
00307     virtual void writeDoc_(std::ostream& os, int indentation) const;
00308 
00309     virtual bool exists_(ParameterSet const& pset, bool isTracked) const;
00310 
00311     virtual void insertDefault_(ParameterSet& pset) const;
00312 
00313     static void writeOneElementToCfi(ParameterSet const& pset,
00314                                      std::ostream& os,
00315                                      int indentation,
00316                                      bool& nextOneStartsWithAComma);
00317 
00318     value_ptr<ParameterSetDescription> psetDesc_;
00319     std::vector<ParameterSet> vPset_;
00320     bool partOfDefaultOfVPSet_;
00321   };
00322 }
00323 #endif