CMS 3D CMS Logo

EcalCPUDigisProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 
20 
21 #include "DeclsForKernels.h"
22 #include "UnpackGPU.h"
23 
24 class EcalCPUDigisProducer : public edm::stream::EDProducer<edm::ExternalWork> {
25 public:
26  explicit EcalCPUDigisProducer(edm::ParameterSet const& ps);
27  ~EcalCPUDigisProducer() override = default;
29 
30 private:
32  void produce(edm::Event&, edm::EventSetup const&) override;
33 
34  template <typename ProductType, typename... ARGS>
36  return (produceDummyIntegrityCollections_) ? produces<ProductType>(std::forward<ARGS>(args)...)
38  }
39 
40 private:
41  // input digi collections in GPU-friendly format
45 
46  // output digi collections in legacy format
49 
50  // whether to produce dummy integrity collections
52 
53  // dummy producer collections
56 
57  // dummy ECAL raw data collection
59 
60  // dummy integrity for xtal data
64 
65  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
69 
70  // dummy integrity errors
74 
76 
77  // dummy TCC collections
80 
81  // dummy mem integrity collections
86 
87  // FIXME better way to pass pointers from acquire to produce?
88  std::vector<uint32_t, cms::cuda::HostAllocator<uint32_t>> idsebtmp, idseetmp;
89  std::vector<uint16_t, cms::cuda::HostAllocator<uint16_t>> dataebtmp, dataeetmp;
90 };
91 
94 
95  desc.add<edm::InputTag>("digisInLabelEB", edm::InputTag{"ecalRawToDigiGPU", "ebDigis"});
96  desc.add<edm::InputTag>("digisInLabelEE", edm::InputTag{"ecalRawToDigiGPU", "eeDigis"});
97  desc.add<std::string>("digisOutLabelEB", "ebDigis");
98  desc.add<std::string>("digisOutLabelEE", "eeDigis");
99 
100  desc.add<bool>("produceDummyIntegrityCollections", false);
101 
102  std::string label = "ecalCPUDigisProducer";
103  confDesc.add(label, desc);
104 }
105 
107  : // input digi collections in GPU-friendly format
108  digisInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEB"))},
109  digisInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEE"))},
110 
111  // output digi collections in legacy format
112  digisOutEBToken_{produces<EBDigiCollection>(ps.getParameter<std::string>("digisOutLabelEB"))},
113  digisOutEEToken_{produces<EEDigiCollection>(ps.getParameter<std::string>("digisOutLabelEE"))},
114 
115  // whether to produce dummy integrity collections
116  produceDummyIntegrityCollections_{ps.getParameter<bool>("produceDummyIntegrityCollections")},
117 
118  // dummy collections
119  ebSrFlagToken_{dummyProduces<EBSrFlagCollection>()},
120  eeSrFlagToken_{dummyProduces<EESrFlagCollection>()},
121 
122  // dummy ECAL raw data collection
123  ecalRawDataToken_{dummyProduces<EcalRawDataCollection>()},
124 
125  // dummy integrity for xtal data
126  ebIntegrityGainErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainErrors")},
127  ebIntegrityGainSwitchErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors")},
128  ebIntegrityChIdErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityChIdErrors")},
129 
130  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
131  eeIntegrityGainErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainErrors")},
132  eeIntegrityGainSwitchErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors")},
133  eeIntegrityChIdErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityChIdErrors")},
134 
135  // dummy integrity errors
136  integrityTTIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors")},
137  integrityZSXtalIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors")},
138  integrityBlockSizeErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors")},
139 
140  //
141  pnDiodeDigisToken_{dummyProduces<EcalPnDiodeDigiCollection>()},
142 
143  // dummy TCC collections
144  ecalTriggerPrimitivesToken_{dummyProduces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives")},
145  ecalPseudoStripInputsToken_{dummyProduces<EcalPSInputDigiCollection>("EcalPseudoStripInputs")},
146 
147  // dummy mem integrity collections
148  ecalIntegrityMemTtIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemTtIdErrors")},
149  ecalIntegrityMemBlockSizeErrorsToken_{
150  dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemBlockSizeErrors")},
151  ecalIntegrityMemChIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemChIdErrors")},
152  ecalIntegrityMemGainErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityMemGainErrors")}
153 
154 // constructor body
155 {}
156 
158  edm::EventSetup const& setup,
159  edm::WaitingTaskWithArenaHolder taskHolder) {
160  // retrieve data/ctx
161  auto const& ebdigisProduct = event.get(digisInEBToken_);
162  auto const& eedigisProduct = event.get(digisInEEToken_);
163  cms::cuda::ScopedContextAcquire ctx{ebdigisProduct, std::move(taskHolder)};
164  auto const& ebdigis = ctx.get(ebdigisProduct);
165  auto const& eedigis = ctx.get(eedigisProduct);
166 
167  // resize tmp buffers
168  dataebtmp.resize(ebdigis.size * EcalDataFrame::MAXSAMPLES);
169  dataeetmp.resize(eedigis.size * EcalDataFrame::MAXSAMPLES);
170  idsebtmp.resize(ebdigis.size);
171  idseetmp.resize(eedigis.size);
172 
173  // enqeue transfers
174  cudaCheck(cudaMemcpyAsync(
175  dataebtmp.data(), ebdigis.data.get(), dataebtmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
176  cudaCheck(cudaMemcpyAsync(
177  dataeetmp.data(), eedigis.data.get(), dataeetmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
178  cudaCheck(cudaMemcpyAsync(
179  idsebtmp.data(), ebdigis.ids.get(), idsebtmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
180  cudaCheck(cudaMemcpyAsync(
181  idseetmp.data(), eedigis.ids.get(), idseetmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
182 }
183 
185  // output collections
186  auto digisEB = std::make_unique<EBDigiCollection>();
187  auto digisEE = std::make_unique<EEDigiCollection>();
188  digisEB->resize(idsebtmp.size());
189  digisEE->resize(idseetmp.size());
190 
191  // cast constness away
192  // use pointers to buffers instead of move operator= semantics
193  // cause we have different allocators in there...
194  auto* dataEB = const_cast<uint16_t*>(digisEB->data().data());
195  auto* dataEE = const_cast<uint16_t*>(digisEE->data().data());
196  auto* idsEB = const_cast<uint32_t*>(digisEB->ids().data());
197  auto* idsEE = const_cast<uint32_t*>(digisEE->ids().data());
198 
199  // copy data
200  std::memcpy(dataEB, dataebtmp.data(), dataebtmp.size() * sizeof(uint16_t));
201  std::memcpy(dataEE, dataeetmp.data(), dataeetmp.size() * sizeof(uint16_t));
202  std::memcpy(idsEB, idsebtmp.data(), idsebtmp.size() * sizeof(uint32_t));
203  std::memcpy(idsEE, idseetmp.data(), idseetmp.size() * sizeof(uint32_t));
204 
205  digisEB->sort();
206  digisEE->sort();
207 
208  event.put(digisOutEBToken_, std::move(digisEB));
209  event.put(digisOutEEToken_, std::move(digisEE));
210 
212  // dummy collections
213  event.emplace(ebSrFlagToken_);
214  event.emplace(eeSrFlagToken_);
215  // dummy ECAL raw data collection
216  event.emplace(ecalRawDataToken_);
217  // dummy integrity for xtal data
218  event.emplace(ebIntegrityGainErrorsToken_);
219  event.emplace(ebIntegrityGainSwitchErrorsToken_);
220  event.emplace(ebIntegrityChIdErrorsToken_);
221  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
222  event.emplace(eeIntegrityGainErrorsToken_);
223  event.emplace(eeIntegrityGainSwitchErrorsToken_);
224  event.emplace(eeIntegrityChIdErrorsToken_);
225  // dummy integrity errors
226  event.emplace(integrityTTIdErrorsToken_);
227  event.emplace(integrityZSXtalIdErrorsToken_);
228  event.emplace(integrityBlockSizeErrorsToken_);
229  //
230  event.emplace(pnDiodeDigisToken_);
231  // dummy TCC collections
232  event.emplace(ecalTriggerPrimitivesToken_);
233  event.emplace(ecalPseudoStripInputsToken_);
234  // dummy mem integrity collections
235  event.emplace(ecalIntegrityMemTtIdErrorsToken_);
237  event.emplace(ecalIntegrityMemChIdErrorsToken_);
238  event.emplace(ecalIntegrityMemGainErrorsToken_);
239  }
240 }
241 
edm::EDPutTokenT< EcalPSInputDigiCollection > ecalPseudoStripInputsToken_
std::vector< uint16_t, cms::cuda::HostAllocator< uint16_t > > dataeetmp
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDPutTokenT< ProductType > dummyProduces(ARGS &&... args)
edm::EDGetTokenT< InputProduct > digisInEEToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > ecalIntegrityMemTtIdErrorsToken_
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityGainSwitchErrorsToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityGainErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > ecalIntegrityMemBlockSizeErrorsToken_
std::vector< uint16_t, cms::cuda::HostAllocator< uint16_t > > dataebtmp
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityGainErrorsToken_
edm::EDGetTokenT< InputProduct > digisInEBToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityZSXtalIdErrorsToken_
edm::EDPutTokenT< EEDigiCollection > digisOutEEToken_
char const * label
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityChIdErrorsToken_
edm::EDPutTokenT< EBDigiCollection > digisOutEBToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDPutTokenT< EcalElectronicsIdCollection > ecalIntegrityMemGainErrorsToken_
edm::EDPutTokenT< EESrFlagCollection > eeSrFlagToken_
std::vector< uint32_t, cms::cuda::HostAllocator< uint32_t > > idseetmp
void acquire(edm::Event const &, edm::EventSetup const &, edm::WaitingTaskWithArenaHolder) override
edm::EDPutTokenT< EcalPnDiodeDigiCollection > pnDiodeDigisToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityGainSwitchErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > ecalIntegrityMemChIdErrorsToken_
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityTTIdErrorsToken_
edm::EDPutTokenT< EcalTrigPrimDigiCollection > ecalTriggerPrimitivesToken_
~EcalCPUDigisProducer() override=default
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &)
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityChIdErrorsToken_
void produce(edm::Event &, edm::EventSetup const &) override
static constexpr int MAXSAMPLES
Definition: EcalDataFrame.h:48
#define cudaCheck(ARG,...)
Definition: cudaCheck.h:69
EcalCPUDigisProducer(edm::ParameterSet const &ps)
edm::EDPutTokenT< EcalElectronicsIdCollection > integrityBlockSizeErrorsToken_
edm::EDPutTokenT< EBSrFlagCollection > ebSrFlagToken_
def move(src, dest)
Definition: eostools.py:511
edm::EDPutTokenT< EcalRawDataCollection > ecalRawDataToken_
Definition: event.py:1
std::vector< uint32_t, cms::cuda::HostAllocator< uint32_t > > idsebtmp