ATLAS Offline Software
Loading...
Searching...
No Matches
TrigBSExtraction.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
7
11
12TrigBSExtraction::TrigBSExtraction(const std::string& name, ISvcLocator* pSvcLocator)
13 : AthAlgorithm(name, pSvcLocator)
14{
15}
16
17
19
20 // L2 navigation tool is optional
21 if ( !m_l2ResultKeyIn.empty() ) ATH_CHECK( m_navToolL2.retrieve() );
22 else m_navToolL2.disable();
23
24 ATH_CHECK( m_navTool.retrieve() );
25
26 // xAOD converter tool (for Run-1 data)
27 if ( !m_xAODTool.empty() ) ATH_CHECK( m_xAODTool.retrieve() );
28 else m_xAODTool.disable();
29
30 // Initialize handle keys
33
36
37 if ( m_dataScoutingKeysIn.size() != m_dataScoutingKeysOut.size() ) {
38 ATH_MSG_ERROR("Size of DSResultKeysIn/Out does not match: " << m_dataScoutingKeysIn <<
39 " vs " << m_dataScoutingKeysOut );
40 return StatusCode::FAILURE;
41 }
42 ATH_CHECK( m_dataScoutingKeysIn.initialize() );
43 ATH_CHECK( m_dataScoutingKeysOut.initialize() );
44
45 // Initialize the TrigSerializeConcHelper here so that all the additional streamerinfos are read in.
46 // In case of DataScouting this may give problems if the DS ROBs contain containers which
47 // were not compiled with navigation (the container type information is then not known
48 // for a given CLID).
49 ToolHandle<ITrigSerializeConvHelper> trigCnvHelper("TrigSerializeConvHelper",this);
50 ATH_CHECK( trigCnvHelper.retrieve() );
51
52 return StatusCode::SUCCESS;
53}
54
55
56StatusCode TrigBSExtraction::execute(const EventContext& ctx) {
57
58 const bool isRun1 = m_navToolL2.isEnabled();
59 if ( isRun1 ) {
60 if ( repackFeaturesToSG(ctx, *m_navToolL2, m_l2ResultKeyIn, m_l2ResultKeyOut, false, false).isFailure() )
61 ATH_MSG_WARNING( "failed unpacking features from BS to SG for: " << m_l2ResultKeyIn );
62 }
63
64 if ( !m_hltResultKeyIn.empty() ) {
65 // unpack, merge with L2 result and do xAOD conversion
66 // xAOD conversion is only done for HLTResult_EF in Run-1
67 if ( repackFeaturesToSG(ctx, *m_navTool, m_hltResultKeyIn, m_hltResultKeyOut, isRun1, isRun1).isFailure() )
68 ATH_MSG_WARNING( "failed unpacking features from BS to SG for: " << m_hltResultKeyIn );
69 }
70
71 for (size_t i = 0; i<m_dataScoutingKeysIn.size(); i++ ) {
72 if ( repackFeaturesToSG(ctx, *m_navTool, m_dataScoutingKeysIn[i], m_dataScoutingKeysOut[i], false, false).isFailure() )
73 ATH_MSG_WARNING( "failed unpacking features from BS to SG for: " << m_dataScoutingKeysIn[i] );
74 }
75
76 if ( isRun1 ) m_navToolL2->reset();
77 m_navTool->reset();
78
79 return StatusCode::SUCCESS;
80}
81
82
83StatusCode TrigBSExtraction::repackFeaturesToSG (const EventContext& ctx,
84 HLT::Navigation& navTool,
87 bool equalize,
88 bool xAODCnv) {
89
90 ATH_MSG_DEBUG( "Trying to deserialize content of " << key );
91 auto cresult = SG::makeHandle(key, ctx);
92
93 if ( !cresult.get() ) {
94 ATH_MSG_WARNING( "No HLTResult found with key " << key );
95 return StatusCode::SUCCESS;
96 }
97
98 ATH_MSG_DEBUG("HLTResult is level=" << cresult->getHLTLevel() );
99
100 const std::vector<uint32_t>& navData = cresult->getNavigationResult();
101 if ( !navData.empty() ) {
102 ATH_MSG_DEBUG( "Navigation payload obtained from " << key << " has size " << navData.size() );
103 navTool.deserialize( navData );
104 } else {
105 ATH_MSG_WARNING( "Navigation payload obtained from " << key << " has size 0" );
106 }
107
108 if ( equalize && m_navToolL2.isEnabled() ) {
109 ATH_MSG_DEBUG( "Merging L2 and EF navigation structures for " << key );
110 navTool.merge(*m_navToolL2);
111 }
112
113 navTool.prepare();
114
115 // optional xAOD conversion for Run-1 AOD containers
116 if ( xAODCnv && m_xAODTool.isEnabled() ) {
117
118 ATH_CHECK( m_xAODTool->convert(ctx, &navTool) );
119
120 // after AOD TrigPassBitsCollection was converted to xAOD::TrigPassBitsContainer,
121 // let's fill new xAOD::TrigPassBits objects with the proper pointers to
122 // converted xAOD containers
123 ATH_CHECK( m_xAODTool->setTrigPassBits(&navTool) );
124
125 // this will redirect all Features to the xAOD converters
126 ATH_CHECK( m_xAODTool->rewireNavigation(&navTool) );
127 }
128
129 // Create a copy of HLTResult and pack navigation back into it
130 auto result = std::make_unique<HLT::HLTResult>(*cresult);
131
132 result->getNavigationResult().clear();
133 bool status = navTool.serialize(result->getNavigationResult(), result->getNavigationResultCuts());
134 ATH_MSG_DEBUG( "New serialized navigation for " << keyOut << " has size " << result->getNavigationResult().size() );
135
136 ATH_CHECK( SG::makeHandle(keyOut, ctx).record(std::move(result)) );
137
138 return StatusCode(status);
139}
140
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual bool serialize(std::vector< uint32_t > &output) const
method serizlizes the navigation structure The structure is serrizlized in following order ....
bool merge(const NavigationCore &l2)
attemtps to merge two trees
virtual void prepare()
prepapres the navigation for next event
bool deserialize(const std::vector< uint32_t > &input)
The Navigation class, organizes TriggerElements into the tree structure.
Definition Navigation.h:100
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode repackFeaturesToSG(const EventContext &ctx, HLT::Navigation &navTool, const SG::ReadHandleKey< HLT::HLTResult > &key, SG::WriteHandleKey< HLT::HLTResult > &keyOut, bool equalize, bool xAODConv)
method which does loop over objects
SG::ReadHandleKey< HLT::HLTResult > m_hltResultKeyIn
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
ToolHandle< ITrigBStoxAODTool > m_xAODTool
SG::WriteHandleKey< HLT::HLTResult > m_hltResultKeyOut
ToolHandle< HLT::Navigation > m_navToolL2
TrigBSExtraction(const std::string &name, ISvcLocator *pSvcLocator)
SG::WriteHandleKeyArray< HLT::HLTResult > m_dataScoutingKeysOut
SG::ReadHandleKey< HLT::HLTResult > m_l2ResultKeyIn
virtual StatusCode initialize() override
SG::ReadHandleKeyArray< HLT::HLTResult > m_dataScoutingKeysIn
SG::WriteHandleKey< HLT::HLTResult > m_l2ResultKeyOut
ToolHandle< HLT::Navigation > m_navTool
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())