ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCompositeUtils.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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"
21
22
23#ifdef XAOD_STANDALONE
24#include "AsgTools/SgTEvent.h"
25#endif
26
30
32
33#include "HLTIdentifier.h"
34#include "NavGraph.h"
39#include "SGCore/sgkey_t.h"
40
41#define TRIGCOMPUTILS_ENABLE_EARLY_EXIT 1
42
43namespace TrigCompositeUtils {
45
46 // cppcheck-suppress unknownMacro
47 ANA_MSG_HEADER (msgRejected)
48
49
51
57 template<class CONT>
58 SG::WriteHandle<CONT> createAndStoreNoAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
59
65 template<class CONT, class AUX>
66 SG::WriteHandle<CONT> createAndStoreWithAux( const SG::WriteHandleKey<CONT>& key, const EventContext& ctx );
67
72 SG::WriteHandle<DecisionContainer> createAndStore( const SG::WriteHandleKey<DecisionContainer>& key, const EventContext& ctx );
73
77 void createAndStore( SG::WriteHandle<DecisionContainer>& handle );
78
89 Decision* newDecisionIn ( DecisionContainer* dc, const std::string& name = "" );
90
98 Decision* newDecisionIn( DecisionContainer* dc, const Decision* dOld, const std::string& name, const EventContext& ctx );
99
105 void addDecisionID( DecisionID id, Decision* d);
106
112 void insertDecisionIDs( const Decision* src, Decision* dest );
113
119
125 void uniqueDecisionIDs( Decision* dest);
126
127
132
139
146
147
151 bool allFailed( const Decision* d );
152
157 template<typename T>
159
164
169
174
178 void linkToPrevious(Decision* d, const std::string& previousCollectionKey, size_t previousIndex);
179
183 void linkToPrevious(Decision* d, const Decision* dOld, const EventContext& ctx);
184
189
194
200 bool copyLinks(const Decision* src, Decision* dest);
201
208 HLT::Identifier createLegName(const HLT::Identifier& chainIdentifier, size_t counter);
209
216 HLT::Identifier createLegName(const std::string& name, size_t counter);
217
223 HLT::Identifier getIDFromLeg(const HLT::Identifier& legIdentifier);
224
230 int32_t getIndexFromLeg(const HLT::Identifier& legIdentifier);
231
237 int32_t getIndexFromLeg(const std::string& name);
238
245 std::pair<std::string, int32_t> getNameAndIndexFromLeg(const std::string& name);
246
252 bool isLegId(const HLT::Identifier& legIdentifier);
253
259 bool isLegId(const std::string& name);
260
266 bool isChainId(const HLT::Identifier& chainIdentifier);
267
273 bool isChainId(const std::string& name);
274
279 const Decision* find(const Decision*, const std::function<bool(const Decision*)>& filter);
280
284 class HasObject {
285 public:
289 HasObject(const std::string& name): m_name(name) {}
294 bool operator()(const Decision* ) const;
295 private:
296 std::string m_name;
297 };
298
303 public:
307 HasObjectCollection(const std::string& name): m_name(name) {}
312 bool operator()(const Decision* ) const;
313 private:
314 std::string m_name;
315 };
316
317
325
326
333
334
341 const Decision* getNodeByName(const DecisionContainer& container, const std::string& nodeName);
342
343
353 std::vector<const Decision*> getRejectedDecisionNodes(const asg::EventStoreType* eventStore,
354 const EventContext& ctx,
355 const std::string& summaryCollectionKey,
356 const DecisionIDContainer& ids = {},
357 const std::set<std::string>& keysToIgnore = std::set<std::string>());
358
359
370 NavGraph& navGraph,
371 const DecisionIDContainer& ids = {},
372 const bool enforceDecisionOnStartNode = true);
373
374
382 const Decision* comingFrom,
383 NavGraph& navGraph,
384 std::set<const Decision*>& fullyExploredFrom,
385 const DecisionIDContainer& ids,
386 const bool enforceDecisionOnNode);
387
388
397 const bool keepOnlyFinalFeatures,
398 const bool removeEmptySteps,
399 const std::vector<std::string>& nodesToDrop);
400
401
408 bool modeKeep,
409 std::set<NavGraphNode*>& fullyExploredFrom,
410 const bool keepOnlyFinalFeatures,
411 const bool removeEmptySteps,
412 const std::vector<std::string>& nodesToDrop);
413
414
417 inline const std::string& initialRoIString() { return Decision::s_initialRoIString; }
418 inline const std::string& initialRecRoIString() { return Decision::s_initialRecRoIString; }
419 inline const std::string& roiString() { return Decision::s_roiString; }
420 inline const std::string& viewString() { return Decision::s_viewString; }
421 inline const std::string& featureString() { return Decision::s_featureString; }
422 inline const std::string& seedString() { return Decision::s_seedString; }
423
424 inline const std::string& hltSeedingNodeName() { return Decision::s_hltSeedingNodeNameString; }
425 inline const std::string& filterNodeName() { return Decision::s_filterNodeNameString; }
426 inline const std::string& inputMakerNodeName() { return Decision::s_inputMakerNodeNameString; }
427 inline const std::string& hypoAlgNodeName() { return Decision::s_hypoAlgNodeNameString; }
428 inline const std::string& comboHypoAlgNodeName() { return Decision::s_comboHypoAlgNodeNameString; }
430 inline const std::string& summaryPassNodeName() { return Decision::s_summaryPassNodeNameString; }
434
441 template<class CONTAINER>
442 void filterLinkVectorByContainerKey(const std::string& containerSGKey, std::vector<ElementLink<CONTAINER>>& vector);
443
444
457 template<class CONTAINER>
458 const std::vector< LinkInfo<CONTAINER> > recursiveGetFeaturesOfType(
459 const NavGraph& navGraph,
460 const std::string& containerSGKey = "",
461 const unsigned int behaviour = TrigDefs::lastFeatureOfType,
462 const std::string& navElementLinkKey = featureString(),
463 const DecisionIDContainer& chainIDs = DecisionIDContainer());
464
473 template<class CONTAINER>
475 std::vector< LinkInfo<CONTAINER> >& features,
476 std::set<const NavGraphNode*>& fullyExploredFrom,
477 const NavGraphNode* navGraphNode,
478 const std::string& containerSGKey,
479 const unsigned int behaviour,
480 const std::string& navElementLinkKey,
481 const DecisionIDContainer& chainIDs);
482
491 template<typename T>
493 findLink(const Decision* start,
494 const std::string& linkName,
495 const bool suppressMultipleLinksWarning = false);
496
509 template<typename T>
510 void
511 findLinks(const Decision* start,
512 const std::string& linkName,
513 std::vector<LinkInfo<T>>& links,
514 unsigned int behaviour = TrigDefs::allFeaturesOfType,
515 std::set<const xAOD::TrigComposite*>* fullyExploredFrom = nullptr);
516
528 template<typename T>
529 std::vector<LinkInfo<T>>
530 findLinks(const Decision* start,
531 const std::string& linkName,
532 unsigned int behaviour = TrigDefs::allFeaturesOfType);
533
547 bool typelessFindLink(const Decision* start,
548 const std::string& linkName,
549 sgkey_t& key,
550 CLID& clid,
552 const Decision*& source,
553 const bool suppressMultipleLinksWarning = false);
554
559 bool typelessFindLink(const NavGraph& subGraph,
560 const std::string& linkName,
561 sgkey_t& key,
562 CLID& clid,
564 const Decision*& source,
565 const bool suppressMultipleLinksWarning = false);
566
582 bool typelessFindLinks(const Decision* start,
583 const std::string& linkName,
584 std::vector<sgkey_t>& keyVec,
585 std::vector<CLID>& clidVec,
586 std::vector<Decision::index_type>& indexVec,
587 std::vector<const Decision*>& sourceVec,
588 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
589 std::set<const Decision*>* fullyExploredFrom = nullptr);
590
594 bool typelessFindLinks(const NavGraphNode* start,
595 const std::string& linkName,
596 std::vector<sgkey_t>& key,
597 std::vector<CLID>& clid,
598 std::vector<Decision::index_type>& index,
599 std::vector<const Decision*>& sourceVec,
600 const unsigned int behaviour = TrigDefs::allFeaturesOfType,
601 std::set<const Decision*>* fullyExploredFrom = nullptr);
602
608 const std::string& linkName,
609 std::vector<sgkey_t>& keyVec,
610 std::vector<CLID>& clidVec,
611 std::vector<Decision::index_type>& indexVec,
612 std::vector<const Decision*>& sourceVec);
613
628 const std::string& chainName,
629 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
630 const std::vector<std::size_t>& legMultiplicities,
631 const std::function<bool(const std::vector<LinkInfo<xAOD::IParticleContainer>>&)>& filter);
632
647 const std::string& chainName,
648 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
649 const std::vector<std::size_t>& legMultiplicities,
651
668 const std::string& chainName,
669 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
670 const TrigConf::HLTChain *chainInfo,
671 const std::function<bool(const std::vector<LinkInfo<xAOD::IParticleContainer>>&)>& filter);
672
689 const std::string& chainName,
690 const std::vector<LinkInfo<xAOD::IParticleContainer>>& features,
691 const TrigConf::HLTChain *chainInfo,
693
698 std::string dump( const Decision* tc, const std::function< std::string( const Decision* )>& printerFnc );
699
700}
701
703
704#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
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
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()
Combinations buildCombinations(const std::string &chainName, const std::vector< LinkInfo< xAOD::IParticleContainer > > &features, const std::vector< std::size_t > &legMultiplicities, const std::function< bool(const std::vector< LinkInfo< xAOD::IParticleContainer > > &)> &filter)
Produce the combinations for a set of features.
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'
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.
void findLinks(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...
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.
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.
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...
LinkInfo< T > findLink(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::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