Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-26 04:25:19

0001 #include <string>
0002 
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 
0012 namespace edmtest {
0013 
0014   class GlobalStringAnalyzer : public edm::global::EDAnalyzer<> {
0015   public:
0016     explicit GlobalStringAnalyzer(edm::ParameterSet const& ps);
0017 
0018     void analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const& es) const override;
0019 
0020     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0021 
0022   private:
0023     edm::EDGetTokenT<std::string> token_;
0024     std::string expected_;
0025   };
0026 
0027   GlobalStringAnalyzer::GlobalStringAnalyzer(edm::ParameterSet const& config)
0028       : token_(consumes(config.getParameter<edm::InputTag>("source"))),
0029         expected_(config.getParameter<std::string>("expected")) {}
0030 
0031   void GlobalStringAnalyzer::analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const& es) const {
0032     std::string const& value = event.get(token_);
0033     if (value != expected_) {
0034       throw cms::Exception("LogicError") << "expected value \"" << expected_ << "\"\nreceived value \"" << value << '"';
0035     }
0036   }
0037 
0038   void GlobalStringAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0039     edm::ParameterSetDescription desc;
0040     desc.add<edm::InputTag>("source");
0041     desc.add<std::string>("expected", "");
0042     descriptions.addDefault(desc);
0043   }
0044 
0045 }  // namespace edmtest
0046 
0047 #include "FWCore/Framework/interface/MakerMacros.h"
0048 DEFINE_FWK_MODULE(edmtest::GlobalStringAnalyzer);