File indexing completed on 2024-09-11 04:32:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0024
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029
0030 #include "FWCore/ServiceRegistry/interface/Service.h"
0031
0032
0033
0034
0035 namespace {
0036 typedef dqm::legacy::MonitorElement MonitorElement;
0037 typedef dqm::legacy::DQMStore DQMStore;
0038
0039 class FillerBase {
0040 public:
0041 virtual ~FillerBase() = default;
0042 virtual void fill() = 0;
0043 virtual void reset() = 0;
0044 };
0045
0046 class TH1FFiller : public FillerBase {
0047 public:
0048 TH1FFiller(const edm::ParameterSet& iPSet, DQMStore& iStore, bool iSetLumiFlag)
0049 : m_min(iPSet.getUntrackedParameter<double>("lowX")), m_steps(iPSet.getUntrackedParameter<int>("nchX")) {
0050 std::string extension;
0051 if (iSetLumiFlag) {
0052 extension = "_lumi";
0053 }
0054 m_element = iStore.book1D(iPSet.getUntrackedParameter<std::string>("name") + extension,
0055 iPSet.getUntrackedParameter<std::string>("title") + extension,
0056 m_steps,
0057 m_min,
0058 iPSet.getUntrackedParameter<double>("highX"));
0059 m_valueToFill = iPSet.getUntrackedParameter<double>("value");
0060 }
0061
0062 ~TH1FFiller() override {}
0063
0064 void reset() override { m_element->Reset(); }
0065 void fill() override { m_element->Fill(m_valueToFill); }
0066
0067 private:
0068 double m_valueToFill;
0069 double m_min;
0070 unsigned int m_steps;
0071 MonitorElement* m_element;
0072 };
0073
0074 class TH2FFiller : public FillerBase {
0075 public:
0076 TH2FFiller(const edm::ParameterSet& iPSet, DQMStore& iStore, bool iSetLumiFlag)
0077 : m_min(iPSet.getUntrackedParameter<double>("lowX")), m_steps(iPSet.getUntrackedParameter<int>("nchX")) {
0078 std::string extension;
0079 if (iSetLumiFlag) {
0080 extension = "_lumi";
0081 }
0082 m_element = iStore.book2D(iPSet.getUntrackedParameter<std::string>("name") + extension,
0083 iPSet.getUntrackedParameter<std::string>("title") + extension,
0084 m_steps,
0085 m_min,
0086 iPSet.getUntrackedParameter<double>("highX"),
0087 iPSet.getUntrackedParameter<int>("nchY"),
0088 iPSet.getUntrackedParameter<double>("lowY"),
0089 iPSet.getUntrackedParameter<double>("highY"));
0090 m_valueToFill = iPSet.getUntrackedParameter<double>("value");
0091 }
0092
0093 ~TH2FFiller() override {}
0094
0095 void reset() override { m_element->Reset(); }
0096 void fill() override { m_element->Fill(m_valueToFill, m_valueToFill); }
0097
0098 private:
0099 double m_valueToFill;
0100 double m_min;
0101 unsigned int m_steps;
0102 MonitorElement* m_element;
0103 };
0104
0105 }
0106
0107 class DummyFillDQMStore : public DQMOneLumiEDAnalyzer<> {
0108 public:
0109 explicit DummyFillDQMStore(const edm::ParameterSet&);
0110 ~DummyFillDQMStore() override;
0111
0112 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0113
0114 void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0115 void analyze(edm::Event const&, edm::EventSetup const&) override;
0116 void dqmEndRun(edm::Run const&, edm::EventSetup const&) override;
0117 void dqmBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0118 void dqmEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) override;
0119
0120 private:
0121
0122 edm::ParameterSet iConfig;
0123 std::vector<std::shared_ptr<FillerBase> > m_runFillers;
0124 std::vector<std::shared_ptr<FillerBase> > m_lumiFillers;
0125 bool m_fillRuns;
0126 bool m_fillLumis;
0127 };
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 DummyFillDQMStore::DummyFillDQMStore(const edm::ParameterSet& iConfig)
0141 : m_fillRuns(iConfig.getUntrackedParameter<bool>("fillRuns")),
0142 m_fillLumis(iConfig.getUntrackedParameter<bool>("fillLumis")) {
0143 this->iConfig = iConfig;
0144 }
0145
0146 void DummyFillDQMStore::bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) {
0147
0148 edm::Service<DQMStore> dstore;
0149
0150 typedef std::vector<edm::ParameterSet> PSets;
0151 const PSets& elements = iConfig.getUntrackedParameter<std::vector<edm::ParameterSet> >("elements");
0152 if (m_fillRuns) {
0153 dstore->setScope(MonitorElementData::Scope::RUN);
0154 m_runFillers.clear();
0155 m_runFillers.reserve(elements.size());
0156 for (PSets::const_iterator it = elements.begin(), itEnd = elements.end(); it != itEnd; ++it) {
0157 switch (it->getUntrackedParameter<unsigned int>("type", 1)) {
0158 case 1:
0159 m_runFillers.push_back(std::shared_ptr<FillerBase>(new TH1FFiller(*it, *dstore, false)));
0160 break;
0161 case 2:
0162 m_runFillers.push_back(std::shared_ptr<FillerBase>(new TH2FFiller(*it, *dstore, false)));
0163 break;
0164 }
0165 }
0166 }
0167
0168 if (m_fillLumis) {
0169 dstore->setScope(MonitorElementData::Scope::LUMI);
0170 m_lumiFillers.clear();
0171 m_lumiFillers.reserve(elements.size());
0172 for (PSets::const_iterator it = elements.begin(), itEnd = elements.end(); it != itEnd; ++it) {
0173 switch (it->getUntrackedParameter<unsigned int>("type", 1)) {
0174 case 1:
0175 m_lumiFillers.push_back(std::shared_ptr<FillerBase>(new TH1FFiller(*it, *dstore, true)));
0176 break;
0177 case 2:
0178 m_lumiFillers.push_back(std::shared_ptr<FillerBase>(new TH2FFiller(*it, *dstore, true)));
0179 break;
0180 }
0181 }
0182 }
0183 }
0184
0185 DummyFillDQMStore::~DummyFillDQMStore() {
0186
0187
0188 }
0189
0190
0191
0192
0193
0194
0195 void DummyFillDQMStore::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0196 using namespace edm;
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 }
0214
0215
0216 void DummyFillDQMStore::dqmEndRun(edm::Run const&, edm::EventSetup const&) {
0217 for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_runFillers.begin(), itEnd = m_runFillers.end();
0218 it != itEnd;
0219 ++it) {
0220 (*it)->fill();
0221 }
0222 }
0223
0224
0225 void DummyFillDQMStore::dqmBeginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0226 for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_lumiFillers.begin(), itEnd = m_lumiFillers.end();
0227 it != itEnd;
0228 ++it) {
0229 (*it)->reset();
0230 }
0231 }
0232
0233
0234 void DummyFillDQMStore::dqmEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) {
0235 for (std::vector<std::shared_ptr<FillerBase> >::iterator it = m_lumiFillers.begin(), itEnd = m_lumiFillers.end();
0236 it != itEnd;
0237 ++it) {
0238 (*it)->fill();
0239 }
0240 }
0241
0242
0243 void DummyFillDQMStore::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0244
0245
0246 edm::ParameterSetDescription desc;
0247 desc.setUnknown();
0248 descriptions.addDefault(desc);
0249 }
0250
0251
0252 DEFINE_FWK_MODULE(DummyFillDQMStore);