CMS 3D CMS Logo

CaloRecHitSoAProducer.cc
Go to the documentation of this file.
1 #include <utility>
2 
3 #include <alpaka/alpaka.hpp>
4 
15 #include "CalorimeterDefinitions.h"
16 
19 
20 #define DEBUG false
21 
23  using namespace particleFlowRecHitProducer;
24 
25  template <typename CAL>
27  public:
29  : recHitsToken_(consumes(config.getParameter<edm::InputTag>("src"))),
30  deviceToken_(produces()),
31  synchronise_(config.getUntrackedParameter<bool>("synchronise")) {}
32 
33  void produce(edm::StreamID sid, device::Event& event, device::EventSetup const&) const override {
34  const edm::SortedCollection<typename CAL::CaloRecHitType>& recHits = event.get(recHitsToken_);
35  const int32_t num_recHits = recHits.size();
36  if (DEBUG)
37  printf("Found %d recHits\n", num_recHits);
38 
39  hcal::RecHitHostCollection hostProduct{num_recHits, event.queue()};
40  auto& view = hostProduct.view();
41 
42  for (int i = 0; i < num_recHits; i++) {
43  convertRecHit(view[i], recHits[i]);
44 
45  if (DEBUG && i < 10)
46  printf("recHit %4d %u %f %f\n", i, view.detId(i), view.energy(i), view.timeM0(i));
47  }
48 
49  hcal::RecHitDeviceCollection deviceProduct{num_recHits, event.queue()};
50  alpaka::memcpy(event.queue(), deviceProduct.buffer(), hostProduct.buffer());
51  if (synchronise_)
52  alpaka::wait(event.queue());
53  event.emplace(deviceToken_, std::move(deviceProduct));
54  }
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
58  desc.add<edm::InputTag>("src", edm::InputTag(""))->setComment("Input calorimeter rec hit collection");
59  desc.addUntracked<bool>("synchronise", false)
60  ->setComment("Add synchronisation point after execution (for benchmarking asynchronous execution)");
61  descriptions.addWithDefaultLabel(desc);
62  }
63 
64  private:
67  const bool synchronise_;
68 
69  static void convertRecHit(hcal::RecHitHostCollection::View::element to, const typename CAL::CaloRecHitType& from);
70  };
71 
72  template <>
73  void CaloRecHitSoAProducer<HCAL>::convertRecHit(hcal::RecHitHostCollection::View::element to,
74  const HCAL::CaloRecHitType& from) {
75  // Fill SoA from HCAL rec hit
76  to.detId() = from.id().rawId();
77  to.energy() = from.energy();
78  to.timeM0() = from.time();
79  }
80 
81  /*
82  The ECALRecHitSoAProducer currently has no use, but is available via this
83  module. In the case where ECAL PF Clustering is moved to Alpaka, we can then
84  decide to use this converted solely for ECAL, or if the SoA is available
85  we can switch to using just the ECAL RecHit SoA.
86  */
87 
88  /*
89  template <>
90  void CaloRecHitSoAProducer<ECAL>::convertRecHit(reco::CaloRecHitHostCollection::View::element to,
91  const ECAL::CaloRecHitType& from) {
92  // Fill SoA from ECAL rec hit
93  to.detId() = from.id().rawId();
94  to.energy() = from.energy();
95  to.time() = from.time();
96  to.flags() = from.flagsBits();
97  }
98  */
99 
101 
102  // Purposely commented out; see above.
103  //using ECALRecHitSoAProducer = CaloRecHitSoAProducer<ECAL>;
104 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
105 
108 //DEFINE_FWK_ALPAKA_MODULE(ECALRecHitSoAProducer);
void produce(edm::StreamID sid, device::Event &event, device::EventSetup const &) const override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
#define DEBUG
CaloRecHitSoAProducer< HCAL > HCALRecHitSoAProducer
const device::EDPutToken< hcal::RecHitDeviceCollection > deviceToken_
Definition: config.py:1
const edm::EDGetTokenT< edm::SortedCollection< typename CAL::CaloRecHitType > > recHitsToken_
static void convertRecHit(hcal::RecHitHostCollection::View::element to, const typename CAL::CaloRecHitType &from)
constexpr float energy() const
Definition: CaloRecHit.h:29
constexpr HcalDetId id() const
get the id
Definition: HBHERecHit.h:41
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
constexpr float time() const
Definition: CaloRecHit.h:31
HLT enums.
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
def move(src, dest)
Definition: eostools.py:511
PortableCollection< HcalRecHitSoA > RecHitDeviceCollection
Definition: event.py:1