35 : inputLabel_(iConfig.getParameter<edm::
InputTag>(
"inputLabel")),
36 fedId_(iConfig.getUntrackedParameter<int>(
"rctFedId",
FEDNumbering::MINRCTFEDID)),
37 verbose_(iConfig.getUntrackedParameter<bool>(
"verbose",
false)) {
41 produces<L1CaloEmCollection>();
42 produces<L1CaloRegionCollection>();
74 if (rctRcd.
size() > 0) {
75 LogError(
"L1T") <<
"Cannot unpack: empty/invalid L1T raw data (size = " << rctRcd.
size() <<
") for ID "
76 <<
fedId_ <<
". Returning empty collections!";
88 LogError(
"L1T") <<
"Cannot unpack: no collection found";
95 const unsigned char*
data = d.
data();
102 if (header.
check()) {
103 LogDebug(
"L1T") <<
"Found SLink header:"
104 <<
" Trigger type " << header.
triggerType() <<
" L1 event ID " << header.
lvl1ID() <<
" BX Number "
105 << header.
bxID() <<
" FED source " << header.
sourceID() <<
" FED version " << header.
version();
107 LogWarning(
"L1T") <<
"Did not find a valid SLink header!";
112 if (trailer.
check()) {
113 LogDebug(
"L1T") <<
"Found SLink trailer:"
114 <<
" Length " << trailer.
fragmentLength() <<
" CRC " << trailer.
crc() <<
" Status "
117 LogWarning(
"L1T") <<
"Did not find a SLink trailer!";
120 unpackCTP7(reinterpret_cast<const uint32_t*>(data), 0,
sizeof(data), colls);
124 const unsigned block_id,
129 LogDebug(
"L1T") <<
"Block ID = " << block_id <<
" size = " <<
size;
131 CTP7Format ctp7Format;
132 RctDataDecoder rctDataDecoder;
133 uint32_t nBXTemp = 0;
134 uint32_t ctp7FWVersion;
135 uint32_t L1ID, L1aBCID;
136 std::vector<RCTInfo> allCrateRCTInfo[5];
139 L1aBCID = data[5 +
of] & 0x00000FFF;
140 nBXTemp = (data[5 +
of] & 0x00FF0000) >> 16;
141 ctp7FWVersion = data[4 +
of];
143 if (nBXTemp != 1 && nBXTemp != 3 && nBXTemp != 5)
146 const uint32_t nBX = nBXTemp;
148 LogDebug(
"L1T") <<
"CTP7 L1ID = " << L1ID <<
" L1A BCID = " << L1aBCID <<
" BXs in capture = " << nBX
149 <<
" CTP7 DAQ FW = " << ctp7FWVersion;
153 unsigned int crateID;
154 unsigned int ctp7LinkNumber;
155 std::vector<unsigned int>
uint;
159 link_data allLinks[5][36];
160 const uint32_t NLinks = ctp7Format.NLINKS;
164 uint32_t iDAQBuffer = 0;
167 for (
unsigned int iLink = 0; iLink < NLinks; iLink++) {
168 iDAQBuffer = of + ctp7Format.EVENT_HEADER_WORDS +
169 iLink * (ctp7Format.CHANNEL_HEADER_WORDS + nBX * ctp7Format.CHANNEL_DATA_WORDS_PER_BX);
172 uint32_t linkID = data[iDAQBuffer++];
173 uint32_t
tmp = data[iDAQBuffer++];
174 uint32_t CRCErrCnt = tmp & 0x0000FFFF;
177 uint32_t crateID = 0;
178 uint32_t expectedCrateID = 0;
180 bool expectedEven =
false;
183 rctDataDecoder.getExpectedLinkID(iLink, expectedCrateID, expectedEven);
185 rctDataDecoder.decodeLinkID(linkID, crateID, even);
188 if (expectedCrateID != crateID || even != expectedEven) {
189 LogError(
"L1T") <<
"Expected Crate ID " << expectedCrateID <<
" expectedEven " << expectedEven
190 <<
"does not match actual Crate ID " << crateID <<
" even " << even;
194 LogError(
"L1T") <<
"WARNING CRC ErrorFound linkID " << linkID <<
" expected crateID " << expectedCrateID;
197 for (uint32_t iBX = 0; iBX < nBX; iBX++) {
198 allLinks[iBX][iLink].uint.reserve(6);
199 allLinks[iBX][iLink].ctp7LinkNumber = iLink;
200 allLinks[iBX][iLink].crateID = expectedCrateID;
201 allLinks[iBX][iLink].even = expectedEven;
204 for (
unsigned int iWord = 0; iWord < 6; iWord++) {
205 allLinks[iBX][iLink].uint.push_back(data[iDAQBuffer + iWord + iBX * 6]);
211 uint32_t nCratesFound = 0;
212 for (
unsigned int iCrate = 0; iCrate < 18; iCrate++) {
213 bool foundEven =
false, foundOdd =
false;
217 for (
unsigned int iLink = 0; iLink < NLinks; iLink++) {
218 if ((allLinks[0][iLink].crateID == iCrate) && (allLinks[0][iLink].even ==
true)) {
220 for (
unsigned int iBX = 0; iBX < nBX; iBX++)
221 even[iBX] = allLinks[iBX][iLink];
222 }
else if ((allLinks[0][iLink].crateID == iCrate) && (allLinks[0][iLink].even ==
false)) {
224 for (
unsigned int iBX = 0; iBX < nBX; iBX++)
225 odd[iBX] = allLinks[iBX][iLink];
229 if (foundEven && foundOdd) {
233 for (
unsigned int iBX = 0; iBX < nBX; iBX++) {
235 std::vector<RCTInfo> rctInfoData;
236 rctDataDecoder.decodeLinks(even[iBX].
uint, odd[iBX].uint, rctInfoData);
237 rctDataDecoder.setRCTInfoCrateID(rctInfoData, iCrate);
238 allCrateRCTInfo[iBX].push_back(rctInfoData.at(0));
245 if (nCratesFound != 18)
246 LogError(
"L1T") <<
"Warning -- only found " << nCratesFound <<
" valid crates";
259 for (uint32_t iBX = 0; iBX < nBX; iBX++, startBX++) {
260 for (
unsigned int iCrate = 0; iCrate < nCratesFound; iCrate++) {
261 RCTInfo rctInfo = allCrateRCTInfo[iBX].at(iCrate);
263 for (
int j = 0;
j < 4;
j++) {
266 colls->
rctEm()->push_back(em);
269 for (
int j = 0;
j < 4;
j++) {
272 colls->
rctEm()->push_back(em);
275 for (
int j = 0;
j < 7;
j++) {
276 for (
int k = 0;
k < 2;
k++) {
277 bool o = (((rctInfo.oBits >> (
j * 2 +
k)) & 0x1) == 0x1);
278 bool t = (((rctInfo.tBits >> (
j * 2 +
k)) & 0x1) == 0x1);
279 bool m = (((rctInfo.mBits >> (
j * 2 +
k)) & 0x1) == 0x1);
280 bool q = (((rctInfo.qBits >> (
j * 2 +
k)) & 0x1) == 0x1);
283 colls->
rctCalo()->push_back(rgn);
287 for (
int k = 0;
k < 4;
k++) {
288 for (
int j = 0;
j < 2;
j++) {
290 uint32_t
offset =
j * 2 +
k % 2 + (
k / 2) * 4;
291 bool fg = (((rctInfo.hfQBits >>
offset) & 0x1) == 0x1);
294 colls->
rctCalo()->push_back(rgn);
302 for (
unsigned i = 0;
i <
size;
i++) {
313 std::ostringstream os;
324 edm::LogError(
"RCT") <<
"Encountered " << total <<
" unpacking errors: " << os.str();
std::vector< unsigned > errorCounters_
Counts number of errors for each code (index)
static const unsigned sLinkTrailerSize_
static const unsigned sLinkHeaderSize_
virtual void endJob()
method called at job end - use to print summary report
static const unsigned amc13TrailerSize_
#define DEFINE_FWK_MODULE(type)
L1CaloRegionCollection *const rctCalo() const
Input calo regions from the RCT to the RCT.
void setBx(int16_t bx)
set bx
void setBx(int16_t bx)
set BX
uint16_t crc() const
Cyclic Redundancy Code of the event fragment including header and trailer.
Level-1 Region Calorimeter Trigger EM candidate.
bool check() const
Check that the trailer is OK.
static const unsigned MIN_DATA
The minimum number of blocks we will try to unpack before thinking something is wrong (really this sh...
L1CaloEmCollection *const rctEm() const
Input electrons from the RCT to the RCT.
Log< level::Error, false > LogError
size_t size() const
Lenght of the data buffer in bytes.
uint32_t fragmentLength() const
The length of the event fragment counted in 64-bit words including header and trailer.
void unpackCTP7(const uint32_t *data, const unsigned block_id, const unsigned size, RctUnpackCollections *const colls)
bool get(ProductID const &oid, Handle< PROD > &result) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
static const unsigned MAX_ERR_CODE
RctRawToDigi(const edm::ParameterSet &)
edm::InputTag inputLabel_
FED collection label.
uint8_t ttsBits() const
Current value of the Trigger Throttling System bits.
uint8_t evtStatus() const
Event fragment status information.
char data[epos_bytes_allocation]
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void produce(edm::Event &, const edm::EventSetup &) override
A calorimeter trigger region (sum of 4x4 trigger towers)
void unpack(const FEDRawData &d, edm::Event &e, RctUnpackCollections *const colls)
Unpacks the raw data.
Log< level::Warning, false > LogWarning
bool printAll(const unsigned char *data, const unsigned size)
tuple size
Write out results.
const bool verbose_
If true, then debug print out for each event.
static const unsigned amc13HeaderSize_