ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
StreamTagMakerTool Class Reference

Makes stream tags out of chain decisions. More...

#include <StreamTagMakerTool.h>

Inheritance diagram for StreamTagMakerTool:
Collaboration diagram for StreamTagMakerTool:

Public Types

using StreamTagInfo = std::tuple< std::string, std::string, bool, bool >
 Type describing StreamTag information needed by the tool: {name, type, obeysLumiBlock, forceFullEventBuilding}. More...
 

Public Member Functions

 StreamTagMakerTool (const std::string &type, const std::string &name, const IInterface *parent)
 
virtual ~StreamTagMakerTool () override=default
 
virtual StatusCode fill (HLT::HLTResultMT &resultToFill, const EventContext &ctx) const override
 
virtual StatusCode initialize () override
 
virtual StatusCode start () override
 

Private Member Functions

StatusCode fillPEBInfoMap (std::unordered_map< TrigCompositeUtils::DecisionID, PEBInfoWriterToolBase::PEBInfo > &map, const EventContext &ctx) const
 Helper method to fill the chainID->PEBInfo map. More...
 

Private Attributes

SG::ReadHandleKey< TrigConf::HLTMenum_hltMenuKey {"DetectorStore+HLTTriggerMenu"}
 
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainerm_finalChainDecisions
 
SG::ReadHandleKeyArray< TrigCompositeUtils::DecisionContainerm_pebDecisionKeys
 
std::unordered_map< TrigCompositeUtils::DecisionID, std::vector< StreamTagInfo > > m_mapping
 Chain to streams map filled from the HLT Menu JSON. More...
 

Detailed Description

Makes stream tags out of chain decisions.

Definition at line 25 of file StreamTagMakerTool.h.

Member Typedef Documentation

◆ StreamTagInfo

using StreamTagMakerTool::StreamTagInfo = std::tuple<std::string, std::string, bool, bool>

Type describing StreamTag information needed by the tool: {name, type, obeysLumiBlock, forceFullEventBuilding}.

Definition at line 36 of file StreamTagMakerTool.h.

Constructor & Destructor Documentation

◆ StreamTagMakerTool()

StreamTagMakerTool::StreamTagMakerTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 24 of file StreamTagMakerTool.cxx.

24  :
25  base_class( type, name, parent ) {}

◆ ~StreamTagMakerTool()

virtual StreamTagMakerTool::~StreamTagMakerTool ( )
overridevirtualdefault

Member Function Documentation

◆ fill()

StatusCode StreamTagMakerTool::fill ( HLT::HLTResultMT resultToFill,
const EventContext &  ctx 
) const
overridevirtual

Definition at line 96 of file StreamTagMakerTool.cxx.

