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  if (includeErrors_) {
98  digiErrorPutToken_ = produces();
99  fmtErrorToken_ = produces();
100  }
101 
102  // regions
103  if (!iConfig.getParameter<edm::ParameterSet>("Regions").getParameterNames().empty()) {
104  regions_ = std::make_unique<PixelUnpackingRegions>(iConfig, consumesCollector());
105  }
106  }
107 
108  template <typename TrackerTraits>
111  desc.add<bool>("IncludeErrors", true);
112  desc.add<bool>("UseQualityInfo", false);
113  // Note: this parameter is obsolete: it is ignored and will have no effect.
114  // It is kept to avoid breaking older configurations, and will not be printed in the generated cfi.py file.
115  desc.addOptionalNode(edm::ParameterDescription<uint32_t>("MaxFEDWords", 0, true), false)
116  ->setComment("This parameter is obsolete and will be ignored.");
117  desc.add<int32_t>("clusterThreshold_layer1", pixelClustering::clusterThresholdLayerOne);
118  desc.add<int32_t>("clusterThreshold_otherLayers", pixelClustering::clusterThresholdOtherLayers);
119  desc.add<double>("VCaltoElectronGain", 47.f);
120  desc.add<double>("VCaltoElectronGain_L1", 50.f);
121  desc.add<double>("VCaltoElectronOffset", -60.f);
122  desc.add<double>("VCaltoElectronOffset_L1", -670.f);
123 
124  desc.add<edm::InputTag>("InputLabel", edm::InputTag("rawDataCollector"));
125  {
127  psd0.addOptional<std::vector<edm::InputTag>>("inputs");
128  psd0.addOptional<std::vector<double>>("deltaPhi");
129  psd0.addOptional<std::vector<double>>("maxZ");
130  psd0.addOptional<edm::InputTag>("beamSpot");
131  desc.add<edm::ParameterSetDescription>("Regions", psd0)
132  ->setComment("## Empty Regions PSet means complete unpacking");
133  }
134  desc.add<std::string>("CablingMapLabel", "")->setComment("CablingMap label"); //Tav
135  descriptions.addWithDefaultLabel(desc);
136  }
137 
138  template <typename TrackerTraits>
140  auto const& hMap = iSetup.getData(mapToken_);
141  auto const& dGains = iSetup.getData(gainsToken_);
142 
143  // initialize cabling map or update if necessary
144  if (recordWatcher_.check(iSetup)) {
145  // cabling map, which maps online address (fed->link->ROC->local pixel) to offline (DetId->global pixel)
146  cablingMap_ = &iSetup.getData(cablingMapToken_);
147  fedIds_ = cablingMap_->fedIds();
148  cabling_ = cablingMap_->cablingTree();
149  LogDebug("map version:") << cablingMap_->version();
150  }
151 
152  // if used, the buffer is guaranteed to stay alive until the after the execution of makePhase1ClustersAsync completes
153  std::optional<cms::alpakatools::device_buffer<Device, unsigned char[]>> modulesToUnpackRegional;
154  const unsigned char* modulesToUnpack;
155  if (regions_) {
156  regions_->run(iEvent, iSetup);
157  LogDebug("SiPixelRawToCluster") << "region2unpack #feds: " << regions_->nFEDs();
158  LogDebug("SiPixelRawToCluster") << "region2unpack #modules (BPIX,EPIX,total): " << regions_->nBarrelModules()
159  << " " << regions_->nForwardModules() << " " << regions_->nModules();
160 
161  modulesToUnpackRegional = SiPixelMappingUtilities::getModToUnpRegionalAsync(
162  *(regions_->modulesToUnpack()), cabling_.get(), fedIds_, iEvent.queue());
163  modulesToUnpack = modulesToUnpackRegional->data();
164  } else {
165  modulesToUnpack = hMap->modToUnpDefault();
166  }
167 
168  const auto& buffers = iEvent.get(rawGetToken_);
169 
170  errors_.clear();
171 
172  // GPU specific: Data extraction for RawToDigi GPU
173  unsigned int wordCounter = 0;
174  unsigned int fedCounter = 0;
175  bool errorsInEvent = false;
176  std::vector<unsigned int> index(fedIds_.size(), 0);
177  std::vector<cms_uint32_t const*> start(fedIds_.size(), nullptr);
178  std::vector<ptrdiff_t> words(fedIds_.size(), 0);
179  // In CPU algorithm this loop is part of PixelDataFormatter::interpretRawData()
180  ErrorChecker errorcheck;
181  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
182  const int fedId = fedIds_[i];
183  if (regions_ && !regions_->mayUnpackFED(fedId))
184  continue;
185 
186  // for GPU
187  // first 150 index stores the fedId and next 150 will store the
188  // start index of word in that fed
190  fedCounter++;
191 
192  // get event data for this fed
193  const FEDRawData& rawData = buffers.FEDData(fedId);
194 
195  // GPU specific
196  int nWords = rawData.size() / sizeof(cms_uint64_t);
197  if (nWords == 0) {
198  continue;
199  }
200  // check CRC bit
201  const cms_uint64_t* trailer = reinterpret_cast<const cms_uint64_t*>(rawData.data()) + (nWords - 1);
202  if (not errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors_)) {
203  continue;
204  }
205  // check headers
206  const cms_uint64_t* header = reinterpret_cast<const cms_uint64_t*>(rawData.data());
207  header--;
208  bool moreHeaders = true;
209  while (moreHeaders) {
210  header++;
211  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors_);
212  moreHeaders = headerStatus;
213  }
214 
215  // check trailers
216  bool moreTrailers = true;
217  trailer++;
218  while (moreTrailers) {
219  trailer--;
220  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors_);
221  moreTrailers = trailerStatus;
222  }
223 
224  const cms_uint32_t* bw = (const cms_uint32_t*)(header + 1);
225  const cms_uint32_t* ew = (const cms_uint32_t*)(trailer);
226 
227  assert(0 == (ew - bw) % 2);
228  index[i] = wordCounter;
229  start[i] = bw;
230  words[i] = (ew - bw);
231  wordCounter += (ew - bw);
232 
233  } // end of for loop
234  nDigis_ = wordCounter;
235  if (nDigis_ == 0)
236  return;
237 
238  // copy the FED data to a single cpu buffer
239  pixelDetails::WordFedAppender wordFedAppender(iEvent.queue(), nDigis_);
240  for (uint32_t i = 0; i < fedIds_.size(); ++i) {
241  wordFedAppender.initializeWordFed(fedIds_[i], index[i], start[i], words[i]);
242  }
243  Algo_.makePhase1ClustersAsync(iEvent.queue(),
244  clusterThresholds_,
245  hMap.const_view(),
246  modulesToUnpack,
247  dGains.const_view(),
248  wordFedAppender,
249  wordCounter,
250  fedCounter,
251  useQuality_,
252  includeErrors_,
254  }
255 
256  template <typename TrackerTraits>
258  if (nDigis_ == 0) {
259  // Cannot use the default constructor here, as it would not allocate memory.
260  // In the case of no digis, clusters_d are not being instantiated, but are
261  // still used downstream to initialize TrackingRecHitSoADevice. If there
262  // are no valid pointers to clusters' Collection columns, instantiation
263  // of TrackingRecHits fail. Example: workflow 11604.0
264 
265  iEvent.emplace(digiPutToken_, nDigis_, iEvent.queue());
266  iEvent.emplace(clusterPutToken_, pixelTopology::Phase1::numberOfModules, iEvent.queue());
267  if (includeErrors_) {
268  iEvent.emplace(digiErrorPutToken_);
269  iEvent.emplace(fmtErrorToken_);
270  }
271  return;
272  }
273 
274  iEvent.emplace(digiPutToken_, Algo_.getDigis());
275  iEvent.emplace(clusterPutToken_, Algo_.getClusters());
276  if (includeErrors_) {
277  iEvent.emplace(digiErrorPutToken_, Algo_.getErrors());
278  iEvent.emplace(fmtErrorToken_, std::move(errors_));
279  }
280  }
281 
284 
285 } // namespace ALPAKA_ACCELERATOR_NAMESPACE
286 
287 // 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)