Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:22

0001 // -*- C++ -*-
0002 //
0003 // Package:    EventSetupIntProductAnalyzer
0004 // Class:      EventSetupIntProductAnalyzer
0005 //
0006 /**\class EventSetupIntProductAnalyzer EventSetupIntProductAnalyzer.cc test/EventSetupIntProductAnalyzer/src/EventSetupIntProductAnalyzer.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Fri Jun 24 19:13:25 EDT 2005
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <iostream>
0022 #include <vector>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0030 #include "PhysicsTools/CondLiteIO/test/IntProductRecord.h"
0031 
0032 #include "FWCore/Framework/interface/ESHandle.h"
0033 #include "FWCore/Framework/interface/EventSetup.h"
0034 #include "FWCore/Utilities/interface/Exception.h"
0035 
0036 //
0037 // class decleration
0038 //
0039 
0040 namespace edmtest {
0041 
0042   class EventSetupIntProductAnalyzer : public edm::one::EDAnalyzer<> {
0043   public:
0044     explicit EventSetupIntProductAnalyzer(const edm::ParameterSet&);
0045     ~EventSetupIntProductAnalyzer();
0046 
0047     virtual void analyze(const edm::Event&, const edm::EventSetup&);
0048 
0049   private:
0050     // ----------member data ---------------------------
0051     std::vector<int> expectedValues_;
0052     unsigned int index_;
0053     edm::ESGetToken<edmtest::IntProduct, IntProductRecord> token_;
0054   };
0055 
0056   //
0057   // constants, enums and typedefs
0058   //
0059 
0060   //
0061   // static data member definitions
0062   //
0063 
0064   //
0065   // constructors and destructor
0066   //
0067   EventSetupIntProductAnalyzer::EventSetupIntProductAnalyzer(const edm::ParameterSet& iConfig)
0068       : expectedValues_(iConfig.getUntrackedParameter<std::vector<int> >("expectedValues", std::vector<int>())),
0069         index_(0),
0070         token_(esConsumes()) {
0071     //now do what ever initialization is needed
0072   }
0073 
0074   EventSetupIntProductAnalyzer::~EventSetupIntProductAnalyzer() {
0075     // do anything here that needs to be done at desctruction time
0076     // (e.g. close files, deallocate resources etc.)
0077   }
0078 
0079   //
0080   // member functions
0081   //
0082 
0083   // ------------ method called to produce the data  ------------
0084   void EventSetupIntProductAnalyzer::analyze(const edm::Event& /*iEvent*/, const edm::EventSetup& iSetup) {
0085     using namespace edm;
0086     auto const& setup = iSetup.getData(token_);
0087 
0088     std::cout << "edmtest::IntProduct " << setup.value << std::endl;
0089     if (!expectedValues_.empty()) {
0090       if (expectedValues_.at(index_) != setup.value) {
0091         throw cms::Exception("TestFail") << "expected value " << expectedValues_[index_] << " but was got "
0092                                          << setup.value;
0093       }
0094       ++index_;
0095     }
0096   }
0097 }  // namespace edmtest
0098 using namespace edmtest;
0099 //define this as a plug-in
0100 DEFINE_FWK_MODULE(EventSetupIntProductAnalyzer);