96  {
97  // obtain chain decisions,
98  using namespace TrigCompositeUtils;
100  if (!chainsHandle.isValid()) {
101  SmartIF<IAlgExecStateSvc> aess = svcLoc()->service<IAlgExecStateSvc>("AlgExecStateSvc", false);
102  if (aess.isValid() && aess->eventStatus(ctx) != EventStatus::Success) {
103  ATH_MSG_WARNING("Failed event, " << m_finalChainDecisions.key() << " is unavailable. Skipping stream tag making.");
104  return StatusCode::SUCCESS;
105  }
106  ATH_MSG_ERROR("Unable to read in the " << m_finalChainDecisions.key() << " from the DecisionSummaryMakerAlg");
107  return StatusCode::FAILURE;
108  }
109 
110  // Extract DecisionIDContainer from DecisionContainer
111  auto getPassIDs = [this](const DecisionContainer& finalDecisions, const std::string& nodeName, DecisionIDContainer& passIDs) {
112  const Decision* passNode = getNodeByName(finalDecisions, nodeName);
113  if (passNode==nullptr) {
114  ATH_MSG_ERROR("Unable to read in the " << nodeName << " node from the " << m_finalChainDecisions.key() << " collection from the DecisionSummaryMakerAlg");
115  return StatusCode::FAILURE;
116  }
117  decisionIDs(passNode, passIDs);
118  return StatusCode::SUCCESS;
119  };
120 
121  // Get raw pass decisions
122  DecisionIDContainer passRawIDs;
123  ATH_CHECK(getPassIDs(*chainsHandle,summaryPassNodeName(),passRawIDs));
124  if (passRawIDs.empty()) {
125  ATH_MSG_DEBUG("No chains passed, event rejected");
126  return StatusCode::SUCCESS;
127  }
128 
129  // Get express pass decisions
130  DecisionIDContainer passExpressIDs;
131  ATH_CHECK(getPassIDs(*chainsHandle,summaryPassExpressNodeName(),passExpressIDs));
132 
133  std::unordered_map<unsigned int, PEBInfoWriterToolBase::PEBInfo> chainToPEBInfo;
134  ATH_CHECK(fillPEBInfoMap(chainToPEBInfo, ctx));
135 
136  // for each accepted chain look up the map of chainID -> ST
137  for ( DecisionID chain: passRawIDs ) {
138 
140  continue;
141 
142  auto mappingIter = m_mapping.find( chain );
143  if( mappingIter == m_mapping.end() ) {
144  ATH_MSG_ERROR("Each chain has to have the StreamTag associated whereas the " << HLT::Identifier( chain ) << " does not" );
145  return StatusCode::FAILURE;
146  }
147 
148  const std::vector<StreamTagInfo>& streams = mappingIter->second;
149  for (const StreamTagInfo& streamTagInfo : streams) {
150  const auto& [st_name, st_type, obeysLB, forceFullEvent] = streamTagInfo;
151  ATH_MSG_DEBUG("Chain " << HLT::Identifier( chain ) << " accepted event into stream " << st_type << "_" << st_name
152  << " (obeysLB=" << obeysLB << ", forceFullEvent=" << forceFullEvent << ")");
153 
154  // express stream prescaling
155  if (st_type == "express") {
156  const auto activeExpress = std::find(passExpressIDs.begin(), passExpressIDs.end(), chain);
157  // chain didn't pass express stream prescale so don't add stream tag
158  if (activeExpress == passExpressIDs.end()) continue;
159  }
160 
161  std::set<uint32_t> robs;
162  std::set<eformat::SubDetector> subdets;
163  if (!forceFullEvent) {
164  auto it = chainToPEBInfo.find(chain);
165  if (it != chainToPEBInfo.end()) {
166  ATH_MSG_DEBUG("Chain " << HLT::Identifier( chain ) << " adds PEBInfo " << it->second << " to stream " << st_type << "_" << st_name);
167  // Copy ROB IDs directly
168  robs = it->second.robs;
169  // Convert SubDet IDs from uint32_t to eformat::SubDetector aka uint8_t
170  for (const uint32_t subdetid : it->second.subdets) {
171  subdets.insert(static_cast<eformat::SubDetector>( subdetid & 0xFF ));
172  }
173  }
174  }
175 
176  eformat::helper::StreamTag streamTag(st_name, st_type, obeysLB, robs, subdets);
177  ATH_CHECK(resultToFill.addStreamTag(streamTag));
178  }
179  }
180 
181  ATH_MSG_DEBUG("Number of streams for event " << resultToFill.getStreamTags().size() );
182  return StatusCode::SUCCESS;
183 }

◆ fillPEBInfoMap()

StatusCode StreamTagMakerTool::fillPEBInfoMap ( std::unordered_map< TrigCompositeUtils::DecisionID, PEBInfoWriterToolBase::PEBInfo > &  map,
const EventContext &  ctx 
) const
private

Helper method to fill the chainID->PEBInfo map.

Definition at line 187 of file StreamTagMakerTool.cxx.

