6#include "eformat/DetectorMask.h"
7#include "eformat/SourceIdentifier.h"
8#include "eformat/Problem.h"
13 std::string u32toHexString(uint32_t num) {
14 std::string hexRobId(
"0x ");
15 std::to_chars(hexRobId.data()+2, hexRobId.data()+hexRobId.size(), num, 16);
16 hexRobId.resize(std::min(10ul,hexRobId.find(
' ')));
20 struct FractionPerLBNMonitor {
21 FractionPerLBNMonitor(std::string&& name, EventIDBase::number_type lbn,
float denom,
const ToolHandle<GenericMonitoringTool>& monTool)
22 : errorFraction(Monitored::Scalar<
float>{std::move(name), 0}),
23 errorFractionLBN(Monitored::Scalar<EventIDBase::number_type>{
"LumiBlock", lbn}),
26 ~FractionPerLBNMonitor() {
30 errorFraction /= denominator;
32 Monitored::Group{tool, errorFraction, errorFractionLBN};
35 Monitored::Scalar<float> errorFraction;
36 Monitored::Scalar<EventIDBase::number_type> errorFractionLBN;
38 const ToolHandle<GenericMonitoringTool>& tool;
42 std::vector<eformat::FragmentProblem> problems;
43 rob->problems(problems);
44 s << problems.size() <<
" problems: [";
45 bool firstProblem{
true};
46 for (eformat::FragmentProblem problem : problems) {
47 if (firstProblem) {firstProblem=
false;}
49 s << eformat::helper::FragmentProblemDictionary.string(problem);
53 std::string robIdsToString(
const std::vector<uint32_t>& robIds) {
54 std::ostringstream
ss;
57 for (
const uint32_t robId : robIds) {
58 if (first) {
first=
false;}
60 ss <<
"0x" << std::hex << robId << std::dec;
87 const std::vector<uint32_t>& ids = decoderTool->robIds();
97 auto setRobCheckBehaviour = [
this](
const Gaudi::Property<std::string>& prop,
ROBCheckBehaviour& out) -> StatusCode {
104 <<
"\" but needs to be one of [\"None\", \"Warning\", \"Error\", \"Fatal\"]");
105 return StatusCode::FAILURE;
107 return StatusCode::SUCCESS;
113 return StatusCode::SUCCESS;
122 return StatusCode::SUCCESS;
130 const eformat::helper::DetectorMask detectorMask{metadata->getDetectorMask(), metadata->getDetectorMask2()};
133 for (
const uint32_t robId :
m_robIds) {
134 const eformat::helper::SourceIdentifier sid{robId};
135 if (!detectorMask.is_set(sid.subdetector_id())) {
137 ATH_MSG_WARNING(
"ROB ID 0x" << MSG::hex << robId << MSG::dec <<
" was requested for decoding, "
138 <<
"but the SubDetector " << sid.human_detector() <<
" is disabled in "
139 <<
"the detector mask. Will not require this ROB ID to be present in every event.");
144 return StatusCode::SUCCESS;
154 return StatusCode::SUCCESS;
170 std::string toolName{decoderTool->name().substr(decoderTool->name().rfind(
'.')+1)};
178 ATH_CHECK(decoderTool->convertFromBS(vrobfForTool, eventContext));
179 }
catch (
const std::exception& ex) {
180 ATH_MSG_ERROR(
"Exception in " << toolName <<
"::convertFromBS: " << ex.what());
181 return StatusCode::FAILURE;
188 return StatusCode::SUCCESS;
194 const std::vector<uint32_t>& ids,
195 std::string_view toolName,
196 const EventContext& eventContext)
const {
197 std::copy_if(in.cbegin(), in.cend(), std::back_inserter(out),
199 return (std::find(ids.cbegin(),ids.cend(),rob->source_id()) != ids.cend());
202 std::string missingFractionName{
"MissingROBFraction_"};
203 missingFractionName.append(toolName);
204 FractionPerLBNMonitor monMissingFraction{std::move(missingFractionName), eventContext.eventID().lumi_block(),
static_cast<float>(ids.size()),
m_monTool};
207 if (ids.size() != out.size()) {
209 for (
const uint32_t
id : ids) {
211 if (std::find_if(out.cbegin(),out.cend(),eqRobId) == out.cend()) {
212 ++monMissingFraction;
213 std::string hexRobId = u32toHexString(
id);
215 ATH_MSG_DEBUG(
"Missing ROBFragment with ID " << hexRobId <<
" ("
216 << eformat::helper::SourceIdentifier(
id).human() <<
") requested by " << toolName
217 <<
" but it is allowed to be missing due to the detector mask or the "
222 ATH_MSG_ERROR(
"Missing ROBFragment with ID " << hexRobId <<
" ("
223 << eformat::helper::SourceIdentifier(
id).human() <<
") requested by " << toolName);
231 return StatusCode::FAILURE;
234 ATH_MSG_DEBUG(
"Found " << out.size() <<
" out of " << ids.size() <<
" ROBFragments requested by " << toolName);
235 return StatusCode::SUCCESS;
240 std::string_view toolName,
241 const EventContext& eventContext)
const {
242 StatusCode
sc{StatusCode::SUCCESS};
246 std::string corruptedFractionName{
"CorruptedROBFraction_"};
247 std::string errorFractionName{
"ErroneousROBFraction_"};
248 corruptedFractionName.append(toolName);
249 errorFractionName.append(toolName);
250 FractionPerLBNMonitor monCorruptedFraction{std::move(corruptedFractionName), eventContext.eventID().lumi_block(),
static_cast<float>(robs.size()),
m_monTool};
251 FractionPerLBNMonitor monErrorFraction{std::move(errorFractionName), eventContext.eventID().lumi_block(),
static_cast<float>(robs.size()),
m_monTool};
252 auto printCheckMsg = [
this](std::ostringstream&
ss,
ROBCheckBehaviour checkBehaviour,
bool maybeMissing, StatusCode&
sc) {
261 sc = StatusCode::FAILURE;
268 ++monCorruptedFraction;
269 const uint32_t
id{rob->rob_source_id()};
270 std::string hexRobId = u32toHexString(
id);
276 std::ostringstream
ss;
277 ss <<
"ROBFragment with ID " << hexRobId <<
" (" << eformat::helper::SourceIdentifier(
id).human()
278 <<
") requested by " << toolName <<
" has corrupted data with ";
279 printRobProblems(
ss, rob);
285 const uint32_t
id{rob->rob_source_id()};
286 std::string hexRobId = u32toHexString(
id);
292 std::ostringstream
ss;
293 ss <<
"ROBFragment with ID " << hexRobId <<
" (" << eformat::helper::SourceIdentifier(
id).human()
294 <<
") requested by " << toolName <<
" has non-zero status 0x" << std::hex << rob->status()[0] << std::dec;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)
An algorithm that can be simultaneously executed in multiple threads.
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment ROBF
std::vector< const ROBF * > VROBFRAG
std::set< uint32_t > m_maybeMissingRobs
Set of ROB IDs allowed to be missing because they are disabled.
virtual StatusCode finalize() override
virtual StatusCode initialize() override
virtual StatusCode execute(const EventContext &eventContext) const override
StatusCode checkRobs(const IROBDataProviderSvc::VROBFRAG &robs, std::string_view toolName, const EventContext &eventContext) const
Check ROB status word and report if different from zero.
ROBCheckBehaviour m_robStatusCheck
ROBCheckBehaviour
The behaviour for non-zero ROB status words.
StatusCode filterRobs(const IROBDataProviderSvc::VROBFRAG &in, IROBDataProviderSvc::VROBFRAG &out, const std::vector< uint32_t > &ids, std::string_view toolName, const EventContext &eventContext) const
Copy over ROBFragment pointers from in to out for ROBs with IDs from the ids list.
Gaudi::Property< std::string > m_robFormatCheckLevel
Set behaviour for corrupted ROB data.
std::vector< uint32_t > m_robIds
Vector of ROB IDs to request, filled from all decoder tools in initialize.
Gaudi::Property< std::string > m_robStatusCheckLevel
Set behaviour for non-zero ROB status words.
virtual StatusCode start() override
L1TriggerByteStreamDecoderAlg(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
ROBDataProvider service handle.
Gaudi::Property< std::vector< uint32_t > > m_maybeMissingRobsProp
Allow some ROBs to be missing.
ROBCheckBehaviour m_robFormatCheck
ToolHandleArray< IL1TriggerByteStreamTool > m_decoderTools
Tool performing the decoding work.
ToolHandle< GenericMonitoringTool > m_monTool
Monitoring tool to create online histograms.
SG::ReadHandleKey< ByteStreamMetadataContainer > m_bsMetaDataContRHKey
StoreGate key for the ByteStreamMetadata container to retrieve detector mask.
Group of local monitoring quantities and retain correlation when filling histograms
Declare a monitored scalar variable.
TGCHBChip operator++(TGCHBChip &rs, int)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
DataModel_detail::iterator< DVL > unique(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of unique for DataVector/List.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.