CMS 3D CMS Logo

EcalCPUDigisProducer.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <utility>
3 
19 
20 #include "DeclsForKernels.h"
21 #include "UnpackGPU.h"
22 
23 class EcalCPUDigisProducer : public edm::stream::EDProducer<edm::ExternalWork> {
24 public:
25  explicit EcalCPUDigisProducer(edm::ParameterSet const& ps);
26  ~EcalCPUDigisProducer() override = default;
28 
29 private:
31  void produce(edm::Event&, edm::EventSetup const&) override;
32 
33  template <typename ProductType, typename... ARGS>
35  return (produceDummyIntegrityCollections_) ? produces<ProductType>(std::forward<ARGS>(args)...)
37  }
38 
39 private:
40  // input digi collections in GPU-friendly format
44 
45  // output digi collections in legacy format
48 
49  // whether to produce dummy integrity collections
51 
52  // dummy producer collections
55 
56  // dummy integrity for xtal data
60 
61  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
65 
66  // dummy integrity errors
70 
72 
73  // dummy TCC collections
76 
77  // FIXME better way to pass pointers from acquire to produce?
78  std::vector<uint32_t, cms::cuda::HostAllocator<uint32_t>> idsebtmp, idseetmp;
79  std::vector<uint16_t, cms::cuda::HostAllocator<uint16_t>> dataebtmp, dataeetmp;
80 };
81 
84 
85  desc.add<edm::InputTag>("digisInLabelEB", edm::InputTag{"ecalRawToDigiGPU", "ebDigis"});
86  desc.add<edm::InputTag>("digisInLabelEE", edm::InputTag{"ecalRawToDigiGPU", "eeDigis"});
87  desc.add<std::string>("digisOutLabelEB", "ebDigis");
88  desc.add<std::string>("digisOutLabelEE", "eeDigis");
89 
90  desc.add<bool>("produceDummyIntegrityCollections", false);
91 
92  std::string label = "ecalCPUDigisProducer";
93  confDesc.add(label, desc);
94 }
95 
97  : // input digi collections in GPU-friendly format
98  digisInEBToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEB"))},
99  digisInEEToken_{consumes<InputProduct>(ps.getParameter<edm::InputTag>("digisInLabelEE"))},
100 
101  // output digi collections in legacy format
102  digisOutEBToken_{produces<EBDigiCollection>(ps.getParameter<std::string>("digisOutLabelEB"))},
103  digisOutEEToken_{produces<EEDigiCollection>(ps.getParameter<std::string>("digisOutLabelEE"))},
104 
105  // whether to produce dummy integrity collections
106  produceDummyIntegrityCollections_{ps.getParameter<bool>("produceDummyIntegrityCollections")},
107 
108  // dummy collections
109  ebSrFlagToken_{dummyProduces<EBSrFlagCollection>()},
110  eeSrFlagToken_{dummyProduces<EESrFlagCollection>()},
111 
112  // dummy integrity for xtal data
113  ebIntegrityGainErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainErrors")},
114  ebIntegrityGainSwitchErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityGainSwitchErrors")},
115  ebIntegrityChIdErrorsToken_{dummyProduces<EBDetIdCollection>("EcalIntegrityChIdErrors")},
116 
117  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
118  eeIntegrityGainErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainErrors")},
119  eeIntegrityGainSwitchErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityGainSwitchErrors")},
120  eeIntegrityChIdErrorsToken_{dummyProduces<EEDetIdCollection>("EcalIntegrityChIdErrors")},
121 
122  // dummy integrity errors
123  integrityTTIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityTTIdErrors")},
124  integrityZSXtalIdErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityZSXtalIdErrors")},
125  integrityBlockSizeErrorsToken_{dummyProduces<EcalElectronicsIdCollection>("EcalIntegrityBlockSizeErrors")},
126 
127  //
128  pnDiodeDigisToken_{dummyProduces<EcalPnDiodeDigiCollection>()},
129 
130  // dummy TCC collections
131  ecalTriggerPrimitivesToken_{dummyProduces<EcalTrigPrimDigiCollection>("EcalTriggerPrimitives")},
132  ecalPseudoStripInputsToken_{dummyProduces<EcalPSInputDigiCollection>("EcalPseudoStripInputs")}
133 // constructor body
134 {}
135 
137  edm::EventSetup const& setup,
138  edm::WaitingTaskWithArenaHolder taskHolder) {
139  // retrieve data/ctx
140  auto const& ebdigisProduct = event.get(digisInEBToken_);
141  auto const& eedigisProduct = event.get(digisInEEToken_);
142  cms::cuda::ScopedContextAcquire ctx{ebdigisProduct, std::move(taskHolder)};
143  auto const& ebdigis = ctx.get(ebdigisProduct);
144  auto const& eedigis = ctx.get(eedigisProduct);
145 
146  // resize tmp buffers
147  dataebtmp.resize(ebdigis.size * EcalDataFrame::MAXSAMPLES);
148  dataeetmp.resize(eedigis.size * EcalDataFrame::MAXSAMPLES);
149  idsebtmp.resize(ebdigis.size);
150  idseetmp.resize(eedigis.size);
151 
152  // enqeue transfers
153  cudaCheck(cudaMemcpyAsync(
154  dataebtmp.data(), ebdigis.data.get(), dataebtmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
155  cudaCheck(cudaMemcpyAsync(
156  dataeetmp.data(), eedigis.data.get(), dataeetmp.size() * sizeof(uint16_t), cudaMemcpyDeviceToHost, ctx.stream()));
157  cudaCheck(cudaMemcpyAsync(
158  idsebtmp.data(), ebdigis.ids.get(), idsebtmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
159  cudaCheck(cudaMemcpyAsync(
160  idseetmp.data(), eedigis.ids.get(), idseetmp.size() * sizeof(uint32_t), cudaMemcpyDeviceToHost, ctx.stream()));
161 }
162 
164  // output collections
165  auto digisEB = std::make_unique<EBDigiCollection>();
166  auto digisEE = std::make_unique<EEDigiCollection>();
167  digisEB->resize(idsebtmp.size());
168  digisEE->resize(idseetmp.size());
169 
170  // cast constness away
171  // use pointers to buffers instead of move operator= semantics
172  // cause we have different allocators in there...
173  auto* dataEB = const_cast<uint16_t*>(digisEB->data().data());
174  auto* dataEE = const_cast<uint16_t*>(digisEE->data().data());
175  auto* idsEB = const_cast<uint32_t*>(digisEB->ids().data());
176  auto* idsEE = const_cast<uint32_t*>(digisEE->ids().data());
177 
178  // copy data
179  std::memcpy(dataEB, dataebtmp.data(), dataebtmp.size() * sizeof(uint16_t));
180  std::memcpy(dataEE, dataeetmp.data(), dataeetmp.size() * sizeof(uint16_t));
181  std::memcpy(idsEB, idsebtmp.data(), idsebtmp.size() * sizeof(uint32_t));
182  std::memcpy(idsEE, idseetmp.data(), idseetmp.size() * sizeof(uint32_t));
183 
184  digisEB->sort();
185  digisEE->sort();
186 
187  event.put(digisOutEBToken_, std::move(digisEB));
188  event.put(digisOutEEToken_, std::move(digisEE));
189 
191  // dummy collections
192  event.emplace(ebSrFlagToken_);
193  event.emplace(eeSrFlagToken_);
194  // dummy integrity for xtal data
195  event.emplace(ebIntegrityGainErrorsToken_);
196  event.emplace(ebIntegrityGainSwitchErrorsToken_);
197  event.emplace(ebIntegrityChIdErrorsToken_);
198  // dummy integrity for xtal data - EE specific (to be rivisited towards EB+EE common collection)
199  event.emplace(eeIntegrityGainErrorsToken_);
200  event.emplace(eeIntegrityGainSwitchErrorsToken_);
201  event.emplace(eeIntegrityChIdErrorsToken_);
202  // dummy integrity errors
203  event.emplace(integrityTTIdErrorsToken_);
204  event.emplace(integrityZSXtalIdErrorsToken_);
205  event.emplace(integrityBlockSizeErrorsToken_);
206  //
207  event.emplace(pnDiodeDigisToken_);
208  // dummy TCC collections
209  event.emplace(ecalTriggerPrimitivesToken_);
210  event.emplace(ecalPseudoStripInputsToken_);
211  }
212 }
213 
edm::EDPutTokenT< EcalPSInputDigiCollection > ecalPseudoStripInputsToken_
std::vector< uint16_t, cms::cuda::HostAllocator< uint16_t > > dataeetmp
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDPutTokenT< ProductType > dummyProduces(ARGS &&... args)
edm::EDGetTokenT< InputProduct > digisInEEToken_
edm::EDPutTokenT< EEDetIdCollection > eeIntegrityGainSwitchErrorsToken_
edm::EDPutTokenT< EBDetIdCollection > ebIntegrityGainErrorsToken_
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< 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 > 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
Definition: event.py:1
std::vector< uint32_t, cms::cuda::HostAllocator< uint32_t > > idsebtmp