ATLAS Offline Software
Loading...
Searching...
No Matches
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}.

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.

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.

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;
99 SG::ReadHandle<DecisionContainer> chainsHandle{m_finalChainDecisions, ctx};
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
139 if (TrigCompositeUtils::isLegId(HLT::Identifier(chain)) )
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}
#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)
const std::vector< eformat::helper::StreamTag > & getStreamTags() const
Const-getter for stream tags.
StatusCode addStreamTag(const eformat::helper::StreamTag &streamTag)
Append one stream tag to the stored list.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
std::unordered_map< TrigCompositeUtils::DecisionID, std::vector< StreamTagInfo > > m_mapping
Chain to streams map filled from the HLT Menu JSON.
std::tuple< std::string, std::string, bool, bool > StreamTagInfo
Type describing StreamTag information needed by the tool: {name, type, obeysLumiBlock,...
SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_finalChainDecisions
StatusCode fillPEBInfoMap(std::unordered_map< TrigCompositeUtils::DecisionID, PEBInfoWriterToolBase::PEBInfo > &map, const EventContext &ctx) const
Helper method to fill the chainID->PEBInfo map.
unsigned int DecisionID
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.
std::set< DecisionID > DecisionIDContainer
const std::string & summaryPassNodeName()
const std::string & summaryPassExpressNodeName()
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.

◆ 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}
TrigCompositeUtils::DecisionID numeric() const
numeric ID
std::string name() const
reports human redable name
static std::string robListKey()
Returns the key used to record/retrieve the ROB list.
static std::string subDetListKey()
Returns the key used to record/retrieve the SubDet list.
SG::ReadHandleKeyArray< TrigCompositeUtils::DecisionContainer > m_pebDecisionKeys
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
HLT::Identifier getIDFromLeg(const HLT::Identifier &legIdentifier)
Generate the HLT::Identifier which corresponds to the chain name from the leg name.

◆ 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() );
33 ATH_CHECK( m_hltMenuKey.initialize() );
34 return StatusCode::SUCCESS;
35}
SG::ReadHandleKey< TrigConf::HLTMenu > m_hltMenuKey

◆ 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}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)

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.

41 {this, "ChainDecisions", "HLTNav_Summary",
42 "Container with final chain decisions" };

◆ m_hltMenuKey

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

Definition at line 39 of file StreamTagMakerTool.h.

39{"DetectorStore+HLTTriggerMenu"};

◆ 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.

44 {this, "PEBDecisionKeys", {},
45 "Decisions including PEBInfo" };

The documentation for this class was generated from the following files: