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"
36 const IInterface* parent)
37 : base_class(
type, name, parent),
86 for (std::atomic<EventContext::ContextEvt_t>& evt : m_lastPrint) {
87 evt = EventContext::INVALID_CONTEXT_EVT;
120 std::vector<int>::iterator it;
125 ATH_MSG_INFO(
"Not reading bad Compress Table Version: " << *it);
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()) {
201 const uint32_t* rob_status;
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) {
326 uint32_t word = vint[v_index++];
328 for (
int j = 0; j < 2; j++) {
329 uint32_t stat = (word >> (16 * j)) & 0xffff;
332 int DTMROC_index = stat & 0x7f;
333 int DTMROC_head = (stat >> 7) & 0x1ff;
335 uint32_t
Index = (rod_SourceID << 8) | DTMROC_index;
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);
363 uint32_t expected_BCID;
364 if (rod_BCID < 7 * 16) {
365 expected_BCID = (rod_BCID + 12) & 0xf;
367 expected_BCID = rod_BCID & 0xf;
384 uint32_t errorWord = 0;
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) <<
" "
464 <<
m_trt_id->print_to_string(idStraw))
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 = "
481 <<
m_trt_id->show_to_string(idStraw));
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);
542 theColl->setIdentifier(ident);
547 if (!dataItemsPool) {
555 theColl->push_back(rdo);
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) & 0x1;
660 for (
int i = 0; i < 4; i++) {
661 v = (vint[in_ptr] >> bit) & 0x1;
676 <<
"Turning message off.");
679 return StatusCode::RECOVERABLE;
682 for (
int i = 0; i < 27; i++) {
683 word = word | (((vint[in_ptr] >> bit) & 0x1) << i);
698 ATH_MSG_VERBOSE((hex) << robid <<
" " << bufferOffset <<
" " << word <<
" "
699 << idHash << (dec) <<
" "
700 <<
m_trt_id->print_to_string(idStraw));
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 = "
716 <<
m_trt_id->show_to_string(idStraw));
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);
769 theColl->setIdentifier(ident);
778 if (!dataItemsPool) {
788 theColl->push_back(rdo);
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 {
835 for (phase = 0; phase < 2; phase++) {
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) & 0x1;
897 v = 2 * v + ((vint[in_ptr] >> bit) & 0x1);
921 word = Ctable.
m_syms[idx];
929 <<
"Turning message off.");
933 return StatusCode::RECOVERABLE;
941 for (i = 0; i < 27; i++) {
942 word = word | (((vint[in_ptr] >> bit) & 0x1) << i);
960 <<
" " << idHash << (dec) <<
" "
961 <<
m_trt_id->print_to_string(idStraw));
966 (eformat::SubDetector)0 , robid, bufferOffset, idHash);
968 if (NULLId == idStraw) {
970 ATH_MSG_DEBUG(
"Null Identifier for bufferOffset " << bufferOffset);
978 <<
" Straw ID = " <<
m_trt_id->show_to_string(idStraw));
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) {
1010 ATH_MSG_DEBUG(
"Collection for Hash not to be decoded, skip");
1023 std::unique_ptr<TRT_RDO_Collection>& theColl = colls[idHash];
1029 <<
" does not exist, create it ");
1032 theColl = std::make_unique<TRT_RDO_Collection>(idHash);
1033 if (dataItemsPool) {
1041 theColl->setIdentifier(ident);
1046 if (!dataItemsPool) {
1056 theColl->push_back(rdo);
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);
1110 std::ifstream inFile(
file.c_str());
1112 if (!inFile.is_open()) {
1113 ATH_MSG_FATAL(
"Could not open Compression Table File " << TableFilename);
1114 return StatusCode::FAILURE;
1127 while (!inFile.eof()) {
1128 inFile.getline(line, MAXLINE);
1130 tok = strtok(line,
" \t\n<");
1135 if (!strncmp(tok,
"Version", 7)) {
1136 tok = strtok(NULL,
" \t\n");
1141 tok = strtok(NULL,
" \t\n");
1143 inFile.getline(line, MAXLINE);
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");
1181 inFile.getline(line, MAXLINE);
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)) {
1231 Ctable->
m_syms[i++] = atoi(tok);
1232 tok = strtok(NULL,
" \t\n");
1236 inFile.getline(line, MAXLINE);
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");
1277 inFile.getline(line, MAXLINE);
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");
1308 inFile.getline(line, MAXLINE);
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");
1339 inFile.getline(line, MAXLINE);
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");
1380 inFile.getline(line, MAXLINE);
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]
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) {
1496 const coral::AttributeList& atrlist = catrIt->second;
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;
1521 Ctable->m_syms = std::make_unique<unsigned int[]>(Ctable->m_Nsymbols);
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++] = *(
reinterpret_cast<const unsigned int*
>(BlobStart + i));
1546 Ctable->m_firstcode[i++] = atoi(tok.c_str());
1549 std::istringstream iss2(
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;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
IndexedConstituentUserInfo::Index Index
InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > TRT_RDO_Container
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
ChanAttrListMap::const_iterator const_iterator
a typed memory pool that saves time spent allocation small object.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
virtual StatusCode addOrDelete(std::unique_ptr< T >, IdentifierHash hashId) override final
Tries to add the item to the cache, if the item already exists then it is deleted This is a convenien...
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
This is a "hash" representation of an Identifier.
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
void add_bcid_error(uint32_t DTMROC_idx, uint32_t bcid)
void add_l1id_error(uint32_t DTMROC_idx, uint32_t l1id)
void add_rob_error(uint32_t robSourceId, uint32_t robStatus)
void add_error_error(const uint32_t DTMROC_idx)
void add_missing_error(const uint32_t DTMROC_idx)
void add_sid_error(const uint32_t DTMROC_idx)
StatusCode int_fillExpanded(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, TRT_RDO_Container *rodIdc, DataPool< TRT_LoLumRawData > *dataItemsPool, const std::vector< IdentifierHash > *vecHash=0) const
private methods
std::atomic< int > m_err_count_fillCollection
SG::ReadCondHandleKey< CondAttrListCollection > m_CompressKey
virtual ~TRT_RodDecoder()
destructor
StatusCode ReadCompressTableFile(const std::string &TableFilename)
StatusCode update(const EventContext &ctx) const
std::vector< CxxUtils::CachedUniquePtr< t_CompressTable > > m_CompressionTables
IdContext m_straw_layer_context
std::vector< int > m_LoadCompressTableVersions
StatusCode int_fillMinimalCompress(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, TRT_RDO_Container *rdoIdo, DataPool< TRT_LoLumRawData > *dataItemsPool, const std::vector< IdentifierHash > *vecHash=0) const
virtual StatusCode initialize() override
initialize
std::atomic< uint32_t > m_Nrdos
std::atomic< unsigned int > m_skip
TRT_RodDecoder(const std::string &type, const std::string &name, const IInterface *parent)
constructor
bool m_loadCompressTableFile
std::atomic< unsigned int > m_accept
StatusCode int_fillFullCompress(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, TRT_RDO_Container *rdoIdo, DataPool< TRT_LoLumRawData > *dataItemsPool, const t_CompressTable &Ctable, const std::vector< IdentifierHash > *vecHash=0) const
std::atomic< int > m_err_count_int_fillFullCompress
ServiceHandle< ITRT_CablingSvc > m_CablingSvc
virtual StatusCode finalize() override
finalize
virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment *robFrag, TRT_RDO_Container *rdoIdc, TRT_BSErrContainer *bserr, DataPool< TRT_LoLumRawData > *dataItemsPool, const EventContext &ctx, const std::vector< IdentifierHash > *vecHash=0) const override
the method to fill the IDC
std::atomic< int > m_err_count_int_fillMinimalCompress
bool m_loadCompressTableDB
const int m_maxCompressionVersion
bool m_lookAtMissingErrors
std::string find(const std::string &s)
return a remapped string
const DataType * PointerType
eformat::ROBFragment< PointerType > ROBFragment
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
void stable_sort(DataModel_detail::iterator< DVL > beg, DataModel_detail::iterator< DVL > end)
Specialization of stable_sort for DataVector/List.
int m_lengths_integral[CTABLE_FC_LENGTH]
std::unique_ptr< unsigned int[]> m_syms
int m_firstcode[CTABLE_FC_LENGTH]