16 #include "GaudiKernel/ThreadLocalContext.h"
32 ISvcLocator* pSvcLocator )
33 : base_class(
name, pSvcLocator),
34 m_trigDecisionTool(
"Trig::TrigDecisionTool/TrigDecisionTool")
37 declareProperty(
"TrigDecisionTool",
m_trigDecisionTool,
"Tool handle to TDT/Navigation.");
38 declareProperty(
"ChainsRegex",
m_chainsRegex=
"",
"Keep only information related to this chains");
39 declareProperty(
"FeatureInclusionList",
m_featureInclusionList,
"This features will be kept. This setting overrules the FeatureExclusionList. Only list of types or type#key pairs are supported.");
40 declareProperty(
"FeatureExclusionList",
m_featureExclusionList,
"This features will be dropeed. It can be specified as * meaning all, or as a list of typenames, or typename#key pairs.");
41 declareProperty(
"ReportOperations",
m_report=
false,
"Additional verbosity flag, when enabled the operations on trigger elements are reported (VERBOSE logging level)");
57 std::string possibleActions;
59 possibleActions +=
a.first +
" ";
60 declareProperty(
"Actions",
m_actions,
"Operations which need to be done on the navigation"+possibleActions);
74 m_checkToolDeps =
false;
81 return StatusCode::FAILURE;
83 ATH_MSG_INFO (
"Successfully retrived the TrigDecisionTool!" );
86 ATH_MSG_FATAL (
"Could not retrive the TrigDecisionTool as it was not specified!" );
87 return StatusCode::FAILURE;
90 ATH_MSG_DEBUG (
"Leaving TrigNavigationThinningSvc::Initialize" );
93 ATH_MSG_ERROR(
"Can't use the features inclusion and exclusion lists at the same time.");
94 return StatusCode::FAILURE;
104 ATH_MSG_FATAL(
"Dropping features is demanded but neither inclusion and exclusion lists are set");
105 return StatusCode::FAILURE;
115 return StatusCode::FAILURE;
118 return StatusCode::SUCCESS;
127 return StatusCode::SUCCESS;
134 std::vector<unsigned int>
cuts;
135 std::vector<uint32_t>
temp;
140 ATH_MSG_DEBUG (
"Reloaded the navigation content in TDT (all clients will see reduced navigation content) ..." );
141 return StatusCode::SUCCESS;
146 std::vector<unsigned int>
cuts;
149 return StatusCode::SUCCESS;
159 return StatusCode::SUCCESS;
166 return StatusCode::SUCCESS;
181 return StatusCode::SUCCESS;
190 std::set<std::pair<CLID, uint16_t> > toDelete;
191 std::set<std::pair<CLID, uint16_t> > toRetain;
196 if ( holders.empty() ) {
197 ATH_MSG_ERROR(
"The navigation does not contain any features. This is likely a configuration problem.");
198 return StatusCode::FAILURE;
201 for(
auto h : holders ) {
212 toRetain.insert(std::make_pair(
h->typeClid(),
h->subTypeIndex() ));
213 ATH_MSG_DEBUG(
"will be keeping references associated to: " <<
h->collectionName()<<
"#"<<
h->key() <<
" clid: " <<
h->typeClid() );
220 toDelete.insert(std::make_pair(
h->typeClid(),
h->subTypeIndex() ));
221 ATH_MSG_DEBUG(
"will be dropping references associated to: " <<
h->collectionName()<<
"#"<<
h->key() );
227 if ( not toRetain.empty() )
229 if ( not toDelete.empty() )
237 return StatusCode::SUCCESS;
246 return StatusCode::SUCCESS;
252 and te->getRelated(TriggerElement::seedsRelation).empty() )
255 return StatusCode::SUCCESS;
260 if ( te->getFeatureAccessHelpers().empty() )
263 return StatusCode::SUCCESS;
269 return StatusCode::SUCCESS;
281 return StatusCode::SUCCESS;
288 std::vector<uint32_t>& slimmed_and_serialized)
const {
290 ATH_MSG_DEBUG(
name() <<
" is obtaining the TrigNavigationThinningSvc lock in slot " << ctx.slot() <<
" for event " << ctx.eventID().event_number() );
299 ATH_MSG_WARNING (
"Could not get navigation from Trigger Decision Tool" );
302 return StatusCode::SUCCESS;
305 State state (ctx, *cnav, slimmed_and_serialized);
309 std::vector<uint32_t>
cuts;
317 auto function = ifunc->second;
318 CHECK( (this->*
function)(state) );
322 return StatusCode::SUCCESS;
328 return StatusCode::SUCCESS;
339 ATH_MSG_DEBUG(
"Will keep information related to this chains" << chainGroup->getListOfTriggers());
340 auto confTEs = chainGroup->getHLTTriggerElements();
341 for (
auto&
vec: confTEs) {
342 for (
auto confTEPtr:
vec) {
346 return StatusCode::SUCCESS;
351 bool propagateFeatures)
const {
354 return StatusCode::SUCCESS;
363 if ( propagateFeatures )
370 const std::vector<TriggerElement*>& sameRoI = te->
getRelated(TriggerElement::sameRoIRelation);
372 for(
auto nodeInRoI : sameRoI ) {
375 std::vector<TriggerElement*>& relations = nodeInRoI->m_relations[ TriggerElement::sameRoIRelation ];
382 std::vector<TriggerElement*> seededBy = te->
m_relations[TriggerElement::seededByRelation];
384 for(
auto seededByNode: seededBy ) {
387 std::vector<TriggerElement*>& relations = seededByNode->m_relations[ TriggerElement::seedsRelation ];
394 seededByNode->relate( te->
m_relations[ TriggerElement::seedsRelation ], TriggerElement::seedsRelation );
400 std::vector<TriggerElement*>& seeds = te->
m_relations[TriggerElement::seedsRelation];
402 for(
auto seedsNode: seeds ) {
405 std::vector<TriggerElement*>& relations = seedsNode->m_relations[ TriggerElement::seededByRelation ];
410 seedsNode->relate( te->
m_relations[ TriggerElement::seededByRelation ], TriggerElement::seededByRelation );
413 return StatusCode::SUCCESS;
422 const std::set<std::pair<CLID, uint16_t> >& toDelete)
const {
435 ATH_MSG_DEBUG(
"Will remove " << toDelete.size()<<
" feature type/key");
438 for (
auto& fea: te->getFeatureAccessHelpers() ) {
439 if ( toDelete.find( std::make_pair(fea.getCLID(), fea.getIndex().subTypeIndex()) ) != toDelete.end() )
449 return StatusCode::SUCCESS;
454 const std::set<std::pair<CLID, uint16_t> >& toRetain)
const {
455 ATH_MSG_DEBUG(
"Will retain " << toRetain.size()<<
" feature type/key");
458 for (
auto& fea: te->getFeatureAccessHelpers() ) {
459 if ( toRetain.find( std::make_pair(fea.getCLID(), fea.getIndex().subTypeIndex()) ) == toRetain.end() )
463 return StatusCode::SUCCESS;
473 size_t featuresCount = std::count_if(te->getFeatureAccessHelpers().begin(),
474 te->getFeatureAccessHelpers().end(),
477 if( featuresCount == 0 ) {
481 return StatusCode::SUCCESS;
492 return StatusCode::SUCCESS;
495 v.erase(newend,
v.end());
497 return StatusCode::SUCCESS;
502 std::vector<std::string> *inclusionList, std::vector<std::string> *exclusionList) {
505 if(inclusionList && inclusionList->size() > 0) {
508 int onExclusionList = 0;
509 for(std::vector< TriggerElement::FeatureAccessHelper >::const_iterator iter =
516 if(exclusionList &&
std::find(exclusionList->begin(), exclusionList->end(),
534 if(!exclusionList || exclusionList->size() == 0)
537 for(std::vector< TriggerElement::FeatureAccessHelper >::const_iterator iter =
552 std::vector<TriggerElement*> *inclusionList,
553 std::vector<TriggerElement*> *exclusionList) {
566 if(inclusionList && inclusionList->size() > 0) {
569 if(std::find_if(inclusionList->begin(), inclusionList->end(),
573 if(exclusionList && std::find_if(exclusionList->begin(), exclusionList->end(),
583 if(!exclusionList || exclusionList->size() == 0)
587 if(std::find_if(exclusionList->begin(), exclusionList->end(),
601 return StatusCode::SUCCESS;
603 const std::vector<TriggerElement::FeatureAccessHelper>& features = te->getFeatureAccessHelpers() ;
605 const std::vector<TriggerElement*>
children = te->getRelated(TriggerElement::seedsRelation);
610 for(
auto& fea: features ) {
614 std::stringstream
ss;
618 ch->getFeatureAccessHelpers().insert(
ch->getFeatureAccessHelpers().begin(), fea );
622 return StatusCode::SUCCESS;
637 while( mother->
getRelated(TriggerElement::seededByRelation).size() > 0 ) {
639 mother = m_RoI->
getRelated(TriggerElement::seededByRelation)[0];
654 if(te->
getId() != m_id)
664 while( mother->
getRelated(TriggerElement::seededByRelation).size() > 0 ) {
666 mother = RoI->
getRelated(TriggerElement::seededByRelation)[0];
672 const std::vector< TriggerElement::FeatureAccessHelper > firstFeatures = m_RoI->getFeatureAccessHelpers();
673 const std::vector< TriggerElement::FeatureAccessHelper > secondFeatures = m_RoI->getFeatureAccessHelpers();
675 if(firstFeatures.size() != secondFeatures.size())
678 for(
unsigned int i = 0;
i < firstFeatures.size();
i++) {
704 struct IndexRecalculator {
709 size_t getNewIndex(
size_t oldIndex) {
710 if ( oldIndex >= m_indices.size() ) {
713 return m_indices[oldIndex];
716 void expand(
size_t maxIndex ) {
717 const size_t checkedSoFar = m_validIndices.size();
718 m_indices.resize(maxIndex+1, RemovedIdx);
719 m_validIndices.resize(maxIndex+1);
721 for (
size_t toScan = checkedSoFar; toScan <= maxIndex; ++ toScan ) {
722 size_t newIndex = m_dec->index(toScan);
723 m_validIndices[toScan] = newIndex;
726 for (
size_t toScan = checkedSoFar; toScan <= maxIndex; ++toScan ) {
727 m_indices[toScan] = std::count_if(m_validIndices.begin(), m_validIndices.begin()+toScan,
728 [](
const size_t x){ return x != RemovedIdx; } );
733 std::vector<size_t> m_indices = {0};
734 std::vector<size_t> m_validIndices;
740 const EventContext& ctx = Gaudi::Hive::currentContext();
746 if ( holders.empty() ) {
747 ATH_MSG_ERROR(
"The navigation does not contain any features. This is likely a configuration problem.");
748 return StatusCode::FAILURE;
751 for(
auto holder : holders) {
753 if ( not ipd->
proxy(holder->containerClid(), holder->label() ) ) {
754 ATH_MSG_DEBUG(
"Skipping feature missing in the store: " << holder->label());
757 holder->syncWithSG();
761 ATH_MSG_DEBUG (
"Thinning occured for this container" << *holder <<
", going to ajust the indices" );
770 IndexRecalculator recalculator( dec );
773 for (
auto& fea: te->getFeatureAccessHelpers() ) {
774 if ( fea.getCLID() == holder->typeClid()
775 and fea.getIndex().subTypeIndex() == holder->subTypeIndex() ) {
782 idx.updateBeginAndEnd(newBegin, newEnd);
794 return StatusCode::SUCCESS;