From 432b426b8c1a06707b45501b3760da09f9cfb107 Mon Sep 17 00:00:00 2001
From: Tomasz Bold <tomasz.bold@gmail.com>
Date: Tue, 19 Sep 2017 13:14:43 +0200
Subject: [PATCH] Added debugging, introduced CF to egamma test

Former-commit-id: 2c6b9f7319c3899834087714d76d32cf2b74d035
---
 .../DecisionHandling/src/DumpDecisions.cxx    |  9 ++--
 .../DecisionHandling/src/DumpDecisions.h      |  5 ++-
 .../DecisionHandling/src/RoRSeqFilter.cxx     | 34 ++++++++++-----
 .../ViewAlgs/src/EventViewCreatorAlgorithm.h  |  5 +--
 .../TrigUpgradeTest/share/egamma.withViews.py | 41 ++++++++++++++-----
 5 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.cxx b/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.cxx
index 8112a9b62fa..9898df207fe 100644
--- a/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.cxx
+++ b/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.cxx
@@ -19,15 +19,12 @@
 ////////////////
 DumpDecisions::DumpDecisions( const std::string& name, 
 			      ISvcLocator* pSvcLocator )
-  : AthReentrantAlgorithm( name, pSvcLocator )
-{
-  declareProperty( "Decisions", m_decisionKey, "Input Decisions" );
-  declareProperty( "VerbosityLevel", m_verbosityLevel, "3 - tries to print as much possible, 2 - only list of objects and their decisions, 1 - only list of active objets" );
-}
+  : AthReentrantAlgorithm( name, pSvcLocator ) 
+{}
 
 // Destructor
 ///////////////
-DumpDecisions::~DumpDecisions()
+DumpDecisions::~DumpDecisions() 
 {}
 
 // Athena Algorithm's Hooks
diff --git a/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.h b/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.h
index 50da48fe7e9..e335311a8b3 100644
--- a/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.h
+++ b/Trigger/TrigSteer/DecisionHandling/src/DumpDecisions.h
@@ -35,8 +35,9 @@ class DumpDecisions
   StatusCode finalize() override;
  private: 
 
-  SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> m_decisionKey;
-  size_t m_verbosityLevel = 3;  // see docu. of property
+  SG::ReadHandleKey<TrigCompositeUtils::DecisionContainer> m_decisionKey{ this, "Decisions", "Unspecified", "Input Decisions to dump" };
+  Gaudi::Property<size_t> m_verbosityLevel{ "VerbosityLevel", 3, "3 - tries to print as much possible, 2 - only list of objects and their decisions, 1 - only list of active objets" };
+
   /// Default constructor: 
   DumpDecisions();
 
diff --git a/Trigger/TrigSteer/DecisionHandling/src/RoRSeqFilter.cxx b/Trigger/TrigSteer/DecisionHandling/src/RoRSeqFilter.cxx
index 634db973a64..b50c771c4e3 100644
--- a/Trigger/TrigSteer/DecisionHandling/src/RoRSeqFilter.cxx
+++ b/Trigger/TrigSteer/DecisionHandling/src/RoRSeqFilter.cxx
@@ -38,9 +38,12 @@ StatusCode RoRSeqFilter::initialize()
   
   CHECK( not m_chainsProperty.empty() );
   
-  for ( auto& el: m_chainsProperty ) 
+  for ( const std::string& el: m_chainsProperty ) 
     m_chains.insert( HLT::Identifier( el ).numeric() );
 
+  for ( const HLT::Identifier& id: m_chains )
+    ATH_MSG_DEBUG( "Configured to require chain " << id );
+  
   return StatusCode::SUCCESS;
 }
 
