17#include "GaudiKernel/IRegistry.h"
20#include "eformat/Issue.h"
21#include "eformat/SourceIdentifier.h"
29 constexpr uint16_t fullResultModuleId = 0;
35 bool isStreamTagType(
const eformat::helper::StreamTag& st,
const eformat::TagType
type) {
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);
68 return StatusCode::SUCCESS;
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;
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 << 8u) | 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) {
178 uint32_t nStreamTagWords = eformat::helper::size_word(hltResult->
getStreamTags());
179 cache->
streamTagData = std::make_unique<uint32_t[]>(nStreamTagWords);
184 catch (
const std::exception& e) {
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);
231 const std::vector<uint32_t>& status = hltResult->
getRobStatus(resultId.module_id());
232 hltROB->status(status.size(), status.data());
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;
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
uint32_t CLID
The Class ID type.
char data[hepevt_bytes_allocation_ATLAS]
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
convert to and from a SG storable
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
static constexpr long storageType()
virtual StatusCode initialize() override
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
Create ByteStream from RDO (HLTResultMT)
SG::SlotSpecificObj< Cache > m_cache
static const CLID & classID()
CLID of the class HLTResultMT converted by this converter.
virtual StatusCode finalize() override
virtual ~HLTResultMTByteStreamCnv()
Standard destructor.
HLTResultMTByteStreamCnv(ISvcLocator *svcLoc)
Standard constructor.
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Create RDO (HLTResultMT) from ByteStream.
static long storageType()
Storage type used by this converter.
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Helper to obtain the RawEvent pointer.
A container class for data required to build online output from HLT.
const std::vector< uint32_t > & getHltBitsAsWords() const
Const-getter for HLT bits as uint32_t array. Ordering: PassRaw, Prescaled.
RODMinorVersion getVersion() const
ROD minor version getter.
const std::vector< eformat::helper::StreamTag > & getStreamTags() const
Const-getter for stream tags.
std::pair< uint8_t, uint8_t > RODMinorVersion
Type to store decoded ROD minor version (16-bit version split into two 8-bit numbers)
const std::unordered_map< uint16_t, std::vector< uint32_t > > & getSerialisedData() const
Serialised data getter.
const std::vector< uint32_t > & getStatus() const
Full event status reference getter (1 bit-mask status word + error code words)
const std::vector< uint32_t > & getRobStatus(uint16_t moduleId) const
Status words for ROB with given moduleId.
std::vector< eformat::helper::StreamTag > & getStreamTagsNonConst()
Non-const-getter for stream tags needed by the result maker to remove disabled ROBs/SubDets.
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
Cache tracking memory allocation for serialised stream tag data and ROBFragment objects.
std::vector< std::unique_ptr< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment > > robFragments
std::unique_ptr< uint32_t[]> streamTagData