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  if (record.getLink() > 80)
150  return;
151  link.setAMCInput(record.getLink());
152 
153  int bx_offset = (int)(record.getBXCounterMod() + 31 - bx_counter_mod) % 27 - 4;
154 
155  if (record.isError()) {
156  if (fill_counters_ && bx_offset == 0) {
158  }
159  LogDebug("RPCCPPFRawToDigi") << "Link in error for " << link;
160  return;
161  } else if (!record.isAcknowledge()) {
162  if (fill_counters_ && bx_offset == 0) {
164  }
165  LogDebug("RPCCPPFRawToDigi") << "Link without acknowledge for " << link;
166  return;
167  }
168 
169  std::uint8_t data(record.getPartitionData());
170  if (!data) {
171  return;
172  }
173 
174  int bx(bx_offset - (int)(record.getDelay()));
175  LogDebug("RPCCPPFRawToDigi") << "RPC BX " << bx << " for offset " << bx_offset;
176 
177  if (fill_counters_ && bx == 0 && record.isEOD()) { // EOD comes at the last delay
179  }
180 
181  RPCAMCLinkMap::map_type::const_iterator link_it = es_cppf_link_map_->getMap().find(link);
182  if (link_it == es_cppf_link_map_->getMap().end()) {
183  if (fill_counters_ && bx_offset == 0) {
185  }
186  LogDebug("RPCCPPFRawToDigi") << "Skipping unknown RPCCPPFLink " << link;
187  return;
188  }
189 
190  RPCLBLink lb_link = link_it->second;
191 
192  if (record.getLinkBoard() > (unsigned int)RPCLBLink::max_linkboard_) {
193  if (fill_counters_ && bx_offset == 0) {
195  }
196  LogDebug("RPCCPPFRawToDigi") << "Skipping invalid LinkBoard " << record.getLinkBoard() << " for record " << link
197  << " (" << std::hex << record.getRecord() << " in " << record.getRecord() << std::dec
198  << " from " << link;
199  return;
200  }
201 
202  if (record.getConnector() > (unsigned int)RPCLBLink::max_connector_) {
203  if (fill_counters_ && bx_offset == 0) {
205  }
206  LogDebug("RPCCPPFRawToDigi") << "Skipping invalid Connector " << record.getConnector() << " for record " << link
207  << " (" << std::hex << record.getRecord() << " in " << record.getRecord() << std::dec
208  << ") from " << link;
209  return;
210  }
211 
212  lb_link.setLinkBoard(record.getLinkBoard());
213  lb_link.setConnector(record.getConnector());
214 
215  RPCLBLinkMap::map_type::const_iterator lb_link_it = es_lb_link_map_->getMap().find(lb_link);
216  if (lb_link_it == es_lb_link_map_->getMap().end()) {
217  if (fill_counters_ && bx_offset == 0) {
219  }
220  LogDebug("RPCCPPFRawToDigi") << "Could not find " << lb_link << " for record " << link << " (" << std::hex
221  << record.getRecord() << " in " << record.getRecord() << std::dec << ") from " << link;
222  return;
223  }
224 
225  auto bx_corrected = bx - cppfDaq_Delay;
226  if (bx_corrected < bx_min || bx_corrected > bx_max) {
227  return;
228  }
229 
230  if (fill_counters_ && bx == 0) {
232  }
233 
234  RPCFebConnector const& feb_connector(lb_link_it->second);
235  RPCDetId det_id(feb_connector.getRPCDetId());
236  unsigned int channel_offset(record.getPartition() ? 9 : 1); // 1-16
237 
238  for (unsigned int channel = 0; channel < 8; ++channel) {
239  if (data & (0x1 << channel)) {
240  unsigned int strip(feb_connector.getStrip(channel + channel_offset));
241  if (strip) {
242  rpc_digis.insert(std::pair<RPCDetId, RPCDigi>(det_id, RPCDigi(strip, bx - cppfDaq_Delay_)));
243  LogDebug("RPCCPPFRawToDigi") << "RPCDigi " << det_id.rawId() << ", " << strip << ", " << bx << ", "
244  << bx - cppfDaq_Delay_;
245  }
246  }
247  }
248 }
249 
251  unsigned int block,
252  unsigned int word,
253  rpccppf::TXRecord const& record,
254  l1t::CPPFDigiCollection& rpc_cppf_digis) const {
255  if (!record.isValid(0) && !record.isValid(1)) {
256  return;
257  }
258 
259  // This translation should become part of a CondFormat
260  if (word > 5) {
261  return;
262  }
263  static int const ring[6] = {2, 2, 2, 3, 2, 3};
264  static int const station[6] = {1, 2, 3, 3, 4, 4};
265  int region(link.getAMCNumber() < 7 ? 1 : -1);
266  unsigned int endcap_sector((35 + (link.getAMCNumber() - (region > 0 ? 3 : 7)) * 9 + (block >> 1)) % 36 + 1);
267  unsigned int emtf_link(((34 + (link.getAMCNumber() - (region > 0 ? 3 : 7)) * 9 + (block >> 1)) % 36) % 6 + 1);
268  unsigned int emtf_sector(((34 + (link.getAMCNumber() - (region > 0 ? 3 : 7)) * 9 + (block >> 1)) % 36) / 6 + 1);
269  RPCDetId rpc_id(region,
270  ring[word] // ring
271  ,
272  station[word] // station
273  ,
274  ((endcap_sector - 1) / 6) + 1 // sector
275  ,
276  1 // layer
277  ,
278  (endcap_sector - 1) % 6 + 1 // subsector
279  ,
280  0); // roll
281 
282  if (record.isValid(0)) {
283  rpc_cppf_digis.push_back(
284  l1t::CPPFDigi(rpc_id, 0, record.getPhi(0), record.getTheta(0), 0, 0, 0, emtf_sector, emtf_link, 0, 0, 0, 0));
285  }
286  if (record.isValid(1)) {
287  rpc_cppf_digis.push_back(
288  l1t::CPPFDigi(rpc_id, 0, record.getPhi(1), record.getTheta(1), 1, 0, 0, emtf_sector, emtf_link, 0, 0, 0, 0));
289  }
290 }
291 
292 void RPCCPPFUnpacker::putRPCDigis(edm::Event& event, std::set<std::pair<RPCDetId, RPCDigi> > const& rpc_digis) const {
293  std::unique_ptr<RPCDigiCollection> rpc_digi_collection(new RPCDigiCollection());
294  RPCDetId rpc_det_id;
295  std::vector<RPCDigi> local_rpc_digis;
296  for (std::pair<RPCDetId, RPCDigi> const& rpc_digi : rpc_digis) {
297  LogDebug("RPCCPPFRawToDigi") << "RPCDigi " << rpc_digi.first.rawId() << ", " << rpc_digi.second.strip() << ", "
298  << rpc_digi.second.bx();
299  if (rpc_digi.first != rpc_det_id) {
300  if (!local_rpc_digis.empty()) {
301  rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
302  local_rpc_digis.clear();
303  }
304  rpc_det_id = rpc_digi.first;
305  }
306  local_rpc_digis.push_back(rpc_digi.second);
307  }
308  if (!local_rpc_digis.empty()) {
309  rpc_digi_collection->put(RPCDigiCollection::Range(local_rpc_digis.begin(), local_rpc_digis.end()), rpc_det_id);
310  }
311 
312  event.put(std::move(rpc_digi_collection));
313 }
314 
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_
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
TupleMultiplicity< TrackerTraits > const HitToTuple< TrackerTraits > const cms::cuda::AtomicPairCounter GPUCACellT< TrackerTraits > const *__restrict__ uint32_t const *__restrict__ CellNeighborsVector< TrackerTraits > const CellTracksVector< TrackerTraits > const OuterHitOfCell< TrackerTraits > const int32_t uint32_t Counters * counters
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_