37 inputLabel_(iConfig.getParameter<edm::
InputTag>(
"inputLabel")),
38 fedId_(iConfig.getUntrackedParameter<int>(
"rctFedId",
FEDNumbering::MINTriggerUpgradeFEDID)),
39 verbose_(iConfig.getUntrackedParameter<bool>(
"verbose",
false))
44 produces<L1CaloEmCollection>();
45 produces<L1CaloRegionCollection>();
83 if (rctRcd.
size() > 0) {
84 LogError(
"L1T") <<
"Cannot unpack: empty/invalid L1T raw data (size = "
85 << rctRcd.
size() <<
") for ID " <<
fedId_ <<
". Returning empty collections!";
99 LogError(
"L1T") <<
"Cannot unpack: no collection found";
109 const unsigned char *
data = d.
data();
117 if (header.
check()) {
118 LogDebug(
"L1T") <<
"Found SLink header:"
120 <<
" L1 event ID " << header.
lvl1ID()
121 <<
" BX Number " << header.
bxID()
122 <<
" FED source " << header.
sourceID()
123 <<
" FED version " << header.
version();
125 LogWarning(
"L1T") <<
"Did not find a valid SLink header!";
130 if (trailer.
check()) {
131 LogDebug(
"L1T") <<
"Found SLink trailer:"
132 <<
" Length " << trailer.
lenght()
133 <<
" CRC " << trailer.
crc()
135 <<
" Throttling bits " << trailer.
ttsBits();
137 LogWarning(
"L1T") <<
"Did not find a SLink trailer!";
140 unpackCTP7((uint32_t*)data, 0,
sizeof(data), colls);
150 LogDebug(
"L1T") <<
"Block ID = " << block_id <<
" size = " <<
size;
152 CTP7Format ctp7Format;
153 RctDataDecoder rctDataDecoder;
154 uint32_t nBXTemp = 0;
155 uint32_t ctp7FWVersion;
156 uint32_t L1ID, L1aBCID;
157 std::vector<RCTInfo> allCrateRCTInfo[5];
160 L1aBCID = data[5+of] & 0x00000FFF;
161 nBXTemp = (data[5+of] & 0x00FF0000) >> 16;
162 ctp7FWVersion = data[4+of];
164 if(nBXTemp != 1 && nBXTemp != 3 && nBXTemp != 5)
167 const uint32_t nBX = nBXTemp;
169 LogDebug(
"L1T") <<
"CTP7 L1ID = " << L1ID <<
" L1A BCID = " << L1aBCID <<
" BXs in capture = " << nBX <<
" CTP7 DAQ FW = " << ctp7FWVersion;
173 unsigned int crateID;
174 unsigned int ctp7LinkNumber;
175 std::vector <unsigned int> uint;
179 link_data allLinks[5][36];
180 const uint32_t NLinks = ctp7Format.NLINKS;
184 uint32_t iDAQBuffer = 0;
187 for(
unsigned int iLink = 0; iLink < NLinks; iLink++ ){
189 ctp7Format.EVENT_HEADER_WORDS + iLink * (ctp7Format.CHANNEL_HEADER_WORDS +
190 nBX * ctp7Format.CHANNEL_DATA_WORDS_PER_BX);
193 uint32_t linkID = data[iDAQBuffer++];
194 uint32_t
tmp = data[iDAQBuffer++];
195 uint32_t CRCErrCnt = tmp & 0x0000FFFF;
198 uint32_t crateID = 0; uint32_t expectedCrateID = 0;
199 bool even =
false;
bool expectedEven =
false;
202 rctDataDecoder.getExpectedLinkID(iLink, expectedCrateID, expectedEven);
204 rctDataDecoder.decodeLinkID(linkID, crateID, even);
207 if(expectedCrateID!=crateID || even!=expectedEven ){
208 LogError(
"L1T") <<
"Expected Crate ID "<< expectedCrateID <<
" expectedEven "<< expectedEven
209 <<
"does not match actual Crate ID "<<crateID<<
" even "<<even;
213 LogError(
"L1T")<<
"WARNING CRC ErrorFound linkID "<< linkID<<
" expected crateID "<< expectedCrateID;
216 for (uint32_t iBX=0; iBX<nBX; iBX++){
217 allLinks[iBX][iLink].uint.reserve(6);
218 allLinks[iBX][iLink].ctp7LinkNumber = iLink;
219 allLinks[iBX][iLink].crateID = expectedCrateID;
220 allLinks[iBX][iLink].even = expectedEven;
223 for(
unsigned int iWord = 0; iWord < 6 ; iWord++ ){
224 allLinks[iBX][iLink].uint.push_back(data[iDAQBuffer+iWord+iBX*6]);
230 uint32_t nCratesFound = 0;
231 for(
unsigned int iCrate = 0; iCrate < 18 ; iCrate++){
233 bool foundEven =
false, foundOdd =
false;
237 for(
unsigned int iLink = 0; iLink < NLinks; iLink++){
239 if( (allLinks[0][iLink].crateID==iCrate) && (allLinks[0][iLink].even ==
true) ){
241 for (
unsigned int iBX=0; iBX<nBX; iBX++)
242 even[iBX] = allLinks[iBX][iLink];
244 else if( (allLinks[0][iLink].crateID==iCrate) && (allLinks[0][iLink].even ==
false) ){
246 for (
unsigned int iBX=0; iBX<nBX; iBX++)
247 odd[iBX] = allLinks[iBX][iLink];
251 if(foundEven && foundOdd){
255 for (
unsigned int iBX=0; iBX<nBX; iBX++){
257 std::vector <RCTInfo> rctInfoData;
258 rctDataDecoder.decodeLinks(even[iBX].uint, odd[iBX].uint, rctInfoData);
259 rctDataDecoder.setRCTInfoCrateID(rctInfoData, iCrate);
260 allCrateRCTInfo[iBX].push_back(rctInfoData.at(0));
267 if(nCratesFound != 18)
268 LogError(
"L1T") <<
"Warning -- only found "<< nCratesFound <<
" valid crates";
281 for (uint32_t iBX=0; iBX<nBX; iBX++, startBX++){
283 for(
unsigned int iCrate = 0; iCrate < nCratesFound; iCrate++ ){
285 RCTInfo rctInfo = allCrateRCTInfo[iBX].at(iCrate);
287 for(
int j = 0;
j < 4;
j++) {
294 colls->
rctEm()->push_back(em);
297 for(
int j = 0;
j < 4;
j++) {
304 colls->
rctEm()->push_back(em);
307 for(
int j = 0;
j < 7;
j++) {
308 for(
int k = 0;
k < 2;
k++) {
309 bool o = (((rctInfo.oBits >> (
j * 2 +
k)) & 0x1) == 0x1);
310 bool t = (((rctInfo.tBits >> (
j * 2 +
k)) & 0x1) == 0x1);
311 bool m = (((rctInfo.mBits >> (
j * 2 +
k)) & 0x1) == 0x1);
312 bool q = (((rctInfo.qBits >> (
j * 2 +
k)) & 0x1) == 0x1);
315 colls->
rctCalo()->push_back(rgn);
319 for(
int k = 0;
k < 4;
k++) {
320 for(
int j = 0;
j < 2;
j++) {
323 bool fg=(((rctInfo.hfQBits >>
offset) & 0x1) == 0x1);
326 colls->
rctCalo()->push_back(rgn);
338 for(
unsigned i = 0;
i <
size;
i ++){
351 std::ostringstream os;
360 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.
int evtStatus()
Event fragment status information.
void setBx(int16_t bx)
set bx
void setBx(int16_t bx)
set BX
Level-1 Region Calorimeter Trigger EM candidate.
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.
size_t size() const
Lenght of the data buffer in bytes.
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
int ttsBits()
Current value of the Trigger Throttling System bitsAQ).
static const unsigned MAX_ERR_CODE
RctRawToDigi(const edm::ParameterSet &)
edm::InputTag inputLabel_
FED collection label.
int lenght()
The length of the event fragment counted in 64-bit words including header and trailer.
std::vector< std::vector< double > > tmp
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
A calorimeter trigger region (sum of 4x4 trigger towers)
int crc()
Cyclic Redundancy Code of the event fragment including header and trailer.
volatile std::atomic< bool > shutdown_flag false
void unpack(const FEDRawData &d, edm::Event &e, RctUnpackCollections *const colls)
Unpacks the raw data.
bool printAll(const unsigned char *data, const unsigned size)
tuple size
Write out results.
void produce(edm::Event &, const edm::EventSetup &)
const bool verbose_
If true, then debug print out for each event.
static const unsigned amc13HeaderSize_