Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 02:27:21

0001 // -*- C++ -*-
0002 //
0003 // Package:    Modules
0004 // Class:      AbortOnEventIDAnalyzer
0005 //
0006 /**\class AbortOnEventIDAnalyzer AbortOnEventIDAnalyzer.cc FWCore/Modules/src/AbortOnEventIDAnalyzer.cc
0007 
0008  Description: Does a system abort when it seens the specified EventID. Useful for testing error handling.
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Tue Jun 16 15:42:17 CDT 2009
0016 //
0017 //
0018 
0019 // user include files
0020 #include "DataFormats/Provenance/interface/EventID.h"
0021 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 
0028 // system include files
0029 #include <algorithm>
0030 #include <memory>
0031 #include <vector>
0032 #include <cstdlib>
0033 
0034 //
0035 // class decleration
0036 //
0037 
0038 class AbortOnEventIDAnalyzer : public edm::global::EDAnalyzer<> {
0039 public:
0040   explicit AbortOnEventIDAnalyzer(edm::ParameterSet const&);
0041   ~AbortOnEventIDAnalyzer() override;
0042   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043 
0044 private:
0045   void beginJob() override;
0046   void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0047   void endJob() override;
0048 
0049   // ----------member data ---------------------------
0050   std::vector<edm::EventID> ids_;
0051   bool throwException_;
0052 };
0053 
0054 //
0055 // constants, enums and typedefs
0056 //
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 AbortOnEventIDAnalyzer::AbortOnEventIDAnalyzer(edm::ParameterSet const& iConfig)
0066     : ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventsToAbort")),
0067       throwException_(iConfig.getUntrackedParameter<bool>("throwExceptionInsteadOfAbort")) {
0068   //now do what ever initialization is needed
0069 }
0070 
0071 AbortOnEventIDAnalyzer::~AbortOnEventIDAnalyzer() {
0072   // do anything here that needs to be done at desctruction time
0073   // (e.g. close files, deallocate resources etc.)
0074 }
0075 
0076 //
0077 // member functions
0078 //
0079 
0080 namespace {
0081   struct CompareWithoutLumi {
0082     CompareWithoutLumi(edm::EventID const& iThis) : m_this(iThis) {}
0083     bool operator()(edm::EventID const& iOther) {
0084       return m_this.run() == iOther.run() && m_this.event() == iOther.event();
0085     }
0086     edm::EventID m_this;
0087   };
0088 }  // namespace
0089 
0090 // ------------ method called to for each event  ------------
0091 void AbortOnEventIDAnalyzer::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0092   auto itFind = std::find_if(ids_.begin(), ids_.end(), CompareWithoutLumi(iEvent.id()));
0093   if (itFind != ids_.end()) {
0094     if (throwException_) {
0095       throw cms::Exception("AbortEvent") << "Found event " << iEvent.id() << "\n";
0096     } else {
0097       abort();
0098     }
0099   }
0100 }
0101 
0102 // ------------ method called once each job just before starting event loop  ------------
0103 void AbortOnEventIDAnalyzer::beginJob() {}
0104 
0105 // ------------ method called once each job just after ending the event loop  ------------
0106 void AbortOnEventIDAnalyzer::endJob() {}
0107 
0108 // ------------ method called once each job for validation
0109 void AbortOnEventIDAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0110   edm::ParameterSetDescription desc;
0111   desc.addUntracked<std::vector<edm::EventID> >("eventsToAbort");
0112   desc.addUntracked<bool>("throwExceptionInsteadOfAbort", false);
0113   descriptions.add("abortOnEventID", desc);
0114 }
0115 
0116 //define this as a plug-in
0117 DEFINE_FWK_MODULE(AbortOnEventIDAnalyzer);