187  {
188  for (const auto& key: m_pebDecisionKeys) {
189  // Retrieve the decision container
190  auto handle = SG::makeHandle(key, ctx);
191  if (not handle.isValid()) {
192  ATH_MSG_DEBUG("Missing input " << key.key() << " likely rejected");
193  continue;
194  }
195  ATH_MSG_DEBUG("Processing decision container " << key.key());
196  // Loop over decisions
197  for (const Decision* d : *handle) {
198  ATH_MSG_DEBUG("Processing decision " << *d);
200  decisionIDs(d,ids);
201  if (ids.empty()) {
202  ATH_MSG_DEBUG("No chain passed for this decision object, skip retrieving PEB info");
203  continue;
204  }
205  std::vector<uint32_t> robs;
206  std::vector<uint32_t> subdets;
207  if (d->getDetail(PEBInfoWriterToolBase::robListKey(), robs)) {
208  ATH_MSG_DEBUG("Retrieved a list of " << robs.size() << " ROBs for this decision");
209  }
210  else {
211  ATH_MSG_ERROR("Failed to retrieve " << PEBInfoWriterToolBase::robListKey() << " for decision container "
212  << key.key() << ", decision " << *d);
213  return StatusCode::FAILURE;
214  }
215  if (d->getDetail(PEBInfoWriterToolBase::subDetListKey(), subdets)) {
216  ATH_MSG_DEBUG("Retrieved a list of " << subdets.size() << " SubDets for this decision");
217  }
218  else {
219  ATH_MSG_ERROR("Failed to retrieve " << PEBInfoWriterToolBase::subDetListKey() << " for decision container "
220  << key.key() << ", decision " << *d);
221  return StatusCode::FAILURE;
222  }
223  // Assign PEBInfo to all passed chains for this decision
224  for (const unsigned int id : ids) {
225  // Convert leg id to chain id - changes nothing if id is already chain id
226  const HLT::Identifier chainId = getIDFromLeg(id);
227  ATH_MSG_DEBUG("Mapping PEBInfo to passed chain " << chainId.name());
228  PEBInfoWriterToolBase::PEBInfo& pebi = map[chainId.numeric()];
229  pebi.robs.insert(robs.begin(),robs.end());
230  pebi.subdets.insert(subdets.begin(),subdets.end());
231  if (pebi.robs.empty() && pebi.subdets.empty()) {
232  // This would mean streaming the full event to a PEB stream
233  ATH_MSG_ERROR("Empty PEB info for decision container " << key.key() << ", decision " << *d);
234  return StatusCode::FAILURE;
235  }
236  }
237  } // Loop over decisions
238  } // Loop over decision containers
239  return StatusCode::SUCCESS;
240 }

◆ initialize()

StatusCode StreamTagMakerTool::initialize ( )
overridevirtual

Definition at line 29 of file StreamTagMakerTool.cxx.

29  {
30  renounceArray( m_pebDecisionKeys );
31  ATH_CHECK( m_pebDecisionKeys.initialize() );
32  ATH_CHECK( m_finalChainDecisions.initialize() );
34  return StatusCode::SUCCESS;
35 }

◆ start()

StatusCode StreamTagMakerTool::start ( )
overridevirtual

Definition at line 39 of file StreamTagMakerTool.cxx.

