ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCompositeUtils.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TrigCompositeUtils_TrigCompositeUtils_h
6#define TrigCompositeUtils_TrigCompositeUtils_h
7
8
9
10#include "AthLinks/ElementLink.h"
19
20
21#ifdef XAOD_STANDALONE
22#include "AsgTools/SgEvent.h"
23#endif
24
28
30
31#include "HLTIdentifier.h"
32#include "NavGraph.h"
37#include "SGCore/sgkey_t.h"
38
39#include <set>
40#include <memory>
41#include <functional>
42#include <string>
43#include <string_view>
44
45
46#define TRIGCOMPUTILS_ENABLE_EARLY_EXIT 1
47
48namespace TrigCompositeUtils {
50
51 // cppcheck-suppress unknownMacro
52 ANA_MSG_HEADER (msgRejected)
53
54
56
62 template<class CONT>
63 SG::WriteHandle<CONT> createAndStoreNoAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
64
70 template<class CONT, class AUX>
71 SG::WriteHandle<CONT> createAndStoreWithAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
72
77 SG::WriteHandle<DecisionContainer> createAndStore( const SG::WriteHandleKey<DecisionContainer>& key, const EventContext& ctx );
78
82 void createAndStore( SG::WriteHandle<DecisionContainer>& handle );
83
94 Decision* newDecisionIn ( DecisionContainer* dc, const std::string& name = "" );
95
103 Decision* newDecisionIn( DecisionContainer* dc, const Decision* dOld, const std::string& name, const EventContext& ctx );
104
110 void addDecisionID( DecisionID id, Decision* d);
111
117 void insertDecisionIDs( const Decision* src, Decision* dest );
118
124
130 void uniqueDecisionIDs( Decision* dest);
131
132
137
144
151
152
156 bool allFailed( const Decision* d );
157
162 template<typename T>
164
169
174
179
183 void linkToPrevious(Decision* d, const std::string& previousCollectionKey, size_t previousIndex);
184
188 void linkToPrevious(Decision* d, const Decision* dOld, const EventContext& ctx);
189
194
199
205 bool copyLinks(const Decision* src, Decision* dest);
206
213 HLT::Identifier createLegName(const HLT::Identifier& chainIdentifier, size_t counter);
214
221 HLT::Identifier createLegName(const std::string& name, size_t counter);
222
228 HLT::Identifier getIDFromLeg(const HLT::Identifier& legIdentifier);
229
235 int32_t getIndexFromLeg(const HLT::Identifier& legIdentifier);
236
242 int32_t getIndexFromLeg(const std::string& name);
243
250 std::pair<std::string, int32_t> getNameAndIndexFromLeg(const std::string& name);
251
257 bool isLegId(const HLT::Identifier& legIdentifier);
258
264 bool isLegId(const std::string& name);
265
271 bool isChainId(const HLT::Identifier& chainIdentifier);
272
278 bool isChainId(const std::string& name);
279
284 const Decision* find(const Decision*, const std::function<bool(const Decision*)>& filter);
285
289 class HasObject {
290 public:
294 HasObject(const std::string& name): m_name(name) {}
299 bool operator()(const Decision* ) const;
300 private:
301 std::string m_name;
302 };
303
308 public:
312 HasObjectCollection(const std::string& name): m_name(name) {}
317 bool operator()(const Decision* ) const;
318 private:
319 std::string m_name;
320 };
321
322
328 const Decision* getTerminusNode(const DecisionContainer& container);
329 const Decision* getTerminusNode(SG::ReadHandle<DecisionContainer>& container); // older signature
330
331
337 const Decision* getExpressTerminusNode(const DecisionContainer& container);
338
339
346 const Decision* getNodeByName(const DecisionContainer& container, const std::string& nodeName);
347
348
358 std::vector<const Decision*> getRejectedDecisionNodes(const asg::EventStoreType* eventStore,
359 const EventContext& ctx,
360 const std::string& summaryCollectionKey,
361 const DecisionIDContainer& ids = {},
362 const std::set<std::string>& keysToIgnore = std::set<std::string>());
363
364
375 NavGraph& navGraph,
376 const DecisionIDContainer& ids = {},
377 const bool enforceDecisionOnStartNode = true);
378
379
387 const Decision* comingFrom,
388 NavGraph& navGraph,
389 std::set<const Decision*>& fullyExploredFrom,
390 const DecisionIDContainer& ids,
391 const bool enforceDecisionOnNode);
392
393
402 const bool keepOnlyFinalFeatures,
403 const bool removeEmptySteps,
404 const std::vector<std::string>& nodesToDrop);
405
406
413 bool modeKeep,
414 std::set<NavGraphNode*>& fullyExploredFrom,
415 const bool keepOnlyFinalFeatures,
416 const bool removeEmptySteps,
417 const std::vector<std::string>& nodesToDrop);
418
419
422 inline const std::string& initialRoIString() { return Decision::s_initialRoIString; }
423 inline const std::string& initialRecRoIString() { return Decision::s_initialRecRoIString; }
424 inline const std::string& roiString() { return Decision::s_roiString; }
425 inline const std::string& viewString() { return Decision::s_viewString; }
426 inline const std::string& featureString() { return Decision::s_featureString; }
427 inline const std::string& seedString() { return Decision::s_seedString; }
428
429 inline const std::string& hltSeedingNodeName() { return Decision::s_hltSeedingNodeNameString; }
430 inline const std::string& filterNodeName() { return Decision::s_filterNodeNameString; }
431 inline const std::string& inputMakerNodeName() { return Decision::s_inputMakerNodeNameString; }
432 inline const std::string& hypoAlgNodeName() { return Decision::s_hypoAlgNodeNameString; }
433 inline const std::string& comboHypoAlgNodeName() { return Decision::s_comboHypoAlgNodeNameString; }
435 inline const std::string& summaryPassNodeName() { return Decision::s_summaryPassNodeNameString; }
439
446 template<class CONTAINER>
447 void filterLinkVectorByContainerKey(std::string_view containerSGKey, std::vector<ElementLink<CONTAINER>>& vector);
448
449
462 template<class CONTAINER>
463 const std::vector< LinkInfo<CONTAINER> > recursiveGetFeaturesOfType(
464 const NavGraph& navGraph,
465 std::string_view containerSGKey = "",
466 const unsigned int behaviour = TrigDefs::lastFeatureOfType,
467 const std::string& navElementLinkKey = featureString(),
468 const DecisionIDContainer& chainIDs = DecisionIDContainer());
469
478 template<class CONTAINER>
480 std::vector< LinkInfo<CONTAINER> >& features,
481 std::set<const NavGraphNode*>& fullyExploredFrom,
482 const NavGraphNode* navGraphNode,
483 std::string_view containerSGKey,
484 const unsigned int behaviour,
485 const std::string& navElementLinkKey,
486 const DecisionIDContainer& chainIDs);
487
497 template<typename T>
499 findLink(const EventContext& ctx,
500 const Decision* start,
501 const std::string& linkName,
502 const bool suppressMultipleLinksWarning = false);
503
517 template<typename T>
518 void
519 findLinks(const EventContext& ctx,
520 const Decision* start,
521 const std::string& linkName,
522 std::vector<LinkInfo<T>>& links,
523 unsigned int behaviour = TrigDefs::allFeaturesOfType,
524 std::set<const xAOD::TrigComposite*>* fullyExploredFrom = nullptr);
525
538 template<typename T>
539 std::vector<LinkInfo<T>>
540 findLinks(const EventContext& ctx,
541 const Decision* start,
542 const std::string& linkName,
543 unsigned int behaviour = TrigDefs::allFeaturesOfType);
544
558 bool typelessFindLink(const Decision* start,
559 const std::string& linkName,
560 sgkey_t& key,
561 CLID& clid,
563 const Decision*& source,
564 const bool suppressMultipleLinksWarning = false);
565
570 bool typelessFindLink(const NavGraph& subGraph,
571 const std::string& linkName,
572 sgkey_t& key,
573 CLID& clid,
575 const Decision*& source,
576 const bool suppressMultipleLinksWarning = false);
577
593 bool typelessFindLinks(const Decision* start,
594 const std::string& linkName,
595 std::vector<sgkey_t>& keyVec,
596 std::vector<CLID>& clidVec,
597 std::vector<Decision::index_type>& indexVec,
598 std::vector<const Decision*>& sourceVec,
599 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
600 std::set<const Decision*>* fullyExploredFrom = nullptr);
601
605 bool typelessFindLinks(const NavGraphNode* start,
606 const std::string& linkName,
607 std::vector<sgkey_t>& key,
608 std::vector<CLID>& clid,
609 std::vector<Decision::index_type>& index,
610 std::vector<const Decision*>& sourceVec,
611 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
612 std::set<const Decision*>* fullyExploredFrom = nullptr);
613
619 const std::string& linkName,
620 std::vector<sgkey_t>& keyVec,
621 std::vector<CLID>& clidVec,
622 std::vector<Decision::index_type>& indexVec,
623 std::vector<const Decision*>& sourceVec);
624
639 const std::string& chainName,
640 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
641 const std::vector<std::size_t>& legMultiplicities,
642 const IPartCombItr::FilterFunc_t& filter);
643
658 const std::string& chainName,
659 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
660 const std::vector<std::size_t>& legMultiplicities,
662
679 const std::string& chainName,
680 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
681 const TrigConf::HLTChain *chainInfo,
682 const IPartCombItr::FilterFunc_t& filter);
683
700 const std::string& chainName,
701 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
702 const TrigConf::HLTChain *chainInfo,
704
709 std::string dump( const Decision* tc, const std::function< std::string( const Decision* )>& printerFnc );
710
711}
712
714
715#endif // TrigCompositeUtils_TrigCompositeUtils_h
Property holding a SG store/key/clid from which a ReadHandle is made.
Handle class for reading from StoreGate.
Property holding a SG store/key/clid from which a WriteHandle is made.
Handle class for recording to StoreGate.
Base class for elements of a container that can have aux data.
macros for messaging and checking status codes
#define ANA_MSG_HEADER(NAME)
for standalone code this creates a new message category
uint32_t CLID
The Class ID type.
static Double_t tc
xAOD::TrigComposite Decision
std::set< DecisionID > DecisionIDContainer
void operator()(T1)
HasObjectCollection(const std::string &name)
constructor specifying the link name
bool operator()(const Decision *) const
checks if the arg Decision object has link collection of name specified at construction
HasObject(const std::string &name)
constructor specifying the link name
std::function< bool(const IPartCombItr::VecLInfo_t &)> FilterFunc_t
Transient utility class to represent a node in a graph (m_decisionObject), and a vector of edges (m_f...
Definition NavGraph.h:20
Structure to hold a transient Directed Acyclic Graph (DAG) structure.
Definition NavGraph.h:111
HLT chain configuration information.
Definition node.h:24
STL class.
static const std::string s_summaryFilterNodeNameString
Constant used to identify a navigation graph node as being from a final Filter created by the Decisio...
static const std::string s_filterNodeNameString
Constant used to identify a navigation graph node as being from a Filter.
static const std::string s_inputMakerNodeNameString
Constant used to identify a navigation graph node as being from a Input Maker.
static const std::string s_summaryPrescaledNodeNameString
Constant used to identify the single prescaled graph node.
static const std::string s_seedString
Constant used to identify a seed (parent).
static const std::string s_hltSeedingNodeNameString
Constant used to identify a navigation graph node as being from the HLTSeeding.
static const std::string s_initialRoIString
Constant used to identify an initial ROI from L1.
static const std::string s_viewString
Constant used to identify a view.
static const std::string s_comboHypoAlgNodeNameString
Constant used to identify a navigation graph node as being from a Combo Hypo Alg.
static const std::string s_featureString
Constant used to identify a feature.
static const std::string s_summaryPassExpressNodeNameString
Constant used to identify the single express-accept graph node.
static const std::string s_initialRecRoIString
Constant used to identify an initial HLT ROI derived from L1.
static const std::string s_hypoAlgNodeNameString
Constant used to identify a navigation graph node as being from a Hypo Alg.
static const std::string s_summaryPassNodeNameString
Constant used to identify the single terminus graph node the end point of all chains which accept the...
static const std::string s_roiString
Constant used to identify an (explicitly) updated HLT ROI.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Forward declaration.
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
bool isChainId(const HLT::Identifier &chainIdentifier)
Recognise whether the HLT identifier corresponds to a whole chain.
SG::WriteHandle< CONT > createAndStoreNoAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx)
Creates and right away records the Container CONT with the key.
HLT::Identifier createLegName(const HLT::Identifier &chainIdentifier, size_t counter)
Generate the HLT::Identifier which corresponds to a specific leg of a given chain.
const std::string & summaryPrescaledNodeName()
const std::string & inputMakerNodeName()
unsigned int DecisionID
void recursiveGetFeaturesOfTypeInternal(std::vector< LinkInfo< CONTAINER > > &features, std::set< const NavGraphNode * > &fullyExploredFrom, const NavGraphNode *navGraphNode, std::string_view containerSGKey, const unsigned int behaviour, const std::string &navElementLinkKey, const DecisionIDContainer &chainIDs)
DEPRECATED.
const std::string & viewString()
const std::string & summaryFilterNodeName()
void filterLinkVectorByContainerKey(std::string_view containerSGKey, std::vector< ElementLink< CONTAINER > > &vector)
DEPRECATED.
xAOD::TrigComposite Decision
const Decision * find(const Decision *start, const std::function< bool(const Decision *)> &filter)
traverses Decision object links for another Decision object fulfilling the prerequisite specified by ...
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.
void insertDecisionIDs(const Decision *src, Decision *dest)
Appends the decision IDs of src to the dest decision object.
const std::string & roiString()
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.
const std::vector< ElementLink< DecisionContainer > > getLinkToPrevious(const Decision *d)
returns links to previous decision object 'seed'
Combinations buildCombinations(const std::string &chainName, const std::vector< LinkInfo< xAOD::IParticleContainer > > &features, const std::vector< std::size_t > &legMultiplicities, const IPartCombItr::FilterFunc_t &filter)
Produce the combinations for a set of features.
DecisionIDContainer passedDecisionIDs(const Decision *d, const T &required)
return DecisionIDs in Decision object that match the required ones
SG::WriteHandle< CONT > createAndStoreWithAux(const SG::WriteHandleKey< CONT > &key, const EventContext &ctx)
Creates and right away records the Container CONT with the key.
const std::string & featureString()
int32_t getIndexFromLeg(const HLT::Identifier &legIdentifier)
Extract the numeric index of a leg identifier.
const Decision * getExpressTerminusNode(const DecisionContainer &container)
Returns the express-accept navigation node from a collection or nullptr if missing.
void recursiveGetDecisions(const Decision *start, NavGraph &navGraph, const DecisionIDContainer &ids, const bool enforceDecisionOnStartNode)
Search back in time from "node" and locate all paths back through Decision objects for a given chain.
HLT::Identifier getIDFromLeg(const HLT::Identifier &legIdentifier)
Generate the HLT::Identifier which corresponds to the chain name from the leg name.
const std::string & filterNodeName()
std::vector< const Decision * > getRejectedDecisionNodes(const asg::EventStoreType *eventStore, const EventContext &ctx, const std::string &summaryCollectionKey, const DecisionIDContainer &ids, const std::set< std::string > &keysToIgnore)
Query all DecisionCollections in the event store, locate all Decision nodes in the graph where an obj...
bool copyLinks(const Decision *src, Decision *dest)
copy all links from src to dest TC objects
bool hasLinkToPrevious(const Decision *d)
checks if there is at least one 'seed' link to previous object
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
void recursiveFlagForThinningInternal(NavGraphNode *node, bool modeKeep, std::set< NavGraphNode * > &fullyExploredFrom, const bool keepOnlyFinalFeatures, const bool removeEmptySteps, const std::vector< std::string > &nodesToDrop)
Used by recursiveFlagForThinning.
const std::string & comboHypoAlgNodeName()
std::set< DecisionID > DecisionIDContainer
const std::vector< LinkInfo< CONTAINER > > recursiveGetFeaturesOfType(const NavGraph &navGraph, std::string_view containerSGKey="", const unsigned int behaviour=TrigDefs::lastFeatureOfType, const std::string &navElementLinkKey=featureString(), const DecisionIDContainer &chainIDs=DecisionIDContainer())
DEPRECATED.
const Decision * getTerminusNode(SG::ReadHandle< DecisionContainer > &container)
const std::string & initialRecRoIString()
void recursiveFlagForThinning(NavGraph &graph, const bool keepOnlyFinalFeatures, const bool removeEmptySteps, const std::vector< std::string > &nodesToDrop)
Used by trigger navigation thinning.
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void recursiveGetDecisionsInternal(const Decision *node, const Decision *comingFrom, NavGraph &navGraph, std::set< const Decision * > &fullyExploredFrom, const DecisionIDContainer &ids, const bool enforceDecisionOnNode)
Used by recursiveGetDecisions.
const std::string & hypoAlgNodeName()
void linkToPrevious(Decision *d, const std::string &previousCollectionKey, size_t previousIndex)
Links to the previous object, location of previous 'seed' decision supplied by hand.
LinkInfo< T > findLink(const EventContext &ctx, const Decision *start, const std::string &linkName, const bool suppressMultipleLinksWarning=false)
Perform a recursive search for ElementLinks of type T and name 'linkName', starting from Decision obj...
bool allFailed(const Decision *d)
return true if there is no positive decision stored
@ UniqueObjects
Do not allow any repeated objects.
void uniqueDecisionIDs(Decision *dest)
Make unique list of decision IDs of dest Decision object.
void findLinks(const EventContext &ctx, const Decision *start, const std::string &linkName, std::vector< LinkInfo< T > > &links, unsigned int behaviour=TrigDefs::allFeaturesOfType, std::set< const xAOD::TrigComposite * > *fullyExploredFrom=nullptr)
search back the TC links for the object of type T linked to the one of TC (recursively) Populates pro...
bool typelessFindLinksCommonLinkCollection(const Decision *start, const std::string &linkName, std::vector< sgkey_t > &keyVec, std::vector< CLID > &clidVec, std::vector< Decision::index_type > &indexVec, std::vector< const Decision * > &sourceVec)
Common functionality shared by both typelessFindLinks interfaces Returns true if at least one link wa...
const std::string & initialRoIString()
std::pair< std::string, int32_t > getNameAndIndexFromLeg(const std::string &name)
Extract the name and numeric index of a leg identifier.
const std::string & seedString()
const std::string & summaryPassNodeName()
bool typelessFindLinks(const Decision *start, const std::string &linkName, std::vector< sgkey_t > &keyVec, std::vector< CLID > &clidVec, std::vector< Decision::index_type > &indexVec, std::vector< const Decision * > &sourceVec, const unsigned int behaviour, std::set< const Decision * > *fullyExploredFrom)
search back the TC links for the object of type T linked to the one of TC (recursively) Returns the l...
const std::string & summaryPassExpressNodeName()
xAOD::TrigCompositeContainer DecisionContainer
SG::WriteHandle< DecisionContainer > DecisionWriteHandle
alias types, for readability and to simplify future evolution
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
const std::string & hltSeedingNodeName()
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
bool isAnyIDPassing(const Decision *d, const DecisionIDContainer &required)
Checks if any of the DecisionIDs passed in arg required is availble in Decision object.
ElementLink< DecisionContainer > decisionToElementLink(const Decision *d, const EventContext &ctx)
Takes a raw pointer to a Decision and returns an ElementLink to the Decision.
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
bool typelessFindLink(const Decision *start, const std::string &linkName, sgkey_t &key, CLID &clid, Decision::index_type &index, const Decision *&source, const bool suppressMultipleLinksWarning)
Perform a recursive search for ElementLinks of any time and name 'linkName', starting from Decision o...
static const unsigned int lastFeatureOfType
Run 3 "enum". Only return the final feature along each route through the navigation.
static const unsigned int allFeaturesOfType
Run 3 "enum". Return all features along legs (still with type and container checks).
StoreGateSvc EventStoreType
the type returned by AsgTool::evtStore
-event-from-file
Definition index.py:1
STL namespace.
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22