File indexing completed on 2024-04-06 12:10:59
0001
0002
0003
0004
0005
0006
0007
0008 #include "EventFilter/RPCRawToDigi/interface/RPCRecordFormatter.h"
0009
0010 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0011 #include "DataFormats/RPCDigi/interface/RPCDigi.h"
0012
0013 #include "CondFormats/RPCObjects/interface/RPCReadOutMapping.h"
0014 #include "CondFormats/RPCObjects/interface/LinkBoardElectronicIndex.h"
0015
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/Utilities/interface/Exception.h"
0018
0019 #include "DataFormats/RPCDigi/interface/ReadoutError.h"
0020
0021 #include <bitset>
0022 #include <sstream>
0023
0024 using namespace std;
0025 using namespace edm;
0026 using namespace rpcrawtodigi;
0027
0028 RPCRecordFormatter::RPCRecordFormatter(int fedId, const RPCReadOutMapping* r) : currentFED(fedId), readoutMapping(r) {}
0029
0030 RPCRecordFormatter::~RPCRecordFormatter() {}
0031
0032 std::vector<EventRecords> RPCRecordFormatter::recordPack(uint32_t rawDetId, const RPCDigi& digi, int trigger_BX) const {
0033 std::vector<EventRecords> result;
0034
0035 LogTrace("") << " DIGI; det: " << rawDetId << ", strip: " << digi.strip() << ", bx: " << digi.bx();
0036 int stripInDU = digi.strip();
0037
0038
0039 typedef std::vector<std::pair<LinkBoardElectronicIndex, LinkBoardPackedStrip> > RawDataFrames;
0040 RPCReadOutMapping::StripInDetUnit duFrame(rawDetId, stripInDU);
0041 RawDataFrames rawDataFrames = readoutMapping->rawDataFrame(duFrame);
0042
0043 for (RawDataFrames::const_iterator ir = rawDataFrames.begin(); ir != rawDataFrames.end(); ir++) {
0044 const LinkBoardElectronicIndex& eleIndex = (*ir).first;
0045 const LinkBoardPackedStrip& lbPackedStrip = (*ir).second;
0046
0047 if (eleIndex.dccId == currentFED) {
0048 LogTrace("pack:") << " dccId= " << eleIndex.dccId << " dccInputChannelNum= " << eleIndex.dccInputChannelNum
0049 << " tbLinkInputNum= " << eleIndex.tbLinkInputNum << " lbNumInLink=" << eleIndex.lbNumInLink;
0050
0051
0052 int current_BX = trigger_BX + digi.bx();
0053 RecordBX bxr(current_BX);
0054
0055
0056 int tbLinkInputNumber = eleIndex.tbLinkInputNum;
0057 int rmb = eleIndex.dccInputChannelNum;
0058 RecordSLD lbr(tbLinkInputNumber, rmb);
0059
0060
0061 int lbInLink = eleIndex.lbNumInLink;
0062 int eod = 0;
0063 int halfP = 0;
0064 int packedStrip = lbPackedStrip.packedStrip();
0065 int partitionNumber = packedStrip / 8;
0066 RecordCD cdr(lbInLink, partitionNumber, eod, halfP, vector<int>(1, packedStrip));
0067
0068 result.push_back(EventRecords(trigger_BX, bxr, lbr, cdr));
0069 }
0070 }
0071 return result;
0072 }
0073
0074 int RPCRecordFormatter::recordUnpack(const EventRecords& event,
0075 RPCDigiCollection* prod,
0076 RPCRawDataCounts* counter,
0077 RPCRawSynchro::ProdItem* synchro) {
0078 static bool debug = edm::MessageDrop::instance()->debugEnabled;
0079 ReadoutError error;
0080 int currentRMB = event.recordSLD().rmb();
0081 int currentTbLinkInputNumber = event.recordSLD().tbLinkInputNumber();
0082
0083 LinkBoardElectronicIndex eleIndex;
0084 eleIndex.dccId = currentFED;
0085 eleIndex.dccInputChannelNum = currentRMB;
0086 eleIndex.tbLinkInputNum = currentTbLinkInputNumber;
0087 eleIndex.lbNumInLink = event.recordCD().lbInLink();
0088
0089 if (event.recordCD().eod()) {
0090 if (counter)
0091 counter->addReadoutError(currentFED, ReadoutError(eleIndex, ReadoutError::EOD));
0092 }
0093
0094 if (readoutMapping == nullptr)
0095 return error.type();
0096 const LinkBoardSpec* linkBoard = readoutMapping->location(eleIndex);
0097 if (!linkBoard) {
0098 if (debug)
0099 LogDebug("") << " ** PROBLEM ** Invalid Linkboard location, skip CD event, "
0100 << "dccId: " << eleIndex.dccId << "dccInputChannelNum: " << eleIndex.dccInputChannelNum
0101 << " tbLinkInputNum: " << eleIndex.tbLinkInputNum << " lbNumInLink: " << eleIndex.lbNumInLink;
0102 error = ReadoutError(eleIndex, ReadoutError::InvalidLB);
0103 if (counter)
0104 counter->addReadoutError(currentFED, error);
0105 return error.type();
0106 }
0107
0108 std::vector<int> packStrips = event.recordCD().packedStrips();
0109 if (packStrips.empty()) {
0110 error = ReadoutError(eleIndex, ReadoutError::EmptyPackedStrips);
0111 if (counter)
0112 counter->addReadoutError(currentFED, error);
0113 return error.type();
0114 }
0115
0116 for (std::vector<int>::iterator is = packStrips.begin(); is != packStrips.end(); ++is) {
0117 RPCReadOutMapping::StripInDetUnit duFrame = readoutMapping->detUnitFrame(*linkBoard, LinkBoardPackedStrip(*is));
0118
0119 uint32_t rawDetId = duFrame.first;
0120 int geomStrip = duFrame.second;
0121 if (!rawDetId) {
0122 if (debug)
0123 LogTrace("") << " ** PROBLEM ** no rawDetId, skip at least part of CD data";
0124 error = ReadoutError(eleIndex, ReadoutError::InvalidDetId);
0125 if (counter)
0126 counter->addReadoutError(currentFED, error);
0127 continue;
0128 }
0129 if (geomStrip == 0) {
0130 if (debug)
0131 LogTrace("") << " ** PROBLEM ** no strip found";
0132 error = ReadoutError(eleIndex, ReadoutError::InvalidStrip);
0133 if (counter)
0134 counter->addReadoutError(currentFED, error);
0135 continue;
0136 }
0137
0138
0139 RPCDigi digi(geomStrip, event.dataToTriggerDelay() - 3);
0140
0141
0142 if (debug) {
0143
0144 LogTrace("") << " DIGI; det: " << rawDetId << ", strip: " << digi.strip() << ", bx: " << digi.bx();
0145 }
0146 if (prod)
0147 prod->insertDigi(RPCDetId(rawDetId), digi);
0148
0149
0150
0151
0152
0153
0154
0155
0156 }
0157
0158 if (synchro)
0159 synchro->push_back(make_pair(eleIndex, event.dataToTriggerDelay()));
0160
0161 return error.type();
0162 }