File indexing completed on 2024-04-06 12:04:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0019 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0020 #include "FWCore/Framework/interface/Event.h"
0021 #include "FWCore/Framework/interface/Frameworkfwd.h"
0022 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0023 #include "FWCore/Framework/interface/MakerMacros.h"
0024 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0026 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0027 #include "FWCore/Utilities/interface/EDGetToken.h"
0028 #include "FWCore/Utilities/interface/Exception.h"
0029 #include "FWCore/Utilities/interface/InputTag.h"
0030 #include "FWCore/Utilities/interface/StreamID.h"
0031
0032 #include <vector>
0033
0034 namespace edmtest {
0035
0036 class TestReadFEDRawDataCollection : public edm::global::EDAnalyzer<> {
0037 public:
0038 TestReadFEDRawDataCollection(edm::ParameterSet const&);
0039 void analyze(edm::StreamID, edm::Event const&, edm::EventSetup const&) const override;
0040 void throwWithMessage(const char*) const;
0041 static void fillDescriptions(edm::ConfigurationDescriptions&);
0042
0043 private:
0044
0045
0046
0047
0048
0049 std::vector<unsigned int> expectedFEDData0_;
0050 std::vector<unsigned int> expectedFEDData3_;
0051 edm::EDGetTokenT<FEDRawDataCollection> fedRawDataCollectionToken_;
0052 };
0053
0054 TestReadFEDRawDataCollection::TestReadFEDRawDataCollection(edm::ParameterSet const& iPSet)
0055 : expectedFEDData0_(iPSet.getParameter<std::vector<unsigned int>>("expectedFEDData0")),
0056 expectedFEDData3_(iPSet.getParameter<std::vector<unsigned int>>("expectedFEDData3")),
0057 fedRawDataCollectionToken_(consumes(iPSet.getParameter<edm::InputTag>("fedRawDataCollectionTag"))) {}
0058
0059 void TestReadFEDRawDataCollection::analyze(edm::StreamID, edm::Event const& iEvent, edm::EventSetup const&) const {
0060 auto const& fedRawDataCollection = iEvent.get(fedRawDataCollectionToken_);
0061 auto const& fedData0 = fedRawDataCollection.FEDData(0);
0062 if (fedData0.size() != expectedFEDData0_.size()) {
0063 throwWithMessage("fedData0 does not have expected size");
0064 }
0065 for (unsigned int i = 0; i < fedData0.size(); ++i) {
0066 if (fedData0.data()[i] != expectedFEDData0_[i]) {
0067 throwWithMessage("fedData0 does not have expected contents");
0068 }
0069 }
0070 auto const& fedData3 = fedRawDataCollection.FEDData(3);
0071 if (fedData3.size() != expectedFEDData3_.size()) {
0072 throwWithMessage("fedData3 does not have expected size");
0073 }
0074 for (unsigned int i = 0; i < fedData3.size(); ++i) {
0075 if (fedData3.data()[i] != expectedFEDData3_[i]) {
0076 throwWithMessage("fedData3 does not have expected contents");
0077 }
0078 }
0079 }
0080
0081 void TestReadFEDRawDataCollection::throwWithMessage(const char* msg) const {
0082 throw cms::Exception("TestFailure") << "TestReadFEDRawDataCollection::analyze, " << msg;
0083 }
0084
0085 void TestReadFEDRawDataCollection::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0086 edm::ParameterSetDescription desc;
0087 desc.add<std::vector<unsigned int>>("expectedFEDData0");
0088 desc.add<std::vector<unsigned int>>("expectedFEDData3");
0089 desc.add<edm::InputTag>("fedRawDataCollectionTag");
0090 descriptions.addDefault(desc);
0091 }
0092 }
0093
0094 using edmtest::TestReadFEDRawDataCollection;
0095 DEFINE_FWK_MODULE(TestReadFEDRawDataCollection);