Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:27

0001 
0002 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
0003 #include "FWCore/ParameterSet/interface/ParameterDescriptionCases.h"
0004 #include "FWCore/ParameterSet/src/ANDGroupDescription.h"
0005 #include "FWCore/ParameterSet/src/ORGroupDescription.h"
0006 #include "FWCore/ParameterSet/src/XORGroupDescription.h"
0007 #include "FWCore/ParameterSet/interface/DocFormatHelper.h"
0008 
0009 #include <vector>
0010 #include <cassert>
0011 #include <ostream>
0012 
0013 #define TYPE_TO_ENUM(type, e_val)                      \
0014   template <>                                          \
0015   ParameterTypes ParameterTypeToEnum::toEnum<type>() { \
0016     return e_val;                                      \
0017   }
0018 #define TYPE_TO_NAME(type) \
0019   case k_##type:           \
0020     return #type
0021 
0022 namespace edm {
0023 
0024   class EventID;
0025   class LuminosityBlockID;
0026   class LuminosityBlockRange;
0027   class EventRange;
0028   class InputTag;
0029   class ESInputTag;
0030   class FileInPath;
0031 
0032   TYPE_TO_ENUM(int, k_int32)
0033   TYPE_TO_ENUM(std::vector<int>, k_vint32)
0034   TYPE_TO_ENUM(unsigned, k_uint32)
0035   TYPE_TO_ENUM(std::vector<unsigned>, k_vuint32)
0036   TYPE_TO_ENUM(long long, k_int64)
0037   TYPE_TO_ENUM(std::vector<long long>, k_vint64)
0038   TYPE_TO_ENUM(unsigned long long, k_uint64)
0039   TYPE_TO_ENUM(std::vector<unsigned long long>, k_vuint64)
0040   TYPE_TO_ENUM(double, k_double)
0041   TYPE_TO_ENUM(std::vector<double>, k_vdouble)
0042   TYPE_TO_ENUM(bool, k_bool)
0043   TYPE_TO_ENUM(std::string, k_string)
0044   TYPE_TO_ENUM(std::vector<std::string>, k_vstring)
0045   TYPE_TO_ENUM(EventID, k_EventID)
0046   TYPE_TO_ENUM(std::vector<EventID>, k_VEventID)
0047   TYPE_TO_ENUM(LuminosityBlockID, k_LuminosityBlockID)
0048   TYPE_TO_ENUM(std::vector<LuminosityBlockID>, k_VLuminosityBlockID)
0049   TYPE_TO_ENUM(InputTag, k_InputTag)
0050   TYPE_TO_ENUM(std::vector<InputTag>, k_VInputTag)
0051   TYPE_TO_ENUM(ESInputTag, k_ESInputTag)
0052   TYPE_TO_ENUM(std::vector<ESInputTag>, k_VESInputTag)
0053   TYPE_TO_ENUM(FileInPath, k_FileInPath)
0054   TYPE_TO_ENUM(LuminosityBlockRange, k_LuminosityBlockRange)
0055   TYPE_TO_ENUM(std::vector<LuminosityBlockRange>, k_VLuminosityBlockRange)
0056   TYPE_TO_ENUM(EventRange, k_EventRange)
0057   TYPE_TO_ENUM(std::vector<EventRange>, k_VEventRange)
0058   // These are intentionally not implemented to prevent one
0059   // from calling add<ParameterSet>.  One should call
0060   // add<ParameterSetDescription> instead.
0061   // TYPE_TO_ENUM(ParameterSet,k_PSet)
0062   // TYPE_TO_ENUM(std::vector<ParameterSet>,k_VPSet)
0063 
0064   std::string parameterTypeEnumToString(ParameterTypes iType) {
0065     switch (iType) {
0066       TYPE_TO_NAME(int32);
0067       TYPE_TO_NAME(vint32);
0068       TYPE_TO_NAME(uint32);
0069       TYPE_TO_NAME(vuint32);
0070       TYPE_TO_NAME(int64);
0071       TYPE_TO_NAME(vint64);
0072       TYPE_TO_NAME(uint64);
0073       TYPE_TO_NAME(vuint64);
0074       TYPE_TO_NAME(double);
0075       TYPE_TO_NAME(vdouble);
0076       TYPE_TO_NAME(bool);
0077       TYPE_TO_NAME(string);
0078       TYPE_TO_NAME(vstring);
0079       TYPE_TO_NAME(EventID);
0080       TYPE_TO_NAME(VEventID);
0081       TYPE_TO_NAME(LuminosityBlockID);
0082       TYPE_TO_NAME(VLuminosityBlockID);
0083       TYPE_TO_NAME(InputTag);
0084       TYPE_TO_NAME(VInputTag);
0085       TYPE_TO_NAME(ESInputTag);
0086       TYPE_TO_NAME(VESInputTag);
0087       TYPE_TO_NAME(FileInPath);
0088       TYPE_TO_NAME(PSet);
0089       TYPE_TO_NAME(VPSet);
0090       TYPE_TO_NAME(LuminosityBlockRange);
0091       TYPE_TO_NAME(VLuminosityBlockRange);
0092       TYPE_TO_NAME(EventRange);
0093       TYPE_TO_NAME(VEventRange);
0094       default:
0095         assert(false);
0096     }
0097     return "";
0098   }
0099 
0100   Comment::Comment() {}
0101   Comment::Comment(std::string const& iComment) : comment_(iComment) {}
0102   Comment::Comment(char const* iComment) : comment_(iComment) {}
0103 
0104   ParameterDescriptionNode::~ParameterDescriptionNode() {}
0105 
0106   void ParameterDescriptionNode::setComment(std::string const& value) { comment_ = value; }
0107 
0108   void ParameterDescriptionNode::setComment(char const* value) { comment_ = value; }
0109 
0110   void ParameterDescriptionNode::print(std::ostream& os, bool optional, bool writeToCfi, DocFormatHelper& dfh) const {
0111     if (hasNestedContent()) {
0112       dfh.incrementCounter();
0113     }
0114     print_(os, optional, writeToCfi, dfh);
0115   }
0116 
0117   void ParameterDescriptionNode::printNestedContent(std::ostream& os, bool optional, DocFormatHelper& dfh) const {
0118     if (hasNestedContent()) {
0119       dfh.incrementCounter();
0120       printNestedContent_(os, optional, dfh);
0121     }
0122   }
0123 
0124   void ParameterDescriptionNode::printSpaces(std::ostream& os, int n) {
0125     char oldFill = os.fill(' ');
0126     os.width(n);
0127     os << "";
0128     os.fill(oldFill);
0129   }
0130 
0131   // operator>> ---------------------------------------------
0132 
0133   std::unique_ptr<ParameterDescriptionCases<bool>> operator>>(bool caseValue, ParameterDescriptionNode const& node) {
0134     std::unique_ptr<ParameterDescriptionNode> clonedNode(node.clone());
0135     return caseValue >> std::move(clonedNode);
0136   }
0137 
0138   std::unique_ptr<ParameterDescriptionCases<int>> operator>>(int caseValue, ParameterDescriptionNode const& node) {
0139     std::unique_ptr<ParameterDescriptionNode> clonedNode(node.clone());
0140     return caseValue >> std::move(clonedNode);
0141   }
0142 
0143   std::unique_ptr<ParameterDescriptionCases<std::string>> operator>>(std::string const& caseValue,
0144                                                                      ParameterDescriptionNode const& node) {
0145     std::unique_ptr<ParameterDescriptionNode> clonedNode(node.clone());
0146     return caseValue >> std::move(clonedNode);
0147   }
0148 
0149   std::unique_ptr<ParameterDescriptionCases<std::string>> operator>>(char const* caseValue,
0150                                                                      ParameterDescriptionNode const& node) {
0151     std::unique_ptr<ParameterDescriptionNode> clonedNode(node.clone());
0152     return caseValue >> std::move(clonedNode);
0153   }
0154 
0155   std::unique_ptr<ParameterDescriptionCases<bool>> operator>>(bool caseValue,
0156                                                               std::unique_ptr<ParameterDescriptionNode> node) {
0157     return std::unique_ptr<ParameterDescriptionCases<bool>>(
0158         new ParameterDescriptionCases<bool>(caseValue, std::move(node)));
0159   }
0160 
0161   std::unique_ptr<ParameterDescriptionCases<int>> operator>>(int caseValue,
0162                                                              std::unique_ptr<ParameterDescriptionNode> node) {
0163     return std::unique_ptr<ParameterDescriptionCases<int>>(
0164         new ParameterDescriptionCases<int>(caseValue, std::move(node)));
0165   }
0166 
0167   std::unique_ptr<ParameterDescriptionCases<std::string>> operator>>(std::string const& caseValue,
0168                                                                      std::unique_ptr<ParameterDescriptionNode> node) {
0169     return std::unique_ptr<ParameterDescriptionCases<std::string>>(
0170         new ParameterDescriptionCases<std::string>(caseValue, std::move(node)));
0171   }
0172 
0173   std::unique_ptr<ParameterDescriptionCases<std::string>> operator>>(char const* caseValue,
0174                                                                      std::unique_ptr<ParameterDescriptionNode> node) {
0175     std::string caseValueString(caseValue);
0176     return std::unique_ptr<ParameterDescriptionCases<std::string>>(
0177         new ParameterDescriptionCases<std::string>(caseValue, std::move(node)));
0178   }
0179 
0180   // operator&& ---------------------------------------------
0181 
0182   std::unique_ptr<ParameterDescriptionNode> operator&&(ParameterDescriptionNode const& node_left,
0183                                                        ParameterDescriptionNode const& node_right) {
0184     return std::make_unique<ANDGroupDescription>(node_left, node_right);
0185   }
0186 
0187   std::unique_ptr<ParameterDescriptionNode> operator&&(std::unique_ptr<ParameterDescriptionNode> node_left,
0188                                                        ParameterDescriptionNode const& node_right) {
0189     return std::make_unique<ANDGroupDescription>(std::move(node_left), node_right);
0190   }
0191 
0192   std::unique_ptr<ParameterDescriptionNode> operator&&(ParameterDescriptionNode const& node_left,
0193                                                        std::unique_ptr<ParameterDescriptionNode> node_right) {
0194     return std::make_unique<ANDGroupDescription>(node_left, std::move(node_right));
0195   }
0196 
0197   std::unique_ptr<ParameterDescriptionNode> operator&&(std::unique_ptr<ParameterDescriptionNode> node_left,
0198                                                        std::unique_ptr<ParameterDescriptionNode> node_right) {
0199     return std::make_unique<ANDGroupDescription>(std::move(node_left), std::move(node_right));
0200   }
0201 
0202   // operator|| ---------------------------------------------
0203 
0204   std::unique_ptr<ParameterDescriptionNode> operator||(ParameterDescriptionNode const& node_left,
0205                                                        ParameterDescriptionNode const& node_right) {
0206     return std::make_unique<ORGroupDescription>(node_left, node_right);
0207   }
0208 
0209   std::unique_ptr<ParameterDescriptionNode> operator||(std::unique_ptr<ParameterDescriptionNode> node_left,
0210                                                        ParameterDescriptionNode const& node_right) {
0211     return std::make_unique<ORGroupDescription>(std::move(node_left), node_right);
0212   }
0213 
0214   std::unique_ptr<ParameterDescriptionNode> operator||(ParameterDescriptionNode const& node_left,
0215                                                        std::unique_ptr<ParameterDescriptionNode> node_right) {
0216     return std::make_unique<ORGroupDescription>(node_left, std::move(node_right));
0217   }
0218 
0219   std::unique_ptr<ParameterDescriptionNode> operator||(std::unique_ptr<ParameterDescriptionNode> node_left,
0220                                                        std::unique_ptr<ParameterDescriptionNode> node_right) {
0221     return std::make_unique<ORGroupDescription>(std::move(node_left), std::move(node_right));
0222   }
0223 
0224   // operator^  ---------------------------------------------
0225 
0226   std::unique_ptr<ParameterDescriptionNode> operator^(ParameterDescriptionNode const& node_left,
0227                                                       ParameterDescriptionNode const& node_right) {
0228     return std::make_unique<XORGroupDescription>(node_left, node_right);
0229   }
0230 
0231   std::unique_ptr<ParameterDescriptionNode> operator^(std::unique_ptr<ParameterDescriptionNode> node_left,
0232                                                       ParameterDescriptionNode const& node_right) {
0233     return std::make_unique<XORGroupDescription>(std::move(node_left), node_right);
0234   }
0235 
0236   std::unique_ptr<ParameterDescriptionNode> operator^(ParameterDescriptionNode const& node_left,
0237                                                       std::unique_ptr<ParameterDescriptionNode> node_right) {
0238     return std::make_unique<XORGroupDescription>(node_left, std::move(node_right));
0239   }
0240 
0241   std::unique_ptr<ParameterDescriptionNode> operator^(std::unique_ptr<ParameterDescriptionNode> node_left,
0242                                                       std::unique_ptr<ParameterDescriptionNode> node_right) {
0243     return std::make_unique<XORGroupDescription>(std::move(node_left), std::move(node_right));
0244   }
0245 }  // namespace edm