CMS 3D CMS Logo

SiPixelRawToCluster.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <stdexcept>
3 #include <string>
4 #include <utility>
5 #include <vector>
6 
37 
39 
41 
42  template <typename TrackerTraits>
44  public:
45  explicit SiPixelRawToCluster(const edm::ParameterSet& iConfig);
46  ~SiPixelRawToCluster() override = default;
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50 
51  private:
52  void acquire(device::Event const& iEvent, device::EventSetup const& iSetup) override;
53  void produce(device::Event& iEvent, device::EventSetup const& iSetup) override;
54 
60 
65 
66  std::unique_ptr<SiPixelFedCablingTree> cabling_;
67  std::vector<unsigned int> fedIds_;
69  std::unique_ptr<PixelUnpackingRegions> regions_;
70 
73 
74  const bool includeErrors_;
75  const bool useQuality_;
76  uint32_t nDigis_;
78  };
79 
80  template <typename TrackerTraits>
82  : rawGetToken_(consumes(iConfig.getParameter<edm::InputTag>("InputLabel"))),
83  digiPutToken_(produces()),
84  clusterPutToken_(produces()),
85  mapToken_(esConsumes()),
86  gainsToken_(esConsumes()),
88  edm::ESInputTag("", iConfig.getParameter<std::string>("CablingMapLabel")))),
89  includeErrors_(iConfig.getParameter<bool>("IncludeErrors")),
90  useQuality_(iConfig.getParameter<bool>("UseQualityInfo")),
91  clusterThresholds_{iConfig.getParameter<int32_t>("clusterThreshold_layer1"),
92  iConfig.getParameter<int32_t>("clusterThreshold_otherLayers"),
93  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronGain")),
94  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronGain_L1")),
95  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronOffset")),
96  static_cast<float>(iConfig.getParameter<double>("VCaltoElectronOffset_L1"))} {
97  // Workaround until the ProductID problem in issue https://github.com/cms-sw/cmssw/issues/44643 is fixed
98 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED
99  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::SiPixelDigisSoACollection>");
100  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::SiPixelDigiErrorsSoACollection>");
101  producesTemporarily("edm::DeviceProduct<alpaka_cuda_async::SiPixelClustersSoACollection>");
102 #endif
103 
104  if (includeErrors_) {
105  digiErrorPutToken_ = produces();
106  fmtErrorToken_ = produces();
107  }
108 
109  // regions
110  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
111  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
112  }
113  }
114 
115  template <typename TrackerTraits>
118  desc.add<bool>("IncludeErrors", true);
119  desc.add<bool>("UseQualityInfo", false);
120  // Note: this parameter is obsolete: it is ignored and will have no effect.
121  // It is kept to avoid breaking older configurations, and will not be printed in the generated cfi.py file.
122  desc.addOptionalNode(edm::ParameterDescription<uint32_t>("MaxFEDWords", 0, true), false)
123  ->setComment("This parameter is obsolete and will be ignored.");
124  desc.add<int32_t>("clusterThreshold_layer1", pixelClustering::clusterThresholdLayerOne);
125  desc.add<int32_t>("clusterThreshold_otherLayers", pixelClustering::clusterThresholdOtherLayers);
126  desc.add<double>("VCaltoElectronGain", 47.f);
127  desc.add<double>("VCaltoElectronGain_L1", 50.f);
128  desc.add<double>("VCaltoElectronOffset", -60.f);
129  desc.add<double>("VCaltoElectronOffset_L1", -670.f);
130 
131  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
132  {
134  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
135  psd0.addOptional<std::vector<double>>("deltaPhi");
136  psd0.addOptional<std::vector<double>>("maxZ");
137  psd0.addOptional<edm::InputTag>("beamSpot");
138  desc.add<edm::ParameterSetDescription>("Regions", psd0)
139  ->setComment("## Empty Regions PSet means complete unpacking");
140  }
141  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
142  descriptions.addWithDefaultLabel(desc);
143  }
144 
145  template <typename TrackerTraits>
147  auto const& hMap = iSetup.getData(mapToken_);
148  auto const& dGains = iSetup.getData(gainsToken_);
149 
150  // initialize cabling map or update if necessary
151  if (recordWatcher_.check(iSetup)) {
152  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
153  cablingMap_ = &iSetup.getData(cablingMapToken_);
154  fedIds_ = cablingMap_->fedIds();
155  cabling_ = cablingMap_->cablingTree();
156  LogDebug("map version:") << cablingMap_->version();
157  }
158 
159  // if used, the buffer is guaranteed to stay alive until the after the execution of makePhase1ClustersAsync completes
160  std::optional<cms::alpakatools::device_buffer<Device, unsigned char[]>> modulesToUnpackRegional;
161  const unsigned char* modulesToUnpack;
162  if (regions_) {
163  regions_->run(iEvent, iSetup);
164  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
165  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules()
166  << " " << regions_->nForwardModules() << " " << regions_->nModules();
167 
168  modulesToUnpackRegional = SiPixelMappingUtilities::getModToUnpRegionalAsync(
169  *(regions_->modulesToUnpack()), cabling_.get(), fedIds_, iEvent.queue());
170  modulesToUnpack = modulesToUnpackRegional->data();
171  } else {
172  modulesToUnpack = hMap->modToUnpDefault();
173  }
174 
175  const auto& buffers = iEvent.get(rawGetToken_);
176 
177  errors_.clear();
178 
179  // GPU specific: Data extraction for RawToDigi GPU
180  unsigned int wordCounter = 0;
181  unsigned int fedCounter = 0;
182  bool errorsInEvent = false;
183  std::vector<unsigned int> index(fedIds_.size(), 0);
184  std::vector<cms_uint32_t const*> start(fedIds_.size(), nullptr);
185  std::vector<ptrdiff_t> words(fedIds_.size(), 0);
186  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
187  ErrorChecker errorcheck;
188  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
189  const int fedId = fedIds_[i];
190  if (regions_ && !regions_->mayUnpackFED(fedId))
191  continue;
192 
193  // for GPU
194  // first 150 index stores the fedId and next 150 will store the
195  // start index of word in that fed
197  fedCounter++;
198 
199  // get event data for this fed
200  const FEDRawData& rawData = buffers.FEDData(fedId);
201 
202  // GPU specific
203  int nWords = rawData.size() / sizeof(cms_uint64_t);
204  if (nWords == 0) {
205  continue;
206  }
207  // check CRC bit
208  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
209  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
210  continue;
211  }
212  // check headers
213  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
214  header--;
215  bool moreHeaders = true;
216  while (moreHeaders) {
217  header++;
218  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
219  moreHeaders = headerStatus;
220  }
221 
222  // check trailers
223  bool moreTrailers = true;
224  trailer++;
225  while (moreTrailers) {
226  trailer--;
227  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
228  moreTrailers = trailerStatus;
229  }
230 
231  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
232  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
233 
234  assert(0 == (ew - bw) % 2);
235  index[i] = wordCounter;
236  start[i] = bw;
237  words[i] = (ew - bw);
238  wordCounter += (ew - bw);
239 
240  } // end of for loop
241  nDigis_ = wordCounter;
242  if (nDigis_ == 0)
243  return;
244 
245  // copy the FED data to a single cpu buffer
246  pixelDetails::WordFedAppender wordFedAppender(iEvent.queue(), nDigis_);
247  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
248  wordFedAppender.initializeWordFed(fedIds_[i], index[i], start[i], words[i]);
249  }
250  Algo_.makePhase1ClustersAsync(iEvent.queue(),
251  clusterThresholds_,
252  hMap.const_view(),
253  modulesToUnpack,
254  dGains.const_view(),
255  wordFedAppender,
256  wordCounter,
257  fedCounter,
258  useQuality_,
259  includeErrors_,
261  }
262 
263  template <typename TrackerTraits>
265  if (nDigis_ == 0) {
266  // Cannot use the default constructor here, as it would not allocate memory.
267  // In the case of no digis, clusters_d are not being instantiated, but are
268  // still used downstream to initialize TrackingRecHitSoADevice. If there
269  // are no valid pointers to clusters' Collection columns, instantiation
270  // of TrackingRecHits fail. Example: workflow 11604.0
271 
272  iEvent.emplace(digiPutToken_, nDigis_, iEvent.queue());
273  iEvent.emplace(clusterPutToken_, pixelTopology::Phase1::numberOfModules, iEvent.queue());
274  if (includeErrors_) {
275  iEvent.emplace(digiErrorPutToken_);
276  iEvent.emplace(fmtErrorToken_);
277  }
278  return;
279  }
280 
281  iEvent.emplace(digiPutToken_, Algo_.getDigis());
282  iEvent.emplace(clusterPutToken_, Algo_.getClusters());
283  if (includeErrors_) {
284  iEvent.emplace(digiErrorPutToken_, Algo_.getErrors());
285  iEvent.emplace(fmtErrorToken_, std::move(errors_));
286  }
287  }
288 
291 
292 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
293 
294 // define as framework plugin
Definition: start.py:1
constexpr uint16_t clusterThresholdOtherLayers
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
SiPixelRawToCluster< pixelTopology::Phase1 > SiPixelRawToClusterPhase1
edm::ESWatcher< SiPixelFedCablingMapRcd > recordWatcher_
const edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > cablingMapToken_
static MessageDrop * instance()
Definition: MessageDrop.cc:33
device::EDPutToken< SiPixelDigisSoACollection > digiPutToken_
edm::EDPutTokenT< SiPixelFormatterErrors > fmtErrorToken_
assert(be >=bs)
int iEvent
Definition: GenABIO.cc:224
const device::ESGetToken< SiPixelMappingDevice, SiPixelMappingSoARecord > mapToken_
void acquire(device::Event const &iEvent, device::EventSetup const &iSetup) override
constexpr uint16_t clusterThresholdLayerOne
void produce(device::Event &iEvent, device::EventSetup const &iSetup) override
unsigned int cms_uint32_t
Definition: typedefs.h:15
SiPixelRawToCluster< pixelTopology::HIonPhase1 > SiPixelRawToClusterHIonPhase1
T const & getData(edm::ESGetToken< T, R > const &iToken) const
Definition: EventSetup.h:32
device::EDPutToken< SiPixelClustersSoACollection > clusterPutToken_
edm::EDGetTokenT< FEDRawDataCollection > rawGetToken_
HLT enums.
std::unique_ptr< SiPixelFedCablingTree > cabling_
#define DEFINE_FWK_ALPAKA_MODULE(name)
Definition: MakerMacros.h:16
SiPixelRawToCluster(const edm::ParameterSet &iConfig)
void initializeWordFed(int fedId, unsigned int wordCounterGPU, const uint32_t *src, unsigned int length)
const device::ESGetToken< SiPixelGainCalibrationForHLTDevice, SiPixelGainCalibrationForHLTSoARcd > gainsToken_
unsigned long long cms_uint64_t
Definition: typedefs.h:17
device::EDPutToken< SiPixelDigiErrorsSoACollection > digiErrorPutToken_
ALPAKA_FN_HOST_ACC ALPAKA_FN_ACC static ALPAKA_FN_INLINE cms::alpakatools::device_buffer< Device, unsigned char[]> getModToUnpRegionalAsync(std::set< unsigned int > const &modules, const SiPixelFedCablingTree *cabling, std::vector< unsigned int > const &fedIds, Queue &queue)
std::vector< std::string > getParameterNames() const
std::unique_ptr< PixelUnpackingRegions > regions_
def move(src, dest)
Definition: eostools.py:511
std::map< cms_uint32_t, DetErrors > Errors
static constexpr uint16_t numberOfModules
#define LogDebug(id)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)