ATLAS Offline Software
HLTSeeding.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
4 */
5 
6 #include "HLTSeeding.h"
10 
11 #include "StoreGate/WriteHandle.h"
12 #include "GaudiKernel/EventContext.h"
13 
15 
16 HLTSeeding::HLTSeeding(const std::string& name, ISvcLocator* pSvcLocator)
17  : AthReentrantAlgorithm(name, pSvcLocator) {}
18 
19 
21  ATH_MSG_INFO( "Reading RoIB information from: " << m_RoIBResultKey.objKey() << " : "
22  << m_RoIBResultKey.fullKey() << " : " << m_RoIBResultKey.key() );
23 
24  if ( m_RoIBResultKey.empty() && m_l1TriggerResultKey.empty() ) {
25  ATH_MSG_INFO( "RoIBResult and L1TriggerResult keys both empty: assume we're running with CTP emulation" );
26  }
27 
29  ATH_CHECK( m_l1TriggerResultKey.initialize(!m_l1TriggerResultKey.empty()) );
30 
31  ATH_CHECK( m_summaryKey.initialize() );
33 
34  ATH_CHECK( m_ctpUnpacker.retrieve() );
35  ATH_CHECK( m_roiUnpackers_roib.retrieve() );
36  ATH_CHECK( m_roiUnpackers_xaod.retrieve() );
37  ATH_CHECK( m_prescaler.retrieve() );
38 
39  if ( !m_keyWriterTool.empty() ) {
40  ATH_CHECK( m_keyWriterTool.retrieve() );
41  }
42 
43  if ( !m_consistencyChecker.empty() ) {
44  ATH_CHECK( m_consistencyChecker.retrieve() );
45  }
46 
47  if (m_doCostMonitoring) {
48  ATH_CHECK( m_trigCostSvcHandle.retrieve() );
49  }
50 
51  if ( m_roiZedWidthDefault!=0 ) {
52  ATH_MSG_INFO( "CHANGING THE DEFAULT ROI Z WIDTH: " << m_roiZedWidthDefault );
54  }
55 
56  return StatusCode::SUCCESS;
57 }
58 
59 
60 StatusCode HLTSeeding::execute (const EventContext& ctx) const {
61  {
62  auto timeStampHandle = SG::makeHandle( m_startStampKey, ctx );
63  ATH_CHECK( timeStampHandle.record( std::make_unique<TrigTimeStamp>() ) );
64  }
65  using namespace TrigCompositeUtils;
66  const bool decodeRoIB = !m_RoIBResultKey.empty();
67  const bool decodexAOD = !m_l1TriggerResultKey.empty();
68 
69  const ROIB::RoIBResult* roib = nullptr;
70  if (decodeRoIB) {
72  roib = roibH.cptr();
73  ATH_MSG_DEBUG( "Obtained RoIBResult" );
74  }
75 
76  const xAOD::TrigComposite* l1TriggerResult = nullptr;
77  if (decodexAOD) {
78  auto l1TriggerResultCont = SG::makeHandle(m_l1TriggerResultKey, ctx);
79  if (!l1TriggerResultCont.isValid()) {
80  ATH_MSG_ERROR("Failed to retrieve L1TriggerResult with key " << m_l1TriggerResultKey.key());
81  return StatusCode::FAILURE;
82  }
83  if (l1TriggerResultCont->size() != 1) {
84  ATH_MSG_ERROR("Size of the L1TriggerResultContainer is " << l1TriggerResultCont->size() << " but 1 expected");
85  return StatusCode::FAILURE;
86  }
87  l1TriggerResult = l1TriggerResultCont->at(0);
88  if (msgLvl(MSG::DEBUG)) {
89  const std::vector<std::string>& linkNames = l1TriggerResult->linkColNames();
90  const std::vector<uint32_t>& linkClids = l1TriggerResult->linkColClids();
91  ATH_MSG_DEBUG("L1TriggerResult has " << linkNames.size() << " links:");
92  for (size_t i=0; i<linkNames.size(); ++i) {
93  ATH_MSG_DEBUG("--> " << linkNames.at(i) << " CLID: " << linkClids.at(i));
94  }
95  }
96  }
97 
99  auto *chainsInfo = handle.ptr();
100 
101  HLT::IDVec l1SeededChains;
102  if (decodeRoIB) {
103  ATH_CHECK( m_ctpUnpacker->decode( *roib, l1SeededChains ) );
104  } else if (m_ctpUnpacker->isEmulated()) {
105  ATH_CHECK( m_ctpUnpacker->decode( ROIB::RoIBResult{}, l1SeededChains ) );
106  }
107 
108  // important: sorting of the list of seeded chains is needed so that the deduplication and following set difference are correct
109  std::sort( l1SeededChains.begin(), l1SeededChains.end() );
110 
111  // Multiple items can seed some chains, remove duplicates from the sorted vector
112  HLT::IDVec::iterator removeFrom = std::unique(l1SeededChains.begin(), l1SeededChains.end());
113  l1SeededChains.erase(removeFrom, l1SeededChains.end());
114 
115  HLT::IDVec activeChains; // Chains which are activated to run in the first pass (seeded and pass prescale)
116  HLT::IDVec prescaledChains; // Chains which are activated but do not run in the first pass (seeded but prescaled out)
117 
118  ATH_CHECK( m_prescaler->prescaleChains( ctx, l1SeededChains, activeChains ) );
119 
120  // important: sorting of the list of active chains is needed so that the set difference is correct
121  std::sort( activeChains.begin(), activeChains.end() );
122 
123  std::set_difference(l1SeededChains.begin(), l1SeededChains.end(),
124  activeChains.begin(), activeChains.end(),
125  std::back_inserter(prescaledChains));
126 
127  // Validation
128  for (const HLT::Identifier& id : prescaledChains) {
129  if (std::find(activeChains.begin(), activeChains.end(), id) != activeChains.end()) {
130  ATH_MSG_ERROR("Prescaled chain cannot also be an active chain (" << id << ")");
131  }
132  }
133 
134  ATH_CHECK( saveChainsInfo( l1SeededChains, chainsInfo, "l1seeded" ) );
135  ATH_CHECK( saveChainsInfo( activeChains, chainsInfo, "unprescaled" ) );
136  ATH_CHECK( saveChainsInfo( prescaledChains, chainsInfo, "prescaled" ) );
137  // Note: 'prescaled' is deduced from 'l1seeded' and 'unprescaled'.
138 
139  // Do cost monitoring, this utilises the HLT_costmonitor chain
140  if (m_doCostMonitoring) {
141  const static HLT::Identifier costMonitorChain(m_costMonitoringChain);
142  const auto activeCostMonIt = std::find(activeChains.begin(), activeChains.end(), costMonitorChain);
143  if (activeCostMonIt == activeChains.end()){
144  ATH_CHECK(m_trigCostSvcHandle->discardEvent(ctx));
145  }
146  }
147 
148  ATH_MSG_DEBUG( "Unpacking RoIs" );
149  HLT::IDSet activeChainSet( activeChains.begin(), activeChains.end() );
150  if (decodeRoIB) {
151  for ( auto unpacker: m_roiUnpackers_roib ) {
152  ATH_CHECK( unpacker->unpack( ctx, *roib, activeChainSet ) );
153  }
154  } else if (m_ctpUnpacker->isEmulated()) {
155  ROIB::RoIBResult roib{};
156  for ( auto unpacker: m_roiUnpackers_roib ) {
157  ATH_CHECK( unpacker->unpack( ctx, roib, activeChainSet ) );
158  }
159  }
160  if (decodexAOD) {
161  for ( auto unpacker: m_roiUnpackers_xaod ) {
162  try {
163  ATH_CHECK( unpacker->unpack( ctx, *l1TriggerResult, activeChainSet ) );
164  } catch (const std::exception& ex) {
165  ATH_MSG_ERROR("Exception in " << unpacker->name() << "::unpack: " << ex.what());
166  return StatusCode::FAILURE;
167  }
168  }
169  }
170 
171  if ( !m_keyWriterTool.empty() ) {
172  ATH_CHECK( m_keyWriterTool->writeKeys(ctx) );
173  }
174 
175  if ( !m_consistencyChecker.empty() ) {
176  ATH_CHECK( m_consistencyChecker->consistencyCheck(l1SeededChains, ctx) );
177  }
178 
179  return StatusCode::SUCCESS;
180 }
181 
182 
185  const std::string& type) {
186  using namespace TrigCompositeUtils;
187  Decision* d = newDecisionIn( storage, type );
188  for ( auto c: chains) {
189  addDecisionID(c.numeric(), d);
190  }
191  return StatusCode::SUCCESS;
192 }
HLTSeeding::m_consistencyChecker
ToolHandle< L1DataConsistencyChecker > m_consistencyChecker
Definition: HLTSeeding.h:92
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
HLTSeeding::m_roiUnpackers_xaod
ToolHandleArray< IRoIsUnpackingTool > m_roiUnpackers_xaod
Definition: HLTSeeding.h:83
HLTSeeding::m_prescaler
ToolHandle< IPrescalingTool > m_prescaler
Definition: HLTSeeding.h:86
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
HLTSeeding::m_doCostMonitoring
Gaudi::Property< bool > m_doCostMonitoring
Definition: HLTSeeding.h:61
TrigCompositeUtils.h
ROIB::RoIBResult
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition: RoIBResult.h:47
HLTSeeding::saveChainsInfo
static StatusCode saveChainsInfo(const HLT::IDVec &chains, xAOD::TrigCompositeContainer *storage, const std::string &type)
Definition: HLTSeeding.cxx:183
TrigCompositeUtils::newDecisionIn
Decision * newDecisionIn(DecisionContainer *dc, const std::string &name)
Helper method to create a Decision object, place it in the container and return a pointer to it.
Definition: TrigCompositeUtilsRoot.cxx:46
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
HLTSeeding::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: HLTSeeding.cxx:60
hist_file_dump.d
d
Definition: hist_file_dump.py:137
HLTSeeding::m_l1TriggerResultKey
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultKey
Level-1 result with RoIs from Run-3 hardware systems.
Definition: HLTSeeding.h:49
TrigCompositeUtils::addDecisionID
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
Definition: TrigCompositeUtilsRoot.cxx:61
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
TrigCompositeUtils::createAndStore
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
Definition: TrigCompositeUtilsRoot.cxx:30
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
HLTSeeding.h
xAOD::TrigComposite_v1::linkColClids
const std::vector< uint32_t > & linkColClids() const
Raw access to the persistent link CLIDs.
HLTSeeding::m_startStampKey
SG::WriteHandleKey< TrigTimeStamp > m_startStampKey
Definition: HLTSeeding.h:55
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLTSeeding::m_RoIBResultKey
SG::ReadHandleKey< ROIB::RoIBResult > m_RoIBResultKey
Definition: HLTSeeding.h:45
HLTSeeding::m_roiUnpackers_roib
ToolHandleArray< IRoIsUnpackingTool > m_roiUnpackers_roib
Definition: HLTSeeding.h:80
WriteHandle.h
Handle class for recording to StoreGate.
HLT::IDVec
std::vector< HLT::Identifier > IDVec
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:62
HLTSeeding::m_trigCostSvcHandle
ServiceHandle< ITrigCostSvc > m_trigCostSvcHandle
Definition: HLTSeeding.h:74
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
calibdata.exception
exception
Definition: calibdata.py:496
RoiDescriptor.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
xAOD::TrigComposite_v1
Class used to describe composite objects in the HLT.
Definition: TrigComposite_v1.h:52
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
TrigCompositeAuxContainer.h
HLTSeeding::m_roiZedWidthDefault
Gaudi::Property< float > m_roiZedWidthDefault
Definition: HLTSeeding.h:69
HLTSeeding::m_costMonitoringChain
Gaudi::Property< std::string > m_costMonitoringChain
Definition: HLTSeeding.h:64
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::TrigComposite_v1::linkColNames
const std::vector< std::string > & linkColNames() const
Raw access to the persistent link names.
python.copyTCTOutput.chains
chains
Definition: copyTCTOutput.py:81
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
HLTSeeding::m_keyWriterTool
ToolHandle< TrigConf::IKeyWriterTool > m_keyWriterTool
Definition: HLTSeeding.h:89
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
HLTSeeding::initialize
virtual StatusCode initialize() override
Definition: HLTSeeding.cxx:20
RoiDescriptor::zedWidthDefault
static double zedWidthDefault()
Definition: RoiDescriptor.h:183
DEBUG
#define DEBUG
Definition: page_access.h:11
IKeyWriterTool.h
HLTSeeding::m_ctpUnpacker
ToolHandle< ICTPUnpackingTool > m_ctpUnpacker
Definition: HLTSeeding.h:77
HLT::IDSet
std::set< HLT::Identifier > IDSet
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:63
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
HLTSeeding::HLTSeeding
HLTSeeding(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HLTSeeding.cxx:16
HLTSeeding::m_summaryKey
SG::WriteHandleKey< TrigCompositeUtils::DecisionContainer > m_summaryKey
Definition: HLTSeeding.h:52
python.compressB64.c
def c
Definition: compressB64.py:93