File indexing completed on 2024-04-06 12:10:59
0001 #include "EventFilter/RPCRawToDigi/interface/RPCLBPacker.h"
0002
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include <algorithm>
0005 #include "CondFormats/RPCObjects/interface/RPCInverseLBLinkMap.h"
0006 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
0007
0008 void RPCLBPacker::getRPCLBRecords(RPCInverseLBLinkMap const& lb_map,
0009 int min_bx,
0010 int max_bx,
0011 unsigned int bcn,
0012 RPCDigiCollection const& digis,
0013 std::map<RPCLBLink, std::vector<std::pair<int, RPCLBRecord> > >& mlb_bx_lbrecord,
0014 bool ignore_eod) {
0015 if (max_bx - min_bx >= 128 || min_bx < -3564) {
0016 throw cms::Exception("RPCLBPacker") << "Out-of-range input for min_bx, max_bx (" << min_bx << ": " << max_bx << ")";
0017 }
0018
0019 std::map<RPCLBLink, std::vector<RPCLBRecord> > mlb_lbrecords;
0020
0021
0022 RPCDigiCollection::DigiRangeIterator digi_range_end(digis.end());
0023 for (RPCDigiCollection::DigiRangeIterator digi_range = digis.begin(); digi_range != digi_range_end; ++digi_range) {
0024 RPCDigiCollection::DigiRangeIterator::value_type digi_range_value(*digi_range);
0025 std::pair<RPCInverseLBLinkMap::map_type::const_iterator, RPCInverseLBLinkMap::map_type::const_iterator> lookup_range(
0026 lb_map.getMap().equal_range(digi_range_value.first.rawId()));
0027
0028 for (RPCDigiCollection::const_iterator digi = digi_range_value.second.first; digi != digi_range_value.second.second;
0029 ++digi) {
0030 if (digi->bx() < min_bx || digi->bx() > max_bx) {
0031 continue;
0032 }
0033
0034 for (RPCInverseLBLinkMap::map_type::const_iterator link_it = lookup_range.first; link_it != lookup_range.second;
0035 ++link_it) {
0036 if (link_it->second.second.hasStrip(digi->strip())) {
0037 unsigned int channel(link_it->second.second.getChannel(digi->strip()));
0038 RPCLBLink lb_link(link_it->second.first);
0039 RPCLBLink mlb_link(lb_link);
0040 mlb_link.setLinkBoard().setConnector();
0041 mlb_lbrecords[mlb_link].push_back(RPCLBRecord(digi->bx() - min_bx,
0042 false,
0043 lb_link.getLinkBoard(),
0044 false,
0045 0,
0046 lb_link.getConnector(),
0047 (channel > 8 ? 1 : 0),
0048 0x01 << ((channel - 1) % 8)));
0049 break;
0050 }
0051 }
0052 }
0053 }
0054
0055
0056 for (std::map<RPCLBLink, std::vector<RPCLBRecord> >::iterator mlb_lbrecords_it = mlb_lbrecords.begin();
0057 mlb_lbrecords_it != mlb_lbrecords.end();
0058 ++mlb_lbrecords_it) {
0059 std::vector<RPCLBRecord>& input(mlb_lbrecords_it->second);
0060 std::sort(input.begin(), input.end());
0061
0062 std::vector<std::pair<int, RPCLBRecord> > bx_lbrecord;
0063 bx_lbrecord.reserve(input.size());
0064
0065 RPCLBRecord last_lbrecord(input.front());
0066 unsigned int idx(0);
0067 for (std::vector<RPCLBRecord>::const_iterator input_it = input.begin() + 1; input_it <= input.end(); ++input_it) {
0068 if (input_it != input.end() && ((last_lbrecord.getRecord() & ~RPCLBRecord::partition_data_mask_) ==
0069 (input_it->getRecord() & ~RPCLBRecord::partition_data_mask_))) {
0070 last_lbrecord.set(last_lbrecord.getRecord() | input_it->getRecord());
0071 } else {
0072 unsigned int last_bcn(last_lbrecord.getBCN());
0073 if (last_bcn > idx) {
0074 idx = last_bcn;
0075 }
0076 unsigned int delay(idx - last_bcn);
0077 if (ignore_eod && delay == 8) {
0078 --idx;
0079 --delay;
0080 bx_lbrecord.back().second.setEOD(true);
0081 last_lbrecord.setEOD(true);
0082 }
0083 if (delay < 8) {
0084 last_lbrecord.setDelay(delay);
0085 last_bcn = (3564 + bcn + min_bx + idx) % 3564;
0086 last_lbrecord.setBCN(last_bcn);
0087 last_lbrecord.setBC0(last_bcn == 0);
0088 bx_lbrecord.push_back(std::pair<int, RPCLBRecord>(min_bx + idx, last_lbrecord));
0089 ++idx;
0090 } else {
0091 bx_lbrecord.back().second.setEOD(true);
0092 }
0093 if (input_it != input.end()) {
0094 last_lbrecord = *input_it;
0095 }
0096 }
0097 }
0098
0099 mlb_bx_lbrecord.insert(std::map<RPCLBLink, std::vector<std::pair<int, RPCLBRecord> > >::value_type(
0100 mlb_lbrecords_it->first, bx_lbrecord));
0101 }
0102 }