7 #include "CoralBase/Attribute.h"
9 #include "CoolApplication/DatabaseSvcFactory.h"
10 #include "CoolKernel/DatabaseId.h"
11 #include "CoolKernel/Exception.h"
12 #include "CoolKernel/IDatabase.h"
13 #include "CoolKernel/IDatabaseSvc.h"
14 #include "CoolKernel/IFolder.h"
15 #include "CoolKernel/IObject.h"
16 #include "CoolKernel/IObjectIterator.h"
17 #include "CoolKernel/Record.h"
18 #include "CoolKernel/RecordSpecification.h"
23 #include "CoolApplication/Application.h"
38 m_CablingSvc(
"TRT_CablingSvc",
name),
39 m_recordBSErrors(true),
40 m_lookAtSidErrors(true),
41 m_lookAtErrorErrors(false),
42 m_lookAtL1idErrors(true),
43 m_lookAtBcidErrors(true),
44 m_lookAtMissingErrors(true),
45 m_loadCompressTableFile(false),
46 m_loadCompressTableDB(true),
47 m_maxCompressionVersion(255),
48 m_forceRodVersion(-1),
50 m_eventTypeIsSim(false),
51 m_escape_marker(0x8000000),
86 for (std::atomic<EventContext::ContextEvt_t>&
evt : m_lastPrint) {
87 evt = EventContext::INVALID_CONTEXT_EVT;
127 std::ostringstream ssVersion;
129 std::string compressTableFile =
130 "Compress_Table-" + ssVersion.str() +
".dat";
132 ATH_MSG_INFO(
"Reading Compress Table: " << compressTableFile);
147 return StatusCode::SUCCESS;
165 return StatusCode::SUCCESS;
183 const EventContext& ctx,
184 const std::vector<IdentifierHash>* vecHash)
const {
190 int RodBlockVersion = (robFrag->rod_version() & 0xff);
195 uint32_t robid = robFrag->rod_source_id();
200 if (robFrag->nstatus()) {
202 robFrag->status(rob_status);
212 std::atomic<EventContext::ContextEvt_t>*
evt = m_lastPrint.get(ctx);
213 EventContext::ContextEvt_t lastEvt = *
evt;
215 while (lastEvt != ctx.evt() &&
216 !
evt->compare_exchange_strong(lastEvt, ctx.evt()));
218 if (lastEvt != ctx.evt()) {
221 << MSG::hex << robFrag->rob_source_id() <<
" ( "
222 << *rob_status <<
" ) " << MSG::dec
223 <<
" Skipping decoding...");
226 sc = StatusCode::RECOVERABLE;
232 if (3 < RodBlockVersion &&
242 <<
", but Compression Table not loaded! ROD ID = "
243 << MSG::hex << robid << MSG::dec);
247 <<
"Turning message off.");
251 sc = StatusCode::FAILURE;
253 }
else if (3 == RodBlockVersion) {
255 }
else if ((2 == RodBlockVersion) || (1 == RodBlockVersion)) {
257 }
else if (0 == RodBlockVersion) {
258 if (0 == robFrag->rod_ndata()) {
264 <<
"and event_type is not EventType::IS_SIMULATION, "
265 <<
"ROD ID = " << MSG::hex << robid << MSG::dec);
266 return StatusCode::FAILURE;
277 if ((RodBlockVersion >= 2) && (
sc == StatusCode::SUCCESS)) {
282 int error_errors = 0;
285 int missing_errors = 0;
288 uint32_t rod_L1ID = robFrag->rod_lvl1_id();
289 uint32_t rod_BCID = robFrag->rod_bc_id();
290 uint32_t rod_SourceID = robFrag->rod_source_id();
293 robFrag->rod_status(vint);
303 uint32_t n_status = vint[v_index++];
305 if (n_status > robFrag->rod_nstatus()) {
306 if (n_status > robFrag->rod_fragment_size_word()) {
308 "Rejecting fragment because the number of status words exceeds "
309 "the fragement size: "
310 << n_status <<
" > " << robFrag->rod_fragment_size_word()
311 <<
" (nstatus from fragment header = " << robFrag->rod_nstatus()
313 return StatusCode::RECOVERABLE;
316 "The number of status words exceeds the number of status words "
317 "marked in the header: "
318 << n_status <<
" !< " << robFrag->rod_nstatus()
319 <<
" (fragment size = " << robFrag->rod_fragment_size_word()
325 while (
i < n_status) {
328 for (
int j = 0; j < 2; j++) {
332 int DTMROC_index =
stat & 0x7f;
333 int DTMROC_head = (
stat >> 7) & 0x1ff;
338 int D_sid = DTMROC_head & 0x100;
339 uint32_t D_L1ID = (DTMROC_head >> 5) & 0x7;
340 uint32_t D_BCID = (DTMROC_head >> 1) & 0xf;
341 int D_error = !(DTMROC_head & 1);
364 if (rod_BCID < 7 * 16) {
365 expected_BCID = (rod_BCID + 12) & 0xf;
367 expected_BCID = rod_BCID & 0xf;
386 errorWord = l1id_errors;
387 errorWord |= (bcid_errors << 7);
388 errorWord |= (missing_errors << 14);
389 errorWord |= (error_errors << 21);
390 if (sid_errors > 0xf)
392 errorWord |= ((
static_cast<uint32_t>(sid_errors) & 0xf)
396 sc = StatusCode::RECOVERABLE;
420 const std::vector<IdentifierHash>* vecHash)
const {
422 uint32_t robid = robFrag->rod_source_id();
430 ATH_MSG_DEBUG(
"fillCollections for " << MSG::hex << robid << MSG::dec);
436 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
441 robFrag->rod_data(vint);
443 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
448 uint32_t v_size = robFrag->rod_ndata();
449 int bufferOffset = -1;
450 for (
i = 0;
i < v_size;
i++) {
457 digit = word & 0x07ffffff;
462 ATH_MSG_VERBOSE((hex) << robid <<
" " << bufferOffset <<
" " << word <<
" "
463 << idHash << (dec) <<
" "
468 idStraw =
m_CablingSvc->getIdentifier((eformat::SubDetector)0 ,
469 robid, bufferOffset, idHash);
471 if (NULLId == idStraw) {
474 << bufferOffset <<
" word " << MSG::hex << word << MSG::dec)
480 ATH_MSG_DEBUG(
" Collection ID = " << idHash <<
" Straw ID = "
486 if (idHash == skipHash) {
488 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
491 }
else if (idHash != lastHash) {
497 std::vector<IdentifierHash>::const_iterator
p =
498 find(vecHash->begin(), vecHash->end(), idHash);
499 if (
p == vecHash->end()) {
501 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
509 if (idHash == skipHash) {
512 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
524 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
530 <<
" does not exist, create it ");
533 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
547 if (!dataItemsPool) {
562 for (
auto &[
id, coll] : colls) {
564 return a->identify() < b->identify();
570 for (
auto&
p : colls) {
574 return StatusCode::SUCCESS;
604 const std::vector<IdentifierHash>* vecHash)
const {
605 uint32_t robid = robFrag->rod_source_id();
613 ATH_MSG_DEBUG(
"fillCollection3 for " << MSG::hex << robid << MSG::dec);
619 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
624 robFrag->rod_data(vint);
626 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
633 unsigned int in_ptr = 0;
634 unsigned int out_ptr = 0;
635 int bufferOffset = -1;
636 uint32_t v_size = robFrag->rod_ndata();
641 while ((in_ptr < v_size) && (out_ptr < 1920))
649 v = (vint[in_ptr] >> bit) & 0
x1;
660 for (
int i = 0;
i < 4;
i++) {
661 v = (vint[in_ptr] >> bit) & 0
x1;
676 <<
"Turning message off.");
679 return StatusCode::RECOVERABLE;
682 for (
int i = 0;
i < 27;
i++) {
683 word = word | (((vint[in_ptr] >> bit) & 0
x1) <<
i);
698 ATH_MSG_VERBOSE((hex) << robid <<
" " << bufferOffset <<
" " << word <<
" "
699 << idHash << (dec) <<
" "
704 idStraw =
m_CablingSvc->getIdentifier((eformat::SubDetector)0 ,
705 robid, bufferOffset, idHash);
707 if (NULLId == idStraw) {
709 ATH_MSG_DEBUG(
"Null Identifier for bufferOffset " << bufferOffset);
715 ATH_MSG_DEBUG(
" Collection ID = " << idHash <<
" Straw ID = "
721 if (idHash == skipHash) {
723 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
726 }
else if (idHash != lastHash) {
732 std::vector<IdentifierHash>::const_iterator
p =
733 find(vecHash->begin(), vecHash->end(), idHash);
734 if (
p == vecHash->end()) {
736 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
751 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
757 <<
" does not exist, create it ");
760 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
778 if (!dataItemsPool) {
795 for (
auto &[
id, coll] : colls) {
797 return a->identify() < b->identify();
803 for (
auto&
p : colls) {
807 return StatusCode::SUCCESS;
833 const std::vector<IdentifierHash>* vecHash)
const {
837 uint32_t robid = robFrag->rod_source_id();
845 ATH_MSG_DEBUG(
"fillCollection3 for " << MSG::hex << robid << MSG::dec);
851 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
856 robFrag->rod_data(vint);
858 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
866 unsigned int in_ptr = 0;
867 unsigned int out_ptr = 0;
868 int bufferOffset = -1;
869 uint32_t v_size = robFrag->rod_ndata();
874 while ((in_ptr < v_size) && (out_ptr < 1920))
882 v = (vint[in_ptr] >> bit) & 0
x1;
897 v = 2 *
v + ((vint[in_ptr] >> bit) & 0
x1);
929 <<
"Turning message off.");
933 return StatusCode::RECOVERABLE;
941 for (
i = 0;
i < 27;
i++) {
942 word = word | (((vint[in_ptr] >> bit) & 0
x1) <<
i);
960 <<
" " << idHash << (dec) <<
" "
966 (eformat::SubDetector)0 , robid, bufferOffset, idHash);
968 if (NULLId == idStraw) {
970 ATH_MSG_DEBUG(
"Null Identifier for bufferOffset " << bufferOffset);
984 if (idHash == skipHash) {
986 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
989 }
else if (idHash != lastHash) {
995 std::vector<IdentifierHash>::const_iterator
p =
996 find(vecHash->begin(), vecHash->end(), idHash);
997 if (
p == vecHash->end()) {
999 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
1007 if (idHash == skipHash) {
1009 #ifdef TRT_BSC_DEBUG
1010 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
1023 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
1027 #ifdef TRT_BSC_DEBUG
1029 <<
" does not exist, create it ");
1032 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
1033 if (dataItemsPool) {
1046 if (!dataItemsPool) {
1064 for (
auto &[
id, coll] : colls) {
1066 return a->identify() < b->identify();
1072 for (
auto&
p : colls) {
1076 if ((out_ptr != 1920) || ((in_ptr == v_size) && bit != 0) ||
1077 ((in_ptr == (v_size - 1)) && (bit == 0)) || (in_ptr < (v_size - 1))) {
1079 <<
"L1ID = " << MSG::hex << robFrag->rod_lvl1_id()
1080 <<
" ROD = " << robFrag->rod_source_id() << MSG::dec
1081 <<
" bit = " << bit <<
" " << in_ptr <<
" / " << v_size
1082 <<
" : " << out_ptr <<
" / 1920");
1083 return StatusCode::RECOVERABLE;
1087 return StatusCode::SUCCESS;
1094 #ifdef TRT_READCOMPTABLE_FILE
1099 "Reading Compression Table from File is not supported anymore!");
1101 return StatusCode::FAILURE;
1103 #ifdef TRT_READCOMPTABLE_FILE
1107 ATH_MSG_INFO(
"Reading Compress Table File: " << TableFilename);
1113 ATH_MSG_FATAL(
"Could not open Compression Table File " << TableFilename);
1114 return StatusCode::FAILURE;
1117 #define MAXLINE 1024
1130 tok = strtok(
line,
" \t\n<");
1135 if (!strncmp(tok,
"Version", 7)) {
1136 tok = strtok(NULL,
" \t\n");
1141 tok = strtok(NULL,
" \t\n");
1145 tok = strtok(
line,
" \t\n");
1148 if (strncmp(tok,
">", 1)) {
1158 return StatusCode::FAILURE;
1173 if (!strncmp(tok,
"Nsymbols", 8)) {
1174 tok = strtok(NULL,
" \t\n");
1179 tok = strtok(NULL,
" \t\n");
1183 tok = strtok(
line,
" \t\n");
1186 if (strncmp(tok,
">", 1)) {
1196 return StatusCode::FAILURE;
1211 if (!strncmp(tok,
"syms", 4)) {
1223 return StatusCode::FAILURE;
1228 tok = strtok(NULL,
" \t\n");
1229 while (i < Ctable->m_Nsymbols) {
1230 while ((tok) && (i < Ctable->m_Nsymbols)) {
1232 tok = strtok(NULL,
" \t\n");
1237 tok = strtok(
line,
" \t\n");
1241 if (strncmp(tok,
">", 1)) {
1251 return StatusCode::FAILURE;
1256 if (!strncmp(tok,
"codewords", 9)) {
1264 return StatusCode::FAILURE;
1269 tok = strtok(NULL,
" \t\n");
1270 while (i < Ctable->m_Nsymbols) {
1271 while ((tok) && (i < Ctable->m_Nsymbols)) {
1272 codewords[
i++] =
atoi(tok);
1273 tok = strtok(NULL,
" \t\n");
1278 tok = strtok(
line,
" \t\n");
1282 if (strncmp(tok,
">", 1)) {
1292 return StatusCode::FAILURE;
1297 if (!strncmp(tok,
"firstcode", 9)) {
1300 tok = strtok(NULL,
" \t\n");
1302 while ((tok) && (
i < 33)) {
1304 tok = strtok(NULL,
" \t\n");
1309 tok = strtok(
line,
" \t\n");
1313 if (strncmp(tok,
">", 1)) {
1323 return StatusCode::FAILURE;
1328 if (!strncmp(tok,
"lengths_integral", 16)) {
1331 tok = strtok(NULL,
" \t\n");
1333 while ((tok) && (
i < 33)) {
1335 tok = strtok(NULL,
" \t\n");
1340 tok = strtok(
line,
" \t\n");
1344 if (strncmp(tok,
">", 1)) {
1354 return StatusCode::FAILURE;
1359 if (!strncmp(tok,
"lengths", 7)) {
1367 return StatusCode::FAILURE;
1372 tok = strtok(NULL,
" \t\n");
1373 while (i < Ctable->m_Nsymbols) {
1374 while ((tok) && (i < Ctable->m_Nsymbols)) {
1375 lengths[
i++] =
atoi(tok);
1376 tok = strtok(NULL,
" \t\n");
1381 tok = strtok(
line,
" \t\n");
1385 if (strncmp(tok,
">", 1)) {
1395 return StatusCode::FAILURE;
1402 if (!codewords || !lengths) {
1411 return StatusCode::FAILURE;
1418 int escape_length = 0;
1433 return StatusCode::FAILURE;
1436 escape_length = lengths[
i];
1438 if (escape_length != 5)
1440 <<
" rather than 5!");
1444 for (
int j = 0; j < Ctable->
m_Nsymbols; j++) {
1445 ATH_MSG_INFO(
"Table: " << j <<
" " << lengths[j] <<
" " << MSG::hex
1446 << codewords[j] <<
" " << Ctable->
m_syms[j]
1449 #endif // PRINT_TABLE
1459 "Invalid Compression Table Version: " << Ctable->
m_TableVersion);
1461 return StatusCode::FAILURE;
1466 <<
" already loaded! Not overwriting");
1472 return StatusCode::SUCCESS;
1489 return StatusCode::FAILURE;
1495 while (catrIt != last_catr) {
1498 int TableVersion = (atrlist)[
"Version"].data<cool::Int32>();
1501 ATH_MSG_WARNING(
"Invalid Compression Table Version: " << TableVersion);
1510 <<
" already loaded! Not overwriting");
1516 auto Ctable = std::make_unique<t_CompressTable>();
1517 Ctable->m_TableVersion = TableVersion;
1518 Ctable->m_Nsymbols = (atrlist)[
"Nsymbols"].data<cool::Int32>();
1521 Ctable->m_syms = std::make_unique<unsigned int[]>(Ctable->m_Nsymbols);
1523 const cool::Blob16M&
blob = (atrlist)[
"syms"].data<cool::Blob16M>();
1526 (
unsigned int)(Ctable->m_Nsymbols *
sizeof(
unsigned int))) {
1528 <<
blob.size() <<
" != "
1529 << (Ctable->m_Nsymbols *
sizeof(
unsigned int)) <<
" )");
1531 return StatusCode::FAILURE;
1534 const unsigned char* BlobStart =
1535 static_cast<const unsigned char*
>(
blob.startingAddress());
1537 for (
int i = 0; (
i <
blob.size()) && (j < Ctable->m_Nsymbols);
1538 i +=
sizeof(
unsigned int)) {
1539 Ctable->m_syms[j++] = *((
unsigned int*)(BlobStart +
i));
1542 std::istringstream iss((atrlist)[
"firstcode"].data<cool::String4k>());
1546 Ctable->m_firstcode[
i++] =
atoi(tok.c_str());
1549 std::istringstream iss2(
1550 (atrlist)[
"lengths_integral"].data<cool::String4k>());
1553 Ctable->m_lengths_integral[
i++] =
atoi(tok.c_str());
1556 int ctable_version = Ctable->m_TableVersion;
1557 ATH_MSG_INFO(
"Loaded Compress Table Version: " << ctable_version);
1563 return StatusCode::SUCCESS;