Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-22 02:23:22

0001 #include "DataFormats/L1Scouting/interface/L1ScoutingBMTFStub.h"
0002 #include "DataFormats/L1Scouting/interface/L1ScoutingMuon.h"
0003 #include "DataFormats/L1Scouting/interface/L1ScoutingCalo.h"
0004 #include "DataFormats/L1Scouting/interface/OrbitCollection.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/Frameworkfwd.h"
0007 #include "FWCore/Framework/interface/global/EDProducer.h"
0008 #include "FWCore/Framework/interface/MakerMacros.h"
0009 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0012 #include "FWCore/Utilities/interface/EDPutToken.h"
0013 #include "FWCore/Utilities/interface/StreamID.h"
0014 
0015 #include <memory>
0016 #include <utility>
0017 #include <vector>
0018 
0019 namespace edmtest {
0020   using namespace l1ScoutingRun3;
0021   class TestWriteL1Scouting : public edm::global::EDProducer<> {
0022   public:
0023     TestWriteL1Scouting(edm::ParameterSet const&);
0024     void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
0025     static void fillDescriptions(edm::ConfigurationDescriptions&);
0026 
0027   private:
0028     void produceMuons(edm::Event& iEvent) const;
0029     void produceJets(edm::Event& iEvent) const;
0030     void produceEGammas(edm::Event& iEvent) const;
0031     void produceTaus(edm::Event& iEvent) const;
0032     void produceBxSums(edm::Event& iEvent) const;
0033     void produceBmtfStubs(edm::Event& iEvent) const;
0034 
0035     void throwWithMessage(const char*) const;
0036 
0037     const std::vector<unsigned int> bxValues_;
0038 
0039     const std::vector<int> muonValues_;
0040     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::Muon>> muonsPutToken_;
0041 
0042     const std::vector<int> jetValues_;
0043     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::Jet>> jetsPutToken_;
0044 
0045     const std::vector<int> eGammaValues_;
0046     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::EGamma>> eGammasPutToken_;
0047 
0048     const std::vector<int> tauValues_;
0049     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::Tau>> tausPutToken_;
0050 
0051     const std::vector<int> bxSumsValues_;
0052     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::BxSums>> bxSumsPutToken_;
0053 
0054     const std::vector<int> bmtfStubsValues_;
0055     const edm::EDPutTokenT<OrbitCollection<l1ScoutingRun3::BMTFStub>> bmtfStubsPutToken_;
0056   };
0057 
0058   TestWriteL1Scouting::TestWriteL1Scouting(edm::ParameterSet const& iPSet)
0059       : bxValues_(iPSet.getParameter<std::vector<unsigned>>("bxValues")),
0060         muonValues_(iPSet.getParameter<std::vector<int>>("muonValues")),
0061         muonsPutToken_(produces()),
0062         jetValues_(iPSet.getParameter<std::vector<int>>("jetValues")),
0063         jetsPutToken_(produces()),
0064         eGammaValues_(iPSet.getParameter<std::vector<int>>("eGammaValues")),
0065         eGammasPutToken_(produces()),
0066         tauValues_(iPSet.getParameter<std::vector<int>>("tauValues")),
0067         tausPutToken_(produces()),
0068         bxSumsValues_(iPSet.getParameter<std::vector<int>>("bxSumsValues")),
0069         bxSumsPutToken_(produces()),
0070         bmtfStubsValues_(iPSet.getParameter<std::vector<int>>("bmtfStubValues")),
0071         bmtfStubsPutToken_(produces()) {
0072     if (bxValues_.size() != 2) {
0073       throwWithMessage("bxValues must have 2 elements and it does not");
0074     }
0075     if (muonValues_.size() != 3) {
0076       throwWithMessage("muonValues must have 3 elements and it does not");
0077     }
0078     if (jetValues_.size() != 4) {
0079       throwWithMessage("jetValues must have 4 elements and it does not");
0080     }
0081     if (eGammaValues_.size() != 3) {
0082       throwWithMessage("eGammaValues must have 3 elements and it does not");
0083     }
0084     if (tauValues_.size() != 2) {
0085       throwWithMessage("tauValues must have 2 elements and it does not");
0086     }
0087     if (bxSumsValues_.size() != 1) {
0088       throwWithMessage("bxSumsValues_ must have 1 elements and it does not");
0089     }
0090     if (bmtfStubsValues_.size() != 2) {
0091       throwWithMessage("bmtfStubsValues_ must have 2 elements and it does not");
0092     }
0093   }
0094 
0095   void TestWriteL1Scouting::produce(edm::StreamID, edm::Event& iEvent, edm::EventSetup const&) const {
0096     produceMuons(iEvent);
0097     produceJets(iEvent);
0098     produceEGammas(iEvent);
0099     produceTaus(iEvent);
0100     produceBxSums(iEvent);
0101     produceBmtfStubs(iEvent);
0102   }
0103 
0104   void TestWriteL1Scouting::produceMuons(edm::Event& iEvent) const {
0105     std::unique_ptr<l1ScoutingRun3::MuonOrbitCollection> muons(new l1ScoutingRun3::MuonOrbitCollection);
0106 
0107     std::vector<std::vector<l1ScoutingRun3::Muon>> orbitBufferMuons(3565);
0108     int nMuons = 0;
0109     for (const unsigned& bx : bxValues_) {
0110       for (const int& val : muonValues_) {
0111         orbitBufferMuons[bx].emplace_back(val, val, val, val, val, val, val, val, val, val, val, val);
0112         nMuons++;
0113       }
0114     }
0115 
0116     muons->fillAndClear(orbitBufferMuons, nMuons);
0117     iEvent.put(muonsPutToken_, std::move(muons));
0118   }
0119 
0120   void TestWriteL1Scouting::produceJets(edm::Event& iEvent) const {
0121     std::unique_ptr<l1ScoutingRun3::JetOrbitCollection> jets(new l1ScoutingRun3::JetOrbitCollection);
0122 
0123     std::vector<std::vector<l1ScoutingRun3::Jet>> orbitBufferJets(3565);
0124     int nJets = 0;
0125     for (const unsigned& bx : bxValues_) {
0126       for (const int& val : jetValues_) {
0127         orbitBufferJets[bx].emplace_back(val, val, val, val);
0128         nJets++;
0129       }
0130     }
0131 
0132     jets->fillAndClear(orbitBufferJets, nJets);
0133     iEvent.put(jetsPutToken_, std::move(jets));
0134   }
0135 
0136   void TestWriteL1Scouting::produceEGammas(edm::Event& iEvent) const {
0137     std::unique_ptr<l1ScoutingRun3::EGammaOrbitCollection> eGammas(new l1ScoutingRun3::EGammaOrbitCollection);
0138 
0139     std::vector<std::vector<l1ScoutingRun3::EGamma>> orbitBufferEGammas(3565);
0140     int nEGammas = 0;
0141     for (const unsigned& bx : bxValues_) {
0142       for (const int& val : eGammaValues_) {
0143         orbitBufferEGammas[bx].emplace_back(val, val, val, val);
0144         nEGammas++;
0145       }
0146     }
0147 
0148     eGammas->fillAndClear(orbitBufferEGammas, nEGammas);
0149     iEvent.put(eGammasPutToken_, std::move(eGammas));
0150   }
0151 
0152   void TestWriteL1Scouting::produceTaus(edm::Event& iEvent) const {
0153     std::unique_ptr<l1ScoutingRun3::TauOrbitCollection> taus(new l1ScoutingRun3::TauOrbitCollection);
0154 
0155     std::vector<std::vector<l1ScoutingRun3::Tau>> orbitBufferTaus(3565);
0156     int nTaus = 0;
0157     for (const unsigned& bx : bxValues_) {
0158       for (const int& val : tauValues_) {
0159         orbitBufferTaus[bx].emplace_back(val, val, val, val);
0160         nTaus++;
0161       }
0162     }
0163 
0164     taus->fillAndClear(orbitBufferTaus, nTaus);
0165     iEvent.put(tausPutToken_, std::move(taus));
0166   }
0167 
0168   void TestWriteL1Scouting::produceBxSums(edm::Event& iEvent) const {
0169     std::unique_ptr<l1ScoutingRun3::BxSumsOrbitCollection> bxSums(new l1ScoutingRun3::BxSumsOrbitCollection);
0170 
0171     std::vector<std::vector<l1ScoutingRun3::BxSums>> orbitBufferBxSums(3565);
0172     int nBxSums = 0;
0173     for (const unsigned& bx : bxValues_) {
0174       for (const int& val : bxSumsValues_) {
0175         orbitBufferBxSums[bx].emplace_back(
0176             val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val);
0177         nBxSums++;
0178       }
0179     }
0180 
0181     bxSums->fillAndClear(orbitBufferBxSums, nBxSums);
0182     iEvent.put(bxSumsPutToken_, std::move(bxSums));
0183   }
0184 
0185   void TestWriteL1Scouting::produceBmtfStubs(edm::Event& iEvent) const {
0186     std::unique_ptr<l1ScoutingRun3::BMTFStubOrbitCollection> stubs(new l1ScoutingRun3::BMTFStubOrbitCollection);
0187 
0188     std::vector<std::vector<l1ScoutingRun3::BMTFStub>> orbitBufferStubs(3565);
0189     int nStubs = 0;
0190     for (const unsigned& bx : bxValues_) {
0191       for (const int& val : bmtfStubsValues_) {
0192         orbitBufferStubs[bx].emplace_back(val + 8, val + 7, val + 6, val + 5, val + 4, val + 3, val + 2, val + 1, val);
0193         nStubs++;
0194       }
0195     }
0196 
0197     stubs->fillAndClear(orbitBufferStubs, nStubs);
0198     iEvent.put(bmtfStubsPutToken_, std::move(stubs));
0199   }
0200 
0201   void TestWriteL1Scouting::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0202     edm::ParameterSetDescription desc;
0203     desc.add<std::vector<unsigned int>>("bxValues");
0204     desc.add<std::vector<int>>("muonValues");
0205     desc.add<std::vector<int>>("jetValues");
0206     desc.add<std::vector<int>>("eGammaValues");
0207     desc.add<std::vector<int>>("tauValues");
0208     desc.add<std::vector<int>>("bxSumsValues");
0209     desc.add<std::vector<int>>("bmtfStubValues");
0210     descriptions.addDefault(desc);
0211   }
0212 
0213   void TestWriteL1Scouting::throwWithMessage(const char* msg) const {
0214     throw cms::Exception("TestFailure") << "TestWriteL1Scouting constructor, test configuration error, " << msg;
0215   }
0216 
0217 }  // namespace edmtest
0218 
0219 using edmtest::TestWriteL1Scouting;
0220 DEFINE_FWK_MODULE(TestWriteL1Scouting);