39  {
40  m_mapping.clear();
41  auto hltMenu = SG::makeHandle( m_hltMenuKey );
42  if( ! hltMenu.isValid() ) {
43  ATH_MSG_FATAL("Failed to get the HLT menu from the DetectorStore");
44  return StatusCode::FAILURE;
45  }
46 
47  ATH_MSG_INFO("Configuring from HLTMenu from DetStore with " << hltMenu->size() << " chains");
48 
49  std::vector<TrigConf::DataStructure> allStreams = hltMenu->streams();
50  ATH_MSG_INFO("Menu has " << allStreams.size() << " streams defined");
51  std::map<std::string, StreamTagInfo> streamDictionary;
52  ATH_MSG_DEBUG("StreamTags [Name,type,obeyLB,forceFullEventBuilding]:");
53  for (const TrigConf::DataStructure& stream : allStreams) {
54  try {
55  std::string stream_name = stream.getAttribute("name");
56  std::string stream_type = stream.getAttribute("type");
57  std::string_view obeyLB = stream.getAttribute("obeyLB");
58  std::string_view fullEventBuild = stream.getAttribute("forceFullEventBuilding");
59  StreamTagInfo streamTag = {
60  stream_name,
61  stream_type,
62  obeyLB == "true",
63  fullEventBuild == "true"
64  };
65  ATH_MSG_DEBUG("-- " << formatStreamTagInfo(streamTag));
66  streamDictionary.insert(std::pair<std::string, StreamTagInfo>(stream.getAttribute("name"),streamTag));
67  } catch (const std::exception& ex) {
68  ATH_MSG_ERROR("Failure reading stream tag configuration from JSON: " << ex.what());
69  return StatusCode::FAILURE;
70  }
71  }
72 
73  for (const TrigConf::Chain & chain : *hltMenu) {
74  std::vector<std::string> streams = chain.streams();
75  if (streams.empty()) {
76  ATH_MSG_ERROR("Chain " << chain.name() << " has no streams assigned");
77  return StatusCode::FAILURE;
78  }
79  ATH_MSG_DEBUG("Chain " << chain.name() << " is assigned to " << streams.size() << " streams");
80  m_mapping[ HLT::Identifier( chain.name() ) ] = {};
81  for (const std::string& stream : streams) {
82  ATH_MSG_DEBUG("-- " << stream);
83  if (const auto streamIt = streamDictionary.find(stream); streamIt != streamDictionary.end()) {
84  m_mapping[ HLT::Identifier(chain.name()).numeric() ].push_back(streamIt->second);
85  }else{
86  ATH_MSG_ERROR("Failure reading stream tag configuration for stream: " << stream);
87  return StatusCode::FAILURE;
88  }
89  }
90  }
91  return StatusCode::SUCCESS;
92 }

Member Data Documentation

◆ m_finalChainDecisions

SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> StreamTagMakerTool::m_finalChainDecisions
private
Initial value:
{this, "ChainDecisions", "HLTNav_Summary",
"Container with final chain decisions" }

Definition at line 41 of file StreamTagMakerTool.h.

◆ m_hltMenuKey

SG::ReadHandleKey<TrigConf::HLTMenu> StreamTagMakerTool::m_hltMenuKey {"DetectorStore+HLTTriggerMenu"}
private

Definition at line 39 of file StreamTagMakerTool.h.

◆ m_mapping

std::unordered_map<TrigCompositeUtils::DecisionID, std::vector<StreamTagInfo> > StreamTagMakerTool::m_mapping
private

Chain to streams map filled from the HLT Menu JSON.

Definition at line 48 of file StreamTagMakerTool.h.

◆ m_pebDecisionKeys

SG::ReadHandleKeyArray<TrigCompositeUtils::DecisionContainer> StreamTagMakerTool::m_pebDecisionKeys
private
Initial value:
{this, "PEBDecisionKeys", {},
"Decisions including PEBInfo" }

Definition at line 44 of file StreamTagMakerTool.h.


