Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-28 23:10:55

0001 // CMSSW include files
0002 #include "DataFormats/Provenance/interface/EventID.h"
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/ParameterSetDescription.h"
0007 #include "FWCore/Utilities/interface/EDGetToken.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 namespace edmtest {
0011 
0012   class EventIDValidator : public edm::global::EDAnalyzer<> {
0013   public:
0014     EventIDValidator(edm::ParameterSet const& config)
0015         : token_(consumes(config.getUntrackedParameter<edm::InputTag>("source"))) {}
0016 
0017     void analyze(edm::StreamID, edm::Event const& event, edm::EventSetup const&) const final {
0018       auto const& id = event.get(token_);
0019       if (id != event.id()) {
0020         throw cms::Exception("InvalidValue") << "EventIDValidator: found invalid input value\n"
0021                                              << id << "\nwhile expecting\n"
0022                                              << event.id();
0023       }
0024     }
0025 
0026     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0027       edm::ParameterSetDescription desc;
0028       desc.addUntracked("source", edm::InputTag{"eventIDProducer", ""})
0029           ->setComment("EventID product to read from the event");
0030       descriptions.addWithDefaultLabel(desc);
0031     }
0032 
0033   private:
0034     edm::EDGetTokenT<edm::EventID> token_;
0035   };
0036 
0037 }  // namespace edmtest
0038 
0039 #include "FWCore/Framework/interface/MakerMacros.h"
0040 DEFINE_FWK_MODULE(edmtest::EventIDValidator);