144 {
145
146
147
148
149 SG::WriteHandle<xAOD::jFexSRJetRoIContainer> jJContainer(
m_jJWriteKey, ctx);
150 ATH_CHECK(jJContainer.record(std::make_unique<xAOD::jFexSRJetRoIContainer>(), std::make_unique<xAOD::jFexSRJetRoIAuxContainer>()));
151 ATH_MSG_DEBUG(
"Recorded jFexSRJetRoIContainer with key " << jJContainer.key());
152
153
154 SG::WriteHandle<xAOD::jFexLRJetRoIContainer> jLJContainer(
m_jLJWriteKey, ctx);
155 ATH_CHECK(jLJContainer.record(std::make_unique<xAOD::jFexLRJetRoIContainer>(), std::make_unique<xAOD::jFexLRJetRoIAuxContainer>()));
156 ATH_MSG_DEBUG(
"Recorded jFexLRJetRoIContainer with key " << jLJContainer.key());
157
158
159 SG::WriteHandle<xAOD::jFexTauRoIContainer> jTauContainer(
m_jTauWriteKey, ctx);
160 ATH_CHECK(jTauContainer.record(std::make_unique<xAOD::jFexTauRoIContainer>(), std::make_unique<xAOD::jFexTauRoIAuxContainer>()));
161 ATH_MSG_DEBUG(
"Recorded jFexTauRoIContainer with key " << jTauContainer.key());
162
163
164 SG::WriteHandle<xAOD::jFexFwdElRoIContainer> jEMContainer(
m_jEMWriteKey, ctx);
165 ATH_CHECK(jEMContainer.record(std::make_unique<xAOD::jFexFwdElRoIContainer>(), std::make_unique<xAOD::jFexFwdElRoIAuxContainer>()));
166 ATH_MSG_DEBUG(
"Recorded jFexFwdElRoIContainer with key " << jEMContainer.key());
167
168
169 SG::WriteHandle<xAOD::jFexSumETRoIContainer> jTEContainer(
m_jTEWriteKey, ctx);
170 ATH_CHECK(jTEContainer.record(std::make_unique<xAOD::jFexSumETRoIContainer>(), std::make_unique<xAOD::jFexSumETRoIAuxContainer>()));
171 ATH_MSG_DEBUG(
"Recorded jFexSumETRoIContainer with key " << jTEContainer.key());
172
173
174 SG::WriteHandle<xAOD::jFexMETRoIContainer> jXEContainer(
m_jXEWriteKey, ctx);
175 ATH_CHECK(jXEContainer.record(std::make_unique<xAOD::jFexMETRoIContainer>(), std::make_unique<xAOD::jFexMETRoIAuxContainer>()));
176 ATH_MSG_DEBUG(
"Recorded jFexMETRoIContainer with key " << jXEContainer.key());
177
178
179
180
181
182 for (
const ROBF* rob : vrobf) {
183
184
185 ATH_MSG_DEBUG(
"Starting to decode " << rob->rod_ndata() <<
" ROD words from ROB 0x" << std::hex << rob->rob_source_id() << std::dec);
186
187
188 if(rob->rod_ndata() <= 0){
189 std::stringstream sdetail;
190 sdetail << "Not enough ROB words to read: "<<rob->rod_ndata() ;
191 std::stringstream slocation;
192 slocation << "0x"<< std::hex << rob->rob_source_id();
193 std::stringstream stitle;
194 stitle << "Invalid amount of ROB words" ;
195 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
196
197 continue;
198 }
199
200 const auto dataArray = std::span{rob->rod_data(), rob->rod_ndata()};
201 std::vector<uint32_t> vec_words(dataArray.begin(),dataArray.end());
202
203 std::stringstream myPrint;
204
205 myPrint << "jFEX TOB words to decode:"<< std::endl;
206 int aux = 1;
207 for (const uint32_t word : vec_words) {
208 myPrint << aux << " raw word ---> 0x"<< std::hex << word << std::dec << std::endl;
209 aux++;
210 }
212
213
214 bool READ_TOBS = true;
215
217
219 std::stringstream sdetail;
220 sdetail << "Not enough jFEX TOB words to decode (<4). Number of word to decode: "<<vec_words.size()<< ". Position within the vector: "<<trailers_pos ;
221 std::stringstream slocation;
222 slocation << "0x"<< std::hex << rob->rob_source_id();
223 std::stringstream stitle;
224 stitle << "Less than 4 trailers" ;
225 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
226
227 continue;
228 }
229
230
231 const auto [RODerror] =
RODTrailer ( vec_words.at(rob->rod_ndata()-2), vec_words.at(rob->rod_ndata()-1) );
232
233
234 if(RODerror != 0){
242
243 std::stringstream sdetail;
244 sdetail << "ROD Trailer Error bits set - 7-bits error word: 0x"<< std::hex <<RODerror << std::dec<< std::endl;
245 sdetail << "Corrective Trailer: "<< corTrailer << std::endl;
246 sdetail << "Payload CRC : "<< payloadCRC << std::endl;
247 sdetail << "Header CRC : "<< headerCRC << std::endl;
248 sdetail << "Reserved (=0) : "<< reserved << std::endl;
249 sdetail << "Length Mismatch : "<< lenerror << std::endl;
250 sdetail << "Header Mismatch : "<< headmismatch << std::endl;
251 sdetail << "Processor timeout : "<< processerror << std::endl;
252 std::stringstream slocation;
253 slocation << "ROD Error";
254
255
256 if( corTrailer ){
257 std::stringstream stitle;
258 stitle << "Corrective Trailer" ;
259 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
260 return StatusCode::FAILURE;
261 }
262 if( payloadCRC ){
263 std::stringstream stitle;
264 stitle << "Payload CRC" ;
265 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
266 return StatusCode::FAILURE;
267 }
268 if( headerCRC ){
269 std::stringstream stitle;
270 stitle << "Header CRC" ;
271 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
272 return StatusCode::FAILURE;
273 }
274 if( lenerror ){
275 std::stringstream stitle;
276 stitle << "Length mismatch" ;
277 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
278 return StatusCode::FAILURE;
279 }
280 if( headmismatch ){
281 std::stringstream stitle;
282 stitle << "Header mismatch" ;
283 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
284 return StatusCode::FAILURE;
285 }
286 if( processerror ){
287 std::stringstream stitle;
288 stitle << "Processor Timeout" ;
289 printError(slocation.str(),stitle.str(),MSG::ERROR,stitle.str() +
" - "+ sdetail.str());
290 return StatusCode::FAILURE;
291 }
292
293 return StatusCode::FAILURE;
294 }
295
296 while(READ_TOBS){
297
299 const auto [n_xjJ, n_xjLJ, n_xjTau, n_xjEM] =
xTOBCounterTrailer( vec_words.at(trailers_pos-3) );
300 const auto [n_jJ, n_jLJ, n_jTau, n_jEM, n_jTE, n_jXE] =
TOBCounterTrailer ( vec_words.at(trailers_pos-4) );
301 unsigned int n_tobs = n_jJ + n_jLJ + n_jTau + n_jEM + n_jTE + n_jXE;
302 unsigned int n_xtobs = n_xjJ + n_xjLJ + n_xjTau + n_xjEM;
303 unsigned int total_tobs = n_tobs+n_xtobs;
304
305
306
307
308
309
310 unsigned int paddingWord = 0;
311 if(total_tobs % 2){
312 ATH_MSG_DEBUG(
"Odd number of TOBs + xTOBs:"<< total_tobs<<
", there is a padding word!");
313 paddingWord = 1;
314 }
315
316 if(error != 0){
317
324
325 std::stringstream sdetail;
326 sdetail <<
"jFEX to ROD Trailer Error bits set - 6-bits error word: 0x"<< std::hex <<
error << std::dec<< std::endl;
327 sdetail << "Corrective Trailer: "<< corTrailer << std::endl;
328 sdetail << "Safe Mode : "<< safemode << std::endl;
329 sdetail << "Protocol error : "<< proterror << std::endl;
330 sdetail << "Length Mismatch : "<< lenerror << std::endl;
331 sdetail << "Header Mismatch : "<< headmismatch << std::endl;
332 sdetail << "Processor timeout : "<< processerror << std::endl;
333 std::stringstream slocation;
334 slocation << "Error bit set";
335
336 if( corTrailer ){
337 std::stringstream stitle;
338 stitle << "Corrective Trailer" ;
339 printError(slocation.str(),stitle.str(),MSG::ERROR,sdetail.str());
340
341
342 return StatusCode::FAILURE;
343 }
344 if( safemode ){
345 std::stringstream stitle;
346 stitle << "Safe Mode" ;
347 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
348 }
349 if( proterror ){
350 std::stringstream stitle;
351 stitle << "Protocol error" ;
352 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
353 }
354 if( lenerror ){
355 std::stringstream stitle;
356 stitle << "Length mismatch" ;
357 printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
358 }
359 if( headmismatch ){
360 std::stringstream stitle;
361 stitle << "Header mismatch" ;
362 printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
363 }
364 if( processerror ){
365 std::stringstream stitle;
366 stitle << "Processor Timeout" ;
367 printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
368 }
369
370 }
371
373 std::stringstream sdetail;
374 sdetail <<
"Payload="<<
payload<<
" is different from TOBs+Trailers+padding words="<< total_tobs +
jBits::TOB_TRAILERS + paddingWord <<
" in FPGA: "<< fpga <<
" and jFEX: "<< jfex <<
". SKIPPED!" ;
375 std::stringstream slocation;
376 slocation << "jFEX "<< jfex << " FPGA "<< fpga << " in 0x"<< std::hex << rob->rob_source_id();
377 std::stringstream stitle;
378 stitle << "Wrong payload" ;
379 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
380
381
383
384 if(neg_positions < 0){
385 std::stringstream sdetail;
386 sdetail << "jFEX TOB decoder has discarded the whole event. Due to a wrong payload cannot continue decoding" ;
387 std::stringstream slocation;
388 slocation << "jFEX "<< jfex << " FPGA "<< fpga << " in 0x"<< std::hex << rob->rob_source_id();
389 std::stringstream stitle;
390 stitle << "Event discarded" ;
391
392 printError(slocation.str(),stitle.str(),MSG::DEBUG,sdetail.str());
393 break;
394 }
395
396
398
399
400 if(trailers_pos == 0) {
401 READ_TOBS = false;
402 }
403 continue;
404 }
405
406
408 std::stringstream sdetail;
410 std::stringstream slocation;
411 slocation << "jFEX "<< jfex << " FPGA "<< fpga << " in 0x"<< std::hex << rob->rob_source_id();
412 std::stringstream stitle;
413 stitle << "Event discarded" ;
414
415 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
416 break;
417 }
418
419
421
422 if(paddingWord == 1){
423 ATH_MSG_DEBUG(
"Padding word: "<< std::hex << vec_words.at(tobIndex) <<std::dec);
424 }
425
427
428
429
430 for(
unsigned int i=tobIndex;
i>tobIndex-n_xjEM;
i--) {
431 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jEM xTOB");
432 jEMContainer->push_back( std::make_unique<xAOD::jFexFwdElRoI>() );
433 jEMContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),0,
m_jEMRes,
eta,
phi);
434 }
435
436 tobIndex -= n_xjEM;
437
438
439 for(
unsigned int i=tobIndex;
i>tobIndex-n_xjTau;
i--) {
440 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jTau xTOB");
441 jTauContainer->push_back( std::make_unique<xAOD::jFexTauRoI>() );
442 jTauContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),0,
m_jTauRes,
eta,
phi);
443 }
444
445 tobIndex -= n_xjTau;
446
447
448
449
450
451
452
453
454
455
456 tobIndex -= n_xjLJ;
457
458
459 for(
unsigned int i=tobIndex;
i>tobIndex-n_xjJ;
i--) {
460 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jJ xTOB");
461 jJContainer->push_back( std::make_unique<xAOD::jFexSRJetRoI>() );
462 jJContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),0,
m_jJRes,
eta,
phi);
463 }
464
465 tobIndex -= n_xjJ;
466
467
468 tobIndex -= n_tobs;
469
470 }
471 else {
472
473
474
475 tobIndex -= n_xtobs;
476
477
478
480 for(
unsigned int i=tobIndex;
i>tobIndex-n_jXE;
i--) {
481 jXEContainer->push_back( std::make_unique<xAOD::jFexMETRoI>() );
482 jXEContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),
m_jXERes);
483 }
484 }
485
486 tobIndex -= n_jXE;
487
488
489
491 for(
unsigned int i=tobIndex;
i>tobIndex-n_jTE;
i--) {
492 jTEContainer->push_back( std::make_unique<xAOD::jFexSumETRoI>() );
493 jTEContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),
m_jTERes);
494 }
495 }
496
497 tobIndex -= n_jTE;
498
499
500 for(
unsigned int i=tobIndex;
i>tobIndex-n_jEM;
i--) {
501 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jEM TOB");
502 jEMContainer->push_back( std::make_unique<xAOD::jFexFwdElRoI>() );
503 jEMContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),1,
m_jEMRes,
eta,
phi);
504 }
505
506 tobIndex -= n_jEM;
507
508
509 for(
unsigned int i=tobIndex;
i>tobIndex-n_jTau;
i--) {
510 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jTau TOB");
511 jTauContainer->push_back( std::make_unique<xAOD::jFexTauRoI>() );
512 jTauContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),1,
m_jTauRes,
eta,
phi);
513 }
514
515 tobIndex -= n_jTau;
516
517
518 for(
unsigned int i=tobIndex;
i>tobIndex-n_jLJ;
i--) {
519 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jLJ TOB");
520 jLJContainer->push_back( std::make_unique<xAOD::jFexLRJetRoI>() );
521 jLJContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),1,
m_jLJRes,
eta,
phi);
522 }
523
524 tobIndex -= n_jLJ;
525
526
527 for(
unsigned int i=tobIndex;
i>tobIndex-n_jJ;
i--) {
528 const auto [
eta,
phi ] =
getEtaPhi(jfex, fpga, vec_words.at(i-1),
"jJ TOB");
529 jJContainer->push_back( std::make_unique<xAOD::jFexSRJetRoI>() );
530 jJContainer->back()->initialize(jfex, fpga, vec_words.at(i-1),1,
m_jJRes,
eta,
phi);
531 }
532
533 tobIndex -= n_jJ;
534 }
535
537
538 if(trailers_pos != tobIndex){
539 std::stringstream sdetail;
540 sdetail << "Something went wrong decoding jFEX BS data. Trailer position: " << trailers_pos << " should match the TOB index position:" << tobIndex ;
541 std::stringstream slocation;
542 slocation << "jFEX "<< jfex << " FPGA "<< fpga << " in 0x"<< std::hex << rob->rob_source_id();
543 std::stringstream stitle;
544 stitle << "Wrong amount of words" ;
545
546 printError(slocation.str(),stitle.str(),MSG::ERROR,sdetail.str());
547
548 return StatusCode::FAILURE;
549 }
550
551
552 if(trailers_pos == 0){
553 READ_TOBS = false;
554 }
555 }
556 }
557
558 return StatusCode::SUCCESS;
559}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
static constexpr uint32_t ERROR_SAFE_MODE
static constexpr uint32_t ERROR_HEADER_MISMATCH
static constexpr uint32_t ROD_WORDS
Number of jFEX to ROD trailer words.
static constexpr uint32_t ROD_TRAILER_1b
Masking words.
static constexpr uint32_t TOB_TRAILERS
static constexpr uint32_t FPGA_U1
static constexpr uint32_t ROD_ERROR_LENGTH_MISMATCH
static constexpr uint32_t ROD_ERROR_HEADER_CRC
static constexpr uint32_t ERROR_CORR_TRAILER
static constexpr uint32_t jFEX2ROD_WORDS
static constexpr uint32_t ROD_ERROR_HEADER_MISMATCH
static constexpr uint32_t ROD_ERROR_PAYLOAD_CRC
static constexpr uint32_t ERROR_PROC_TIMEOUT
static constexpr uint32_t ERROR_PROTOCOL_ERROR
static constexpr uint32_t ROD_ERROR_RESERVED
static constexpr uint32_t ROD_ERROR_CORR_TRAILER
static constexpr uint32_t ROD_ERROR_PROC_TIMEOUT
static constexpr uint32_t ERROR_LENGTH_MISMATCH
static constexpr uint32_t FPGA_U4