Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-04 04:34:58

0001 // -*- C++ -*-
0002 //
0003 // Package:     FWCore/Integration
0004 // Class  :     ExceptionThrowingProducer
0005 //
0006 // Implementation:
0007 //     Intentionally throws exceptions in various Framework transitions.
0008 //     You can configure which transition. Includes some tests of
0009 //     the Framework behavior after an exception occurs.
0010 //
0011 // Original Author:  W. David Dagenhart
0012 //         Created:  26 September 2022
0013 
0014 #include "DataFormats/Provenance/interface/EventID.h"
0015 #include "DataFormats/Provenance/interface/RunLumiEventNumber.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/Frameworkfwd.h"
0018 #include "FWCore/Framework/interface/global/EDProducer.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Integration/plugins/TestServiceOne.h"
0021 #include "FWCore/Integration/plugins/TestServiceTwo.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "FWCore/ServiceRegistry/interface/Service.h"
0027 #include "FWCore/Utilities/interface/Exception.h"
0028 
0029 #include <atomic>
0030 #include <limits>
0031 #include <memory>
0032 
0033 constexpr unsigned int kTestStreams = 4;
0034 constexpr unsigned int kUnset = std::numeric_limits<unsigned int>::max();
0035 constexpr unsigned int kNumberOfTestModules = 2;
0036 
0037 namespace edmtest {
0038 
0039   namespace {
0040     struct Cache {};
0041   }  // namespace
0042 
0043   class ExceptionThrowingProducer
0044       : public edm::global::EDProducer<edm::StreamCache<Cache>, edm::RunCache<Cache>, edm::LuminosityBlockCache<Cache>> {
0045   public:
0046     explicit ExceptionThrowingProducer(edm::ParameterSet const&);
0047 
0048     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0049 
0050     std::shared_ptr<Cache> globalBeginRun(edm::Run const&, edm::EventSetup const&) const override;
0051     void globalEndRun(edm::Run const&, edm::EventSetup const&) const override;
0052     std::shared_ptr<Cache> globalBeginLuminosityBlock(edm::LuminosityBlock const&,
0053                                                       edm::EventSetup const&) const override;
0054     void globalEndLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&) const override;
0055 
0056     std::unique_ptr<Cache> 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     void endJob() override;
0063 
0064     static void fillDescriptions(edm::ConfigurationDescriptions&);
0065 
0066   private:
0067     bool verbose_;
0068 
0069     edm::EventID eventIDThrowOnEvent_;
0070     edm::EventID eventIDThrowOnGlobalBeginRun_;
0071     edm::EventID eventIDThrowOnGlobalBeginLumi_;
0072     edm::EventID eventIDThrowOnGlobalEndRun_;
0073     edm::EventID eventIDThrowOnGlobalEndLumi_;
0074     edm::EventID eventIDThrowOnStreamBeginRun_;
0075     edm::EventID eventIDThrowOnStreamBeginLumi_;
0076     edm::EventID eventIDThrowOnStreamEndRun_;
0077     edm::EventID eventIDThrowOnStreamEndLumi_;
0078 
0079     mutable std::vector<unsigned int> nStreamBeginLumi_;
0080     mutable std::vector<unsigned int> nStreamEndLumi_;
0081     mutable std::atomic<unsigned int> nGlobalBeginLumi_{0};
0082     mutable std::atomic<unsigned int> nGlobalEndLumi_{0};
0083 
0084     mutable std::vector<unsigned int> nStreamBeginRun_;
0085     mutable std::vector<unsigned int> nStreamEndRun_;
0086     mutable std::atomic<unsigned int> nGlobalBeginRun_{0};
0087     mutable std::atomic<unsigned int> nGlobalEndRun_{0};
0088 
0089     unsigned int expectedStreamBeginLumi_;
0090     unsigned int expectedOffsetNoStreamEndLumi_;
0091     mutable unsigned int streamWithBeginLumiException_ = kUnset;
0092     unsigned int expectedGlobalBeginLumi_;
0093     unsigned int expectedOffsetNoGlobalEndLumi_;
0094     unsigned int expectedOffsetNoWriteLumi_;
0095 
0096     unsigned int expectedStreamBeginRun_;
0097     unsigned int expectedOffsetNoStreamEndRun_;
0098     mutable unsigned int streamWithBeginRunException_ = kUnset;
0099     unsigned int expectedGlobalBeginRun_;
0100     unsigned int expectedOffsetNoGlobalEndRun_;
0101     unsigned int expectedOffsetNoWriteRun_;
0102 
0103     mutable std::atomic<bool> streamBeginLumiExceptionOccurred_ = false;
0104     mutable std::atomic<bool> streamEndLumiExceptionOccurred_ = false;
0105     mutable std::atomic<bool> globalBeginLumiExceptionOccurred_ = false;
0106 
0107     mutable std::atomic<bool> streamBeginRunExceptionOccurred_ = false;
0108     mutable std::atomic<bool> streamEndRunExceptionOccurred_ = false;
0109     mutable std::atomic<bool> globalBeginRunExceptionOccurred_ = false;
0110   };
0111 
0112   ExceptionThrowingProducer::ExceptionThrowingProducer(edm::ParameterSet const& pset)
0113       : verbose_(pset.getUntrackedParameter<bool>("verbose")),
0114         eventIDThrowOnEvent_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnEvent")),
0115         eventIDThrowOnGlobalBeginRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalBeginRun")),
0116         eventIDThrowOnGlobalBeginLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalBeginLumi")),
0117         eventIDThrowOnGlobalEndRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalEndRun")),
0118         eventIDThrowOnGlobalEndLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnGlobalEndLumi")),
0119         eventIDThrowOnStreamBeginRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamBeginRun")),
0120         eventIDThrowOnStreamBeginLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamBeginLumi")),
0121         eventIDThrowOnStreamEndRun_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamEndRun")),
0122         eventIDThrowOnStreamEndLumi_(pset.getUntrackedParameter<edm::EventID>("eventIDThrowOnStreamEndLumi")),
0123         nStreamBeginLumi_(kTestStreams, 0),
0124         nStreamEndLumi_(kTestStreams, 0),
0125         nStreamBeginRun_(kTestStreams, 0),
0126         nStreamEndRun_(kTestStreams, 0),
0127         expectedStreamBeginLumi_(pset.getUntrackedParameter<unsigned int>("expectedStreamBeginLumi")),
0128         expectedOffsetNoStreamEndLumi_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoStreamEndLumi")),
0129         expectedGlobalBeginLumi_(pset.getUntrackedParameter<unsigned int>("expectedGlobalBeginLumi")),
0130         expectedOffsetNoGlobalEndLumi_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoGlobalEndLumi")),
0131         expectedOffsetNoWriteLumi_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoWriteLumi")),
0132         expectedStreamBeginRun_(pset.getUntrackedParameter<unsigned int>("expectedStreamBeginRun")),
0133         expectedOffsetNoStreamEndRun_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoStreamEndRun")),
0134         expectedGlobalBeginRun_(pset.getUntrackedParameter<unsigned int>("expectedGlobalBeginRun")),
0135         expectedOffsetNoGlobalEndRun_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoGlobalEndRun")),
0136         expectedOffsetNoWriteRun_(pset.getUntrackedParameter<unsigned int>("expectedOffsetNoWriteRun")) {}
0137 
0138   void ExceptionThrowingProducer::produce(edm::StreamID, edm::Event& event, edm::EventSetup const&) const {
0139     if (event.id() == eventIDThrowOnEvent_) {
0140       throw cms::Exception("IntentionalTestException")
0141           << "ExceptionThrowingProducer::produce, module configured to throw on: " << eventIDThrowOnEvent_;
0142     }
0143   }
0144 
0145   std::shared_ptr<Cache> ExceptionThrowingProducer::globalBeginRun(edm::Run const& run, edm::EventSetup const&) const {
0146     ++nGlobalBeginRun_;
0147     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0148         eventIDThrowOnGlobalBeginRun_) {
0149       globalBeginRunExceptionOccurred_.store(true);
0150       throw cms::Exception("IntentionalTestException")
0151           << "ExceptionThrowingProducer::globalBeginRun, module configured to throw on: "
0152           << eventIDThrowOnGlobalBeginRun_;
0153     }
0154     return std::make_shared<Cache>();
0155   }
0156 
0157   void ExceptionThrowingProducer::globalEndRun(edm::Run const& run, edm::EventSetup const&) const {
0158     ++nGlobalEndRun_;
0159     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0160         eventIDThrowOnGlobalEndRun_) {
0161       throw cms::Exception("IntentionalTestException")
0162           << "ExceptionThrowingProducer::globalEndRun, module configured to throw on: " << eventIDThrowOnGlobalEndRun_;
0163     }
0164   }
0165 
0166   std::shared_ptr<Cache> ExceptionThrowingProducer::globalBeginLuminosityBlock(edm::LuminosityBlock const& lumi,
0167                                                                                edm::EventSetup const&) const {
0168     ++nGlobalBeginLumi_;
0169     if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0170         eventIDThrowOnGlobalBeginLumi_) {
0171       globalBeginLumiExceptionOccurred_.store(true);
0172       throw cms::Exception("IntentionalTestException")
0173           << "ExceptionThrowingProducer::globalBeginLuminosityBlock, module configured to throw on: "
0174           << eventIDThrowOnGlobalBeginLumi_;
0175     }
0176     return std::make_shared<Cache>();
0177   }
0178 
0179   void ExceptionThrowingProducer::globalEndLuminosityBlock(edm::LuminosityBlock const& lumi,
0180                                                            edm::EventSetup const&) const {
0181     ++nGlobalEndLumi_;
0182     if (edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0183         eventIDThrowOnGlobalEndLumi_) {
0184       throw cms::Exception("IntentionalTestException")
0185           << "ExceptionThrowingProducer::globalEndLuminosityBlock, module configured to throw on: "
0186           << eventIDThrowOnGlobalEndLumi_;
0187     }
0188   }
0189 
0190   std::unique_ptr<Cache> ExceptionThrowingProducer::beginStream(edm::StreamID) const {
0191     return std::make_unique<Cache>();
0192   }
0193 
0194   void ExceptionThrowingProducer::streamBeginRun(edm::StreamID iStream,
0195                                                  edm::Run const& run,
0196                                                  edm::EventSetup const&) const {
0197     if (iStream < kTestStreams) {
0198       ++nStreamBeginRun_[iStream];
0199     }
0200 
0201     bool expected = false;
0202     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0203             eventIDThrowOnStreamBeginRun_ &&
0204         streamBeginRunExceptionOccurred_.compare_exchange_strong(expected, true)) {
0205       // Remember which stream threw
0206       streamWithBeginRunException_ = iStream.value();
0207       throw cms::Exception("IntentionalTestException")
0208           << "ExceptionThrowingProducer::streamBeginRun, module configured to throw on: "
0209           << eventIDThrowOnStreamBeginRun_;
0210     }
0211   }
0212 
0213   void ExceptionThrowingProducer::streamBeginLuminosityBlock(edm::StreamID iStream,
0214                                                              edm::LuminosityBlock const& lumi,
0215                                                              edm::EventSetup const&) const {
0216     if (iStream < kTestStreams) {
0217       ++nStreamBeginLumi_[iStream];
0218     }
0219 
0220     // Throw if this lumi's ID matches the configured ID (this code is written so
0221     // that only the first stream to match it will throw).
0222     bool expected = false;
0223     if (edm::EventID(lumi.run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0224             eventIDThrowOnStreamBeginLumi_ &&
0225         streamBeginLumiExceptionOccurred_.compare_exchange_strong(expected, true)) {
0226       // Remember which stream threw
0227       streamWithBeginLumiException_ = iStream.value();
0228 
0229       throw cms::Exception("IntentionalTestException")
0230           << "ExceptionThrowingProducer::streamBeginLuminosityBlock, module configured to throw on: "
0231           << eventIDThrowOnStreamBeginLumi_;
0232     }
0233   }
0234 
0235   void ExceptionThrowingProducer::streamEndLuminosityBlock(edm::StreamID iStream,
0236                                                            edm::LuminosityBlock const& lumi,
0237                                                            edm::EventSetup const&) const {
0238     if (iStream < kTestStreams) {
0239       ++nStreamEndLumi_[iStream];
0240     }
0241 
0242     bool expected = false;
0243     if (edm::EventID(lumi.run(), lumi.id().luminosityBlock(), edm::invalidEventNumber) ==
0244             eventIDThrowOnStreamEndLumi_ &&
0245         streamEndLumiExceptionOccurred_.compare_exchange_strong(expected, true)) {
0246       throw cms::Exception("IntentionalTestException")
0247           << "ExceptionThrowingProducer::streamEndLuminosityBlock, module configured to throw on: "
0248           << eventIDThrowOnStreamEndLumi_;
0249     }
0250   }
0251 
0252   void ExceptionThrowingProducer::streamEndRun(edm::StreamID iStream,
0253                                                edm::Run const& run,
0254                                                edm::EventSetup const&) const {
0255     if (iStream < kTestStreams) {
0256       ++nStreamEndRun_[iStream];
0257     }
0258 
0259     bool expected = false;
0260     if (edm::EventID(run.id().run(), edm::invalidLuminosityBlockNumber, edm::invalidEventNumber) ==
0261             eventIDThrowOnStreamEndRun_ &&
0262         streamEndRunExceptionOccurred_.compare_exchange_strong(expected, true)) {
0263       throw cms::Exception("IntentionalTestException")
0264           << "ExceptionThrowingProducer::streamEndRun, module configured to throw on: " << eventIDThrowOnStreamEndRun_;
0265     }
0266   }
0267 
0268   void ExceptionThrowingProducer::endJob() {
0269     bool testsPass = true;
0270 
0271     unsigned int totalStreamBeginLumi = 0;
0272     unsigned int i = 0;
0273     for (auto const& nStreamBeginLumi : nStreamBeginLumi_) {
0274       totalStreamBeginLumi += nStreamBeginLumi;
0275 
0276       // Don't know exact number to expect because streams might skip a lumi so
0277       // only throw if it is greater than the maximum possible and we only know
0278       // that for sure if the exception was thrown in stream begin lumi.
0279       if (nStreamBeginLumi > expectedStreamBeginLumi_ && streamWithBeginLumiException_ != kUnset) {
0280         edm::LogAbsolute("ExceptionThrowingProducer")
0281             << "FAILED: More than maximum possible number of streamBeginLumi transitions, stream " << i << " saw "
0282             << nStreamBeginLumi << " max possible " << expectedStreamBeginLumi_;
0283         testsPass = false;
0284       }
0285       unsigned int expectedStreamEndLumi =
0286           (streamWithBeginLumiException_ == i) ? nStreamBeginLumi - 1 : nStreamBeginLumi;
0287       if (nStreamEndLumi_[i] != expectedStreamEndLumi) {
0288         edm::LogAbsolute("ExceptionThrowingProducer")
0289             << "FAILED: Unexpected number of streamEndLumi transitions, stream " << i << " saw " << nStreamEndLumi_[i]
0290             << " expected " << expectedStreamEndLumi;
0291         testsPass = false;
0292       }
0293 
0294       ++i;
0295     }
0296 
0297     unsigned int totalStreamBeginRun = 0;
0298     i = 0;
0299     for (auto const& nStreamBeginRun : nStreamBeginRun_) {
0300       totalStreamBeginRun += nStreamBeginRun;
0301 
0302       // Don't know exact number to expect because streams might skip a run (not yet
0303       // but probably in the future) so only throw if it is greater than the maximum
0304       // possible and we only know that for sure if the exception was thrown in stream begin run.
0305       if (nStreamBeginRun > expectedStreamBeginRun_ && streamWithBeginRunException_ != kUnset) {
0306         edm::LogAbsolute("ExceptionThrowingProducer")
0307             << "FAILED: More than maximum possible number of streamBeginRun transitions, stream " << i << " saw "
0308             << nStreamBeginRun << " max possible " << expectedStreamBeginRun_;
0309         testsPass = false;
0310       }
0311       unsigned int expectedStreamEndRun = (streamWithBeginRunException_ == i) ? nStreamBeginRun - 1 : nStreamBeginRun;
0312       if (nStreamEndRun_[i] != expectedStreamEndRun) {
0313         edm::LogAbsolute("ExceptionThrowingProducer")
0314             << "FAILED: Unexpected number of streamEndRun transitions, stream " << i << " saw " << nStreamEndRun_[i]
0315             << " expected " << expectedStreamEndRun;
0316         testsPass = false;
0317       }
0318 
0319       ++i;
0320     }
0321 
0322     // There has to be at least as many global begin lumi transitions
0323     // as expected. Because of concurrency, the Framework might already have
0324     // started other lumis ahead of the one where an exception occurs.
0325     if (expectedGlobalBeginLumi_ > 0 && nGlobalBeginLumi_.load() < expectedGlobalBeginLumi_) {
0326       edm::LogAbsolute("ExceptionThrowingProducer")
0327           << "FAILED: Less than the expected number of globalBeginLumi transitions, expected at least "
0328           << expectedGlobalBeginLumi_ << " saw " << nGlobalBeginLumi_.load();
0329       testsPass = false;
0330     }
0331 
0332     // There has to be at least as many global begin run transitions
0333     // as expected. Because of concurrency, the Framework might already have
0334     // started other runs ahead of the one where an exception occurs.
0335     if (expectedGlobalBeginRun_ > 0 && nGlobalBeginRun_.load() < expectedGlobalBeginRun_) {
0336       edm::LogAbsolute("ExceptionThrowingProducer")
0337           << "FAILED: Less than the expected number of globalBeginRun transitions, expected at least "
0338           << expectedGlobalBeginRun_ << " saw " << nGlobalBeginRun_.load();
0339       testsPass = false;
0340     }
0341 
0342     unsigned int expectedGlobalEndLumi =
0343         globalBeginLumiExceptionOccurred_.load() ? nGlobalBeginLumi_.load() - 1 : nGlobalBeginLumi_.load();
0344     if (nGlobalEndLumi_.load() != expectedGlobalEndLumi) {
0345       edm::LogAbsolute("ExceptionThrowingProducer")
0346           << "FAILED: number of global end lumi transitions not equal to expected value, expected "
0347           << expectedGlobalEndLumi << " saw " << nGlobalEndLumi_.load();
0348       testsPass = false;
0349     }
0350 
0351     unsigned int expectedGlobalEndRun =
0352         globalBeginRunExceptionOccurred_.load() ? nGlobalBeginRun_.load() - 1 : nGlobalBeginRun_.load();
0353     if (nGlobalEndRun_.load() != expectedGlobalEndRun) {
0354       edm::LogAbsolute("ExceptionThrowingProducer")
0355           << "FAILED: number of global end run transitions not equal to expected value, expected "
0356           << expectedGlobalEndRun << " saw " << nGlobalEndRun_.load();
0357       testsPass = false;
0358     }
0359 
0360     edm::Service<edmtest::TestServiceOne> serviceOne;
0361     if (serviceOne->nPreStreamBeginLumi() != totalStreamBeginLumi ||
0362         serviceOne->nPostStreamBeginLumi() != totalStreamBeginLumi ||
0363         serviceOne->nPreStreamEndLumi() != totalStreamBeginLumi ||
0364         serviceOne->nPostStreamEndLumi() != totalStreamBeginLumi ||
0365         serviceOne->nPreModuleStreamBeginLumi() != totalStreamBeginLumi * kNumberOfTestModules ||
0366         serviceOne->nPostModuleStreamBeginLumi() != totalStreamBeginLumi * kNumberOfTestModules ||
0367         serviceOne->nPreModuleStreamEndLumi() !=
0368             totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_ ||
0369         serviceOne->nPostModuleStreamEndLumi() !=
0370             totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_) {
0371       edm::LogAbsolute("ExceptionThrowingProducer")
0372           << "FAILED: Unexpected number of service transitions in TestServiceOne, stream lumi";
0373       testsPass = false;
0374     }
0375 
0376     edm::Service<edmtest::TestServiceTwo> serviceTwo;
0377     if (serviceTwo->nPreStreamBeginLumi() != totalStreamBeginLumi ||
0378         serviceTwo->nPostStreamBeginLumi() != totalStreamBeginLumi ||
0379         serviceTwo->nPreStreamEndLumi() != totalStreamBeginLumi ||
0380         serviceTwo->nPostStreamEndLumi() != totalStreamBeginLumi ||
0381         serviceTwo->nPreModuleStreamBeginLumi() != totalStreamBeginLumi * kNumberOfTestModules ||
0382         serviceTwo->nPostModuleStreamBeginLumi() != totalStreamBeginLumi * kNumberOfTestModules ||
0383         serviceTwo->nPreModuleStreamEndLumi() !=
0384             totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_ ||
0385         serviceTwo->nPostModuleStreamEndLumi() !=
0386             totalStreamBeginLumi * kNumberOfTestModules - expectedOffsetNoStreamEndLumi_) {
0387       edm::LogAbsolute("ExceptionThrowingProducer")
0388           << "FAILED: Unexpected number of service transitions in TestServiceTwo, stream lumi";
0389       testsPass = false;
0390     }
0391 
0392     unsigned int nGlobalBeginLumi = nGlobalBeginLumi_.load();
0393 
0394     if (serviceOne->nPreGlobalBeginLumi() != nGlobalBeginLumi ||
0395         serviceOne->nPostGlobalBeginLumi() != nGlobalBeginLumi || serviceOne->nPreGlobalEndLumi() != nGlobalBeginLumi ||
0396         serviceOne->nPostGlobalEndLumi() != nGlobalBeginLumi ||
0397         serviceOne->nPreModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules ||
0398         serviceOne->nPostModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules ||
0399         serviceOne->nPreModuleGlobalEndLumi() !=
0400             nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ ||
0401         serviceOne->nPostModuleGlobalEndLumi() !=
0402             nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ ||
0403         serviceOne->nPreGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_ ||
0404         serviceOne->nPostGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_) {
0405       edm::LogAbsolute("ExceptionThrowingProducer")
0406           << "FAILED: Unexpected number of service transitions in TestServiceOne, global lumi";
0407       testsPass = false;
0408     }
0409 
0410     if (serviceTwo->nPreGlobalBeginLumi() != nGlobalBeginLumi ||
0411         serviceTwo->nPostGlobalBeginLumi() != nGlobalBeginLumi || serviceTwo->nPreGlobalEndLumi() != nGlobalBeginLumi ||
0412         serviceTwo->nPostGlobalEndLumi() != nGlobalBeginLumi ||
0413         serviceTwo->nPreModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules ||
0414         serviceTwo->nPostModuleGlobalBeginLumi() != nGlobalBeginLumi * kNumberOfTestModules ||
0415         serviceTwo->nPreModuleGlobalEndLumi() !=
0416             nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ ||
0417         serviceTwo->nPostModuleGlobalEndLumi() !=
0418             nGlobalBeginLumi * kNumberOfTestModules - expectedOffsetNoGlobalEndLumi_ ||
0419         serviceTwo->nPreGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_ ||
0420         serviceTwo->nPostGlobalWriteLumi() != nGlobalBeginLumi - expectedOffsetNoWriteLumi_) {
0421       edm::LogAbsolute("ExceptionThrowingProducer")
0422           << "FAILED: Unexpected number of service transitions in TestServiceTwo, global lumi";
0423       testsPass = false;
0424     }
0425 
0426     if (serviceOne->nPreStreamBeginRun() != totalStreamBeginRun ||
0427         serviceOne->nPostStreamBeginRun() != totalStreamBeginRun ||
0428         serviceOne->nPreStreamEndRun() != totalStreamBeginRun ||
0429         serviceOne->nPostStreamEndRun() != totalStreamBeginRun ||
0430         serviceOne->nPreModuleStreamBeginRun() != totalStreamBeginRun * kNumberOfTestModules ||
0431         serviceOne->nPostModuleStreamBeginRun() != totalStreamBeginRun * kNumberOfTestModules ||
0432         serviceOne->nPreModuleStreamEndRun() !=
0433             totalStreamBeginRun * kNumberOfTestModules - expectedOffsetNoStreamEndRun_ ||
0434         serviceOne->nPostModuleStreamEndRun() !=
0435             totalStreamBeginRun * kNumberOfTestModules - expectedOffsetNoStreamEndRun_) {
0436       edm::LogAbsolute("ExceptionThrowingProducer")
0437           << "FAILED: Unexpected number of service transitions in TestServiceOne, stream run";
0438       testsPass = false;
0439     }
0440 
0441     if (serviceTwo->nPreStreamBeginRun() != totalStreamBeginRun ||
0442         serviceTwo->nPostStreamBeginRun() != totalStreamBeginRun ||
0443         serviceTwo->nPreStreamEndRun() != totalStreamBeginRun ||
0444         serviceTwo->nPostStreamEndRun() != totalStreamBeginRun ||
0445         serviceTwo->nPreModuleStreamBeginRun() != totalStreamBeginRun * kNumberOfTestModules ||
0446         serviceTwo->nPostModuleStreamBeginRun() != totalStreamBeginRun * kNumberOfTestModules ||
0447         serviceTwo->nPreModuleStreamEndRun() !=
0448             totalStreamBeginRun * kNumberOfTestModules - expectedOffsetNoStreamEndRun_ ||
0449         serviceTwo->nPostModuleStreamEndRun() !=
0450             totalStreamBeginRun * kNumberOfTestModules - expectedOffsetNoStreamEndRun_) {
0451       edm::LogAbsolute("ExceptionThrowingProducer")
0452           << "FAILED: Unexpected number of service transitions in TestServiceTwo, stream run";
0453       testsPass = false;
0454     }
0455 
0456     unsigned int nGlobalBeginRun = nGlobalBeginRun_.load();
0457 
0458     if (serviceOne->nPreGlobalBeginRun() != nGlobalBeginRun || serviceOne->nPostGlobalBeginRun() != nGlobalBeginRun ||
0459         serviceOne->nPreGlobalEndRun() != nGlobalBeginRun || serviceOne->nPostGlobalEndRun() != nGlobalBeginRun ||
0460         serviceOne->nPreModuleGlobalBeginRun() != nGlobalBeginRun * kNumberOfTestModules ||
0461         serviceOne->nPostModuleGlobalBeginRun() != nGlobalBeginRun * kNumberOfTestModules ||
0462         serviceOne->nPreModuleGlobalEndRun() !=
0463             nGlobalBeginRun * kNumberOfTestModules - expectedOffsetNoGlobalEndRun_ ||
0464         serviceOne->nPostModuleGlobalEndRun() !=
0465             nGlobalBeginRun * kNumberOfTestModules - expectedOffsetNoGlobalEndRun_ ||
0466         serviceOne->nPreGlobalWriteRun() != nGlobalBeginRun - expectedOffsetNoWriteRun_ ||
0467         serviceOne->nPostGlobalWriteRun() != nGlobalBeginRun - expectedOffsetNoWriteRun_) {
0468       edm::LogAbsolute("ExceptionThrowingProducer")
0469           << "FAILED: Unexpected number of service transitions in TestServiceOne, global run";
0470       testsPass = false;
0471     }
0472 
0473     if (serviceTwo->nPreGlobalBeginRun() != nGlobalBeginRun || serviceTwo->nPostGlobalBeginRun() != nGlobalBeginRun ||
0474         serviceTwo->nPreGlobalEndRun() != nGlobalBeginRun || serviceTwo->nPostGlobalEndRun() != nGlobalBeginRun ||
0475         serviceTwo->nPreModuleGlobalBeginRun() != nGlobalBeginRun * kNumberOfTestModules ||
0476         serviceTwo->nPostModuleGlobalBeginRun() != nGlobalBeginRun * kNumberOfTestModules ||
0477         serviceTwo->nPreModuleGlobalEndRun() !=
0478             nGlobalBeginRun * kNumberOfTestModules - expectedOffsetNoGlobalEndRun_ ||
0479         serviceTwo->nPostModuleGlobalEndRun() !=
0480             nGlobalBeginRun * kNumberOfTestModules - expectedOffsetNoGlobalEndRun_ ||
0481         serviceTwo->nPreGlobalWriteRun() != nGlobalBeginRun - expectedOffsetNoWriteRun_ ||
0482         serviceTwo->nPostGlobalWriteRun() != nGlobalBeginRun - expectedOffsetNoWriteRun_) {
0483       edm::LogAbsolute("ExceptionThrowingProducer")
0484           << "FAILED: Unexpected number of service transitions in TestServiceTwo, global run";
0485       testsPass = false;
0486     }
0487 
0488     if (verbose_) {
0489       edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalBeginLumi_ = " << nGlobalBeginLumi_;
0490       edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalEndLumi_ = " << nGlobalEndLumi_;
0491       edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalBeginRun_ = " << nGlobalBeginRun_;
0492       edm::LogAbsolute("ExceptionThrowingProducer") << "nGlobalEndRun_ = " << nGlobalEndRun_;
0493 
0494       edm::LogAbsolute("ExceptionThrowingProducer")
0495           << "serviceOne->nPreStreamBeginLumi = " << serviceOne->nPreStreamBeginLumi();
0496       edm::LogAbsolute("ExceptionThrowingProducer")
0497           << "serviceOne->nPostStreamBeginLumi = " << serviceOne->nPostStreamBeginLumi();
0498       edm::LogAbsolute("ExceptionThrowingProducer")
0499           << "serviceOne->nPreStreamEndLumi = " << serviceOne->nPreStreamEndLumi();
0500       edm::LogAbsolute("ExceptionThrowingProducer")
0501           << "serviceOne->nPostStreamEndLumi = " << serviceOne->nPostStreamEndLumi();
0502       edm::LogAbsolute("ExceptionThrowingProducer")
0503           << "serviceOne->nPreModuleStreamBeginLumi = " << serviceOne->nPreModuleStreamBeginLumi();
0504       edm::LogAbsolute("ExceptionThrowingProducer")
0505           << "serviceOne->nPostModuleStreamBeginLumi = " << serviceOne->nPostModuleStreamBeginLumi();
0506       edm::LogAbsolute("ExceptionThrowingProducer")
0507           << "serviceOne->nPreModuleStreamEndLumi = " << serviceOne->nPreModuleStreamEndLumi();
0508       edm::LogAbsolute("ExceptionThrowingProducer")
0509           << "serviceOne->nPostModuleStreamEndLumi = " << serviceOne->nPostModuleStreamEndLumi() << "\n";
0510 
0511       edm::LogAbsolute("ExceptionThrowingProducer")
0512           << "serviceOne->nPreGlobalBeginLumi = " << serviceOne->nPreGlobalBeginLumi();
0513       edm::LogAbsolute("ExceptionThrowingProducer")
0514           << "serviceOne->nPostGlobalBeginLumi = " << serviceOne->nPostGlobalBeginLumi();
0515       edm::LogAbsolute("ExceptionThrowingProducer")
0516           << "serviceOne->nPreGlobalEndLumi = " << serviceOne->nPreGlobalEndLumi();
0517       edm::LogAbsolute("ExceptionThrowingProducer")
0518           << "serviceOne->nPostGlobalEndLumi = " << serviceOne->nPostGlobalEndLumi();
0519       edm::LogAbsolute("ExceptionThrowingProducer")
0520           << "serviceOne->nPreModuleGlobalBeginLumi = " << serviceOne->nPreModuleGlobalBeginLumi();
0521       edm::LogAbsolute("ExceptionThrowingProducer")
0522           << "serviceOne->nPostModuleGlobalBeginLumi = " << serviceOne->nPostModuleGlobalBeginLumi();
0523       edm::LogAbsolute("ExceptionThrowingProducer")
0524           << "serviceOne->nPreModuleGlobalEndLumi = " << serviceOne->nPreModuleGlobalEndLumi();
0525       edm::LogAbsolute("ExceptionThrowingProducer")
0526           << "serviceOne->nPostModuleGlobalEndLumi = " << serviceOne->nPostModuleGlobalEndLumi();
0527       edm::LogAbsolute("ExceptionThrowingProducer")
0528           << "serviceOne->nPreGlobalWriteLumi = " << serviceOne->nPreGlobalWriteLumi();
0529       edm::LogAbsolute("ExceptionThrowingProducer")
0530           << "serviceOne->nPostGlobalWriteLumi = " << serviceOne->nPostGlobalWriteLumi() << "\n";
0531 
0532       edm::LogAbsolute("ExceptionThrowingProducer")
0533           << "serviceOne->nPreStreamBeginRun = " << serviceOne->nPreStreamBeginRun();
0534       edm::LogAbsolute("ExceptionThrowingProducer")
0535           << "serviceOne->nPostStreamBeginRun = " << serviceOne->nPostStreamBeginRun();
0536       edm::LogAbsolute("ExceptionThrowingProducer")
0537           << "serviceOne->nPreStreamEndRun = " << serviceOne->nPreStreamEndRun();
0538       edm::LogAbsolute("ExceptionThrowingProducer")
0539           << "serviceOne->nPostStreamEndRun = " << serviceOne->nPostStreamEndRun();
0540       edm::LogAbsolute("ExceptionThrowingProducer")
0541           << "serviceOne->nPreModuleStreamBeginRun = " << serviceOne->nPreModuleStreamBeginRun();
0542       edm::LogAbsolute("ExceptionThrowingProducer")
0543           << "serviceOne->nPostModuleStreamBeginRun = " << serviceOne->nPostModuleStreamBeginRun();
0544       edm::LogAbsolute("ExceptionThrowingProducer")
0545           << "serviceOne->nPreModuleStreamEndRun = " << serviceOne->nPreModuleStreamEndRun();
0546       edm::LogAbsolute("ExceptionThrowingProducer")
0547           << "serviceOne->nPostModuleStreamEndRun = " << serviceOne->nPostModuleStreamEndRun() << "\n";
0548 
0549       edm::LogAbsolute("ExceptionThrowingProducer")
0550           << "serviceOne->nPreGlobalBeginRun = " << serviceOne->nPreGlobalBeginRun();
0551       edm::LogAbsolute("ExceptionThrowingProducer")
0552           << "serviceOne->nPostGlobalBeginRun = " << serviceOne->nPostGlobalBeginRun();
0553       edm::LogAbsolute("ExceptionThrowingProducer")
0554           << "serviceOne->nPreGlobalEndRun = " << serviceOne->nPreGlobalEndRun();
0555       edm::LogAbsolute("ExceptionThrowingProducer")
0556           << "serviceOne->nPostGlobalEndRun = " << serviceOne->nPostGlobalEndRun();
0557       edm::LogAbsolute("ExceptionThrowingProducer")
0558           << "serviceOne->nPreModuleGlobalBeginRun = " << serviceOne->nPreModuleGlobalBeginRun();
0559       edm::LogAbsolute("ExceptionThrowingProducer")
0560           << "serviceOne->nPostModuleGlobalBeginRun = " << serviceOne->nPostModuleGlobalBeginRun();
0561       edm::LogAbsolute("ExceptionThrowingProducer")
0562           << "serviceOne->nPreModuleGlobalEndRun = " << serviceOne->nPreModuleGlobalEndRun();
0563       edm::LogAbsolute("ExceptionThrowingProducer")
0564           << "serviceOne->nPostModuleGlobalEndRun = " << serviceOne->nPostModuleGlobalEndRun();
0565       edm::LogAbsolute("ExceptionThrowingProducer")
0566           << "serviceOne->nPreGlobalWriteRun = " << serviceOne->nPreGlobalWriteRun();
0567       edm::LogAbsolute("ExceptionThrowingProducer")
0568           << "serviceOne->nPostGlobalWriteRun = " << serviceOne->nPostGlobalWriteRun() << "\n";
0569     }
0570 
0571     if (testsPass) {
0572       edm::LogAbsolute("ExceptionThrowingProducer") << "All tests in ExceptionThrowingProducer PASSED";
0573     } else {
0574       edm::LogAbsolute("ExceptionThrowingProducer") << "At least one test in ExceptionThrowingProducer FAILED";
0575     }
0576   }
0577 
0578   void ExceptionThrowingProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0579     edm::ParameterSetDescription desc;
0580     edm::EventID invalidEventID;
0581     desc.addUntracked<bool>("verbose", false);
0582     desc.addUntracked<edm::EventID>("eventIDThrowOnEvent", invalidEventID);
0583     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalBeginRun", invalidEventID);
0584     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalBeginLumi", invalidEventID);
0585     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalEndRun", invalidEventID);
0586     desc.addUntracked<edm::EventID>("eventIDThrowOnGlobalEndLumi", invalidEventID);
0587     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamBeginRun", invalidEventID);
0588     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamBeginLumi", invalidEventID);
0589     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamEndRun", invalidEventID);
0590     desc.addUntracked<edm::EventID>("eventIDThrowOnStreamEndLumi", invalidEventID);
0591 
0592     desc.addUntracked<unsigned int>("expectedStreamBeginLumi", kUnset);
0593     desc.addUntracked<unsigned int>("expectedOffsetNoStreamEndLumi", 0);
0594     desc.addUntracked<unsigned int>("expectedGlobalBeginLumi", 0);
0595     desc.addUntracked<unsigned int>("expectedOffsetNoGlobalEndLumi", 0);
0596     desc.addUntracked<unsigned int>("expectedOffsetNoWriteLumi", 0);
0597 
0598     desc.addUntracked<unsigned int>("expectedStreamBeginRun", kUnset);
0599     desc.addUntracked<unsigned int>("expectedOffsetNoStreamEndRun", 0);
0600     desc.addUntracked<unsigned int>("expectedGlobalBeginRun", 0);
0601     desc.addUntracked<unsigned int>("expectedOffsetNoGlobalEndRun", 0);
0602     desc.addUntracked<unsigned int>("expectedOffsetNoWriteRun", 0);
0603 
0604     descriptions.addDefault(desc);
0605   }
0606 
0607 }  // namespace edmtest
0608 using edmtest::ExceptionThrowingProducer;
0609 DEFINE_FWK_MODULE(ExceptionThrowingProducer);