8#include "eformat/DetectorMask.h"
9#include "eformat/SourceIdentifier.h"
18 template<
typename T>
bool contains(
const std::set<T>&
set,
const T& value) {
19 return set.find(value) !=
set.cend();
21 bool isHLT(
const uint32_t robid) {
22 return eformat::helper::SourceIdentifier(robid).subdetector_id() == eformat::TDAQ_HLT;
24 bool isHLT(
const eformat::SubDetector subdet) {
25 return subdet == eformat::TDAQ_HLT;
28 template<
typename T> std::set<T> removeDisabled(std::set<T>& requestedIds,
const std::set<T>& enabledIds) {
29 std::set<T> removedIds;
30 for (
auto it=requestedIds.begin(); it!=requestedIds.end(); ) {
32 if (!isHLT(*it) && !
contains(enabledIds, *it)) {
33 removedIds.insert(*it);
34 it = requestedIds.erase(it);
41 std::string
format(
const std::set<uint32_t>&
set) {
42 std::ostringstream
ss;
43 for (
const uint32_t
id :
set)
44 ss <<
"0x" << std::hex << std::setfill(
'0') << std::setw(8) <<
id << std::dec <<
" ";
48 std::string
format(
const std::set<eformat::SubDetector>&
set) {
49 std::ostringstream
ss;
50 for (
const eformat::SubDetector
id :
set)
ss << eformat::helper::SubDetectorDictionary.string(
id) <<
" ";
73 return StatusCode::SUCCESS;
82 Gaudi::Property<std::vector<uint32_t>> enabledROBsProp(
"EnabledROBs",{});
83 if (enabledROBsProp.fromString(
m_jobOptionsSvc->get(
"DataFlowConfig.DF_Enabled_ROB_IDs",
"[]")).isSuccess()) {
84 m_enabledROBs.insert(enabledROBsProp.value().begin(), enabledROBsProp.value().end());
86 <<
" ROBs from DataFlowConfig.DF_Enabled_ROB_IDs");
89 ATH_MSG_ERROR(
"Could not parse DataFlowConfig.DF_Enabled_ROB_IDs from JobOptionsSvc");
93 Gaudi::Property<std::vector<uint32_t>> enabledSubDetsProp(
"EnabledSubDets",{});
94 if (enabledSubDetsProp.fromString(
m_jobOptionsSvc->get(
"DataFlowConfig.DF_Enabled_SubDet_IDs",
"[]")).isSuccess()) {
96 for (
const uint32_t
id : enabledSubDetsProp.value()) {
100 <<
" SubDets from DataFlowConfig.DF_Enabled_SubDet_IDs");
103 ATH_MSG_ERROR(
"Could not parse DataFlowConfig.DF_Enabled_SubDet_IDs from JobOptionsSvc");
108 ATH_MSG_INFO(
"The list of enabled ROBs and SubDets was not provided by DataFlowConfig or is empty. "
109 <<
"StreamTag PEBInfo validation will be skipped.");
125 return StatusCode::SUCCESS;
133 return StatusCode::SUCCESS;
141 ATH_CHECK( hltResult.record(std::make_unique<HLT::HLTResultMT>()) );
144 return StatusCode::SUCCESS;
155 runtimeMetadataOutput->push_back(std::make_unique<xAOD::TrigComposite>());
156 char hostname [HOST_NAME_MAX];
157 bool errcode = !gethostname(hostname, HOST_NAME_MAX);
158 std::string hostnameString = std::string(hostname);
159 errcode &= runtimeMetadataOutput->back()->setDetail(
"hostname", hostnameString);
160 if (!errcode)
ATH_MSG_WARNING(
"Failed to append hostname to HLT Runtime Metadata TC");
163 StatusCode finalStatus = StatusCode::SUCCESS;
166 finalStatus = StatusCode::FAILURE;
172 ATH_MSG_DEBUG(
"Calling " << maker->name() <<
" for accepted event");
173 if (StatusCode
sc = maker->fill(hltResult, eventContext);
sc.isFailure()) {
182 ATH_MSG_DEBUG(
"Rejected event, further result filling skipped after stream tag maker");
195 std::vector<eformat::helper::StreamTag> streamTagsToRemove;
198 if (st.robs.empty() && st.dets.empty()) {
continue;}
200 std::set<uint32_t> removedROBs = removeDisabled(st.robs,
m_enabledROBs);
201 if (!removedROBs.empty()) {
202 ATH_MSG_DEBUG(
"StreamTag " << st.type <<
"_" << st.name <<
" requested disabled ROBs: " << format(removedROBs)
203 <<
" - these ROBs were removed from the StreamTag by " << name());
204 std::vector<eformat::SubDetector> removedSubDets;
205 for (
const uint32_t rob : removedROBs) {
206 eformat::SubDetector sd{eformat::helper::SourceIdentifier(rob).subdetector_id()};
207 if (std::find(removedSubDets.begin(),removedSubDets.end(),sd)==removedSubDets.end()) {
208 removedSubDets.push_back(sd);
212 "PEB_RemovedROBs_SubDet", removedSubDets,
213 [](
const eformat::SubDetector sd) ->
const std::string & {
return eformat::helper::SubDetectorDictionary.string(sd);});
216 ATH_MSG_VERBOSE(
"No disabled ROBs were requested by StreamTag " << st.type <<
"_" << st.name);
219 std::set<eformat::SubDetector> removedSubDets = removeDisabled(st.dets,
m_enabledSubDets);
220 if (!removedSubDets.empty()) {
221 ATH_MSG_DEBUG(
"StreamTag " << st.type <<
"_" << st.name <<
" requested disabled SubDets: " << format(removedSubDets)
222 <<
" - these SubDets were removed from the StreamTag by " << name());
223 std::vector<eformat::SubDetector> removedSubDetsVec(removedSubDets.begin(),removedSubDets.end());
225 "PEB_RemovedSubDets", removedSubDetsVec,
226 [](
const eformat::SubDetector sd)->
const std::string & {
return eformat::helper::SubDetectorDictionary.string(sd);});
229 ATH_MSG_VERBOSE(
"No disabled SubDets were requested by StreamTag " << st.type <<
"_" << st.name);
233 if (st.robs.empty() && st.dets.empty()) {
236 ATH_MSG_ERROR(
"Event accepted to stream " << st.type <<
"_" << st.name <<
" but the streaming to this stream "
237 <<
"is forcibly prevented, because all requested ROBs/SubDets in the PEB list are disabled. "
238 <<
"ROBs: " << format(removedROBs) <<
", SubDets: " << format(removedSubDets));
240 streamTagsToRemove.push_back(st);
243 for (
const eformat::helper::StreamTag& st : streamTagsToRemove) {
258 return StatusCode::SUCCESS;
266 const eformat::helper::DetectorMask detectorMask{metadata->getDetectorMask(), metadata->getDetectorMask2()};
269 std::vector<uint32_t> validatedExtraROBs;
270 for (
const uint32_t rob_id :
m_extraROBs.value()) {
271 const eformat::helper::SourceIdentifier sid{rob_id};
272 const eformat::SubDetector subdet_id = sid.subdetector_id();
273 if (detectorMask.is_set(subdet_id)) {
274 validatedExtraROBs.push_back(rob_id);
278 <<
" because SubDetector " << sid.human_detector() <<
" is disabled in the detector mask");
284 std::vector<uint32_t> validatedExtraSubDets;
286 const eformat::SubDetector subdet_id =
static_cast<eformat::SubDetector
>(subdet_id32 & 0xFF);
287 if (detectorMask.is_set(subdet_id)) {
288 validatedExtraSubDets.push_back(subdet_id32);
292 <<
" because SubDetector " << eformat::helper::SourceIdentifier(subdet_id,0,0).human_detector()
293 <<
" is disabled in the detector mask");
298 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
Header file to be included by clients of the Monitored infrastructure.
virtual StatusCode start() override
Gaudi::Property< std::vector< uint32_t > > m_extraEnabledROBs
Extra enabled ROBs.
HLTResultMTMaker(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Gaudi::Property< std::vector< uint32_t > > m_extraROBs
Extra enabled ROBs checked against detector mask.
ToolHandle< GenericMonitoringTool > m_monTool
Monitoring tool.
Gaudi::Property< std::vector< uint32_t > > m_extraSubDets
Extra enabled SubDets checked against detector mask.
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_runtimeMetadataWHKey
StoreGate key for HLT Runtime Metadata container.
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jobOptionsSvc
Handle to JobOptionsSvc used to retrieve the DataFlowConfig property.
bool m_skipValidatePEBInfo
If true, don't call validatePEBInfo.
void validatePEBInfo(HLT::HLTResultMT &hltResult) const
Check ROB and SubDet lists in StreamTags and remove those which are disabled.
ToolHandleArray< HLTResultMTMakerTool > m_makerTools
Tools filling the HLTResultMT object.
SG::ReadHandleKey< ByteStreamMetadataContainer > m_bsMetaDataContRHKey
StoreGate key for the ByteStreamMetadata container to retrieve detector mask.
StatusCode fillResult(HLT::HLTResultMT &hltResult, const EventContext &eventContext) const
Fill an existing HLTResultMT with event information.
SG::WriteHandleKey< HLT::HLTResultMT > m_hltResultWHKey
StoreGate key for the HLTResultMT.
StatusCode makeResult(const EventContext &eventContext) const
Create and fill a new HLTResultMT, and record it in the event store.
virtual StatusCode finalize() override
virtual StatusCode initialize() override
std::set< uint32_t > m_enabledROBs
List of enabled ROBs retrieved during initialisation.
Gaudi::Property< std::vector< uint32_t > > m_extraEnabledSubDets
Extra enabled SubDets.
StatusCode validateExtraROBsAndSubDets()
Check ExtraROBs and ExtraSubDets against the detector mask and drop the masked out IDs.
ToolHandle< HLTResultMTMakerTool > m_streamTagMaker
Tool creating stream tags (defines if event is accepted)
std::set< eformat::SubDetector > m_enabledSubDets
List of enabled SubDets retrieved during initialisation.
std::atomic_bool m_emptyPEBInfoErrorPrinted
Flag if empty PEB list error was already printed.
A container class for data required to build online output from HLT.
bool isAccepted() const
If there is at least one stream tag set, it means the event is accepted.
std::vector< eformat::helper::StreamTag > & getStreamTagsNonConst()
Non-const-getter for stream tags needed by the result maker to remove disabled ROBs/SubDets.
Group of local monitoring quantities and retain correlation when filling histograms
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.