File indexing completed on 2024-04-06 12:25:54
0001 #include <memory>
0002
0003 #include "FWCore/Framework/interface/stream/EDProducer.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "DataFormats/HGCRecHit/interface/HGCRecHit.h"
0006 #include "DataFormats/HGCRecHit/interface/HGCRecHitCollections.h"
0007 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/Utilities/interface/EDPutToken.h"
0010
0011 #include "CUDADataFormats/HGCal/interface/HGCRecHitCPUProduct.h"
0012 #include "CUDADataFormats/HGCal/interface/ConstHGCRecHitSoA.h"
0013
0014 class HEBRecHitFromSoA : public edm::stream::EDProducer<> {
0015 public:
0016 explicit HEBRecHitFromSoA(const edm::ParameterSet& ps);
0017 ~HEBRecHitFromSoA() override;
0018
0019 void produce(edm::Event&, const edm::EventSetup&) override;
0020 void convert_soa_data_to_collection_(uint32_t, HGCRecHitCollection&, ConstHGCRecHitSoA*);
0021
0022 private:
0023 std::unique_ptr<HGChefRecHitCollection> rechits_;
0024 edm::EDGetTokenT<HGCRecHitCPUProduct> recHitSoAToken_;
0025 edm::EDPutTokenT<HGChefRecHitCollection> recHitCollectionToken_;
0026 };
0027
0028 HEBRecHitFromSoA::HEBRecHitFromSoA(const edm::ParameterSet& ps) {
0029 recHitSoAToken_ = consumes<HGCRecHitCPUProduct>(ps.getParameter<edm::InputTag>("HEBRecHitSoATok"));
0030 recHitCollectionToken_ = produces<HGChebRecHitCollection>();
0031 }
0032
0033 HEBRecHitFromSoA::~HEBRecHitFromSoA() {}
0034
0035 void HEBRecHitFromSoA::produce(edm::Event& event, const edm::EventSetup& setup) {
0036 const HGCRecHitCPUProduct& recHits = event.get(recHitSoAToken_);
0037 ConstHGCRecHitSoA recHitsSoA = recHits.get();
0038 rechits_ = std::make_unique<HGCRecHitCollection>();
0039 convert_soa_data_to_collection_(recHits.nHits(), *rechits_, &recHitsSoA);
0040 event.put(std::move(rechits_));
0041 }
0042
0043 void HEBRecHitFromSoA::convert_soa_data_to_collection_(uint32_t nhits,
0044 HGCRecHitCollection& rechits,
0045 ConstHGCRecHitSoA* h_calibSoA) {
0046 rechits.reserve(nhits);
0047 for (uint i = 0; i < nhits; ++i) {
0048 DetId id_converted(h_calibSoA->id_[i]);
0049 rechits.emplace_back(id_converted,
0050 h_calibSoA->energy_[i],
0051 h_calibSoA->time_[i],
0052 0,
0053 h_calibSoA->flagBits_[i],
0054 h_calibSoA->son_[i],
0055 h_calibSoA->timeError_[i]);
0056 }
0057 }
0058
0059 #include "FWCore/Framework/interface/MakerMacros.h"
0060 DEFINE_FWK_MODULE(HEBRecHitFromSoA);