|
ATLAS Offline Software
|
Go to the documentation of this file.
14 #include <unordered_map>
32 auto data = std::make_unique<DecisionContainer>() ;
33 auto aux = std::make_unique<DecisionAuxContainer>() ;
34 data->setStore( aux.get() );
35 handle.
record( std::move(
data ), std::move( aux ) ).ignore();
40 auto data = std::make_unique<DecisionContainer>() ;
41 auto aux = std::make_unique<DecisionAuxContainer>() ;
42 data->setStore( aux.get() );
43 handle.
record( std::move(
data ), std::move( aux ) ).ignore();
49 if ( !
name.empty() ) {
62 std::vector<DecisionID>&
decisions = readWriteAccessor( *
d );
68 const std::vector<DecisionID>&
decisions = readOnlyAccessor( *
d );
73 return readOnlyAccessor( *
d );
77 return readWriteAccessor( *
d );
91 collateIDs.insert(
src.begin(),
src.end() );
104 const std::vector<DecisionID>&
decisions = readOnlyAccessor( *
d );
118 return idSet.find(
id ) != idSet.end();
121 #if !defined(XAOD_STANDALONE) && !defined(XAOD_ANALYSIS) // Full athena
125 throw std::runtime_error(
"TrigCompositeUtils::convertToElementLink Using convertToElementLink(d) requires that the Decision d is already in a container");
129 #else // Analysis or Standalone
133 throw std::runtime_error(
"TrigCompositeUtils::convertToElementLink Using convertToElementLink(d) requires that the Decision d is already in a container");
141 if (!seed.isValid()) {
142 throw std::runtime_error(
"TrigCompositeUtils::linkToPrevious Invalid Decision Link key or index provided");
153 return d->hasObjectCollectionLinks(
seedString() );
162 return dest->copyAllLinksFrom(
src);
167 const std::string&
name = chainIdentifier.
name();
169 throw std::runtime_error(
"TrigCompositeUtils::createLegName chainIdentifier '"+chainIdentifier.
name()+
"' does not start 'HLT_'");
172 throw std::runtime_error(
"TrigCompositeUtils::createLegName Leg counters above 999 are invalid.");
174 std::stringstream legStringStream;
175 legStringStream <<
"leg" << std::setfill(
'0') << std::setw(3) <<
counter <<
"_" <<
name;
181 const std::string&
name = legIdentifier.
name();
183 return legIdentifier;
187 throw std::runtime_error(
"TrigCompositeUtils::getIDFromLeg legIdentifier '"+
name+
"' does not start with 'HLT_' or 'leg' ");
201 return std::stoi(
name.substr(3,3) );
209 return (
name.rfind(
"leg", 0) != std::string::npos);
217 return (
name.rfind(
"HLT_", 0) != std::string::npos);
256 const auto it = std::find_if(container.
begin(), container.
end(), [&nodeName](
const Decision*
d){return d->name()==nodeName;});
257 if (
it==container.
end()) {
return nullptr;}
262 const std::string& summaryCollectionKey,
264 const std::set<std::string>& keysToIgnore) {
269 static const std::vector<std::string> knownDistributedSummaryStores{
276 static const std::vector<std::string> knownCompactSummaryStores{
"HLTNav_Summary_OnlineSlimmed",
277 "HLTNav_Summary_ESDSlimmed",
278 "HLTNav_Summary_AODSlimmed",
279 "HLTNav_Summary_DAODSlimmed",
280 "HLTNav_R2ToR3Summary"
283 std::vector<std::string>
keys;
285 if (
std::find(knownDistributedSummaryStores.cbegin(), knownDistributedSummaryStores.cend(), summaryCollectionKey) != knownDistributedSummaryStores.end() or summaryCollectionKey ==
"") {
289 #ifndef XAOD_STANDALONE
295 throw std::runtime_error(
"Cannot obtain rejected HLT features in AnalysisBase when reading from uncompactified navigation containers, run trigger navigation slimming first if you really need this.");
298 }
else if (
std::find(knownCompactSummaryStores.cbegin(), knownCompactSummaryStores.cend(), summaryCollectionKey) != knownCompactSummaryStores.end()) {
300 keys.push_back(summaryCollectionKey);
304 using namespace msgRejected;
305 ANA_MSG_WARNING(
"getRejectedDecisionNodes has not been told about final collection " << summaryCollectionKey <<
" please update this function. Assuming that it is already compact.");
307 keys.push_back(summaryCollectionKey);
311 std::vector<const Decision*>
output;
314 for (
const std::string&
key :
keys) {
316 if ( ! (
key.starts_with(
"HLTNav_") ||
key.starts_with(
"_HLTNav_")) ) {
319 if (keysToIgnore.count(
key) == 1) {
324 throw std::runtime_error(
"Unable to retrieve " +
key +
" from event store.");
332 if (mySeeds.size() == 0) {
336 if (!allSeedsValid) {
337 using namespace msgRejected;
339 <<
"The trigger navigation information is incomplete. Skipping this Decision object.");
344 decisionIDs(*(mySeeds.at(0)), activeChainsIntoThisDecision);
345 if (mySeeds.size() > 1) {
346 for (
size_t i = 1;
i < mySeeds.size(); ++
i) {
352 moreActiveChains.begin(), moreActiveChains.end(),
362 if (
ids.size() == 0) {
363 chainsToCheck = activeChainsIntoThisDecision;
371 for (
const DecisionID checkID : chainsToCheck) {
372 if (activeChainsPassedByThisDecision.find(checkID) == activeChainsPassedByThisDecision.end() &&
373 activeChainsIntoThisDecision.count(checkID) == 1) {
386 std::set<const Decision*>& fullyExploredFrom,
388 const bool enforceDecisionOnNode) {
398 #if TRIGCOMPUTILS_ENABLE_EARLY_EXIT == 1
400 if (fullyExploredFrom.count(
node) == 1) {
410 const Decision* seedDecision = *(seed);
417 fullyExploredFrom.insert(
node);
425 const bool enforceDecisionOnStartNode) {
427 std::set<const Decision*> fullyExploredFrom;
436 const bool keepOnlyFinalFeatures,
437 const bool removeEmptySteps,
438 const std::vector<std::string>& nodesToDrop)
440 std::set<NavGraphNode*> fullyExploredFrom;
449 std::set<NavGraphNode*>& fullyExploredFrom,
450 const bool keepOnlyFinalFeatures,
451 const bool removeEmptySteps,
452 const std::vector<std::string>& nodesToDrop)
457 bool keep = modeKeep;
463 const Decision*
const myFirstParent = (
node->seeds().size() ?
node->seeds().at(0)->
node() :
nullptr);
464 const Decision*
const myFirstChild = (
node->children().size() ?
node->children().at(0)->
node() :
nullptr);
468 if (keepOnlyFinalFeatures) {
484 if (!specialBphysCase && !specialR2toR3Case) {
498 for (
const std::string& toDrop : nodesToDrop) {
499 if (me->
name() == toDrop) {
547 #if TRIGCOMPUTILS_ENABLE_EARLY_EXIT == 1
561 bool allowEarlyExit =
true;
562 if (keepOnlyFinalFeatures) {
563 allowEarlyExit = (modeKeep ==
false);
565 if (allowEarlyExit && fullyExploredFrom.count(seed) == 1) {
575 fullyExploredFrom.insert(
node);
580 const std::string& linkName,
581 std::vector<sgkey_t>& keyVec,
582 std::vector<uint32_t>& clidVec,
583 std::vector<Decision::index_type>& indexVec,
584 std::vector<const Decision*>& sourceVec,
585 const unsigned int behaviour,
586 std::set<const Decision*>* fullyExploredFrom)
588 using namespace msgFindLink;
591 if (keyVec.size() != clidVec.size() or clidVec.size() != indexVec.size()) {
592 ANA_MSG_WARNING(
"In typelessFindLinks, keyVec, clidVec, indexVec must all be the same size. Instead have:"
593 << keyVec.size() <<
", " << clidVec.size() <<
", " << indexVec.size());
601 if (
found && behaviour == TrigDefs::lastFeatureOfType) {
606 #if TRIGCOMPUTILS_ENABLE_EARLY_EXIT == 1
607 if (fullyExploredFrom !=
nullptr) {
610 if (fullyExploredFrom->count(*seed) == 1) {
615 found |=
typelessFindLinks(*seed, linkName, keyVec, clidVec, indexVec, sourceVec, behaviour, fullyExploredFrom);
618 if (fullyExploredFrom !=
nullptr) {
619 fullyExploredFrom->insert(
start);
626 const std::string& linkName,
627 std::vector<sgkey_t>& keyVec,
628 std::vector<uint32_t>& clidVec,
629 std::vector<Decision::index_type>& indexVec,
630 std::vector<const Decision*>& sourceVec,
631 const unsigned int behaviour,
632 std::set<const Decision*>* fullyExploredFrom)
634 using namespace msgFindLink;
637 if (keyVec.size() != clidVec.size() or clidVec.size() != indexVec.size()) {
638 ANA_MSG_WARNING(
"In typelessFindLinks, keyVec, clidVec, indexVec must all be the same size. Instead have:"
639 << keyVec.size() <<
", " << clidVec.size() <<
", " << indexVec.size());
648 if (
found && behaviour == TrigDefs::lastFeatureOfType) {
653 #if TRIGCOMPUTILS_ENABLE_EARLY_EXIT == 1
654 if (fullyExploredFrom !=
nullptr) {
657 const Decision* seed_decisionObject = seed->node();
658 if (fullyExploredFrom->count(seed_decisionObject) == 1) {
663 found |=
typelessFindLinks(seed, linkName, keyVec, clidVec, indexVec, sourceVec, behaviour, fullyExploredFrom);
666 if (fullyExploredFrom !=
nullptr) {
667 fullyExploredFrom->insert(start_decisionObject);
674 const std::string& linkName,
675 std::vector<sgkey_t>& keyVec,
676 std::vector<uint32_t>& clidVec,
677 std::vector<Decision::index_type>& indexVec,
678 std::vector<const Decision*>& sourceVec)
681 std::vector<sgkey_t> tmpKeyVec;
682 std::vector<uint32_t> tmpClidVec;
683 std::vector<Decision::index_type> tmpIndexVec;
684 if (
start->hasObjectCollectionLinks(linkName)) {
685 found =
start->typelessGetObjectCollectionLinks(linkName, tmpKeyVec, tmpClidVec, tmpIndexVec);
687 if (
start->hasObjectLink(linkName)) {
691 found |=
start->typelessGetObjectLink(linkName, tmpKey, tmpClid, tmpIndex);
692 tmpKeyVec.push_back(tmpKey);
693 tmpClidVec.push_back(tmpClid);
694 tmpIndexVec.push_back(tmpIndex);
697 for (
size_t tmpi = 0; tmpi < tmpKeyVec.size(); ++tmpi) {
698 bool alreadyAdded =
false;
699 const uint32_t tmpKey = tmpKeyVec.at(tmpi);
700 const uint32_t tmpClid = tmpClidVec.at(tmpi);
702 for (
size_t veci = 0; veci < keyVec.size(); ++veci) {
704 and clidVec.at(veci) == tmpClid
705 and indexVec.at(veci) == tmpIndex)
712 keyVec.push_back( tmpKey );
713 clidVec.push_back( tmpClid );
714 indexVec.push_back( tmpIndex );
715 sourceVec.push_back(
start );
724 const std::string& linkName,
729 const bool suppressMultipleLinksWarning)
731 using namespace msgFindLink;
738 std::vector<sgkey_t> keyVec;
739 std::vector<uint32_t> clidVec;
740 std::vector<Decision::index_type> indexVec;
741 std::vector<const Decision*> sourceVec;
742 std::set<const xAOD::TrigComposite*> fullyExploredFrom;
744 const bool result =
typelessFindLinks(
start, linkName, keyVec, clidVec, indexVec, sourceVec, TrigDefs::lastFeatureOfType, &fullyExploredFrom);
749 if (keyVec.size() > 1 && !suppressMultipleLinksWarning) {
750 ANA_MSG_WARNING (keyVec.size() <<
" typeless links found for " << linkName
751 <<
" returning the first link, consider using findLinks.");
754 clid = clidVec.at(0);
755 index = indexVec.at(0);
762 const std::string& linkName,
767 const bool suppressMultipleLinksWarning)
769 using namespace msgFindLink;
773 std::vector<sgkey_t> keyVec;
774 std::vector<uint32_t> clidVec;
775 std::vector<Decision::index_type> indexVec;
776 std::vector<const Decision*> sourceVec;
777 std::set<const Decision*> fullyExploredFrom;
781 result |=
typelessFindLinks(finalNode, linkName, keyVec, clidVec, indexVec, sourceVec, TrigDefs::lastFeatureOfType, &fullyExploredFrom);
788 if (keyVec.size() > 1 && !suppressMultipleLinksWarning) {
789 ANA_MSG_WARNING (keyVec.size() <<
" typeless links found for " << linkName
790 <<
" returning the first link, consider using findLinks.");
793 clid = clidVec.at(0);
794 index = indexVec.at(0);
803 const std::vector<std::size_t>& legMultiplicities,
808 if (legMultiplicities.size() == 1)
811 for (std::size_t legIdx = 0; legIdx < legMultiplicities.size(); ++legIdx)
814 if (legMultiplicities[legIdx] == 0)
817 std::vector<LinkInfo<xAOD::IParticleContainer>> legFeatures;
820 legFeatures.push_back(
info);
821 combinations.addLeg(legMultiplicities.at(legIdx), std::move(legFeatures));
830 const std::vector<std::size_t>& legMultiplicities,
857 ret += printerFnc( tc );
861 ret +=
" -> " +
dump( *seedEL, printerFnc );
const std::string & summaryPrescaledNodeName()
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 std::string & summaryFilterNodeName()
char data[hepevt_bytes_allocation_ATLAS]
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 ...
xAOD::TrigCompositeContainer DecisionContainer
bool passed(DecisionID id, const DecisionIDContainer &idSet)
checks if required decision ID is in the set of IDs in the container
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.
std::string find(const std::string &s)
return a remapped string
const std::string & summaryPassExpressNodeName()
TrigCompositeUtils::DecisionID numeric() const
numeric ID
const std::string & hltSeedingNodeName()
Helper class to provide type-safe access to aux data.
bool operator()(const Decision *) const
checks if the arg Decision object has link collection of name specified at construction
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< NavGraphNode * > & finalNodes() const
Get all final nodes.
const std::string & hypoAlgNodeName()
void addDecisionID(DecisionID id, Decision *d)
Appends the decision (given as ID) to the decision object.
bool hasObjectLink(const std::string &name, const CLID clid=CLID_NULL) const
Check if a link to an object with a given name and type exists. CLID_NULL to not check type.
const OBJECT * object(const std::string &name) const
Get a bare pointer with the requested name.
static const std::string s_featureString
Constant used to identify a feature.
bool typelessFindLinksCommonLinkCollection(const Decision *start, const std::string &linkName, std::vector< sgkey_t > &keyVec, std::vector< uint32_t > &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...
void insertDecisionIDs(const Decision *src, Decision *dest)
Appends the decision IDs of src to the dest decision object.
const std::string & comboHypoAlgNodeName()
SG::WriteHandle< DecisionContainer > createAndStore(const SG::WriteHandleKey< DecisionContainer > &key, const EventContext &ctx)
Creates and right away records the DecisionContainer with the key.
void addNode(const Decision *node, const Decision *comingFrom=nullptr)
Add a new NavGraphNode which shadows the xAOD Decision object "node" from the full navigation graph.
const std::string & initialRecRoIString()
Helper class to provide constant type-safe access to aux data.
static const std::string s_seedString
Constant used to identify a seed (parent)
bool hasObjectCollectionLinks(const std::string &collectionName, const CLID clid=CLID_NULL) const
Check if links exist to a collection of objects with given name and type. CLID_NULL to not check type...
static const std::string s_initialRoIString
Constant used to identify an initial ROI from L1.
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.
bool const RAWDATA *ch2 const
HLT chain configuration information.
void keys(std::vector< std::string > &vkeys, bool includeAlias=false, bool onlyValid=true) const
provide list of all StoreGate keys associated with an object.
std::vector< std::string > intersection(std::vector< std::string > &v1, std::vector< std::string > &v2)
const std::vector< size_t > & leg_multiplicities() const
static const std::string s_hypoAlgNodeNameString
Constant used to identify a navigation graph node as being from a Hypo Alg.
bool operator()(const Decision *) const
checks if the arg TC has link of name specified at construction
static const std::string s_summaryPassNodeNameString
Constant used to identify the single terminus graph node the end point of all chains which accept the...
const Decision * getTerminusNode(SG::ReadHandle< DecisionContainer > &container)
static const CLID & ID()
the CLID of T
The Athena Transient Store API.
static const std::string s_comboHypoAlgNodeNameString
Constant used to identify a navigation graph node as being from a Combo Hypo Alg.
std::vector< const Decision * > getRejectedDecisionNodes(const asg::EventStoreType *eventStore, 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...
const std::string & initialRoIString()
const std::vector< ElementLink< DecisionContainer > > getLinkToPrevious(const Decision *d)
returns links to previous decision object 'seed'
bool typelessFindLinks(const Decision *start, const std::string &linkName, std::vector< sgkey_t > &keyVec, std::vector< uint32_t > &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 Decision * getExpressTerminusNode(const DecisionContainer &container)
Returns the express-accept navigation node from a collection or nullptr if missing.
static const std::string s_filterNodeNameString
Constant used to identify a navigation graph node as being from a Filter.
Default, invalid implementation of ClassID_traits.
bool copyLinks(const Decision *src, Decision *dest)
copy all links from src to dest TC objects
ElementLink< DecisionContainer > decisionToElementLink(const Decision *d, const EventContext &ctx)
Takes a raw pointer to a Decision and returns an ElementLink to the Decision.
static const std::string s_summaryFilterNodeNameString
Constant used to identify a navigation graph node as being from a final Filter created by the Decisio...
Structure to hold a transient Directed Acyclic Graph (DAG) structure. NavGraph is populated from,...
Class used to describe composite objects in the HLT.
uint32_t CLID
The Class ID type.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
static const std::string s_hltSeedingNodeNameString
Constant used to identify a navigation graph node as being from the HLTSeeding.
ElementLink implementation for ROOT usage.
const std::string & featureString()
bool isChainId(const HLT::Identifier &chainIdentifier)
Recognise whether the HLT identifier corresponds to a whole chain.
xAOD::TrigComposite Decision
static const std::string s_initialRecRoIString
Constant used to identify an initial HLT ROI derived from L1.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const std::string & summaryPassNodeName()
std::function< bool(const std::vector< LinkInfo< xAOD::IParticleContainer >> &)> getFilter(FilterType filter)
Get a lambda corresponding to the specified FilterType enum.
HLT::Identifier createLegName(const HLT::Identifier &chainIdentifier, size_t counter)
Generate the HLT::Identifier which corresponds to a specific leg of a given chain.
bool hasLinkToPrevious(const Decision *d)
checks if there is at least one 'seed' link to previous object
def combinations(items, n)
const std::string & filterNodeName()
const std::string & name() const
Get a human-readable name for the object.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
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::string & seedString()
bool isLegId(const HLT::Identifier &legIdentifier)
Recognise whether the chain ID is a leg ID.
int32_t getIndexFromLeg(const HLT::Identifier &legIdentifier)
Extract the numeric index of a leg identifier.
std::set< DecisionID > DecisionIDContainer
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Transient utility class to represent a node in a graph (m_decisionObject), and a vector of edges (m_f...
bool allFailed(const Decision *d)
return true if there is no positive decision stored
void decisionIDs(const Decision *d, DecisionIDContainer &destination)
Extracts DecisionIDs stored in the Decision object.
std::string name() const
reports human redable name if it is enabled or, empty string
void recursiveFlagForThinning(NavGraph &graph, const bool keepOnlyFinalFeatures, const bool removeEmptySteps, const std::vector< std::string > &nodesToDrop)
Used by trigger navigation thinning.
std::string dump(const Decision *tc, const std::function< std::string(const Decision *)> &printerFnc)
Prints the Decision object including the linked seeds @warnign expensive call.
const std::string & roiString()
static const std::string s_viewString
Constant used to identify a view.
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.
HLT::Identifier getIDFromLeg(const HLT::Identifier &legIdentifier)
Generate the HLT::Identifier which corresponds to the chain name from the leg name.
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.
void uniqueDecisionIDs(Decision *dest)
Make unique list of decision IDs of dest Decision object.
static const std::string s_summaryPassExpressNodeNameString
Constant used to identify the single express-accept graph node.
Set * set_intersection(Set *set1, Set *set2)
Perform an intersection of two sets.
bool isAnyIDPassing(const Decision *d, const DecisionIDContainer &required)
Checks if any of the DecisionIDs passed in arg required is availble in Decision object.
const std::string & viewString()
constexpr bool sgkeyEqual(const sgkey_t a, const sgkey_t b)
Compare two sgkeys for equality.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Base class for elements of a container that can have aux data.
const std::string & inputMakerNodeName()
void recursiveGetDecisionsInternal(const Decision *node, const Decision *comingFrom, NavGraph &navGraph, std::set< const Decision * > &fullyExploredFrom, const DecisionIDContainer &ids, const bool enforceDecisionOnNode)
Used by recursiveGetDecisions.
static const std::string s_roiString
Constant used to identify an (explicitly) updated HLT ROI.
bool typelessFindLink(const Decision *start, const std::string &linkName, sgkey_t &key, uint32_t &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...