From 910ff75ef2cb2c67af82b8d4034cde9737d935b6 Mon Sep 17 00:00:00 2001
From: Tim Martin <Tim.Martin@cern.ch>
Date: Wed, 19 Sep 2018 19:13:17 +0200
Subject: [PATCH] Add END OF EVENT hooks to new TrigCostMT service in the
 TriggerSummaryAlg

TriggerSummaryAlg will register the WriteHandle which stores the cost collection,
but it is the service which saves it


Former-commit-id: 70d442e9c18f09da0658a3a595f8e55661bbe294
---
 .../TrigSteer/DecisionHandling/CMakeLists.txt | 37 ++++++++++---------
 .../src/TriggerSummaryAlg.cxx                 | 12 ++++++
 .../DecisionHandling/src/TriggerSummaryAlg.h  | 13 ++++++-
 3 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/Trigger/TrigSteer/DecisionHandling/CMakeLists.txt b/Trigger/TrigSteer/DecisionHandling/CMakeLists.txt
index 1373ca5692f..89341ea3e0f 100644
--- a/Trigger/TrigSteer/DecisionHandling/CMakeLists.txt
+++ b/Trigger/TrigSteer/DecisionHandling/CMakeLists.txt
@@ -8,23 +8,24 @@ atlas_subdir( DecisionHandling )
 # Declare the package's dependencies:
 atlas_depends_on_subdirs( PUBLIC
                           Event/xAOD/xAODTrigger
-			  #                          GaudiKernel
-			  Control/AthContainers
-			  Control/AthLinks 
+                          #GaudiKernel
+                          Control/AthContainers
+                          Control/AthLinks 
                           PRIVATE
                           Control/AthViews
-                         # Control/StoreGate
+                          #Control/StoreGate
                           Control/AthenaBaseComps
-                         # Control/CxxUtils
+                          #Control/CxxUtils
                           Trigger/TrigConfiguration/TrigConfHLTData
                           #Trigger/TrigEvent/TrigSteeringEvent
                           #Trigger/TrigSteer/L1Decoder
-			  AtlasTest/TestTools
-			  Control/StoreGate
-			  Trigger/TrigSteer/TrigOutputHandling
-			  Trigger/TrigEvent/TrigSteeringEvent
-			  Trigger/TrigTools/TrigTimeAlgs )
-			  
+                          AtlasTest/TestTools
+                          Control/StoreGate
+                          Trigger/TrigSteer/TrigOutputHandling
+                          Trigger/TrigEvent/TrigSteeringEvent
+                          Trigger/TrigTools/TrigTimeAlgs
+                          Trigger/TrigMonitoring/TrigCostMonitorMT )
+
 find_package( ROOT )
 find_package( Boost )
 
@@ -39,16 +40,16 @@ atlas_add_component( DecisionHandling
                      src/components/*.cxx
                      INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
                      LINK_LIBRARIES ${Boost_LIBRARIES}
-		     ${ROOT_LIBRARIES} GaudiKernel AthViews  AthenaBaseComps CxxUtils xAODTrigger DecisionHandlingLib
+                     ${ROOT_LIBRARIES} GaudiKernel AthViews  AthenaBaseComps CxxUtils xAODTrigger DecisionHandlingLib
                      )
 
 
 atlas_add_test( TrigCompositeUtils_test
-                        SOURCES test/TrigCompositeUtils_test.cxx
-                        LINK_LIBRARIES  TestTools xAODTrigger DecisionHandlingLib
-                        AthContainers )
+                SOURCES test/TrigCompositeUtils_test.cxx
+                LINK_LIBRARIES  TestTools xAODTrigger DecisionHandlingLib
+                AthContainers )
 
 atlas_add_test( Combinators_test
-                        SOURCES test/Combinators_test.cxx
-                        LINK_LIBRARIES  TestTools xAODTrigger DecisionHandlingLib
-                        AthContainers )
+                SOURCES test/Combinators_test.cxx
+                LINK_LIBRARIES  TestTools xAODTrigger DecisionHandlingLib
+                AthContainers )
diff --git a/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.cxx b/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.cxx
index 533cf328831..6ffa61ca983 100644
--- a/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.cxx
+++ b/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.cxx
@@ -37,6 +37,11 @@ StatusCode TriggerSummaryAlg::initialize()
 
   CHECK( m_outputTools.retrieve() );
 
+  if (m_enableCostMonitoring) {
+    CHECK( m_trigCostSvcHandle.retrieve() );
+    CHECK( m_costWriteHandleKey.initialize() );
+  }
+
   return StatusCode::SUCCESS;
 }
 
@@ -91,5 +96,12 @@ StatusCode TriggerSummaryAlg::execute_r(const EventContext& context) const
   auto timeStampHandle = SG::makeHandle( m_startStampKey, context );
   ATH_MSG_DEBUG( "Time since the start of L1 decoding " << timeStampHandle.cptr()->millisecondsSince()  << " ms" );
 
+  // Do cost monitoring
+  if (m_enableCostMonitoring) {
+    SG::WriteHandle<xAOD::TrigCompositeContainer> costMonOutput = TrigCompositeUtils::createAndStore(m_costWriteHandleKey, context);
+    // Populate collection (assuming monitored event, otherwise collection will remain empty)
+    ATH_CHECK(m_trigCostSvcHandle->endEvent(context, costMonOutput));
+  }
+
   return StatusCode::SUCCESS;
 }
diff --git a/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.h b/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.h
index 5e8c6b9bc21..793dff98e4e 100644
--- a/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.h
+++ b/Trigger/TrigSteer/DecisionHandling/src/TriggerSummaryAlg.h
@@ -12,7 +12,7 @@
 #include "DecisionHandling/HLTIdentifier.h"
 #include "DecisionHandling/TrigCompositeUtils.h"
 #include "TrigOutputHandling/IHLTOutputTool.h"
-
+#include "TrigCostMonitorMT/ITrigCostMTSvc.h"
 
 /**
  * @class An algorithm reading partial decisions and storing them in an HLTResult
@@ -49,7 +49,16 @@ class TriggerSummaryAlg : public ::AthReentrantAlgorithm {
   std::map<HLT::Identifier, ChainCounter_t> m_chainIdToChainCounter;
   
   ToolHandleArray<IHLTOutputTool> m_outputTools{ this, "OutputTools", {}, "Set of tools to prepare make HLT output ready for writing out" };
-  
+
+  ServiceHandle<ITrigCostMTSvc> m_trigCostSvcHandle { this, "TrigCostMTSvc", "TrigCostMTSvc", 
+    "The trigger cost service" };
+
+  SG::WriteHandleKey<xAOD::TrigCompositeContainer> m_costWriteHandleKey { this, "CostWriteHandleKey", "TrigCostContainer",
+    "Trig composite collections summarising the HLT execution" };
+
+  Gaudi::Property<bool> m_enableCostMonitoring{this, "EnableCostMonitoring", false, 
+    "Enables end-of-event cost monitoring behavior. Only to be enabled on the very final summary alg."};
+
 }; 
 
 
-- 
GitLab