File indexing completed on 2024-04-06 12:07:15
0001 #include "DQM/EcalCommon/interface/MESetUtils.h"
0002
0003 #include "DQM/EcalCommon/interface/MESetChannel.h"
0004 #include "DQM/EcalCommon/interface/MESetDet0D.h"
0005 #include "DQM/EcalCommon/interface/MESetDet1D.h"
0006 #include "DQM/EcalCommon/interface/MESetDet2D.h"
0007 #include "DQM/EcalCommon/interface/MESetEcal.h"
0008 #include "DQM/EcalCommon/interface/MESetMulti.h"
0009 #include "DQM/EcalCommon/interface/MESetNonObject.h"
0010 #include "DQM/EcalCommon/interface/MESetProjection.h"
0011 #include "DQM/EcalCommon/interface/MESetTrend.h"
0012
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015
0016 namespace ecaldqm {
0017 using dqm::reco::MonitorElement;
0018 MESet *createMESet(edm::ParameterSet const &_MEParam) {
0019 std::string path(_MEParam.getUntrackedParameter<std::string>("path"));
0020 binning::ObjectType otype(binning::translateObjectType(_MEParam.getUntrackedParameter<std::string>("otype")));
0021 binning::BinningType btype(binning::translateBinningType(_MEParam.getUntrackedParameter<std::string>("btype")));
0022 MonitorElement::Kind kind(binning::translateKind(_MEParam.getUntrackedParameter<std::string>("kind")));
0023
0024 binning::AxisSpecs xaxis, yaxis, zaxis;
0025 bool hasXaxis(_MEParam.existsAs<edm::ParameterSet>("xaxis", false));
0026 if (hasXaxis)
0027 xaxis = binning::formAxis(_MEParam.getUntrackedParameterSet("xaxis"));
0028 bool hasYaxis(_MEParam.existsAs<edm::ParameterSet>("yaxis", false));
0029 if (hasYaxis)
0030 yaxis = binning::formAxis(_MEParam.getUntrackedParameterSet("yaxis"));
0031 bool hasZaxis(_MEParam.existsAs<edm::ParameterSet>("zaxis", false));
0032 if (hasZaxis)
0033 zaxis = binning::formAxis(_MEParam.getUntrackedParameterSet("zaxis"));
0034
0035 MESet *set(nullptr);
0036
0037 if (btype == binning::kTrend) {
0038 MESetTrend *setTrend(new MESetTrend(path, otype, btype, kind, hasYaxis ? &yaxis : nullptr));
0039 if (_MEParam.existsAs<bool>("minutely", false) && _MEParam.getUntrackedParameter<bool>("minutely"))
0040 setTrend->setMinutely();
0041 if (_MEParam.existsAs<bool>("cumulative", false) && _MEParam.getUntrackedParameter<bool>("cumulative"))
0042 setTrend->setCumulative();
0043 if (_MEParam.existsAs<bool>("shiftAxis", false) && _MEParam.getUntrackedParameter<bool>("shiftAxis"))
0044 setTrend->setShiftAxis();
0045 set = setTrend;
0046 } else if (otype == binning::nObjType)
0047 set = new MESetNonObject(path,
0048 otype,
0049 btype,
0050 kind,
0051 hasXaxis ? &xaxis : nullptr,
0052 hasYaxis ? &yaxis : nullptr,
0053 hasZaxis ? &zaxis : nullptr);
0054 else if (otype == binning::kChannel)
0055
0056 #if 0
0057 set = new MESetChannel(path, otype, btype, kind);
0058 #else
0059 set = nullptr;
0060 #endif
0061 else if (btype == binning::kProjEta || btype == binning::kProjPhi)
0062 set = new MESetProjection(path, otype, btype, kind, hasYaxis ? &yaxis : nullptr);
0063 else {
0064 unsigned logicalDimensions(-1);
0065 switch (kind) {
0066 case MonitorElement::Kind::REAL:
0067 logicalDimensions = 0;
0068 break;
0069 case MonitorElement::Kind::TH1F:
0070 case MonitorElement::Kind::TPROFILE:
0071 logicalDimensions = 1;
0072 break;
0073 case MonitorElement::Kind::TH2F:
0074 case MonitorElement::Kind::TPROFILE2D:
0075 logicalDimensions = 2;
0076 break;
0077 default:
0078 break;
0079 }
0080
0081
0082
0083 if (logicalDimensions == 2 && hasYaxis && btype != binning::kUser)
0084 logicalDimensions = 1;
0085
0086 if (logicalDimensions > 2 || (btype == binning::kReport && logicalDimensions != 0))
0087 throw cms::Exception("InvalidConfiguration") << "Cannot create MESet at " << path;
0088
0089 if (btype == binning::kUser)
0090 set = new MESetEcal(path,
0091 otype,
0092 btype,
0093 kind,
0094 logicalDimensions,
0095 hasXaxis ? &xaxis : nullptr,
0096 hasYaxis ? &yaxis : nullptr,
0097 hasZaxis ? &zaxis : nullptr);
0098 else if (logicalDimensions == 0)
0099 set = new MESetDet0D(path, otype, btype, kind);
0100 else if (logicalDimensions == 1)
0101 set = new MESetDet1D(path, otype, btype, kind, hasYaxis ? &yaxis : nullptr);
0102 else if (logicalDimensions == 2)
0103 set = new MESetDet2D(path, otype, btype, kind, hasZaxis ? &zaxis : nullptr);
0104 }
0105
0106 if (_MEParam.existsAs<edm::ParameterSet>("multi", false)) {
0107 typedef std::vector<std::string> VString;
0108
0109 edm::ParameterSet const &multiParams(_MEParam.getUntrackedParameterSet("multi"));
0110 VString replacementNames(multiParams.getParameterNames());
0111 if (replacementNames.empty())
0112 throw cms::Exception("InvalidConfiguration") << "0 multiplicity for MESet at " << path;
0113
0114 MESetMulti::ReplCandidates candidates;
0115 for (unsigned iD(0); iD != replacementNames.size(); ++iD) {
0116 VString reps;
0117 if (multiParams.existsAs<VString>(replacementNames[iD], false))
0118 reps = multiParams.getUntrackedParameter<VString>(replacementNames[iD]);
0119 else if (multiParams.existsAs<std::vector<int>>(replacementNames[iD], false)) {
0120 std::vector<int> repInts(multiParams.getUntrackedParameter<std::vector<int>>(replacementNames[iD]));
0121 for (unsigned iR(0); iR != repInts.size(); ++iR)
0122 reps.push_back(std::to_string(repInts[iR]));
0123 }
0124
0125 if (reps.empty())
0126 throw cms::Exception("InvalidConfiguration") << "0 multiplicity for MESet at " << path;
0127
0128 candidates[replacementNames[iD]] = reps;
0129 }
0130 MESetMulti *multi(new MESetMulti(*set, candidates));
0131 delete set;
0132 set = multi;
0133 }
0134
0135 if (!set)
0136 throw cms::Exception("InvalidConfiguration") << "MESet " << path << " could not be initialized";
0137
0138 if (_MEParam.getUntrackedParameter<bool>("perLumi"))
0139 set->setLumiFlag();
0140
0141 return set;
0142 }
0143
0144 void fillMESetDescriptions(edm::ParameterSetDescription &_desc) {
0145 _desc.addUntracked<std::string>("path");
0146 _desc.addUntracked<std::string>("kind");
0147 _desc.addUntracked<std::string>("otype");
0148 _desc.addUntracked<std::string>("btype");
0149 _desc.addUntracked<std::string>("description");
0150 _desc.addUntracked<bool>("online", false);
0151 _desc.addUntracked<bool>("perLumi", false);
0152 _desc.addOptionalUntracked<bool>("minutely");
0153 _desc.addOptionalUntracked<bool>("cumulative");
0154 _desc.addOptionalUntracked<bool>("shiftAxis");
0155
0156 edm::ParameterSetDescription axisParameters;
0157 binning::fillAxisDescriptions(axisParameters);
0158 _desc.addOptionalUntracked("xaxis", axisParameters);
0159 _desc.addOptionalUntracked("yaxis", axisParameters);
0160 _desc.addOptionalUntracked("zaxis", axisParameters);
0161
0162 edm::ParameterSetDescription multiParameters;
0163 multiParameters.addWildcardUntracked<std::vector<std::string>>("*");
0164 multiParameters.addWildcardUntracked<std::vector<int>>("*");
0165 _desc.addOptionalUntracked("multi", multiParameters);
0166 }
0167 }