14 #include "eformat/SourceIdentifier.h"
15 #include "eformat/Status.h"
26 std::string
RED =
"\033[1;31m";
27 std::string
ORANGE =
"\033[1;38;5;208m";
29 std::string
GREEN =
"\033[1;32m";
30 std::string
BLUE =
"\033[1;34m";
32 std::string
END =
"\033[0m";
37 std::string
B_RED =
"\033[1;41m";
42 const std::string&
name,
48 ATH_MSG_INFO(
"Initializing L1CaloFEXByteStream/jFexInputByteStreamTool algorithm with name: "<<
name());
59 ATH_MSG_DEBUG((jTowersmode==ConversionMode::Encoding ?
"Encoding" :
"Decoding") <<
" jTowers ROB IDs: " << MSG::hex <<
m_robIds.value() << MSG::dec);
76 return StatusCode::SUCCESS;
86 ATH_CHECK(jTowersContainer.
record(std::make_unique<xAOD::jFexTowerContainer>(), std::make_unique<xAOD::jFexTowerAuxContainer>()));
87 ATH_MSG_DEBUG(
"Recorded jFexTowerContainer with key " << jTowersContainer.
key());
92 for (
const ROBF* rob : vrobf) {
96 ATH_MSG_DEBUG(
"Starting to decode " << rob->rod_ndata() <<
" ROD words from ROB 0x" << std::hex << rob->rob_source_id() << std::dec);
99 if(rob->rod_ndata() <= 0){
100 ATH_MSG_DEBUG(
C.
B_RED<<
" No ROD words to decode: " << rob->rod_ndata() <<
" in ROB 0x"<< std::hex << rob->rob_source_id()<< std::dec <<
". Skipping"<<
C.
END);
104 const auto dataArray =
std::span{rob->rod_data(), rob->rod_ndata()};
105 std::vector<uint32_t> vec_words(dataArray.begin(),dataArray.end());
108 unsigned int trailers_pos = rob->rod_ndata();
111 bool READ_WORDS =
true;
114 if( trailers_pos < jBits::jFEX2ROD_WORDS ){
115 std::stringstream sdetail;
116 sdetail <<
"There are not enough words ("<< trailers_pos <<
") for the jFEX to ROD trailer decoder. Expected at least " << jBits::jFEX2ROD_WORDS<<
". Skipping this FPGA(?)" ;
117 std::stringstream slocation;
118 slocation <<
"0x"<< std::hex << rob->rob_source_id();
119 std::stringstream stitle;
120 stitle <<
"Invalid trailer words" ;
121 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
132 bool corTrailer = ((
error >> jBits::ERROR_CORR_TRAILER ) & jBits::ROD_TRAILER_1b);
133 bool safemode = ((
error >> jBits::ERROR_SAFE_MODE ) & jBits::ROD_TRAILER_1b);
134 bool proterror = ((
error >> jBits::ERROR_PROTOCOL_ERROR ) & jBits::ROD_TRAILER_1b);
135 bool lenerror = ((
error >> jBits::ERROR_LENGTH_MISMATCH ) & jBits::ROD_TRAILER_1b);
136 bool headmismatch = ((
error >> jBits::ERROR_HEADER_MISMATCH ) & jBits::ROD_TRAILER_1b);
137 bool processerror = ((
error >> jBits::ERROR_PROC_TIMEOUT ) & jBits::ROD_TRAILER_1b);
139 std::stringstream sdetail;
140 sdetail <<
"jFEX to ROD Trailer Error bits set - 6-bits error word: 0x"<< std::hex <<
error << std::dec<< std::endl;
141 sdetail <<
"Corrective Trailer: "<< corTrailer << std::endl;
142 sdetail <<
"Safe Mode : "<< safemode << std::endl;
143 sdetail <<
"Protocol error : "<< proterror << std::endl;
144 sdetail <<
"Length Mismatch : "<< lenerror << std::endl;
145 sdetail <<
"Header Mismatch : "<< headmismatch << std::endl;
146 sdetail <<
"Processor timeout : "<< processerror << std::endl;
147 std::stringstream slocation;
148 slocation <<
"Error bit set";
151 std::stringstream stitle;
152 stitle <<
"Corrective Trailer" ;
153 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
157 std::stringstream stitle;
158 stitle <<
"Safe Mode" ;
159 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
163 std::stringstream stitle;
164 stitle <<
"Protocol error" ;
165 printError(slocation.str(),stitle.str(),MSG::WARNING,sdetail.str());
169 std::stringstream stitle;
170 stitle <<
"Length mismatch" ;
175 std::stringstream stitle;
176 stitle <<
"Header mismatch" ;
181 std::stringstream stitle;
182 stitle <<
"Processor Timeout" ;
189 if(
payload % jBits::DATA_BLOCKS != 0){
190 ATH_MSG_DEBUG(
" Not full readout activated (" <<
payload <<
"). Data blocks/channels expected (" << jBits::DATA_BLOCKS <<
")"<<
C.
END);
193 if(
payload % jBits::DATA_WORDS_PER_BLOCK != 0) {
194 std::stringstream sdetail;
195 sdetail <<
" Payload number (" <<
payload <<
") not a multiple of data words per channel. Expected: " << jBits::DATA_WORDS_PER_BLOCK ;
196 std::stringstream slocation;
197 slocation <<
"jFEX "<< jfex <<
" FPGA "<< fpga <<
" in 0x"<< std::hex << rob->rob_source_id();
198 std::stringstream stitle;
199 stitle <<
"Invalid Data Blocks" ;
207 unsigned int wordIndex = trailers_pos - (jBits::jFEX2ROD_WORDS);
210 unsigned int Max_iter =
payload/jBits::DATA_WORDS_PER_BLOCK;
212 if(Max_iter>trailers_pos) {
213 std::stringstream sdetail;
214 sdetail <<
"Block size error in fragment 0x"<< std::hex << rob->rob_source_id() << std::dec<<
". Words available: " << trailers_pos <<
". Number of words wanted to decode: " << Max_iter ;
215 std::stringstream slocation;
216 slocation <<
"jFEX "<< jfex <<
" FPGA "<< fpga <<
" in 0x"<< std::hex << rob->rob_source_id();
217 std::stringstream stitle;
218 stitle <<
"Block Size Error" ;
222 return StatusCode::SUCCESS;
229 for (
unsigned int iblock = 0; iblock < Max_iter; iblock++){
232 const auto [DATA13_low , DATA15, DATA14] =
Dataformat1(vec_words.at(wordIndex-3));
233 const auto [DATA13_up,DATA10_up , DATA12, DATA11] =
Dataformat2(vec_words.at(wordIndex-4));
234 const auto [DATA10_low , DATA9 , DATA8 ] =
Dataformat1(vec_words.at(wordIndex-5));
235 const auto [DATA5_low , DATA7 , DATA6 ] =
Dataformat1(vec_words.at(wordIndex-6));
236 const auto [DATA5_up ,DATA2_up , DATA4 , DATA3 ] =
Dataformat2(vec_words.at(wordIndex-7));
237 const auto [DATA2_low , DATA1 , DATA0 ] =
Dataformat1(vec_words.at(wordIndex-8));
240 uint16_t DATA2 = ( DATA2_up << jBits::BS_MERGE_DATA ) + DATA2_low;
241 uint16_t DATA5 = ( DATA5_up << jBits::BS_MERGE_DATA ) + DATA5_low;
242 uint16_t DATA10 = ( DATA10_up << jBits::BS_MERGE_DATA ) + DATA10_low;
243 uint16_t DATA13 = ( DATA13_up << jBits::BS_MERGE_DATA ) + DATA13_low;
245 std::array<uint16_t,16> allDATA = {DATA0, DATA1, DATA2, DATA3, DATA4, DATA5, DATA6, DATA7, DATA8, DATA9, DATA10, DATA11, DATA12, DATA13, DATA14, DATA15 };
248 for(
uint idata = 0; idata < allDATA.size(); idata++){
250 char et_saturation = ((saturation >> idata) & jBits::BS_TRAILER_1b);
268 std::vector<uint16_t> vtower_ET;
270 vtower_ET.push_back(allDATA[idata]);
272 std::vector<char> vtower_SAT;
274 vtower_SAT.push_back(et_saturation);
277 jTowersContainer->
push_back( std::make_unique<xAOD::jFexTower>() );
278 jTowersContainer->
back()->initialize(
eta,
phi,
iEta,
iPhi, IDsim,
source, vtower_ET, jfex, fpga,
channel, idata, vtower_SAT );
303 wordIndex -= jBits::DATA_WORDS_PER_BLOCK;
307 trailers_pos -= (
payload + jBits::jFEX2ROD_WORDS);
309 if(trailers_pos == 0){
315 return StatusCode::SUCCESS;
322 uint32_t payload = ((word0 >> jBits::PAYLOAD_ROD_TRAILER ) & jBits::ROD_TRAILER_16b);
323 uint32_t jfex = ((word0 >> jBits::jFEX_ROD_TRAILER ) & jBits::ROD_TRAILER_4b );
324 uint32_t fpga = ((word0 >> jBits::FPGA_ROD_TRAILER ) & jBits::ROD_TRAILER_2b );
335 uint16_t Satur_high = ((
word1 >> jBits::BS_SATUR_1_TRAILER ) & jBits::BS_TRAILER_8b );
336 uint16_t Satur_down = ((
word1 >> jBits::BS_SATUR_0_TRAILER ) & jBits::BS_TRAILER_8b );
337 uint16_t Channel = ((word0 >> jBits::BS_CHANNEL_TRAILER ) & jBits::BS_TRAILER_8b );
340 bool isTileFibre =
false;
353 uint16_t Satur = ( Satur_high << jBits::BS_SATUR_1_TRAILER ) + Satur_down;
363 uint16_t data_low = ((word0 >> jBits::BS_ET_DATA_0 ) & jBits::BS_TRAILER_12b);
364 uint16_t data_mid = ((word0 >> jBits::BS_ET_DATA_1 ) & jBits::BS_TRAILER_12b );
365 uint16_t data_up = ((word0 >> jBits::BS_ET_DATA_4 ) & jBits::BS_TRAILER_8b );
367 return {data_up,data_mid,data_low};
374 uint16_t data_low = ((word0 >> jBits::BS_ET_DATA_0 ) & jBits::BS_TRAILER_12b);
375 uint16_t data_mid = ((word0 >> jBits::BS_ET_DATA_1 ) & jBits::BS_TRAILER_12b );
376 uint16_t data_up_1 = ((word0 >> jBits::BS_ET_DATA_4 ) & jBits::BS_TRAILER_4b );
377 uint16_t data_up_2 = ((word0 >> jBits::BS_ET_DATA_7 ) & jBits::BS_TRAILER_4b );
379 return {data_up_2,data_up_1,data_mid,data_low};
412 return StatusCode::SUCCESS;
422 if ( !myfile.is_open() ){
424 return StatusCode::FAILURE;
428 while ( std::getline (myfile, myline) ) {
431 if(myline[0] ==
'#')
continue;
434 std::stringstream oneLine(myline);
437 std::vector<float> elements;
439 while(std::getline(oneLine, element,
' '))
441 elements.push_back(std::stof(element));
446 if(elements.size() != 10){
448 return StatusCode::FAILURE;
451 std::array<float,6> aux_arr{ {elements.at(7),elements.at(8),elements.at(9),elements.at(4),elements.at(5),elements.at(6)} };
459 return StatusCode::SUCCESS;
465 return (jfex << 16) | (fpga << 12) | (
channel << 4) | tower;
472 Monitored::Scalar(
"jfexDecoderErrorLocation",location.empty() ? std::string(
"UNKNOWN") : location),