Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-30 08:50:55

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