File indexing completed on 2024-04-06 12:22:09
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 "L1Trigger/TrackTrigger/interface/Setup.h"
0014 #include "L1Trigger/TrackFindingTracklet/interface/ChannelAssignment.h"
0015
0016 #include <string>
0017 #include <vector>
0018 #include <deque>
0019 #include <iterator>
0020 #include <cmath>
0021 #include <numeric>
0022
0023 using namespace std;
0024 using namespace edm;
0025 using namespace tt;
0026
0027 namespace trklet {
0028
0029
0030
0031
0032
0033
0034 class ProducerIRin : public stream::EDProducer<> {
0035 public:
0036 explicit ProducerIRin(const ParameterSet&);
0037 ~ProducerIRin() override {}
0038
0039 private:
0040 void beginRun(const Run&, const EventSetup&) override;
0041 void produce(Event&, const EventSetup&) override;
0042 virtual void endJob() {}
0043
0044 EDGetTokenT<TTDTC> edGetTokenTTDTC_;
0045
0046 EDPutTokenT<StreamsStub> edPutTokenStubs_;
0047
0048 ESGetToken<Setup, SetupRcd> esGetTokenSetup_;
0049
0050 ESGetToken<ChannelAssignment, ChannelAssignmentRcd> esGetTokenChannelAssignment_;
0051
0052 ParameterSet iConfig_;
0053
0054 const Setup* setup_;
0055
0056 const ChannelAssignment* channelAssignment_;
0057
0058 vector<int> channelEncoding_;
0059 };
0060
0061 ProducerIRin::ProducerIRin(const ParameterSet& iConfig) : iConfig_(iConfig) {
0062 const InputTag& inputTag = iConfig.getParameter<InputTag>("InputTagDTC");
0063 const string& branchStubs = iConfig.getParameter<string>("BranchAcceptedStubs");
0064
0065 edGetTokenTTDTC_ = consumes<TTDTC>(inputTag);
0066 edPutTokenStubs_ = produces<StreamsStub>(branchStubs);
0067
0068 esGetTokenSetup_ = esConsumes<Setup, SetupRcd, Transition::BeginRun>();
0069 esGetTokenChannelAssignment_ = esConsumes<ChannelAssignment, ChannelAssignmentRcd, Transition::BeginRun>();
0070
0071 setup_ = nullptr;
0072 }
0073
0074 void ProducerIRin::beginRun(const Run& iRun, const EventSetup& iSetup) {
0075
0076 setup_ = &iSetup.getData(esGetTokenSetup_);
0077 if (!setup_->configurationSupported())
0078 return;
0079
0080 if (iConfig_.getParameter<bool>("CheckHistory"))
0081 setup_->checkHistory(iRun.processHistory());
0082 channelAssignment_ = const_cast<ChannelAssignment*>(&iSetup.getData(esGetTokenChannelAssignment_));
0083
0084 channelEncoding_ = channelAssignment_->channelEncoding();
0085 }
0086
0087 void ProducerIRin::produce(Event& iEvent, const EventSetup& iSetup) {
0088
0089 StreamsStub streamStubs;
0090
0091 if (setup_->configurationSupported()) {
0092 Handle<TTDTC> handleTTDTC;
0093 iEvent.getByToken<TTDTC>(edGetTokenTTDTC_, handleTTDTC);
0094 const int numChannel = channelEncoding_.size();
0095 streamStubs.reserve(numChannel);
0096 for (int tfpRegion : handleTTDTC->tfpRegions())
0097 for (int tfpChannel : channelEncoding_)
0098 streamStubs.emplace_back(handleTTDTC->stream(tfpRegion, tfpChannel));
0099 }
0100
0101 iEvent.emplace(edPutTokenStubs_, std::move(streamStubs));
0102 }
0103
0104 }
0105
0106 DEFINE_FWK_MODULE(trklet::ProducerIRin);