File indexing completed on 2024-04-06 12:04:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "DataFormats/DetId/interface/DetId.h"
0019 #include "FWCore/Framework/interface/Event.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/global/EDAnalyzer.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 #include "FWCore/Utilities/interface/StreamID.h"
0030
0031 #include <vector>
0032
0033 namespace edmtest {
0034
0035 class TestReadVectorDetId : public edm::global::EDAnalyzer<> {
0036 public:
0037 TestReadVectorDetId(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
0044
0045
0046 unsigned int expectedTestValue_;
0047
0048 edm::EDGetTokenT<std::vector<DetId>> collectionToken_;
0049 };
0050
0051 TestReadVectorDetId::TestReadVectorDetId(edm::ParameterSet const& iPSet)
0052 : expectedTestValue_(iPSet.getParameter<unsigned int>("expectedTestValue")),
0053 collectionToken_(consumes(iPSet.getParameter<edm::InputTag>("collectionTag"))) {}
0054
0055 void TestReadVectorDetId::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0056 auto const& vectorDetIds = iEvent.get(collectionToken_);
0057
0058 unsigned int expectedNumberOfDetIds = (iEvent.id().event() - 1) % 10;
0059 unsigned int expectedDetId = expectedTestValue_ + iEvent.id().event();
0060 unsigned int numberOfDetIds = 0;
0061 for (const auto& detId : vectorDetIds) {
0062 ++numberOfDetIds;
0063 expectedDetId += iEvent.id().event();
0064 if (detId.rawId() != expectedDetId) {
0065 throwWithMessage("DetId in vector of DetIds does not have expected value");
0066 }
0067 }
0068 if (numberOfDetIds != expectedNumberOfDetIds) {
0069 throwWithMessage("Number of DetIds does not match expected value");
0070 }
0071 }
0072
0073 void TestReadVectorDetId::throwWithMessage(const char* msg) const {
0074 throw cms::Exception("TestFailure") << "TestReadVectorDetId::analyze, " << msg;
0075 }
0076
0077 void TestReadVectorDetId::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0078 edm::ParameterSetDescription desc;
0079 desc.add<unsigned int>("expectedTestValue");
0080 desc.add<edm::InputTag>("collectionTag");
0081 descriptions.addDefault(desc);
0082 }
0083 }
0084
0085 using edmtest::TestReadVectorDetId;
0086 DEFINE_FWK_MODULE(TestReadVectorDetId);