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