File indexing completed on 2024-04-06 12:04:30
0001 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0002 #include "DataFormats/L1ScoutingRawData/interface/SDSRawDataCollection.h"
0003 #include "FWCore/Framework/interface/Event.h"
0004 #include "FWCore/Framework/interface/Frameworkfwd.h"
0005 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011 #include "FWCore/Utilities/interface/Exception.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 #include "FWCore/Utilities/interface/StreamID.h"
0014
0015 #include <vector>
0016
0017 namespace edmtest {
0018
0019 class TestReadSDSRawDataCollection : public edm::global::EDAnalyzer<> {
0020 public:
0021 TestReadSDSRawDataCollection(edm::ParameterSet const&);
0022 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0023 void throwWithMessage(const char*) const;
0024 static void fillDescriptions(edm::ConfigurationDescriptions&);
0025
0026 private:
0027 std::vector<unsigned int> expectedSDSData1_;
0028 std::vector<unsigned int> expectedSDSData2_;
0029 edm::EDGetTokenT<SDSRawDataCollection> sdsRawDataCollectionToken_;
0030 };
0031
0032 TestReadSDSRawDataCollection::TestReadSDSRawDataCollection(edm::ParameterSet const& iPSet)
0033 : expectedSDSData1_(iPSet.getParameter<std::vector<unsigned int>>("expectedSDSData1")),
0034 expectedSDSData2_(iPSet.getParameter<std::vector<unsigned int>>("expectedSDSData2")),
0035 sdsRawDataCollectionToken_(consumes(iPSet.getParameter<edm::InputTag>("sdsRawDataCollectionTag"))) {}
0036
0037 void TestReadSDSRawDataCollection::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0038 auto const& sdsRawDataCollection = iEvent.get(sdsRawDataCollectionToken_);
0039 auto const& sdsData1 = sdsRawDataCollection.FEDData(1);
0040 if (sdsData1.size() != expectedSDSData1_.size()) {
0041 throwWithMessage("sdsData1 does not have expected size");
0042 }
0043 for (unsigned int i = 0; i < sdsData1.size(); ++i) {
0044 if (sdsData1.data()[i] != expectedSDSData1_[i]) {
0045 throwWithMessage("sdsData1 does not have expected contents");
0046 }
0047 }
0048 auto const& sdsData2 = sdsRawDataCollection.FEDData(2);
0049 if (sdsData2.size() != expectedSDSData2_.size()) {
0050 throwWithMessage("sdsData2 does not have expected size");
0051 }
0052 for (unsigned int i = 0; i < sdsData2.size(); ++i) {
0053 if (sdsData2.data()[i] != expectedSDSData2_[i]) {
0054 throwWithMessage("sdsData2 does not have expected contents");
0055 }
0056 }
0057 }
0058
0059 void TestReadSDSRawDataCollection::throwWithMessage(const char* msg) const {
0060 throw cms::Exception("TestFailure") << "TestReadSDSRawDataCollection::analyze, " << msg;
0061 }
0062
0063 void TestReadSDSRawDataCollection::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0064 edm::ParameterSetDescription desc;
0065 desc.add<std::vector<unsigned int>>("expectedSDSData1");
0066 desc.add<std::vector<unsigned int>>("expectedSDSData2");
0067 desc.add<edm::InputTag>("sdsRawDataCollectionTag");
0068 descriptions.addDefault(desc);
0069 }
0070 }
0071
0072 using edmtest::TestReadSDSRawDataCollection;
0073 DEFINE_FWK_MODULE(TestReadSDSRawDataCollection);