17 #include "GaudiKernel/IRegistry.h"
20 #include "eformat/Issue.h"
21 #include "eformat/SourceIdentifier.h"
29 constexpr
uint16_t fullResultModuleId = 0;
36 return eformat::helper::string_to_tagtype(st.type) ==
type;
39 bool isDebugStreamTag(
const eformat::helper::StreamTag& st) {
40 return isStreamTagType(st, eformat::TagType::DEBUG_TAG);
43 bool isUnknownStreamTag(
const eformat::helper::StreamTag& st) {
44 return isStreamTagType(st, eformat::TagType::UNKNOWN_TAG);
52 Converter(storageType(), classID(), svcLoc),
54 m_ByteStreamEventAccess(
"ByteStreamCnvSvc",
"HLTResultMTByteStreamCnv") {}
66 ATH_CHECK(m_ByteStreamEventAccess.retrieve());
68 return StatusCode::SUCCESS;
76 if (m_ByteStreamEventAccess.release().isFailure())
77 ATH_MSG_WARNING(
"Failed to release service " << m_ByteStreamEventAccess.typeAndName());
79 return StatusCode::SUCCESS;
86 ATH_MSG_ERROR(
"Using BS converter to decode HLTResultMT is not supported!"
87 <<
" Use HLTResultMTByteStreamDecoderAlg instead");
88 return StatusCode::FAILURE;
98 Cache* cache = m_cache.get();
107 if (!castSuccessful || !hltResult) {
108 ATH_MSG_ERROR(
"Failed to convert DataObject to HLTResultMT");
109 return StatusCode::FAILURE;
116 return StatusCode::FAILURE;
119 const uint16_t hltRodMinorVersion16 = (hltRodMinorVersion.first << 8
u) | hltRodMinorVersion.second;
120 ATH_MSG_DEBUG(
"HLT ROD minor version is " << hltRodMinorVersion.first <<
"." << hltRodMinorVersion.second
121 <<
" (0x" << MSG::hex << hltRodMinorVersion16 << MSG::dec <<
")");
126 ATH_MSG_ERROR(
"Failed to obtain a pointer to RawEventWrite");
127 return StatusCode::FAILURE;
135 std::set<eformat::helper::SourceIdentifier> resultIdsToWrite;
136 bool debugEvent=
false;
137 std::string unknownTypeStreams;
138 for (
const eformat::helper::StreamTag& st : hltResult->
getStreamTags()) {
140 if (isUnknownStreamTag(st)) {
141 unknownTypeStreams += st.type +
"_" + st.name +
" ";
144 if (isDebugStreamTag(st)) debugEvent=
true;
146 if (st.robs.empty() && st.dets.empty()) {
147 eformat::helper::SourceIdentifier sid(eformat::SubDetector::TDAQ_HLT, fullResultModuleId);
148 resultIdsToWrite.insert(sid);
151 for (
const uint32_t robid : st.robs) {
152 eformat::helper::SourceIdentifier sid(robid);
153 if (sid.subdetector_id() == eformat::SubDetector::TDAQ_HLT)
154 resultIdsToWrite.insert(sid);
158 if (!debugEvent && !unknownTypeStreams.empty()) {
159 ATH_MSG_ERROR(
"Found stream tag(s) with unknown type: " << unknownTypeStreams);
160 return StatusCode::FAILURE;
167 writableStreamTags.erase(
168 std::remove_if(writableStreamTags.begin(),writableStreamTags.end(),std::not_fn(isDebugStreamTag)),
169 writableStreamTags.end()
171 for (eformat::helper::StreamTag& st : writableStreamTags) {
179 cache->
streamTagData = std::make_unique<uint32_t[]>(nStreamTagWords);
185 ATH_MSG_ERROR(
"StreamTag encoding failed, caught an unexpected std::exception " <<
e.what());
186 return StatusCode::FAILURE;
189 ATH_MSG_ERROR(
"StreamTag encoding failed, caught an unexpected exception");
190 return StatusCode::FAILURE;
197 re->hlt_info(hltBits.size(), hltBits.data());
200 ATH_MSG_DEBUG(
"Iterating over " << resultIdsToWrite.size() <<
" HLT result IDs to assemble output data");
201 const std::unordered_map<uint16_t, std::vector<uint32_t>>& serialisedData = hltResult->
getSerialisedData();
202 for (
const eformat::helper::SourceIdentifier& resultId : resultIdsToWrite) {
204 const auto it = serialisedData.find(resultId.module_id());
205 if (
it==serialisedData.end()) {
207 ATH_MSG_DEBUG(
"HLT result with ID 0x" << MSG::hex << resultId.code() << MSG::dec
208 <<
" requested by a debug stream tag, but missing in the serialised data - skipping this result");
211 ATH_MSG_ERROR(
"HLT result with ID 0x" << MSG::hex << resultId.code() << MSG::dec
212 <<
" requested by a stream tag, but missing in the serialised data");
213 return StatusCode::FAILURE;
215 const std::vector<uint32_t>&
data =
it->second;
218 auto hltROB = std::make_unique<OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment>(
223 re->lvl1_trigger_type(),
229 hltROB->rod_minor_version(hltRodMinorVersion16);
234 re->append(hltROB.get());
236 ATH_MSG_DEBUG(
"Appended data for HLT result ID 0x" << MSG::hex << resultId.code() << MSG::dec <<
" with "
237 <<
data.size() <<
" words of serialised payload to the output full event");
241 if ( pAddr !=
nullptr ) pAddr->release();
243 pAddr =
static_cast<IOpaqueAddress*
>(bsAddr);
247 return StatusCode::SUCCESS;