@@ -51,19 +54,22 @@ StatusCode RoRSeqFilter::finalize() {
 StatusCode RoRSeqFilter::execute() {  
   ATH_MSG_DEBUG ( "Executing " << name() << "..." );
 
+  auto inputHandles  = m_inputKeys.makeHandles();
+  auto outputHandles = m_outputKeys.makeHandles();
+
   size_t passCounter = 0;    
   if ( m_mergeInputs ) {
     auto output = std::make_unique< ConstDataVector< TrigCompositeUtils::DecisionContainer > > ();
     output->clear( SG::VIEW_ELEMENTS );
 
-    for ( auto inputKey: m_inputKeys ) {
-      auto inputHandle = SG::makeHandle( inputKey );      
+    for ( auto inputHandle: inputHandles ) {
+      //auto inputHandle = SG::makeHandle( inputKey );      
       passCounter += copyPassing( *inputHandle, *output );
     }
 
     ATH_MSG_DEBUG( "Recording " <<  m_outputKeys[ 0 ].key() );
-    auto outputHandle = SG::makeHandle( m_outputKeys[ 0 ] );
-    CHECK( outputHandle.record( std::move( output ) ) );
+    //auto outputHandle = SG::makeHandle( m_outputKeys[ 0 ] );
+    CHECK( outputHandles[0].record( std::move( output ) ) );
 
   } else {
     size_t outputIndex = 0;
@@ -76,25 +82,32 @@ StatusCode RoRSeqFilter::execute() {
       passCounter += copyPassing( *inputHandle, *output );
 
       ATH_MSG_DEBUG( "Recording " << outputIndex << " " <<  m_outputKeys[ outputIndex ].key() );
-      auto outputHandle = SG::makeHandle( m_outputKeys[ outputIndex ] );
-      CHECK( outputHandle.record( std::move( output ) ) );
+      //auto outputHandle = SG::makeHandle( m_outputKeys[ outputIndex ] );
+      CHECK( outputHandles[outputIndex].record( std::move( output ) ) );
 
       outputIndex++;
     }
   }
 
   ATH_MSG_DEBUG( "Filter " << ( passCounter != 0 ? "passed" : "rejected") );
-  setFilterPassed( passCounter != 0 );  
+  //setFilterPassed( passCounter != 0 );  
+  setFilterPassed( true );  
   return StatusCode::SUCCESS;
 }
   
 size_t RoRSeqFilter::copyPassing( const TrigCompositeUtils::DecisionContainer& input, 
 				  ConstDataVector<TrigCompositeUtils::DecisionContainer>& output ) const {
   size_t passCounter = 0;
-  for ( auto i: input ) {
+  ATH_MSG_DEBUG( "Input size " << input.size() );
+  for ( const TrigCompositeUtils::Decision* i: input ) {
+    
     TrigCompositeUtils::DecisionIDContainer objDecisions;      
     TrigCompositeUtils::passingIDs( i, objDecisions );
-    
+    ATH_MSG_DEBUG("Number of positive decisions " << objDecisions.size() );
+    for ( TrigCompositeUtils::DecisionID id : objDecisions ) {
+      ATH_MSG_DEBUG( "Positive decision " << HLT::Identifier( id ) );
+    }
+
     std::vector<TrigCompositeUtils::DecisionID> intersection;
     std::set_intersection( m_chains.begin(), m_chains.end(),
 			   objDecisions.begin(), objDecisions.end(),
@@ -105,5 +118,6 @@ size_t RoRSeqFilter::copyPassing( const TrigCompositeUtils::DecisionContainer& i
       passCounter ++;
     }
   }
+  ATH_MSG_DEBUG( "Output size " << output.size() );
   return passCounter;  
 }
diff --git a/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.h b/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.h
index 569b77792a0..8b93f680b1c 100644
--- a/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.h
+++ b/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.h
@@ -27,7 +27,7 @@ class EventViewCreatorAlgorithm : public AthAlgorithm
 
   private:
     //Input trig composite collection to split into views
-    SG::ReadHandleKey< TrigCompositeUtils::DecisionContainer > m_inputDecisionsKey{ this, "Decisions", "Unspecified", "The name of decision container to use in making views" };
+    SG::ReadHandleKey< ConstDataVector< TrigCompositeUtils::DecisionContainer> > m_inputDecisionsKey{ this, "Decisions", "Unspecified", "The name of decision container to use in making views" };
 
     //Output views for merging
     SG::WriteHandleKey< std::vector< SG::View* > > m_viewsKey{ this, "Views", "Unspecified", "The key of views collection produced" };
@@ -36,11 +36,8 @@ class EventViewCreatorAlgorithm : public AthAlgorithm
     SG::WriteHandleKey< ConstDataVector<TrigRoiDescriptorCollection> > m_inViewRoIs{ this, "InViewRoIs", "Unspecified", "Name with which the RoIs shoudl be inserted into the views" };
     SG::WriteHandleKey< ConstDataVector<TrigCompositeUtils::DecisionContainer> > m_inViewDecisions{ this, "InViewDecisions", "Unspecified", "The name of decision container placed in the view" };
 
-
     Gaudi::Property< std::vector<std::string> > m_viewAlgorithmNames{ this, "AlgorithmNameSequence", std::vector<std::string>(), "Algorithms to run in each view" };
 
-
-
     Gaudi::Property<bool> m_viewPerRoI{ this, "ViewPerRoI", false, "Create one View per RoI as opposed to one View per Decision object, needs to be true when multiple decisions per RoI exists" };
     
     Gaudi::Property< std::string > m_algPoolName{ this, "AlgPoolName", "ViewAlgPool", "" };
diff --git a/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py b/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
index 2c3c2710b7e..5f7d4684aab 100644
--- a/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
+++ b/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
@@ -51,21 +51,23 @@ theFastCaloAlgo.OutputLevel=VERBOSE
 theFastCaloAlgo.ClustersName="L2CaloClusters"
 svcMgr.ToolSvc.TrigDataAccess.ApplyOffsetCorrection=False
 
+from AthenaCommon.CFElements import parOR, seqAND, stepSeq
+
 from DecisionHandling.DecisionHandlingConf import RoRSeqFilter
 
+
 from ViewAlgs.ViewAlgsConf import EventViewCreatorAlgorithm
 if viewTest:
-  topSequence += RoRSeqFilter("RoRSeqFilterEMCalo")
-  topSequence.RoRSeqFilterEMCalo.Input = ["EMRoIDecisions"]
-  topSequence.RoRSeqFilterEMCalo.Output = ["FilteredEMRoIDecisions"]
-  topSequence.RoRSeqFilterEMCalo.Chains = ["HLT_e5_etcut", "HLT_e7_etcut"]
-  topSequence.RoRSeqFilterEMCalo.OutputLevel = DEBUG
+  filterL1RoIsAlg = RoRSeqFilter("filterL1RoIsAlg")
+  filterL1RoIsAlg.Input = ["EMRoIDecisions"]
+  filterL1RoIsAlg.Output = ["FilteredEMRoIDecisions"]
+  filterL1RoIsAlg.Chains = ["HLT_e5_etcut", "HLT_e7_etcut"]
+  filterL1RoIsAlg.OutputLevel = DEBUG
   
   allViewAlgorithms += theFastCaloAlgo
   svcMgr.ViewAlgPool.TopAlg += [ theFastCaloAlgo.getName() ]
   l2CaloViewsMaker = EventViewCreatorAlgorithm("l2CaloViewsMaker", OutputLevel=DEBUG)
   
-  topSequence += l2CaloViewsMaker
   l2CaloViewsMaker.Decisions = "FilteredEMRoIDecisions" # from EMRoIsUnpackingTool
   l2CaloViewsMaker.RoIsLink = "initialRoI" # -||-
   l2CaloViewsMaker.InViewRoIs = "EMCaloRoIs" # contract with the fastCalo
@@ -86,7 +88,9 @@ if viewTest:
   for t in theFastCaloHypo.HypoTools:
     t.OutputLevel = DEBUG
 
-  topSequence += theFastCaloHypo
+  # topSequence += theFastCaloHypo
+
+  egammaCaloStep = stepSeq("egammaCaloStep", filterL1RoIsAlg, [ l2CaloViewsMaker, theFastCaloHypo ])
 
 else:
   topSequence += theFastCaloAlgo
@@ -268,9 +272,16 @@ theElectronFex.OutputLevel=VERBOSE
 
 
 if viewTest:
+  filterCaloRoIsAlg = RoRSeqFilter("filterCaloRoIsAlg")
+  filterCaloRoIsAlg.Input = [theFastCaloHypo.Decisions]
+  filterCaloRoIsAlg.Output = ["Filtered"+theFastCaloHypo.Decisions]
+  filterCaloRoIsAlg.Chains = ["HLT_e5_etcut", "HLT_e7_etcut"]
+  filterCaloRoIsAlg.OutputLevel = DEBUG
+
+
   l2ElectronViewsMaker = EventViewCreatorAlgorithm("l2ElectronViewsMaker", OutputLevel=DEBUG)
-  topSequence += l2ElectronViewsMaker
-  l2ElectronViewsMaker.Decisions = theFastCaloHypo.Decisions # output of L2CaloHypo
+  # topSequence += l2ElectronViewsMaker
+  l2ElectronViewsMaker.Decisions = filterCaloRoIsAlg.Output[0] # output of L2CaloHypo
   l2ElectronViewsMaker.RoIsLink = "roi" # -||-
   l2ElectronViewsMaker.InViewRoIs = "EMIDRoIs" # contract with the fastCalo
   l2ElectronViewsMaker.Views = "EMElectronViews"
@@ -303,9 +314,17 @@ if viewTest:
   theElectronHypo.HypoTools = [ TrigL2ElectronHypoToolFromName("HLT_e5_etcut"), TrigL2ElectronHypoToolFromName("HLT_e7_etcut") ]
   for t in theElectronHypo.HypoTools:
     t.OutputLevel = VERBOSE
-  topSequence += theElectronHypo
-
+  # topSequence += theElectronHypo
+  
+  egammaIDStep = stepSeq("egammaIDStep", filterCaloRoIsAlg, [ l2ElectronViewsMaker, theElectronHypo ] )
 
 else:
   # ID algs can't run w/o views yet
   pass
+
+step0 = parOR("step0", [ egammaCaloStep ] )
+step1 = parOR("step1", [ egammaIDStep ] )
+
+steps = seqAND("HLTSteps", [ step0, step1 ]  )
+topSequence += steps
+  
-- 
GitLab