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 LogError(
"L1T") <<
"Cannot unpack: empty/invalid L1T raw data (size = "
84 << rctRcd.
size() <<
") for ID " <<
fedId_ <<
". Returning empty collections!";
95 LogError(
"L1T") <<
"Cannot unpack: no collection found";
105 const unsigned char *
data = d.
data();
113 if (header.
check()) {
114 LogDebug(
"L1T") <<
"Found SLink header:"
116 <<
" L1 event ID " << header.
lvl1ID()
117 <<
" BX Number " << header.
bxID()
118 <<
" FED source " << header.
sourceID()
119 <<
" FED version " << header.
version();
121 LogWarning(
"L1T") <<
"Did not find a valid SLink header!";
126 if (trailer.
check()) {
127 LogDebug(
"L1T") <<
"Found SLink trailer:"
128 <<
" Length " << trailer.
lenght()
129 <<
" CRC " << trailer.
crc()
131 <<
" Throttling bits " << trailer.
ttsBits();
133 LogWarning(
"L1T") <<
"Did not find a SLink trailer!";
136 unpackCTP7((uint32_t*)data, 0,
sizeof(data), colls);
146 LogDebug(
"L1T") <<
"Block ID = " << block_id <<
" size = " <<
size;
148 CTP7Format ctp7Format;
149 RctDataDecoder rctDataDecoder;
150 uint32_t nBXTemp = 0;
151 uint32_t ctp7FWVersion;
152 uint32_t L1ID, L1aBCID;
153 std::vector<RCTInfo> allCrateRCTInfo[5];
156 L1aBCID = data[5+of] & 0x00000FFF;
157 nBXTemp = (data[5+of] & 0x00FF0000) >> 16;
158 ctp7FWVersion = data[4+of];
160 if(nBXTemp != 1 && nBXTemp != 3 && nBXTemp != 5)
163 const uint32_t nBX = nBXTemp;
165 LogDebug(
"L1T") <<
"CTP7 L1ID = " << L1ID <<
" L1A BCID = " << L1aBCID <<
" BXs in capture = " << nBX <<
" CTP7 DAQ FW = " << ctp7FWVersion;
169 unsigned int crateID;
170 unsigned int ctp7LinkNumber;
171 std::vector <unsigned int> uint;
175 link_data allLinks[5][36];
176 const uint32_t NLinks = ctp7Format.NLINKS;
180 uint32_t iDAQBuffer = 0;
183 for(
unsigned int iLink = 0; iLink < NLinks; iLink++ ){
185 ctp7Format.EVENT_HEADER_WORDS + iLink * (ctp7Format.CHANNEL_HEADER_WORDS +
186 nBX * ctp7Format.CHANNEL_DATA_WORDS_PER_BX);
189 uint32_t linkID = data[iDAQBuffer++];
190 uint32_t
tmp = data[iDAQBuffer++];
191 uint32_t CRCErrCnt = tmp & 0x0000FFFF;
194 uint32_t crateID = 0; uint32_t expectedCrateID = 0;
195 bool even =
false;
bool expectedEven =
false;
198 rctDataDecoder.getExpectedLinkID(iLink, expectedCrateID, expectedEven);
200 rctDataDecoder.decodeLinkID(linkID, crateID, even);
203 if(expectedCrateID!=crateID || even!=expectedEven ){
204 LogError(
"L1T") <<
"Expected Crate ID "<< expectedCrateID <<
" expectedEven "<< expectedEven
205 <<
"does not match actual Crate ID "<<crateID<<
" even "<<even;
209 LogError(
"L1T")<<
"WARNING CRC ErrorFound linkID "<< linkID<<
" expected crateID "<< expectedCrateID;
212 for (uint32_t iBX=0; iBX<nBX; iBX++){
213 allLinks[iBX][iLink].uint.reserve(6);
214 allLinks[iBX][iLink].ctp7LinkNumber = iLink;
215 allLinks[iBX][iLink].crateID = expectedCrateID;
216 allLinks[iBX][iLink].even = expectedEven;
219 for(
unsigned int iWord = 0; iWord < 6 ; iWord++ ){
220 allLinks[iBX][iLink].uint.push_back(data[iDAQBuffer+iWord+iBX*6]);
226 uint32_t nCratesFound = 0;
227 for(
unsigned int iCrate = 0; iCrate < 18 ; iCrate++){
229 bool foundEven =
false, foundOdd =
false;
233 for(
unsigned int iLink = 0; iLink < NLinks; iLink++){
235 if( (allLinks[0][iLink].crateID==iCrate) && (allLinks[0][iLink].even ==
true) ){
237 for (
unsigned int iBX=0; iBX<nBX; iBX++)
238 even[iBX] = allLinks[iBX][iLink];
240 else if( (allLinks[0][iLink].crateID==iCrate) && (allLinks[0][iLink].even ==
false) ){
242 for (
unsigned int iBX=0; iBX<nBX; iBX++)
243 odd[iBX] = allLinks[iBX][iLink];
247 if(foundEven && foundOdd){
251 for (
unsigned int iBX=0; iBX<nBX; iBX++){
253 std::vector <RCTInfo> rctInfoData;
254 rctDataDecoder.decodeLinks(even[iBX].uint, odd[iBX].uint, rctInfoData);
255 rctDataDecoder.setRCTInfoCrateID(rctInfoData, iCrate);
256 allCrateRCTInfo[iBX].push_back(rctInfoData.at(0));
263 if(nCratesFound != 18)
264 LogError(
"L1T") <<
"Warning -- only found "<< nCratesFound <<
" valid crates";
277 for (uint32_t iBX=0; iBX<nBX; iBX++, startBX++){
279 for(
unsigned int iCrate = 0; iCrate < nCratesFound; iCrate++ ){
281 RCTInfo rctInfo = allCrateRCTInfo[iBX].at(iCrate);
283 for(
int j = 0;
j < 4;
j++) {
290 colls->
rctEm()->push_back(em);
293 for(
int j = 0;
j < 4;
j++) {
300 colls->
rctEm()->push_back(em);
303 for(
int j = 0;
j < 7;
j++) {
304 for(
int k = 0;
k < 2;
k++) {
305 bool o = (((rctInfo.oBits >> (
j * 2 +
k)) & 0x1) == 0x1);
306 bool t = (((rctInfo.tBits >> (
j * 2 +
k)) & 0x1) == 0x1);
307 bool m = (((rctInfo.mBits >> (
j * 2 +
k)) & 0x1) == 0x1);
308 bool q = (((rctInfo.qBits >> (
j * 2 +
k)) & 0x1) == 0x1);
311 colls->
rctCalo()->push_back(rgn);
315 for(
int k = 0;
k < 4;
k++) {
316 for(
int j = 0;
j < 2;
j++) {
319 bool fg=(((rctInfo.hfQBits >>
offset) & 0x1) == 0x1);
322 colls->
rctCalo()->push_back(rgn);
334 for(
unsigned i = 0;
i <
size;
i ++){
347 std::ostringstream os;
356 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
char data[epos_bytes_allocation]
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_