CMS 3D CMS Logo

EcalRawToDigiPortable.cc
Go to the documentation of this file.
15 
16 #include <alpaka/alpaka.hpp>
17 
18 #include "DeclsForKernels.h"
19 #include "UnpackPortable.h"
20 
22 
24  public:
25  explicit EcalRawToDigiPortable(edm::ParameterSet const& ps);
26  ~EcalRawToDigiPortable() override = default;
28 
29  void produce(device::Event&, device::EventSetup const&) override;
30 
31  private:
37 
38  std::vector<int> fedsToUnpack_;
39 
41  };
42 
45 
46  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
47  std::vector<int> feds(54);
48  for (uint32_t i = 0; i < 54; ++i)
49  feds[i] = i + 601;
50  desc.add<std::vector<int>>("FEDs", feds);
51  desc.add<uint32_t>("maxChannelsEB", 61200);
52  desc.add<uint32_t>("maxChannelsEE", 14648);
53  desc.add<std::string>("digisLabelEB", "ebDigis");
54  desc.add<std::string>("digisLabelEE", "eeDigis");
55 
56  confDesc.addWithDefaultLabel(desc);
57  }
58 
60  : rawDataToken_{consumes<FEDRawDataCollection>(ps.getParameter<edm::InputTag>("InputLabel"))},
61  digisDevEBToken_{produces(ps.getParameter<std::string>("digisLabelEB"))},
62  digisDevEEToken_{produces(ps.getParameter<std::string>("digisLabelEE"))},
63  eMappingToken_{esConsumes()},
64  fedsToUnpack_{ps.getParameter<std::vector<int>>("FEDs")} {
65  config_.maxChannelsEB = ps.getParameter<uint32_t>("maxChannelsEB");
66  config_.maxChannelsEE = ps.getParameter<uint32_t>("maxChannelsEE");
67  }
68 
70  // conditions
71  auto const& eMappingProduct = setup.getData(eMappingToken_);
72 
73  // event data
74  const auto rawDataHandle = event.getHandle(rawDataToken_);
75 
76  // make a first iteration over the FEDs to compute the total buffer size
77  uint32_t size = 0;
78  uint32_t feds = 0;
79  for (auto const& fed : fedsToUnpack_) {
80  auto const& data = rawDataHandle->FEDData(fed);
81  auto const nbytes = data.size();
82 
83  // skip empty FEDs
84  if (nbytes < globalFieds::EMPTYEVENTSIZE)
85  continue;
86 
87  size += nbytes;
88  ++feds;
89  }
90 
91  auto& queue = event.queue();
92 
93  // input host buffers
94  ecal::raw::InputDataHost inputHost(queue, size, feds);
95 
96  // output device collections
97  OutputProduct digisDevEB{static_cast<int32_t>(config_.maxChannelsEB), queue};
98  OutputProduct digisDevEE{static_cast<int32_t>(config_.maxChannelsEE), queue};
99  // reset the size scalar of the SoA
100  // memset takes an alpaka view that is created from the scalar in a view to the device collection
101  auto digiViewEB = cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), digisDevEB.view().size());
102  auto digiViewEE = cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), digisDevEE.view().size());
103  alpaka::memset(queue, digiViewEB, 0);
104  alpaka::memset(queue, digiViewEE, 0);
105 
106  // iterate over FEDs to fill the host buffer
107  uint32_t currentCummOffset = 0;
108  uint32_t fedCounter = 0;
109  for (auto const& fed : fedsToUnpack_) {
110  auto const& data = rawDataHandle->FEDData(fed);
111  auto const nbytes = data.size();
112 
113  // skip empty FEDs
114  if (nbytes < globalFieds::EMPTYEVENTSIZE)
115  continue;
116 
117  // copy raw data into host buffer
118  std::memcpy(inputHost.data.data() + currentCummOffset, data.data(), nbytes);
119  // set the offset in bytes from the start
120  inputHost.offsets[fedCounter] = currentCummOffset;
121  inputHost.feds[fedCounter] = fed;
122 
123  // this is the current offset into the buffer
124  currentCummOffset += nbytes;
125  ++fedCounter;
126  }
127  assert(currentCummOffset == size);
128  assert(fedCounter == feds);
129 
130  // unpack if at least one FED has data
131  if (fedCounter > 0) {
132  ecal::raw::unpackRaw(queue, inputHost, digisDevEB, digisDevEE, eMappingProduct, fedCounter, currentCummOffset);
133  }
134 
135  event.emplace(digisDevEBToken_, std::move(digisDevEB));
136  event.emplace(digisDevEEToken_, std::move(digisDevEE));
137  }
138 
139 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
140 
142 DEFINE_FWK_ALPAKA_MODULE(EcalRawToDigiPortable);
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
device::ESGetToken< EcalElectronicsMappingDevice, EcalMappingElectronicsRcd > eMappingToken_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
device::EDPutToken< OutputProduct > digisDevEEToken_
void unpackRaw(Queue &queue, InputDataHost const &inputHost, EcalDigiDeviceCollection &digisDevEB, EcalDigiDeviceCollection &digisDevEE, EcalElectronicsMappingDevice const &mapping, uint32_t const nfedsWithData, uint32_t const nbytesTotal)
assert(be >=bs)
device::EDPutToken< OutputProduct > digisDevEBToken_
cms::alpakatools::host_buffer< uint32_t[]> offsets
cms::alpakatools::host_buffer< unsigned char[]> data
cms::alpakatools::host_buffer< int[]> feds
void produce(device::Event &, device::EventSetup const &) override
PortableCollection< EcalDigiSoA > EcalDigiDeviceCollection
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static void fillDescriptions(edm::ConfigurationDescriptions &)
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1