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#include <set>
9#include <memory>
10#include <functional>
11#include <regex>
12
13#include "AthLinks/ElementLink.h"
22
23
24#ifdef XAOD_STANDALONE
25#include "AsgTools/SgEvent.h"
26#endif
27
31
33
34#include "HLTIdentifier.h"
35#include "NavGraph.h"
40#include "SGCore/sgkey_t.h"
41
42#define TRIGCOMPUTILS_ENABLE_EARLY_EXIT 1
43
44namespace TrigCompositeUtils {
46
47 // cppcheck-suppress unknownMacro
48 ANA_MSG_HEADER (msgRejected)
49
50
52
58 template<class CONT>
59 SG::WriteHandle<CONT> createAndStoreNoAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
60
66 template<class CONT, class AUX>
67 SG::WriteHandle<CONT> createAndStoreWithAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
68
73 SG::WriteHandle<DecisionContainer> createAndStore( const SG::WriteHandleKey<DecisionContainer>& key, const EventContext& ctx );
74
78 void createAndStore( SG::WriteHandle<DecisionContainer>& handle );
79
90 Decision* newDecisionIn ( DecisionContainer* dc, const std::string& name = "" );
91
99 Decision* newDecisionIn( DecisionContainer* dc, const Decision* dOld, const std::string& name, const EventContext& ctx );
100
106 void addDecisionID( DecisionID id, Decision* d);
107
113 void insertDecisionIDs( const Decision* src, Decision* dest );
114
120
126 void uniqueDecisionIDs( Decision* dest);
127
128
133
140
147
148
152 bool allFailed( const Decision* d );
153
158 template<typename T>
160
165
170
175
179 void linkToPrevious(Decision* d, const std::string& previousCollectionKey, size_t previousIndex);
180
184 void linkToPrevious(Decision* d, const Decision* dOld, const EventContext& ctx);
185
190
195
201 bool copyLinks(const Decision* src, Decision* dest);
202
209 HLT::Identifier createLegName(const HLT::Identifier& chainIdentifier, size_t counter);
210
217 HLT::Identifier createLegName(const std::string& name, size_t counter);
218
224 HLT::Identifier getIDFromLeg(const HLT::Identifier& legIdentifier);
225
231 int32_t getIndexFromLeg(const HLT::Identifier& legIdentifier);
232
238 int32_t getIndexFromLeg(const std::string& name);
239
246 std::pair<std::string, int32_t> getNameAndIndexFromLeg(const std::string& name);
247
253 bool isLegId(const HLT::Identifier& legIdentifier);
254
260 bool isLegId(const std::string& name);
261
267 bool isChainId(const HLT::Identifier& chainIdentifier);
268
274 bool isChainId(const std::string& name);
275
280 const Decision* find(const Decision*, const std::function<bool(const Decision*)>& filter);
281
285 class HasObject {
286 public:
290 HasObject(const std::string& name): m_name(name) {}
295 bool operator()(const Decision* ) const;
296 private:
297 std::string m_name;
298 };
299
304 public:
308 HasObjectCollection(const std::string& name): m_name(name) {}
313 bool operator()(const Decision* ) const;
314 private:
315 std::string m_name;
316 };
317
318
324 const Decision* getTerminusNode(const DecisionContainer& container);
325 const Decision* getTerminusNode(SG::ReadHandle<DecisionContainer>& container); // older signature
326
327
333 const Decision* getExpressTerminusNode(const DecisionContainer& container);
334
335
342 const Decision* getNodeByName(const DecisionContainer& container, const std::string& nodeName);
343
344
354 std::vector<const Decision*> getRejectedDecisionNodes(const asg::EventStoreType* eventStore,
355 const EventContext& ctx,
356 const std::string& summaryCollectionKey,
357 const DecisionIDContainer& ids = {},
358 const std::set<std::string>& keysToIgnore = std::set<std::string>());
359
360
371 NavGraph& navGraph,
372 const DecisionIDContainer& ids = {},
373 const bool enforceDecisionOnStartNode = true);
374
375
383 const Decision* comingFrom,
384 NavGraph& navGraph,
385 std::set<const Decision*>& fullyExploredFrom,
386 const DecisionIDContainer& ids,
387 const bool enforceDecisionOnNode);
388
389
398 const bool keepOnlyFinalFeatures,
399 const bool removeEmptySteps,
400 const std::vector<std::string>& nodesToDrop);
401
402
409 bool modeKeep,
410 std::set<NavGraphNode*>& fullyExploredFrom,
411 const bool keepOnlyFinalFeatures,
412 const bool removeEmptySteps,
413 const std::vector<std::string>& nodesToDrop);
414
415
418 inline const std::string& initialRoIString() { return Decision::s_initialRoIString; }
419 inline const std::string& initialRecRoIString() { return Decision::s_initialRecRoIString; }
420 inline const std::string& roiString() { return Decision::s_roiString; }
421 inline const std::string& viewString() { return Decision::s_viewString; }
422 inline const std::string& featureString() { return Decision::s_featureString; }
423 inline const std::string& seedString() { return Decision::s_seedString; }
424
425 inline const std::string& hltSeedingNodeName() { return Decision::s_hltSeedingNodeNameString; }
426 inline const std::string& filterNodeName() { return Decision::s_filterNodeNameString; }
427 inline const std::string& inputMakerNodeName() { return Decision::s_inputMakerNodeNameString; }
428 inline const std::string& hypoAlgNodeName() { return Decision::s_hypoAlgNodeNameString; }
429 inline const std::string& comboHypoAlgNodeName() { return Decision::s_comboHypoAlgNodeNameString; }
431 inline const std::string& summaryPassNodeName() { return Decision::s_summaryPassNodeNameString; }
435
442 template<class CONTAINER>
443 void filterLinkVectorByContainerKey(const std::string& containerSGKey, std::vector<ElementLink<CONTAINER>>& vector);
444
445
458 template<class CONTAINER>
459 const std::vector< LinkInfo<CONTAINER> > recursiveGetFeaturesOfType(
460 const NavGraph& navGraph,
461 const std::string& containerSGKey = "",
462 const unsigned int behaviour = TrigDefs::lastFeatureOfType,
463 const std::string& navElementLinkKey = featureString(),
464 const DecisionIDContainer& chainIDs = DecisionIDContainer());
465
474 template<class CONTAINER>
476 std::vector< LinkInfo<CONTAINER> >& features,
477 std::set<const NavGraphNode*>& fullyExploredFrom,
478 const NavGraphNode* navGraphNode,
479 const std::string& containerSGKey,
480 const unsigned int behaviour,
481 const std::string& navElementLinkKey,
482 const DecisionIDContainer& chainIDs);
483
493 template<typename T>
495 findLink(const EventContext& ctx,
496 const Decision* start,
497 const std::string& linkName,
498 const bool suppressMultipleLinksWarning = false);
499
503 template<typename T>
504 [[deprecated("pass EventContext as first argument")]]
506 findLink(const Decision* start,
507 const std::string& linkName,
508 const bool suppressMultipleLinksWarning = false)
509 { return findLink<T>(Gaudi::Hive::currentContext(), start, linkName, suppressMultipleLinksWarning); }
510
524 template<typename T>
525 void
526 findLinks(const EventContext& ctx,
527 const Decision* start,
528 const std::string& linkName,
529 std::vector<LinkInfo<T>>& links,
530 unsigned int behaviour = TrigDefs::allFeaturesOfType,
531 std::set<const xAOD::TrigComposite*>* fullyExploredFrom = nullptr);
532
536 template<typename T>
537 [[deprecated("pass EventContext as first argument")]]
538 void
539 findLinks(const Decision* start,
540 const std::string& linkName,
541 std::vector<LinkInfo<T>>& links,
542 unsigned int behaviour = TrigDefs::allFeaturesOfType,
543 std::set<const xAOD::TrigComposite*>* fullyExploredFrom = nullptr)
544 { return findLinks<T>(Gaudi::Hive::currentContext(), start, linkName, links, behaviour, fullyExploredFrom); }
545
558 template<typename T>
559 std::vector<LinkInfo<T>>
560 findLinks(const EventContext& ctx,
561 const Decision* start,
562 const std::string& linkName,
563 unsigned int behaviour = TrigDefs::allFeaturesOfType);
564
568 template<typename T>
569 [[deprecated("pass EventContext as first argument")]]
570 std::vector<LinkInfo<T>>
571 findLinks(const Decision* start,
572 const std::string& linkName,
573 unsigned int behaviour = TrigDefs::allFeaturesOfType)
574 { return findLinks<T>(Gaudi::Hive::currentContext(), start, linkName, behaviour); }
575
589 bool typelessFindLink(const Decision* start,
590 const std::string& linkName,
591 sgkey_t& key,
592 CLID& clid,
594 const Decision*& source,
595 const bool suppressMultipleLinksWarning = false);
596
601 bool typelessFindLink(const NavGraph& subGraph,
602 const std::string& linkName,
603 sgkey_t& key,
604 CLID& clid,
606 const Decision*& source,
607 const bool suppressMultipleLinksWarning = false);
608
624 bool typelessFindLinks(const Decision* start,
625 const std::string& linkName,
626 std::vector<sgkey_t>& keyVec,
627 std::vector<CLID>& clidVec,
628 std::vector<Decision::index_type>& indexVec,
629 std::vector<const Decision*>& sourceVec,
630 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
631 std::set<const Decision*>* fullyExploredFrom = nullptr);
632
636 bool typelessFindLinks(const NavGraphNode* start,
637 const std::string& linkName,
638 std::vector<sgkey_t>& key,
639 std::vector<CLID>& clid,
640 std::vector<Decision::index_type>& index,
641 std::vector<const Decision*>& sourceVec,
642 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
643 std::set<const Decision*>* fullyExploredFrom = nullptr);
644
650 const std::string& linkName,
651 std::vector<sgkey_t>& keyVec,
652 std::vector<CLID>& clidVec,
653 std::vector<Decision::index_type>& indexVec,
654 std::vector<const Decision*>& sourceVec);
655
669 Combinations buildCombinations(
670 const std::string& chainName,
671 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
672 const std::vector<std::size_t>& legMultiplicities,
673 const IPartCombItr::FilterFunc_t& filter);
674
688 Combinations buildCombinations(
689 const std::string& chainName,
690 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
691 const std::vector<std::size_t>& legMultiplicities,
693
709 Combinations buildCombinations(
710 const std::string& chainName,
711 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
712 const TrigConf::HLTChain *chainInfo,
713 const IPartCombItr::FilterFunc_t& filter);
714
730 Combinations buildCombinations(
731 const std::string& chainName,
732 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
733 const TrigConf::HLTChain *chainInfo,
735
740 std::string dump( const Decision* tc, const std::function< std::string( const Decision* )>& printerFnc );
741
742}
743
745
746#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
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
const std::string & viewString()
const std::string & summaryFilterNodeName()
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 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...
const std::vector< LinkInfo< CONTAINER > > recursiveGetFeaturesOfType(const NavGraph &navGraph, const std::string &containerSGKey="", const unsigned int behaviour=TrigDefs::lastFeatureOfType, const std::string &navElementLinkKey=featureString(), const DecisionIDContainer &chainIDs=DecisionIDContainer())
DEPRECATED.
bool allFailed(const Decision *d)
return true if there is no positive decision stored
@ UniqueObjects
Do not allow any repeated objects.
void recursiveGetFeaturesOfTypeInternal(std::vector< LinkInfo< CONTAINER > > &features, std::set< const NavGraphNode * > &fullyExploredFrom, const NavGraphNode *navGraphNode, const std::string &containerSGKey, const unsigned int behaviour, const std::string &navElementLinkKey, const DecisionIDContainer &chainIDs)
DEPRECATED.
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()
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.
void filterLinkVectorByContainerKey(const std::string &containerSGKey, std::vector< ElementLink< CONTAINER > > &vector)
DEPRECATED.
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
Helper to keep a Decision object, ElementLink and ActiveState (with respect to some requested ChainGr...
Definition LinkInfo.h:22