Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:44

0001 #include "FWCore/Framework/interface/stream/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/Framework/interface/EventSetup.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/Utilities/interface/EDGetToken.h"
0007 #include "FWCore/Utilities/interface/EDPutToken.h"
0008 #include "FWCore/Utilities/interface/ESGetToken.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 
0013 #include "DataFormats/L1TrackTrigger/interface/TTDTC.h"
0014 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0015 #include "L1Trigger/TrackTrigger/interface/Setup.h"
0016 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0017 #include "L1Trigger/TrackerTFP/interface/GeometricProcessor.h"
0018 
0019 #include <numeric>
0020 #include <string>
0021 
0022 using namespace std;
0023 using namespace edm;
0024 using namespace tt;
0025 
0026 namespace trackerTFP {
0027 
0028   /*! \class  trackerTFP::ProducerGP
0029    *  \brief  L1TrackTrigger Geometric Processor emulator
0030    *  \author Thomas Schuh
0031    *  \date   2020, March
0032    */
0033   class ProducerGP : public stream::EDProducer<> {
0034   public:
0035     explicit ProducerGP(const ParameterSet&);
0036     ~ProducerGP() override {}
0037 
0038   private:
0039     void beginRun(const Run&, const EventSetup&) override;
0040     void produce(Event&, const EventSetup&) override;
0041     virtual void endJob() {}
0042 
0043     // ED input token of DTC stubs
0044     EDGetTokenT<TTDTC> edGetToken_;
0045     // ED output token for accepted stubs
0046     EDPutTokenT<StreamsStub> edPutTokenAccepted_;
0047     // ED output token for lost stubs
0048     EDPutTokenT<StreamsStub> edPutTokenLost_;
0049     // Setup token
0050     ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0051     // DataFormats token
0052     ESGetToken<DataFormats, DataFormatsRcd> esGetTokenDataFormats_;
0053     // configuration
0054     ParameterSet iConfig_;
0055     // helper classe to store configurations
0056     const Setup* setup_ = nullptr;
0057     // helper class to extract structured data from tt::Frames
0058     const DataFormats* dataFormats_ = nullptr;
0059   };
0060 
0061   ProducerGP::ProducerGP(const ParameterSet& iConfig) : iConfig_(iConfig) {
0062     const string& label = iConfig.getParameter<string>("LabelDTC");
0063     const string& branchAccepted = iConfig.getParameter<string>("BranchAcceptedStubs");
0064     const string& branchLost = iConfig.getParameter<string>("BranchLostStubs");
0065     // book in- and output ED products
0066     edGetToken_ = consumes<TTDTC>(InputTag(label, branchAccepted));
0067     edPutTokenAccepted_ = produces<StreamsStub>(branchAccepted);
0068     edPutTokenLost_ = produces<StreamsStub>(branchLost);
0069     // book ES products
0070     esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0071     esGetTokenDataFormats_ = esConsumes<DataFormats, DataFormatsRcd, Transition::BeginRun>();
0072   }
0073 
0074   void ProducerGP::beginRun(const Run& iRun, const EventSetup& iSetup) {
0075     setup_ = &iSetup.getData(esGetTokenSetup_);
0076     if (!setup_->configurationSupported())
0077       return;
0078     // check process history if desired
0079     if (iConfig_.getParameter<bool>("CheckHistory"))
0080       setup_->checkHistory(iRun.processHistory());
0081     dataFormats_ = &iSetup.getData(esGetTokenDataFormats_);
0082   }
0083 
0084   void ProducerGP::produce(Event& iEvent, const EventSetup& iSetup) {
0085     // empty GP products
0086     StreamsStub accepted(dataFormats_->numStreams(Process::gp));
0087     StreamsStub lost(dataFormats_->numStreams(Process::gp));
0088     // read in DTC Product and produce TFP product
0089     if (setup_->configurationSupported()) {
0090       Handle<TTDTC> handle;
0091       iEvent.getByToken<TTDTC>(edGetToken_, handle);
0092       const TTDTC& ttDTC = *handle.product();
0093       for (int region = 0; region < setup_->numRegions(); region++) {
0094         // object to route Stubs of one region to one stream per sector
0095         GeometricProcessor gp(iConfig_, setup_, dataFormats_, region);
0096         // read in and organize input product
0097         gp.consume(ttDTC);
0098         // fill output products
0099         gp.produce(accepted, lost);
0100       }
0101     }
0102     // store products
0103     iEvent.emplace(edPutTokenAccepted_, std::move(accepted));
0104     iEvent.emplace(edPutTokenLost_, std::move(lost));
0105   }
0106 
0107 }  // namespace trackerTFP
0108 
0109 DEFINE_FWK_MODULE(trackerTFP::ProducerGP);