File indexing completed on 2025-02-14 03:16:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0016 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/Run.h"
0022 #include "FWCore/Integration/interface/ESTestRecords.h"
0023 #include "FWCore/Integration/interface/IOVTestInfo.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 #include "FWCore/Utilities/interface/ESGetToken.h"
0029 #include "FWCore/Utilities/interface/ESInputTag.h"
0030 #include "FWCore/Utilities/interface/Exception.h"
0031 #include "FWCore/Utilities/interface/InputTag.h"
0032
0033 #include <memory>
0034
0035 namespace {
0036 struct Cache {
0037 Cache() : value(0) {}
0038
0039 mutable std::atomic<unsigned int> value;
0040 };
0041
0042 struct UnsafeCache {
0043 UnsafeCache() : value(0) {}
0044 unsigned int value;
0045 };
0046 }
0047
0048 namespace edmtest {
0049
0050 class RunLumiESAnalyzer : public edm::global::EDAnalyzer<edm::StreamCache<UnsafeCache>,
0051 edm::RunCache<Cache>,
0052 edm::LuminosityBlockCache<Cache>> {
0053 public:
0054 explicit RunLumiESAnalyzer(edm::ParameterSet const&);
0055
0056 std::unique_ptr<UnsafeCache> beginStream(edm::StreamID) const override;
0057 void streamBeginRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
0058 void streamBeginLuminosityBlock(edm::StreamID, edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0059 void streamEndLuminosityBlock(edm::StreamID, edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0060 void streamEndRun(edm::StreamID, edm::Run const&, edm::EventSetup const&) const override;
0061
0062 std::shared_ptr<Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
0063 void globalEndRun(edm::Run const& iRun, edm::EventSetup const&) const override;
0064 std::shared_ptr<Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0065 edm::EventSetup const&) const override;
0066 void globalEndLuminosityBlock(edm::LuminosityBlock const& iLB, edm::EventSetup const&) const override;
0067
0068 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0069
0070 static void fillDescriptions(edm::ConfigurationDescriptions&);
0071
0072 private:
0073 void checkIOVInfo(edm::EventSetup const& eventSetup,
0074 unsigned int run,
0075 unsigned int lumiNumber,
0076 edm::ESHandle<IOVTestInfo> const& iovTestInfo,
0077 const char* functionName) const;
0078
0079 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const esToken_;
0080 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const esTokenNonEmptyLabel_;
0081 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const tokenBeginRun_;
0082 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const tokenBeginLumi_;
0083 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const tokenEndLumi_;
0084 edm::ESGetToken<IOVTestInfo, ESTestRecordC> const tokenEndRun_;
0085
0086 bool checkDataProductContents_;
0087 bool getIntProduct_;
0088
0089 edm::EDGetTokenT<IntProduct> token_;
0090 };
0091
0092 RunLumiESAnalyzer::RunLumiESAnalyzer(edm::ParameterSet const& pset)
0093 : esToken_{esConsumes(pset.getParameter<edm::ESInputTag>("esInputTag"))},
0094 esTokenNonEmptyLabel_{esConsumes(edm::ESInputTag("", "nonEmptyLabel"))},
0095 tokenBeginRun_{esConsumes<edm::Transition::BeginRun>(pset.getParameter<edm::ESInputTag>("esInputTag"))},
0096 tokenBeginLumi_{
0097 esConsumes<edm::Transition::BeginLuminosityBlock>(pset.getParameter<edm::ESInputTag>("esInputTag"))},
0098 tokenEndLumi_{
0099 esConsumes<edm::Transition::EndLuminosityBlock>(pset.getParameter<edm::ESInputTag>("esInputTag"))},
0100 tokenEndRun_{esConsumes<edm::Transition::EndRun>(pset.getParameter<edm::ESInputTag>("esInputTag"))},
0101 checkDataProductContents_(pset.getParameter<bool>("checkDataProductContents")),
0102 getIntProduct_(pset.getParameter<bool>("getIntProduct")) {
0103 if (getIntProduct_) {
0104 token_ = consumes<IntProduct>(edm::InputTag("intProducer", ""));
0105 }
0106 }
0107
0108 std::unique_ptr<UnsafeCache> RunLumiESAnalyzer::beginStream(edm::StreamID iID) const {
0109 return std::make_unique<UnsafeCache>();
0110 }
0111
0112 void RunLumiESAnalyzer::checkIOVInfo(edm::EventSetup const& eventSetup,
0113 unsigned int run,
0114 unsigned int lumiNumber,
0115 edm::ESHandle<IOVTestInfo> const& iovTestInfo,
0116 const char* functionName) const {
0117 ESTestRecordC recordC = eventSetup.get<ESTestRecordC>();
0118 edm::ValidityInterval iov = recordC.validityInterval();
0119
0120 if (checkDataProductContents_) {
0121 if (iovTestInfo->iovStartRun_ != run || iovTestInfo->iovEndRun_ != run ||
0122 iovTestInfo->iovStartLumi_ != lumiNumber || iovTestInfo->iovEndLumi_ != lumiNumber) {
0123 throw cms::Exception("TestFailure")
0124 << functionName << ": values read from EventSetup do not agree with auxiliary";
0125 }
0126 }
0127
0128 if (iov.first().eventID().run() != run || iov.last().eventID().run() != run ||
0129 iov.first().luminosityBlockNumber() != lumiNumber || iov.last().luminosityBlockNumber() != lumiNumber) {
0130 throw cms::Exception("TestFailure") << functionName << ": values from EventSetup IOV do not agree with auxiliary";
0131 }
0132 }
0133
0134 void RunLumiESAnalyzer::streamBeginRun(edm::StreamID, edm::Run const& iRun, edm::EventSetup const& eventSetup) const {
0135 auto run = iRun.runAuxiliary().run();
0136 unsigned int lumiNumber = 0;
0137 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginRun_);
0138 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamBeginRun");
0139 }
0140
0141 void RunLumiESAnalyzer::streamBeginLuminosityBlock(edm::StreamID,
0142 edm::LuminosityBlock const& iLumi,
0143 edm::EventSetup const& eventSetup) const {
0144 auto run = iLumi.luminosityBlockAuxiliary().run();
0145 unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
0146 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginLumi_);
0147 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamBeginLuminosityBlock");
0148 }
0149
0150 void RunLumiESAnalyzer::streamEndLuminosityBlock(edm::StreamID,
0151 edm::LuminosityBlock const& iLumi,
0152 edm::EventSetup const& eventSetup) const {
0153 auto run = iLumi.luminosityBlockAuxiliary().run();
0154 unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
0155 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndLumi_);
0156 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamEndLuminosityBlock");
0157 }
0158
0159 void RunLumiESAnalyzer::streamEndRun(edm::StreamID, edm::Run const& iRun, edm::EventSetup const& eventSetup) const {
0160 auto run = iRun.runAuxiliary().run();
0161 unsigned int lumiNumber = 4294967295;
0162 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndRun_);
0163 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::streamEndRun");
0164 }
0165
0166 std::shared_ptr<Cache> RunLumiESAnalyzer::globalBeginRun(edm::Run const& iRun,
0167 edm::EventSetup const& eventSetup) const {
0168 auto run = iRun.runAuxiliary().run();
0169 unsigned int lumiNumber = 0;
0170 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginRun_);
0171 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalBeginRun");
0172 return std::make_shared<Cache>();
0173 }
0174
0175 void RunLumiESAnalyzer::globalEndRun(edm::Run const& iRun, edm::EventSetup const& eventSetup) const {
0176 auto run = iRun.runAuxiliary().run();
0177 unsigned int lumiNumber = 4294967295;
0178 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndRun_);
0179 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalEndRun");
0180 }
0181
0182 std::shared_ptr<Cache> RunLumiESAnalyzer::globalBeginLuminosityBlock(edm::LuminosityBlock const& iLumi,
0183 edm::EventSetup const& eventSetup) const {
0184 auto run = iLumi.luminosityBlockAuxiliary().run();
0185 unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
0186 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenBeginLumi_);
0187 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalBeginLuminosityBlock");
0188 return std::make_shared<Cache>();
0189 }
0190
0191 void RunLumiESAnalyzer::globalEndLuminosityBlock(edm::LuminosityBlock const& iLumi,
0192 edm::EventSetup const& eventSetup) const {
0193 auto run = iLumi.luminosityBlockAuxiliary().run();
0194 unsigned int lumiNumber = iLumi.luminosityBlockAuxiliary().luminosityBlock();
0195 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(tokenEndLumi_);
0196 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::globalEndLuminosityBlock");
0197 }
0198
0199 void RunLumiESAnalyzer::analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const& eventSetup) const {
0200 auto run = event.eventAuxiliary().run();
0201 auto lumiNumber = event.eventAuxiliary().luminosityBlock();
0202 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(esToken_);
0203 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::analyzer");
0204
0205 {
0206 edm::ESHandle<IOVTestInfo> iovTestInfo = eventSetup.getHandle(esTokenNonEmptyLabel_);
0207 checkIOVInfo(eventSetup, run, lumiNumber, iovTestInfo, "RunLumiESAnalyzer::analyzer");
0208 }
0209 if (getIntProduct_) {
0210 event.get(token_);
0211 }
0212 }
0213
0214 void RunLumiESAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0215 edm::ParameterSetDescription desc;
0216 desc.add<edm::ESInputTag>("esInputTag", edm::ESInputTag());
0217 desc.add<bool>("checkDataProductContents", true);
0218 desc.add<bool>("getIntProduct", false);
0219 descriptions.addDefault(desc);
0220 }
0221 }
0222 using namespace edmtest;
0223 DEFINE_FWK_MODULE(RunLumiESAnalyzer);