The documentation for this class was generated from the following files:
HLT::HLTResultMT::getStreamTags
const std::vector< eformat::helper::StreamTag > & getStreamTags() const
Const-getter for stream tags.
Definition: HLTResultMT.cxx:43
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
runLayerRecalibration.chain
chain
Definition: runLayerRecalibration.py:175
TrigCompositeUtils::DecisionID
unsigned int DecisionID
Definition: TrigComposite_v1.h:27
StreamTagMakerTool::m_pebDecisionKeys
SG::ReadHandleKeyArray< TrigCompositeUtils::DecisionContainer > m_pebDecisionKeys
Definition: StreamTagMakerTool.h:44
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
TrigCompositeUtils::summaryPassExpressNodeName
const std::string & summaryPassExpressNodeName()
Definition: TrigCompositeUtilsRoot.cxx:920
HLT::Identifier::numeric
TrigCompositeUtils::DecisionID numeric() const
numeric ID
Definition: TrigCompositeUtils/TrigCompositeUtils/HLTIdentifier.h:47
python.outputTest_v2.streams
streams
Definition: outputTest_v2.py:55
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
hist_file_dump.d
d
Definition: hist_file_dump.py:137
PEBInfoWriterToolBase::robListKey
static std::string robListKey()
Returns the key used to record/retrieve the ROB list.
Definition: PEBInfoWriterToolBase.h:61
skel.it
it
Definition: skel.GENtoEVGEN.py:396
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
StreamTagMakerTool::StreamTagInfo
std::tuple< std::string, std::string, bool, bool > StreamTagInfo
Type describing StreamTag information needed by the tool: {name, type, obeysLumiBlock,...
Definition: StreamTagMakerTool.h:36
HLT::HLTResultMT::addStreamTag
StatusCode addStreamTag(const eformat::helper::StreamTag &streamTag)
Append one stream tag to the stored list.
Definition: HLTResultMT.cxx:62
PEBInfoWriterToolBase::PEBInfo::robs
std::set< uint32_t > robs
Definition: PEBInfoWriterToolBase.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
python.HLT.CommonSequences.EventBuildingSequences.robs
robs
Definition: EventBuildingSequences.py:401
calibdata.exception
exception
Definition: calibdata.py:496
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PEBInfoWriterToolBase::subDetListKey
static std::string subDetListKey()
Returns the key used to record/retrieve the SubDet list.
Definition: PEBInfoWriterToolBase.h:63
StreamTagMakerTool::m_mapping
std::unordered_map< TrigCompositeUtils::DecisionID, std::vector< StreamTagInfo > > m_mapping
Chain to streams map filled from the HLT Menu JSON.
Definition: StreamTagMakerTool.h:48
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
PEBInfoWriterToolBase::PEBInfo::subdets
std::set< uint32_t > subdets
Definition: PEBInfoWriterToolBase.h:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
StreamTagMakerTool::m_finalChainDecisions
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_finalChainDecisions
Definition: StreamTagMakerTool.h:41
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
TrigConf::DataStructure
Base class for Trigger configuration data and wrapper around underlying representation.
Definition: DataStructure.h:37
TrigCompositeUtils::summaryPassNodeName
const std::string & summaryPassNodeName()
Definition: TrigCompositeUtilsRoot.cxx:916
TrigCompositeUtils::isLegId
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
Definition: TrigCompositeUtilsRoot.cxx:204
TrigCompositeUtils::DecisionIDContainer
std::set< DecisionID > DecisionIDContainer
Definition: TrigComposite_v1.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
StreamTagMakerTool::fillPEBInfoMap
StatusCode fillPEBInfoMap(std::unordered_map< TrigCompositeUtils::DecisionID, PEBInfoWriterToolBase::PEBInfo > &map, const EventContext &ctx) const
Helper method to fill the chainID->PEBInfo map.
Definition: StreamTagMakerTool.cxx:187
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigCompositeUtils::decisionIDs
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
Definition: TrigCompositeUtilsRoot.cxx:67
HLT::Identifier::name
std::string name() const
reports human redable name if it is enabled or, empty string
Definition: HLTIdentifier.cxx:14
StreamTagMakerTool::m_hltMenuKey
SG::ReadHandleKey< TrigConf::HLTMenu > m_hltMenuKey
Definition: StreamTagMakerTool.h:39
TrigCompositeUtils
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:19
TrigCompositeUtils::getNodeByName
const Decision * getNodeByName(const DecisionContainer &container, const std::string &nodeName)
Returns the navigation node with a given name from a collection or nullptr if missing.
Definition: TrigCompositeUtilsRoot.cxx:255
PEBInfoWriterToolBase::PEBInfo
Structure holding the list of ROBs and SubDets.
Definition: PEBInfoWriterToolBase.h:44
TrigCompositeUtils::getIDFromLeg
HLT::Identifier getIDFromLeg(const HLT::Identifier &legIdentifier)
Generate the HLT::Identifier which corresponds to the chain name from the leg name.
Definition: TrigCompositeUtilsRoot.cxx:180
TrigConf::Chain
HLT chain configuration.
Definition: TrigConfData/TrigConfData/HLTChain.h:18
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37