File indexing completed on 2024-04-06 12:03:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "DataFormats/Common/interface/TriggerResults.h"
0019 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0026 #include "FWCore/Utilities/interface/EDGetToken.h"
0027 #include "FWCore/Utilities/interface/Exception.h"
0028 #include "FWCore/Utilities/interface/InputTag.h"
0029
0030 #include <string>
0031 #include <vector>
0032
0033 namespace edmtest {
0034
0035 class TestReadTriggerResults : public edm::global::EDAnalyzer<> {
0036 public:
0037 TestReadTriggerResults(edm::ParameterSet const&);
0038 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0039 void throwWithMessage(const char*) const;
0040 static void fillDescriptions(edm::ConfigurationDescriptions&);
0041
0042 private:
0043 std::string expectedParameterSetID_;
0044 std::vector<std::string> expectedNames_;
0045 std::vector<unsigned int> expectedHLTStates_;
0046 std::vector<unsigned int> expectedModuleIndexes_;
0047 edm::EDGetTokenT<edm::TriggerResults> triggerResultsToken_;
0048 };
0049
0050 TestReadTriggerResults::TestReadTriggerResults(edm::ParameterSet const& iPSet)
0051 : expectedParameterSetID_(iPSet.getParameter<std::string>("expectedParameterSetID")),
0052 expectedNames_(iPSet.getParameter<std::vector<std::string>>("expectedNames")),
0053 expectedHLTStates_(iPSet.getParameter<std::vector<unsigned int>>("expectedHLTStates")),
0054 expectedModuleIndexes_(iPSet.getParameter<std::vector<unsigned int>>("expectedModuleIndexes")),
0055 triggerResultsToken_(consumes(iPSet.getParameter<edm::InputTag>("triggerResultsTag"))) {}
0056
0057 void TestReadTriggerResults::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0058 auto const& triggerResults = iEvent.get(triggerResultsToken_);
0059 std::string parameterSetID;
0060 triggerResults.parameterSetID().toString(parameterSetID);
0061 if (parameterSetID != expectedParameterSetID_) {
0062 throwWithMessage("parameterSetID does not match expected value");
0063 }
0064 if (triggerResults.getTriggerNames() != expectedNames_) {
0065 throwWithMessage("names vector does not include expected values");
0066 }
0067 if (expectedHLTStates_.size() != expectedModuleIndexes_.size()) {
0068 throwWithMessage(
0069 "test configuration error, expectedHLTStates and expectedModuleIndexes should have the same size");
0070 }
0071 if (triggerResults.size() != expectedHLTStates_.size()) {
0072 throwWithMessage("paths has unexpected size");
0073 }
0074 for (unsigned int i = 0; i < expectedHLTStates_.size(); ++i) {
0075 if (static_cast<unsigned int>(triggerResults.state(i)) != expectedHLTStates_[i]) {
0076 throwWithMessage("state has unexpected value");
0077 }
0078 if (triggerResults.index(i) != expectedModuleIndexes_[i]) {
0079 throwWithMessage("module index has unexpected value");
0080 }
0081 }
0082 }
0083
0084 void TestReadTriggerResults::throwWithMessage(const char* msg) const {
0085 throw cms::Exception("TestFailure") << "TestReadTriggerResults::analyze, " << msg;
0086 }
0087
0088 void TestReadTriggerResults::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0089 edm::ParameterSetDescription desc;
0090 desc.add<std::string>("expectedParameterSetID");
0091 desc.add<std::vector<std::string>>("expectedNames");
0092 desc.add<std::vector<unsigned int>>("expectedHLTStates");
0093 desc.add<std::vector<unsigned int>>("expectedModuleIndexes");
0094 desc.add<edm::InputTag>("triggerResultsTag");
0095 descriptions.addDefault(desc);
0096 }
0097 }
0098
0099 using edmtest::TestReadTriggerResults;
0100 DEFINE_FWK_MODULE(TestReadTriggerResults);