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),
85 for (std::atomic<EventContext::ContextEvt_t>&
evt : m_lastPrint) {
86 evt = EventContext::INVALID_CONTEXT_EVT;
126 std::ostringstream ssVersion;
128 std::string compressTableFile =
129 "Compress_Table-" + ssVersion.str() +
".dat";
131 ATH_MSG_INFO(
"Reading Compress Table: " << compressTableFile);
146 return StatusCode::SUCCESS;
164 return StatusCode::SUCCESS;
182 const std::vector<IdentifierHash>* vecHash)
const {
188 int RodBlockVersion = (robFrag->rod_version() & 0xff);
193 uint32_t robid = robFrag->rod_source_id();
198 if (robFrag->nstatus()) {
200 robFrag->status(rob_status);
210 const EventContext& ctx{Gaudi::Hive::currentContext()};
211 std::atomic<EventContext::ContextEvt_t>*
evt = m_lastPrint.get();
212 EventContext::ContextEvt_t lastEvt = *
evt;
214 while (lastEvt != ctx.evt() &&
215 !
evt->compare_exchange_strong(lastEvt, ctx.evt()));
217 if (lastEvt != ctx.evt()) {
220 << MSG::hex << robFrag->rob_source_id() <<
" ( "
221 << *rob_status <<
" ) " << MSG::dec
222 <<
" Skipping decoding...");
225 sc = StatusCode::RECOVERABLE;
231 if (3 < RodBlockVersion &&
241 <<
", but Compression Table not loaded! ROD ID = "
242 << MSG::hex << robid << MSG::dec);
246 <<
"Turning message off.");
250 sc = StatusCode::FAILURE;
252 }
else if (3 == RodBlockVersion) {
254 }
else if ((2 == RodBlockVersion) || (1 == RodBlockVersion)) {
256 }
else if (0 == RodBlockVersion) {
257 if (0 == robFrag->rod_ndata()) {
263 <<
"and event_type is not EventType::IS_SIMULATION, "
264 <<
"ROD ID = " << MSG::hex << robid << MSG::dec);
265 return StatusCode::FAILURE;
276 if ((RodBlockVersion >= 2) && (
sc == StatusCode::SUCCESS)) {
281 int error_errors = 0;
284 int missing_errors = 0;
287 uint32_t rod_L1ID = robFrag->rod_lvl1_id();
288 uint32_t rod_BCID = robFrag->rod_bc_id();
289 uint32_t rod_SourceID = robFrag->rod_source_id();
292 robFrag->rod_status(vint);
302 uint32_t n_status = vint[v_index++];
304 if (n_status > robFrag->rod_nstatus()) {
305 if (n_status > robFrag->rod_fragment_size_word()) {
307 "Rejecting fragment because the number of status words exceeds "
308 "the fragement size: "
309 << n_status <<
" > " << robFrag->rod_fragment_size_word()
310 <<
" (nstatus from fragment header = " << robFrag->rod_nstatus()
312 return StatusCode::RECOVERABLE;
315 "The number of status words exceeds the number of status words "
316 "marked in the header: "
317 << n_status <<
" !< " << robFrag->rod_nstatus()
318 <<
" (fragment size = " << robFrag->rod_fragment_size_word()
324 while (
i < n_status) {
327 for (
int j = 0; j < 2; j++) {
331 int DTMROC_index =
stat & 0x7f;
332 int DTMROC_head = (
stat >> 7) & 0x1ff;
337 int D_sid = DTMROC_head & 0x100;
338 uint32_t D_L1ID = (DTMROC_head >> 5) & 0x7;
339 uint32_t D_BCID = (DTMROC_head >> 1) & 0xf;
340 int D_error = !(DTMROC_head & 1);
363 if (rod_BCID < 7 * 16) {
364 expected_BCID = (rod_BCID + 12) & 0xf;
366 expected_BCID = rod_BCID & 0xf;
385 errorWord = l1id_errors;
386 errorWord |= (bcid_errors << 7);
387 errorWord |= (missing_errors << 14);
388 errorWord |= (error_errors << 21);
389 if (sid_errors > 0xf)
391 errorWord |= ((
static_cast<uint32_t>(sid_errors) & 0xf)
395 sc = StatusCode::RECOVERABLE;
419 const std::vector<IdentifierHash>* vecHash)
const {
421 uint32_t robid = robFrag->rod_source_id();
429 ATH_MSG_DEBUG(
"fillCollections for " << MSG::hex << robid << MSG::dec);
435 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
440 robFrag->rod_data(vint);
442 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
447 uint32_t v_size = robFrag->rod_ndata();
448 int bufferOffset = -1;
449 for (
i = 0;
i < v_size;
i++) {
456 digit = word & 0x07ffffff;
461 ATH_MSG_VERBOSE((hex) << robid <<
" " << bufferOffset <<
" " << word <<
" "
462 << idHash << (dec) <<
" "
467 idStraw =
m_CablingSvc->getIdentifier((eformat::SubDetector)0 ,
468 robid, bufferOffset, idHash);
470 if (NULLId == idStraw) {
473 << bufferOffset <<
" word " << MSG::hex << word << MSG::dec)
479 ATH_MSG_DEBUG(
" Collection ID = " << idHash <<
" Straw ID = "
485 if (idHash == skipHash) {
487 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
490 }
else if (idHash != lastHash) {
496 std::vector<IdentifierHash>::const_iterator
p =
497 find(vecHash->begin(), vecHash->end(), idHash);
498 if (
p == vecHash->end()) {
500 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
508 if (idHash == skipHash) {
511 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
523 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
529 <<
" does not exist, create it ");
532 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
546 if (!dataItemsPool) {
559 for (
auto&
p : colls) {
563 return StatusCode::SUCCESS;
593 const std::vector<IdentifierHash>* vecHash)
const {
594 uint32_t robid = robFrag->rod_source_id();
602 ATH_MSG_DEBUG(
"fillCollection3 for " << MSG::hex << robid << MSG::dec);
608 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
613 robFrag->rod_data(vint);
615 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
622 unsigned int in_ptr = 0;
623 unsigned int out_ptr = 0;
624 int bufferOffset = -1;
625 uint32_t v_size = robFrag->rod_ndata();
630 while ((in_ptr < v_size) && (out_ptr < 1920))
638 v = (vint[in_ptr] >> bit) & 0
x1;
649 for (
int i = 0;
i < 4;
i++) {
650 v = (vint[in_ptr] >> bit) & 0
x1;
665 <<
"Turning message off.");
668 return StatusCode::RECOVERABLE;
671 for (
int i = 0;
i < 27;
i++) {
672 word = word | (((vint[in_ptr] >> bit) & 0
x1) <<
i);
687 ATH_MSG_VERBOSE((hex) << robid <<
" " << bufferOffset <<
" " << word <<
" "
688 << idHash << (dec) <<
" "
693 idStraw =
m_CablingSvc->getIdentifier((eformat::SubDetector)0 ,
694 robid, bufferOffset, idHash);
696 if (NULLId == idStraw) {
698 ATH_MSG_DEBUG(
"Null Identifier for bufferOffset " << bufferOffset);
704 ATH_MSG_DEBUG(
" Collection ID = " << idHash <<
" Straw ID = "
710 if (idHash == skipHash) {
712 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
715 }
else if (idHash != lastHash) {
721 std::vector<IdentifierHash>::const_iterator
p =
722 find(vecHash->begin(), vecHash->end(), idHash);
723 if (
p == vecHash->end()) {
725 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
740 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
746 <<
" does not exist, create it ");
749 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
767 if (!dataItemsPool) {
782 for (
auto&
p : colls) {
786 return StatusCode::SUCCESS;
812 const std::vector<IdentifierHash>* vecHash)
const {
816 uint32_t robid = robFrag->rod_source_id();
824 ATH_MSG_DEBUG(
"fillCollection3 for " << MSG::hex << robid << MSG::dec);
830 IdentifierHash idHash, skipHash = 0xffffffff, lastHash = 0xffffffff;
835 robFrag->rod_data(vint);
837 std::unordered_map<IdentifierHash, std::unique_ptr<TRT_RDO_Collection> >
845 unsigned int in_ptr = 0;
846 unsigned int out_ptr = 0;
847 int bufferOffset = -1;
848 uint32_t v_size = robFrag->rod_ndata();
853 while ((in_ptr < v_size) && (out_ptr < 1920))
861 v = (vint[in_ptr] >> bit) & 0
x1;
876 v = 2 *
v + ((vint[in_ptr] >> bit) & 0
x1);
908 <<
"Turning message off.");
912 return StatusCode::RECOVERABLE;
920 for (
i = 0;
i < 27;
i++) {
921 word = word | (((vint[in_ptr] >> bit) & 0
x1) <<
i);
939 <<
" " << idHash << (dec) <<
" "
945 (eformat::SubDetector)0 , robid, bufferOffset, idHash);
947 if (NULLId == idStraw) {
949 ATH_MSG_DEBUG(
"Null Identifier for bufferOffset " << bufferOffset);
963 if (idHash == skipHash) {
965 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
968 }
else if (idHash != lastHash) {
974 std::vector<IdentifierHash>::const_iterator
p =
975 find(vecHash->begin(), vecHash->end(), idHash);
976 if (
p == vecHash->end()) {
978 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
986 if (idHash == skipHash) {
989 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
1002 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
1006 #ifdef TRT_BSC_DEBUG
1008 <<
" does not exist, create it ");
1011 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
1012 if (dataItemsPool) {
1025 if (!dataItemsPool) {
1041 for (
auto&
p : colls) {
1045 if ((out_ptr != 1920) || ((in_ptr == v_size) && bit != 0) ||
1046 ((in_ptr == (v_size - 1)) && (bit == 0)) || (in_ptr < (v_size - 1))) {
1048 <<
"L1ID = " << MSG::hex << robFrag->rod_lvl1_id()
1049 <<
" ROD = " << robFrag->rod_source_id() << MSG::dec
1050 <<
" bit = " << bit <<
" " << in_ptr <<
" / " << v_size
1051 <<
" : " << out_ptr <<
" / 1920");
1052 return StatusCode::RECOVERABLE;
1056 return StatusCode::SUCCESS;
1063 #ifdef TRT_READCOMPTABLE_FILE
1068 "Reading Compression Table from File is not supported anymore!");
1070 return StatusCode::FAILURE;
1072 #ifdef TRT_READCOMPTABLE_FILE
1076 ATH_MSG_INFO(
"Reading Compress Table File: " << TableFilename);
1082 ATH_MSG_FATAL(
"Could not open Compression Table File " << TableFilename);
1083 return StatusCode::FAILURE;
1086 #define MAXLINE 1024
1099 tok = strtok(
line,
" \t\n<");
1104 if (!strncmp(tok,
"Version", 7)) {
1105 tok = strtok(NULL,
" \t\n");
1110 tok = strtok(NULL,
" \t\n");
1114 tok = strtok(
line,
" \t\n");
1117 if (strncmp(tok,
">", 1)) {
1127 return StatusCode::FAILURE;
1142 if (!strncmp(tok,
"Nsymbols", 8)) {
1143 tok = strtok(NULL,
" \t\n");
1148 tok = strtok(NULL,
" \t\n");
1152 tok = strtok(
line,
" \t\n");
1155 if (strncmp(tok,
">", 1)) {
1165 return StatusCode::FAILURE;
1180 if (!strncmp(tok,
"syms", 4)) {
1192 return StatusCode::FAILURE;
1197 tok = strtok(NULL,
" \t\n");
1198 while (i < Ctable->m_Nsymbols) {
1199 while ((tok) && (i < Ctable->m_Nsymbols)) {
1201 tok = strtok(NULL,
" \t\n");
1206 tok = strtok(
line,
" \t\n");
1210 if (strncmp(tok,
">", 1)) {
1220 return StatusCode::FAILURE;
1225 if (!strncmp(tok,
"codewords", 9)) {
1233 return StatusCode::FAILURE;
1238 tok = strtok(NULL,
" \t\n");
1239 while (i < Ctable->m_Nsymbols) {
1240 while ((tok) && (i < Ctable->m_Nsymbols)) {
1241 codewords[
i++] =
atoi(tok);
1242 tok = strtok(NULL,
" \t\n");
1247 tok = strtok(
line,
" \t\n");
1251 if (strncmp(tok,
">", 1)) {
1261 return StatusCode::FAILURE;
1266 if (!strncmp(tok,
"firstcode", 9)) {
1269 tok = strtok(NULL,
" \t\n");
1271 while ((tok) && (
i < 33)) {
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,
"lengths_integral", 16)) {
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", 7)) {
1336 return StatusCode::FAILURE;
1341 tok = strtok(NULL,
" \t\n");
1342 while (i < Ctable->m_Nsymbols) {
1343 while ((tok) && (i < Ctable->m_Nsymbols)) {
1344 lengths[
i++] =
atoi(tok);
1345 tok = strtok(NULL,
" \t\n");
1350 tok = strtok(
line,
" \t\n");
1354 if (strncmp(tok,
">", 1)) {
1364 return StatusCode::FAILURE;
1371 if (!codewords || !lengths) {
1380 return StatusCode::FAILURE;
1387 int escape_length = 0;
1402 return StatusCode::FAILURE;
1405 escape_length = lengths[
i];
1407 if (escape_length != 5)
1409 <<
" rather than 5!");
1413 for (
int j = 0; j < Ctable->
m_Nsymbols; j++) {
1414 ATH_MSG_INFO(
"Table: " << j <<
" " << lengths[j] <<
" " << MSG::hex
1415 << codewords[j] <<
" " << Ctable->
m_syms[j]
1418 #endif // PRINT_TABLE
1428 "Invalid Compression Table Version: " << Ctable->
m_TableVersion);
1430 return StatusCode::FAILURE;
1435 <<
" already loaded! Not overwriting");
1441 return StatusCode::SUCCESS;
1458 return StatusCode::FAILURE;
1464 while (catrIt != last_catr) {
1467 int TableVersion = (atrlist)[
"Version"].data<cool::Int32>();
1470 ATH_MSG_WARNING(
"Invalid Compression Table Version: " << TableVersion);
1479 <<
" already loaded! Not overwriting");
1485 auto Ctable = std::make_unique<t_CompressTable>();
1486 Ctable->m_TableVersion = TableVersion;
1487 Ctable->m_Nsymbols = (atrlist)[
"Nsymbols"].data<cool::Int32>();
1490 Ctable->m_syms = std::make_unique<unsigned int[]>(Ctable->m_Nsymbols);
1492 const cool::Blob16M&
blob = (atrlist)[
"syms"].data<cool::Blob16M>();
1495 (
unsigned int)(Ctable->m_Nsymbols *
sizeof(
unsigned int))) {
1497 <<
blob.size() <<
" != "
1498 << (Ctable->m_Nsymbols *
sizeof(
unsigned int)) <<
" )");
1500 return StatusCode::FAILURE;
1503 const unsigned char* BlobStart =
1504 static_cast<const unsigned char*
>(
blob.startingAddress());
1506 for (
int i = 0; (
i <
blob.size()) && (j < Ctable->m_Nsymbols);
1507 i +=
sizeof(
unsigned int)) {
1508 Ctable->m_syms[j++] = *((
unsigned int*)(BlobStart +
i));
1511 std::istringstream iss((atrlist)[
"firstcode"].data<cool::String4k>());
1515 Ctable->m_firstcode[
i++] =
atoi(tok.c_str());
1518 std::istringstream iss2(
1519 (atrlist)[
"lengths_integral"].data<cool::String4k>());
1522 Ctable->m_lengths_integral[
i++] =
atoi(tok.c_str());
1525 int ctable_version = Ctable->m_TableVersion;
1526 ATH_MSG_INFO(
"Loaded Compress Table Version: " << ctable_version);
1532 return StatusCode::SUCCESS;