File indexing completed on 2025-02-26 04:25:19
0001 #include <vector>
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 {
0013
0014 template <typename T>
0015 T& operator<<(T& out, std::vector<double> const& values) {
0016 if (values.empty()) {
0017 out << "{}";
0018 return out;
0019 }
0020
0021 auto it = values.begin();
0022 out << "{ " << *it;
0023 ++it;
0024 while (it != values.end()) {
0025 out << ", " << *it;
0026 ++it;
0027 }
0028 out << " }";
0029 return out;
0030 }
0031
0032 }
0033
0034 namespace edmtest {
0035
0036 class GlobalVectorAnalyzer : public edm::global::EDAnalyzer<> {
0037 public:
0038 explicit GlobalVectorAnalyzer(edm::ParameterSet const& ps);
0039
0040 void analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const& es) const override;
0041
0042 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043
0044 private:
0045 edm::EDGetTokenT<std::vector<double>> token_;
0046 std::vector<double> expected_;
0047 };
0048
0049 GlobalVectorAnalyzer::GlobalVectorAnalyzer(edm::ParameterSet const& config)
0050 : token_(consumes(config.getParameter<edm::InputTag>("source"))),
0051 expected_(config.getParameter<std::vector<double>>("expected")) {}
0052
0053 void GlobalVectorAnalyzer::analyze(edm::StreamID sid, edm::Event const& event, edm::EventSetup const& es) const {
0054 std::vector<double> const& values = event.get(token_);
0055 if (values != expected_) {
0056 throw cms::Exception("LogicError") << "expected values \"" << expected_ << "\"\nreceived values \"" << values
0057 << '"';
0058 }
0059 }
0060
0061 void GlobalVectorAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0062 edm::ParameterSetDescription desc;
0063 desc.add<edm::InputTag>("source");
0064 desc.add<std::vector<double>>("expected", {});
0065 descriptions.addDefault(desc);
0066 }
0067
0068 }
0069
0070 #include "FWCore/Framework/interface/MakerMacros.h"
0071 DEFINE_FWK_MODULE(edmtest::GlobalVectorAnalyzer);