ATLAS Offline Software
TrigBSExtraction.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "StoreGate/ReadHandle.h"
7 
11 
12 TrigBSExtraction::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 
57 
58  const bool isRun1 = m_navToolL2.isEnabled();
59  if ( isRun1 ) {
60  if ( repackFeaturesToSG(*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(*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(*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 
86  bool equalize,
87  bool xAODCnv) {
88 
89  ATH_MSG_DEBUG( "Trying to deserialize content of " << key );
90  auto cresult = SG::makeHandle(key);
91 
92  if ( !cresult.get() ) {
93  ATH_MSG_WARNING( "No HLTResult found with key " << key );
94  return StatusCode::SUCCESS;
95  }
96 
97  ATH_MSG_DEBUG("HLTResult is level=" << cresult->getHLTLevel() );
98 
99  const std::vector<uint32_t>& navData = cresult->getNavigationResult();
100  if ( !navData.empty() ) {
101  ATH_MSG_DEBUG( "Navigation payload obtained from " << key << " has size " << navData.size() );
102  navTool.deserialize( navData );
103  } else {
104  ATH_MSG_WARNING( "Navigation payload obtained from " << key << " has size 0" );
105  }
106 
107  if ( equalize && m_navToolL2.isEnabled() ) {
108  ATH_MSG_DEBUG( "Merging L2 and EF navigation structures for " << key );
109  navTool.merge(*m_navToolL2);
110  }
111 
112  navTool.prepare();
113 
114  // optional xAOD conversion for Run-1 AOD containers
115  if ( xAODCnv && m_xAODTool.isEnabled() ) {
116 
117  ATH_CHECK( m_xAODTool->convert(&navTool) );
118 
119  // after AOD TrigPassBitsCollection was converted to xAOD::TrigPassBitsContainer,
120  // let's fill new xAOD::TrigPassBits objects with the proper pointers to
121  // converted xAOD containers
122  ATH_CHECK( m_xAODTool->setTrigPassBits(&navTool) );
123 
124  // this will redirect all Features to the xAOD converters
125  ATH_CHECK( m_xAODTool->rewireNavigation(&navTool) );
126  }
127 
128  // Create a copy of HLTResult and pack navigation back into it
129  auto result = std::make_unique<HLT::HLTResult>(*cresult);
130 
131  result->getNavigationResult().clear();
132  bool status = navTool.serialize(result->getNavigationResult(), result->getNavigationResultCuts());
133  ATH_MSG_DEBUG( "New serialized navigation for " << keyOut << " has size " << result->getNavigationResult().size() );
134 
135  ATH_CHECK( SG::makeHandle(keyOut).record(std::move(result)) );
136 
137  return StatusCode(status);
138 }
139 
TrigBSExtraction::m_dataScoutingKeysOut
SG::WriteHandleKeyArray< HLT::HLTResult > m_dataScoutingKeysOut
Definition: TrigBSExtraction.h:66
TrigBSExtraction::m_xAODTool
ToolHandle< ITrigBStoxAODTool > m_xAODTool
Definition: TrigBSExtraction.h:51
get_generator_info.result
result
Definition: get_generator_info.py:21
HLT::NavigationCore::deserialize
bool deserialize(const std::vector< uint32_t > &input)
Definition: NavigationCore.cxx:151
TrigSerializeConvHelper.h
HLT::NavigationCore::merge
bool merge(const NavigationCore &l2)
attemtps to merge two trees
Definition: NavigationCore.cxx:235
SG::ReadHandleKey< HLT::HLTResult >
TrigBSExtraction::m_navToolL2
ToolHandle< HLT::Navigation > m_navToolL2
Definition: TrigBSExtraction.h:46
HLTResult.h
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
TrigBSExtraction::m_hltResultKeyOut
SG::WriteHandleKey< HLT::HLTResult > m_hltResultKeyOut
Definition: TrigBSExtraction.h:61
HLT::NavigationCore::prepare
virtual void prepare()
prepapres the navigation for next event
Definition: NavigationCore.cxx:335
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
TrigBSExtraction::m_dataScoutingKeysIn
SG::ReadHandleKeyArray< HLT::HLTResult > m_dataScoutingKeysIn
Definition: TrigBSExtraction.h:64
WriteHandle.h
Handle class for recording to StoreGate.
TrigBSExtraction::initialize
virtual StatusCode initialize() override
Definition: TrigBSExtraction.cxx:18
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandleKey< HLT::HLTResult >
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigBSExtraction::m_hltResultKeyIn
SG::ReadHandleKey< HLT::HLTResult > m_hltResultKeyIn
Definition: TrigBSExtraction.h:59
TrigBSExtraction::TrigBSExtraction
TrigBSExtraction(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigBSExtraction.cxx:12
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigBSExtraction::repackFeaturesToSG
StatusCode repackFeaturesToSG(HLT::Navigation &navTool, const SG::ReadHandleKey< HLT::HLTResult > &key, SG::WriteHandleKey< HLT::HLTResult > &keyOut, bool equalize, bool xAODConv)
method which does loop over objects
Definition: TrigBSExtraction.cxx:83
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HLT::Navigation
The Navigation class, organizes TriggerElements into the tree structure.
Definition: Navigation.h:100
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TrigBSExtraction::m_navTool
ToolHandle< HLT::Navigation > m_navTool
Definition: TrigBSExtraction.h:48
HLT::NavigationCore::serialize
virtual bool serialize(std::vector< uint32_t > &output) const
method serizlizes the navigation structure The structure is serrizlized in following order ....
Definition: NavigationCore.cxx:81
TrigBSExtraction.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigBSExtraction::m_l2ResultKeyIn
SG::ReadHandleKey< HLT::HLTResult > m_l2ResultKeyIn
Definition: TrigBSExtraction.h:54
merge.status
status
Definition: merge.py:17
ReadHandle.h
Handle class for reading from StoreGate.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
TrigBSExtraction::m_l2ResultKeyOut
SG::WriteHandleKey< HLT::HLTResult > m_l2ResultKeyOut
Definition: TrigBSExtraction.h:56
TrigBSExtraction::execute
virtual StatusCode execute() override
Definition: TrigBSExtraction.cxx:56
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37