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  // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
69 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
70  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::EcalDigiDeviceCollection>",
71  ps.getParameter<std::string>("digisLabelEB"));
72  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::EcalDigiDeviceCollection>",
73  ps.getParameter<std::string>("digisLabelEE"));
74 #endif
75  }
76 
78  // conditions
79  auto const& eMappingProduct = setup.getData(eMappingToken_);
80 
81  // event data
82  const auto rawDataHandle = event.getHandle(rawDataToken_);
83 
84  // make a first iteration over the FEDs to compute the total buffer size
85  uint32_t size = 0;
86  uint32_t feds = 0;
87  for (auto const& fed : fedsToUnpack_) {
88  auto const& data = rawDataHandle->FEDData(fed);
89  auto const nbytes = data.size();
90 
91  // skip empty FEDs
92  if (nbytes < globalFieds::EMPTYEVENTSIZE)
93  continue;
94 
95  size += nbytes;
96  ++feds;
97  }
98 
99  auto& queue = event.queue();
100 
101  // input host buffers
102  ecal::raw::InputDataHost inputHost(queue, size, feds);
103 
104  // output device collections
105  OutputProduct digisDevEB{static_cast<int32_t>(config_.maxChannelsEB), queue};
106  OutputProduct digisDevEE{static_cast<int32_t>(config_.maxChannelsEE), queue};
107  // reset the size scalar of the SoA
108  // memset takes an alpaka view that is created from the scalar in a view to the device collection
109  auto digiViewEB = cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), digisDevEB.view().size());
110  auto digiViewEE = cms::alpakatools::make_device_view<uint32_t>(alpaka::getDev(queue), digisDevEE.view().size());
111  alpaka::memset(queue, digiViewEB, 0);
112  alpaka::memset(queue, digiViewEE, 0);
113 
114  // iterate over FEDs to fill the host buffer
115  uint32_t currentCummOffset = 0;
116  uint32_t fedCounter = 0;
117  for (auto const& fed : fedsToUnpack_) {
118  auto const& data = rawDataHandle->FEDData(fed);
119  auto const nbytes = data.size();
120 
121  // skip empty FEDs
122  if (nbytes < globalFieds::EMPTYEVENTSIZE)
123  continue;
124 
125  // copy raw data into host buffer
126  std::memcpy(inputHost.data.data() + currentCummOffset, data.data(), nbytes);
127  // set the offset in bytes from the start
128  inputHost.offsets[fedCounter] = currentCummOffset;
129  inputHost.feds[fedCounter] = fed;
130 
131  // this is the current offset into the buffer
132  currentCummOffset += nbytes;
133  ++fedCounter;
134  }
135  assert(currentCummOffset == size);
136  assert(fedCounter == feds);
137 
138  // unpack if at least one FED has data
139  if (fedCounter > 0) {
140  ecal::raw::unpackRaw(queue, inputHost, digisDevEB, digisDevEE, eMappingProduct, fedCounter, currentCummOffset);
141  }
142 
143  event.emplace(digisDevEBToken_, std::move(digisDevEB));
144  event.emplace(digisDevEEToken_, std::move(digisDevEE));
145  }
146 
147 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
148 
150 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