ATLAS Offline Software
CTPUnpackingTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "CTPUnpackingTool.h"
8 
10 
11 #include <boost/algorithm/string.hpp>
12 
13 using namespace HLT;
14 
15 
17  const std::string& name,
18  const IInterface* parent )
20 
21 
25 
26 
28 
29  return StatusCode::SUCCESS;
30 }
31 
32 
34  ATH_MSG_INFO( "Updating CTP bits decoding configuration");
35 
36  // iterate over all items and obtain the CPT ID for each item. Then, package that in the map: name -> CTP ID
37  ATH_MSG_INFO( "start(): use new L1 trigger menu" );
38  // Cleanup in case there was a stop/start transition
39  m_itemNametoCTPIDMap.clear();
40  m_ctpToChain.clear();
41 
43  if( l1menu.isValid() ) {
44  for ( const TrigConf::L1Item & item: *l1menu ) {
45  m_itemNametoCTPIDMap[item.name()] = item.ctpId();
46  }
47  } else {
48  ATH_MSG_ERROR( "TrigConf::L1Menu does not exist" );
49  }
50 
51  auto addIfItemExists = [&]( const std::string& itemName, HLT::Identifier id, bool warningOnly = false ) -> StatusCode {
52  if ( m_itemNametoCTPIDMap.find( itemName ) != m_itemNametoCTPIDMap.end() ) {
53  m_ctpToChain[ m_itemNametoCTPIDMap[itemName] ].push_back( id );
54  return StatusCode::SUCCESS;
55  }
56  if( warningOnly ) {
57  // this code should be removed after the L1 menu is migrated to the new json version
58  ATH_MSG_WARNING(itemName << " used to seed the chain " << id <<" not in the configuration ");
59  return StatusCode::SUCCESS;
60  }
61  ATH_MSG_ERROR(itemName << " used to seed the chain " << id <<" not in the configuration ");
62  return StatusCode::FAILURE;
63  };
64 
66  ATH_CHECK( hltMenuHandle.isValid() );
67  for ( const TrigConf::Chain& chain: *hltMenuHandle ) {
68  HLT::Identifier chainID{ chain.name() };
69  if ( chain.l1item().empty() ) { // unseeded chain
70  m_ctpToChain[ s_CTPIDForUnseededChains ].push_back( chainID );
71  } else if ( chain.l1item().find(',') != std::string::npos ) { // OR seeds
72 
73  std::vector<std::string> items;
74  boost::split(items, chain.l1item(), [](char c){return c == ',';});
75  for ( const std::string& i: items ) {
76  ATH_CHECK( addIfItemExists( i, chainID, true ) );
77  }
78  } else { // regular chain
79  ATH_CHECK( addIfItemExists( chain.l1item(), chainID ) );
80  }
81  }
82 
83  for ( const auto& ctpIDtoChain: m_ctpToChain ) {
84  for ( auto chain: ctpIDtoChain.second ) {
85  ATH_MSG_DEBUG( "CTP seed of " << ctpIDtoChain.first << " enables chains " << chain );
86  }
87  }
88 
89  return StatusCode::SUCCESS;
90 }
91 
92 
93 StatusCode CTPUnpackingTool::decode( const ROIB::RoIBResult& roib, HLT::IDVec& enabledChains ) const {
94  auto nItems = Monitored::Scalar( "Items", 0 );
95  auto nChains = Monitored::Scalar( "Chains", 0 );
96 
97  auto ctpBits = m_useTBPBit ? roib.cTPResult().TBP() : roib.cTPResult().TAV();
98  const size_t bitsSize = ctpBits.size();
99  constexpr static size_t wordSize{32};
100 
101  for ( size_t wordCounter = 0; wordCounter < bitsSize; ++wordCounter ) {
102  for ( size_t bitCounter = 0; bitCounter < wordSize; ++bitCounter ) {
103  const size_t ctpIndex = wordSize*wordCounter + bitCounter;
104  const bool decision = ( ctpBits[wordCounter].roIWord() & ((uint32_t)1 << bitCounter) ) > 0;
105 
106  if ( decision or m_forceEnable ) {
107  if ( decision ) {
108  nItems = nItems + 1;
109  ATH_MSG_DEBUG("L1 item " << ctpIndex << " active, enabling chains "
110  << (m_forceEnable ? " due to the forceEnable flag" : " due to the seed"));
111  }
112 
113  auto itr = m_ctpToChain.find( ctpIndex );
114  if ( itr != m_ctpToChain.end() ) {
115  enabledChains.insert( enabledChains.end(), itr->second.begin(), itr->second.end() );
116  }
117  }
118  }
119  }
120  // the unseeded chains are always enabled at this stage
121  const auto itr = m_ctpToChain.find( s_CTPIDForUnseededChains );
122  if ( itr != m_ctpToChain.cend() ) {
123  enabledChains.insert( enabledChains.end(), itr->second.begin(), itr->second.end());
124  }
125 
126  nChains = enabledChains.size();
127  for ( auto chain: enabledChains ) {
128  ATH_MSG_DEBUG( "Enabling chain: " << chain );
129  }
130  if ( nItems == 0 ) {
131  ATH_MSG_ERROR( "All CTP bits were disabled, this event should not have shown here" );
132  return StatusCode::FAILURE;
133  }
134  Monitored::Group( m_monTool, nItems, nChains );
135  return StatusCode::SUCCESS;
136 }
137 
138 
140  const std::vector<std::string>& l1ItemNames,
141  bool& pass) const {
142 
143  pass = false;
144 
145  const auto ctpBits = roib->cTPResult().TBP();
146 
147  for (const std::string& l1name : l1ItemNames) {
148  try {
149  // Retrieve before prescale decision
150  const size_t ctpId = m_itemNametoCTPIDMap.at(l1name);
151  const size_t bitCounter = ctpId % 32;
152  const size_t wordCounter = ctpId / 32;
153 
154  const bool decision = (ctpBits[wordCounter].roIWord() & ((uint32_t)1 << bitCounter)) > 0;
155 
156  pass = (pass || decision);
157  }
158  catch (const std::exception& e) {
159  ATH_MSG_ERROR ( l1name << " is not part of L1Menu!" );
160  return StatusCode::FAILURE;
161  }
162  }
163 
164  return StatusCode::SUCCESS;
165 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
CTPUnpackingToolBase::s_CTPIDForUnseededChains
static constexpr int s_CTPIDForUnseededChains
Definition: CTPUnpackingToolBase.h:44
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ROIB::RoIBResult
Class holding the LVL1 RoIB result build by the RoIBuilder.
Definition: RoIBResult.h:47
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RoIBResult.h
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ROIB::CTPResult::TBP
const std::vector< CTPRoI > TBP() const
get trigger result before prescale
CTPUnpackingTool::m_itemNametoCTPIDMap
std::map< std::string, size_t > m_itemNametoCTPIDMap
Definition: CTPUnpackingTool.h:47
CTPUnpackingToolBase
Base class for CTP unpacking tools.
Definition: CTPUnpackingToolBase.h:24
CTPUnpackingTool::decode
virtual StatusCode decode(const ROIB::RoIBResult &roib, HLT::IDVec &enabledChains) const override
Fills the list of chains that should be activated in a given event (note HLT prescaling happens at a ...
Definition: CTPUnpackingTool.cxx:93
CTPUnpackingTool::m_L1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
Definition: CTPUnpackingTool.h:40
CTPUnpackingTool::initialize
virtual StatusCode initialize() override
Definition: CTPUnpackingTool.cxx:22
CTPUnpackingTool::m_HLTMenuKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_HLTMenuKey
Definition: CTPUnpackingTool.h:38
CTPUnpackingTool::CTPUnpackingTool
CTPUnpackingTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CTPUnpackingTool.cxx:16
CTPUnpackingTool::passBeforePrescaleSelection
virtual StatusCode passBeforePrescaleSelection(const ROIB::RoIBResult *roib, const std::vector< std::string > &l1ItemNames, bool &pass) const override
Definition: CTPUnpackingTool.cxx:139
CTPResult.h
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
HLT::IDVec
std::vector< HLT::Identifier > IDVec
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HLT
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Definition: HLTResultReader.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
CTPUnpackingToolBase::m_ctpToChain
std::unordered_map< int, HLT::IDVec > m_ctpToChain
Definition: CTPUnpackingToolBase.h:45
calibdata.exception
exception
Definition: calibdata.py:496
CTPUnpackingToolBase::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: CTPUnpackingToolBase.h:50
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrigConf::L1Item
L1 threshold configuration.
Definition: L1Item.h:18
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
HLT::Identifier
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:20
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CTPUnpackingTool::m_useTBPBit
Gaudi::Property< bool > m_useTBPBit
Definition: CTPUnpackingTool.h:43
CTPUnpackingTool.h
ROIB::RoIBResult::cTPResult
const CTPResult & cTPResult() const
Gets the CTP part of the L1 RDO.
Definition: RoIBResult.cxx:60
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
item
Definition: ItemListSvc.h:43
CTPUnpackingTool::start
virtual StatusCode start() override
Definition: CTPUnpackingTool.cxx:33
ROIB::CTPResult::TAV
const std::vector< CTPRoI > TAV() const
get trigger result after veto
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
HLTIdentifier.h
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
CTPUnpackingToolBase::m_forceEnable
Gaudi::Property< bool > m_forceEnable
Definition: CTPUnpackingToolBase.h:47
CTPUnpackingToolBase::initialize
virtual StatusCode initialize() override
Definition: CTPUnpackingToolBase.cxx:14
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigConf::Chain
HLT chain configuration.
Definition: TrigConfData/TrigConfData/HLTChain.h:18
python.compressB64.c
def c
Definition: compressB64.py:93
Trk::split
@ split
Definition: LayerMaterialProperties.h:38