CMS 3D CMS Logo

RPCCPPFUnpacker.cc
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
11 
16 
18  edm::ConsumesCollector consumesCollector,
19  edm::ProducesCollector producesCollector)
20  : RPCAMCUnpacker(config, consumesCollector, producesCollector),
21  fill_counters_(config.getParameter<bool>("fillAMCCounters")),
22  bx_min_(config.getParameter<int>("bxMin")),
23  bx_max_(config.getParameter<int>("bxMax")),
24  cppfDaq_Delay_(config.getParameter<int>("cppfDaqDelay")),
25  es_cppf_link_map_br_token_(
26  consumesCollector.esConsumes<RPCAMCLinkMap, RPCCPPFLinkMapRcd, edm::Transition::BeginRun>()),
27  es_cppf_link_map_token_(consumesCollector.esConsumes<RPCAMCLinkMap, RPCCPPFLinkMapRcd>()),
28  es_lb_link_map_token_(consumesCollector.esConsumes<RPCLBLinkMap, RPCLBLinkMapRcd>()) {
29  producesCollector.produces<RPCDigiCollection>();
30  producesCollector.produces<l1t::CPPFDigiCollection>();
31  if (fill_counters_) {
32  producesCollector.produces<RPCAMCLinkCounters>("RPCAMCUnpacker");
33  }
34 }
35 
38  auto link_map = setup.getHandle(es_cppf_link_map_br_token_);
39  std::set<int> feds;
40  for (auto const& cppf_link : link_map->getMap()) {
41  feds.insert(cppf_link.first.getFED());
42  }
43  feds_.assign(feds.begin(), feds.end());
44  }
45 }
46 
48  edm::EventSetup const& setup,
49  std::map<RPCAMCLink, rpcamc13::AMCPayload> const& amc_payload) {
50  // Get EventSetup Electronics Maps
53 
54  std::set<std::pair<RPCDetId, RPCDigi> > rpc_digis;
55  std::unique_ptr<l1t::CPPFDigiCollection> rpc_cppf_digis(new l1t::CPPFDigiCollection());
56  std::unique_ptr<RPCAMCLinkCounters> counters(new RPCAMCLinkCounters());
57 
58  for (std::pair<RPCAMCLink const, rpcamc13::AMCPayload> const& payload : amc_payload) {
59  processCPPF(payload.first, payload.second, *counters, rpc_digis, *rpc_cppf_digis);
60  }
61 
62  putRPCDigis(event, rpc_digis);
63  std::sort(rpc_cppf_digis->begin(), rpc_cppf_digis->end());
64  event.put(std::move(rpc_cppf_digis));
65  if (fill_counters_) {
66  event.put(std::move(counters), "RPCAMCUnpacker");
67  }
68 }
69 
73  std::set<std::pair<RPCDetId, RPCDigi> >& rpc_digis,
74  l1t::CPPFDigiCollection& rpc_cppf_digis) const {
75  LogDebug("RPCCPPFRawToDigi") << "RPCCPPF " << link << ", size " << payload.getData().size();
76 
77  if (!payload.isValid()) {
78  return false;
79  }
80 
81  std::vector<std::uint64_t>::const_iterator word(payload.getData().begin());
83  ++word;
84  ++word;
85  rpcmp7::SubHeader subheader(*word);
86  ++word;
87  std::vector<std::uint64_t>::const_iterator word_end(payload.getData().end());
88  --word_end; // rpcamc::Trailer
89  unsigned int bx_counter(header.getBXCounter());
90  unsigned int bx_counter_mod(bx_counter % 27);
91 
92  int bx_min(bx_min_), bx_max(bx_max_), cppfDaq_Delay(cppfDaq_Delay_);
93  // no adjustable bx window implemented in readout yet
94 
95  unsigned int pos(0), length(0);
96  unsigned int caption_id(0);
97  bool zs_per_bx(false), have_bx_header(false);
98  unsigned int bx_words(0);
99  unsigned int block_id(0);
100  std::uint32_t records[2];
101  for (; word != word_end; ++word) {
102  records[0] = *word & 0xffffffff;
103  records[1] = (*word >> 32) & 0xffffffff;
104  for (std::uint32_t* record = &(records[0]); record < &(records[2]); ++record) {
105  if (pos >= length) {
106  rpcmp7::BlockHeader block_header(*record);
107  LogDebug("RPCCPPFUnpacker") << "block header " << std::hex << block_header.getRecord() << std::dec
108  << " caption id " << block_header.getCaptionId() << " zs per bx "
109  << block_header.hasZeroSuppressionPerBX() << " zs "
110  << block_header.isZeroSuppressed() << " length " << block_header.getLength() << " "
111  << word_end - word;
112  pos = 0;
113  length = block_header.getLength();
114  caption_id = block_header.getCaptionId();
115  zs_per_bx = block_header.hasZeroSuppressionPerBX();
116  have_bx_header = false;
117  bx_words = 6;
118  block_id = block_header.getId();
119  } else if (zs_per_bx && !have_bx_header) {
120  // rpcmp7::BXHeader bx_header(*record);
121  have_bx_header = true;
122  } else {
123  if (caption_id == 0x01) { // RX
125  link, bx_counter_mod, rpccppf::RXRecord(*record), counters, rpc_digis, bx_min, bx_max, cppfDaq_Delay);
126  } else if (caption_id == 0x02) { // TX
127  processTXRecord(link, block_id, 6 - bx_words, rpccppf::TXRecord(*record), rpc_cppf_digis);
128  }
129  ++pos;
130  --bx_words;
131  }
132  }
133  }
134 
135  return true;
136 }
137 
139  unsigned int bx_counter_mod,
140  rpccppf::RXRecord const& record,
142  std::set<std::pair<RPCDetId, RPCDigi> >& rpc_digis,
143  int bx_min,
144  int bx_max,
145  int cppfDaq_Delay) const {
146  LogDebug("RPCCPPFRawToDigi") << "RXRecord " << std::hex << record.getRecord() << std::dec << std::endl;
147  unsigned int fed(link.getFED());
148  unsigned int amc_number(link.getAMCNumber());
149  link.setAMCInput(record.getLink());
150 
151  int bx_offset = (int)(record.getBXCounterMod() + 31 - bx_counter_mod) % 27 - 4;
152 
153  if (record.isError()) {
154  if (fill_counters_ && bx_offset == 0) {
156  }
157  LogDebug("RPCCPPFRawToDigi") << "Link in error for " << link;
158  return;
159  } else if (!record.isAcknowledge()) {
160  if (fill_counters_ && bx_offset == 0) {
162  }
163  LogDebug("RPCCPPFRawToDigi") << "Link without acknowledge for " << link;
164  return;
165  }
166 
167  std::uint8_t data(record.getPartitionData());
168  if (!data) {
169  return;
170  }
171 
172  int bx(bx_offset - (int)(record.getDelay()));
173  LogDebug("RPCCPPFRawToDigi") << "RPC BX " << bx << " for offset " << bx_offset;
174 
175  if (fill_counters_ && bx == 0 && record.isEOD()) { // EOD comes at the last delay
177  }
178 
179  RPCAMCLinkMap::map_type::const_iterator link_it = es_cppf_link_map_->getMap().find(link);
180  if (link_it == es_cppf_link_map_->getMap().end()) {
181  if (fill_counters_ && bx_offset == 0) {
183  }
184  LogDebug("RPCCPPFRawToDigi") << "Skipping unknown RPCCPPFLink " << link;
185  return;
186  }
187 
188  RPCLBLink lb_link = link_it->second;
189 
190  if (record.getLinkBoard() > (unsigned int)RPCLBLink::max_linkboard_) {
191  if (fill_counters_ && bx_offset == 0) {
193  }
194  LogDebug("RPCCPPFRawToDigi") << "Skipping invalid LinkBoard " << record.getLinkBoard() << " for record " << link
195  << " (" << std::hex << record.getRecord() << " in " << record.getRecord() << std::dec
196  << " from " << link;
197  return;
198  }
199 
200  if (record.getConnector() > (unsigned int)RPCLBLink::max_connector_) {
201  if (fill_counters_ && bx_offset == 0) {
203  }
204  LogDebug("RPCCPPFRawToDigi") << "Skipping invalid Connector " << record.getConnector() << " for record " << link
205  << " (" << std::hex << record.getRecord() << " in " << record.getRecord() << std::dec
206  << ") from " << link;
207  return;
208  }
209 
210  lb_link.setLinkBoard(record.getLinkBoard());
211  lb_link.setConnector(record.getConnector());
212 
213  RPCLBLinkMap::map_type::const_iterator lb_link_it = es_lb_link_map_->getMap().find(lb_link);
214  if (lb_link_it == es_lb_link_map_->getMap().end()) {
215  if (fill_counters_ && bx_offset == 0) {
217  }
218  LogDebug("RPCCPPFRawToDigi") << "Could not find " << lb_link << " for record " << link << " (" << std::hex
219  << record.getRecord() << " in " << record.getRecord() << std::dec << ") from " << link;
220  return;
221  }
222 
223  auto bx_corrected = bx - cppfDaq_Delay;
224  if (bx_corrected < bx_min || bx_corrected > bx_max) {
225  return;
226  }
227 
228  if (fill_counters_ && bx == 0) {
230  }
231 
232  RPCFebConnector const& feb_connector(lb_link_it->second);
233  RPCDetId det_id(feb_connector.getRPCDetId());
234  unsigned int channel_offset(record.getPartition() ? 9 : 1); // 1-16
235 
236  for (unsigned int channel = 0; channel < 8; ++channel) {
237  if (data & (0x1 << channel)) {
238  unsigned int strip(feb_connector.getStrip(channel + channel_offset));
239  if (strip) {
240  rpc_digis.insert(std::pair<RPCDetId, RPCDigi>(det_id, RPCDigi(strip, bx - cppfDaq_Delay_)));
241  LogDebug("RPCCPPFRawToDigi") << "RPCDigi " << det_id.rawId() << ", " << strip << ", " << bx << ", "
242  << bx - cppfDaq_Delay_;
243  }
244  }
245  }
246 }
247 
249  unsigned int block,
250  unsigned int word,
251  rpccppf::TXRecord const& record,
252  l1t::CPPFDigiCollection& rpc_cppf_digis) const {
253  if (!record.isValid(0) && !record.isValid(1)) {
254  return;
255  }
256 
257  // This translation should become part of a CondFormat
258  if (word > 5) {
259  return;
260  }
261  static int const ring[6] = {2, 2, 2, 3, 2, 3};
262  static int const station[6] = {1, 2, 3, 3, 4, 4};
263  int region(link.getAMCNumber() < 7 ? 1 : -1);
264  unsigned int endcap_sector((35 + (link.getAMCNumber() - (region > 0 ? 3 : 7)) * 9 + (block >> 1)) % 36 + 1);
265  RPCDetId rpc_id(region,
266  ring[word] // ring
267  ,
268  station[word] // station
269  ,
270  (endcap_sector / 6) + 1 // sector
271  ,
272  1 // layer
273  ,
274  (endcap_sector - 1) % 6 + 1 // subsector
275  ,
276  0); // roll
277 
278  if (record.isValid(0)) {
279  rpc_cppf_digis.push_back(l1t::CPPFDigi(rpc_id, 0, record.getTheta(0), record.getPhi(0)));
280  }
281  if (record.isValid(1)) {
282  rpc_cppf_digis.push_back(l1t::CPPFDigi(rpc_id, 0, record.getTheta(1), record.getPhi(1)));
283  }
284 }
285 
286 void RPCCPPFUnpacker::putRPCDigis(edm::Event& event, std::set<std::pair<RPCDetId, RPCDigi> > const& rpc_digis) const {
287  std::unique_ptr<RPCDigiCollection> rpc_digi_collection(new RPCDigiCollection());
288  RPCDetId rpc_det_id;
289  std::vector<RPCDigi> local_rpc_digis;
290  for (std::pair<RPCDetId, RPCDigi> const& rpc_digi : rpc_digis) {
291  LogDebug("RPCCPPFRawToDigi") << "RPCDigi " << rpc_digi.first.rawId() << ", " << rpc_digi.second.strip() << ", "
292  << rpc_digi.second.bx();
293  if (rpc_digi.first != rpc_det_id) {
294  if (!local_rpc_digis.empty()) {
295  rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
296  local_rpc_digis.clear();
297  }
298  rpc_det_id = rpc_digi.first;
299  }
300  local_rpc_digis.push_back(rpc_digi.second);
301  }
302  if (!local_rpc_digis.empty()) {
303  rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
304  }
305 
306  event.put(std::move(rpc_digi_collection));
307 }
308 
void produce(edm::Event &event, edm::EventSetup const &setup, std::map< RPCAMCLink, rpcamc13::AMCPayload > const &amc_payload) override
void processRXRecord(RPCAMCLink link, unsigned int bx_counter_mod, rpccppf::RXRecord const &record, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &rpc_digis, int bx_min, int bx_max, int cppfDaq_Delay) const
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::ESHandle< RPCLBLinkMap > es_lb_link_map_
static unsigned int const input_connector_not_used_
std::vector< int > feds_
unsigned int getCaptionId() const
edm::ESHandle< RPCAMCLinkMap > es_cppf_link_map_
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
void processTXRecord(RPCAMCLink link, unsigned int block, unsigned int word, rpccppf::TXRecord const &record, l1t::CPPFDigiCollection &rpc_cppf_digis) const
static unsigned int const input_link_error_
static unsigned int const input_lb_invalid_
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t uint32_t CAHitNtupletGeneratorKernelsGPU::Counters * counters
std::uint32_t const & getRecord() const
Definition: config.py:1
edm::ESGetToken< RPCAMCLinkMap, RPCCPPFLinkMapRcd > es_cppf_link_map_br_token_
void beginRun(edm::Run const &run, edm::EventSetup const &setup) override
static unsigned int const amc_link_invalid_
uint64_t word
RPCDetId getRPCDetId() const
MuonDigiCollection< RPCDetId, RPCDigi > RPCDigiCollection
unsigned int getLength() const
map_type & getMap()
Definition: RPCAMCLinkMap.h:27
Transition
Definition: Transition.h:12
bool isZeroSuppressed() const
bool processCPPF(RPCAMCLink const &link, rpcamc13::AMCPayload const &payload, RPCAMCLinkCounters &counters, std::set< std::pair< RPCDetId, RPCDigi > > &rpc_digis, l1t::CPPFDigiCollection &rpc_cppf_digis) const
map_type & getMap()
Definition: RPCLBLinkMap.h:27
edm::ESWatcher< RPCCPPFLinkMapRcd > es_cppf_link_map_watcher_
bool hasZeroSuppressionPerBX() const
edm::ESGetToken< RPCLBLinkMap, RPCLBLinkMapRcd > es_lb_link_map_token_
void putRPCDigis(edm::Event &event, std::set< std::pair< RPCDetId, RPCDigi > > const &digis) const
static unsigned int const input_event_
static unsigned int const input_link_ack_fail_
std::pair< const_iterator, const_iterator > Range
unsigned int getId() const
RPCCPPFUnpacker(edm::ParameterSet const &, edm::ConsumesCollector, edm::ProducesCollector)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
unsigned int getStrip(unsigned int channel) const
edm::ESGetToken< RPCAMCLinkMap, RPCCPPFLinkMapRcd > es_cppf_link_map_token_
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::vector< CPPFDigi > CPPFDigiCollection
Definition: CPPFDigi.h:83
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
Definition: Run.h:45
static unsigned int const input_eod_
#define LogDebug(id)
static unsigned int const input_connector_invalid_