From d342677a1c5c12890258b0f45f11647c1879f9b8 Mon Sep 17 00:00:00 2001
From: Tim Martin <Tim.Martin@cern.ch>
Date: Thu, 30 Aug 2018 19:35:13 +0200
Subject: [PATCH] Initial commit of cost mon MT

Former-commit-id: a588601e0d27a23034241626a1bdcf8506a3f14e
---
 .../TrigCostMonitorMT/CMakeLists.txt          | 23 ++++++
 .../TrigCostMonitorMT/ITrigCostMTSvc.h        | 19 +++++
 .../TrigCostMonitorMT/TrigCostMTAuditor.h     | 60 ++++++++++++++++
 .../TrigCostMonitorMT/TrigCostMTSvc.h         | 26 +++++++
 .../src/TrigCostMTAuditor.cxx                 | 70 +++++++++++++++++++
 .../TrigCostMonitorMT/src/TrigCostMTSvc.cxx   | 59 ++++++++++++++++
 .../components/TrigCostMonitorMT_entries.cxx  |  9 +++
 .../TrigUpgradeTest/share/egamma.withViews.py | 13 ++--
 8 files changed, 270 insertions(+), 9 deletions(-)
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/CMakeLists.txt
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/ITrigCostMTSvc.h
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTAuditor.h
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTSvc.h
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTAuditor.cxx
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
 create mode 100644 Trigger/TrigMonitoring/TrigCostMonitorMT/src/components/TrigCostMonitorMT_entries.cxx

diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/CMakeLists.txt b/Trigger/TrigMonitoring/TrigCostMonitorMT/CMakeLists.txt
new file mode 100644
index 00000000000..b34dad3847b
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/CMakeLists.txt
@@ -0,0 +1,23 @@
+################################################################################
+# Package: TrigCostMonitorMT
+################################################################################
+
+# Declare the package name:
+atlas_subdir( TrigCostMonitorMT )
+
+# Declare the package's dependencies:
+atlas_depends_on_subdirs( PUBLIC
+                          GaudiKernel
+                          PRIVATE
+                          Control/AthenaBaseComps
+                          TestPolicy )
+
+# Component(s) in the package:
+atlas_add_component( TrigCostMonitorMT
+                     src/*.cxx
+                     src/components/*.cxx 
+                     LINK_LIBRARIES GaudiKernel AthenaBaseComps )
+
+# Install files from the package:
+atlas_install_headers( TrigCostMonitorMT )
+atlas_install_joboptions( share/*.py )
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/ITrigCostMTSvc.h b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/ITrigCostMTSvc.h
new file mode 100644
index 00000000000..d02ceeec73c
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/ITrigCostMTSvc.h
@@ -0,0 +1,19 @@
+ /*
+ * Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration.
+ */
+
+#ifndef TRIGCOSTMONITORMT_ITRIGCOSTMTSVC_H
+#define TRIGCOSTMONITORMT_ITRIGCOSTMTSVC_H
+
+#include "GaudiKernel/IInterface.h"
+
+class ITrigCostMTSvc : virtual public IInterface {
+public:
+  DeclareInterfaceID(ITrigCostMTSvc, 1, 0);
+
+  virtual StatusCode beginAlg(const std::string& caller) = 0; 
+  virtual StatusCode endAlg(const std::string& caller) = 0; 
+
+};
+
+#endif // TRIGCOSTMONITORMT_ITRIGCOSTMTSVC_H
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTAuditor.h b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTAuditor.h
new file mode 100644
index 00000000000..4c3190e09a7
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTAuditor.h
@@ -0,0 +1,60 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGCOSTMONITORMT_TRIGCOSTMTAUDITOR_H
+#define TRIGCOSTMONITORMT_TRIGCOSTMTAUDITOR_H
+
+#include "GaudiKernel/Auditor.h"
+#include "GaudiKernel/ServiceHandle.h"
+
+#include "AthenaBaseComps/AthMessaging.h"
+
+#include "ITrigCostMTSvc.h"
+
+
+/////////////////////////////////////////////////////////////////////////////
+class TrigCostMTAuditor : public Auditor, public AthMessaging {
+
+  using AthMessaging::msg;
+
+  public:
+
+  /** Constructor
+      @param name    The algorithm object's name
+      @param svcloc  A pointer to a service location service */
+  TrigCostMTAuditor( const std::string& name, ISvcLocator* svcloc );
+
+  StatusCode initialize() override;
+  StatusCode finalize() override;
+
+  /// StandardEventType = { Initialize, ReInitialize, Execute, BeginRun, EndRun, Finalize, Start, Stop, ReStart };
+  /// typedef std::string CustomEventType 
+ 
+  void before( StandardEventType evt, const std::string& caller) override;
+  void before( CustomEventTypeRef evt, const std::string& caller) override;
+  void after( StandardEventType evt, const std::string&, const StatusCode& sc) override;
+  void after( CustomEventTypeRef evt, const std::string&, const StatusCode& sc) override;
+
+
+  /// Redirect the proper calls using INamedInterface
+  inline void before( StandardEventType evt, INamedInterface* caller) override {
+    return this->before(evt, caller->name());
+  }
+  inline void before( CustomEventTypeRef evt, INamedInterface* caller) override {
+    return this->before(evt, caller->name());
+  }
+  inline void after( StandardEventType evt, INamedInterface* caller, const StatusCode& sc) override {
+    return this->after(evt, caller->name(), sc);
+  }
+  inline void after( CustomEventTypeRef evt, INamedInterface* caller, const StatusCode& sc) override {
+    return this->after(evt, caller->name(), sc);
+  }
+
+private:
+
+  // Todo - interface here
+  ServiceHandle<ITrigCostMTSvc> m_trigCostSvcHandle { this, "TrigCostMTSvc", "TrigCostMTSvc", "The trigger cost service to pass audit information to" };
+};
+
+#endif // TRIGCOSTMONITORMT_TRIGCOSTMTAUDITOR_H
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTSvc.h b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTSvc.h
new file mode 100644
index 00000000000..810d4083637
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/TrigCostMonitorMT/TrigCostMTSvc.h
@@ -0,0 +1,26 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef TRIGCOSTMONITORMT_TRIGCOSTMTSVC_H
+#define TRIGCOSTMONITORMT_TRIGCOSTMTSVC_H
+
+#include "GaudiKernel/ToolHandle.h"
+#include "AthenaBaseComps/AthService.h"
+#include "ITrigCostMTSvc.h"
+
+/////////////////////////////////////////////////////////////////////////////
+class TrigCostMTSvc : public virtual AthService, public ITrigCostMTSvc {
+    public:
+    TrigCostMTSvc(const std::string& name, ISvcLocator* pSvcLocator);
+    ~TrigCostMTSvc();
+
+    StatusCode initialize() override;
+    StatusCode finalize() override;
+
+    StatusCode beginAlg(const std::string& caller) override; 
+    StatusCode endAlg(const std::string& caller) override; 
+
+};
+
+#endif // TRIGCOSTMONITORMT_TRIGCOSTMTSVC_H
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTAuditor.cxx b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTAuditor.cxx
new file mode 100644
index 00000000000..6816d0b3669
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTAuditor.cxx
@@ -0,0 +1,70 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "TrigCostMonitorMT/TrigCostMTAuditor.h"
+#include "TrigCostMonitorMT/TrigCostMTSvc.h"
+
+/////////////////////////////////////////////////////////////////////////////
+
+TrigCostMTAuditor::TrigCostMTAuditor(const std::string& name, ISvcLocator* pSvcLocator) :
+Auditor(name, pSvcLocator),
+AthMessaging(msgSvc(), name)
+{
+  ATH_MSG_INFO("default constructor");
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTAuditor::initialize(){
+  ATH_MSG_INFO("initialize()");
+  ATH_CHECK( m_trigCostSvcHandle.retrieve() );
+  return StatusCode::SUCCESS;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTAuditor::finalize() {
+  ATH_MSG_INFO("finalize()");
+  return StatusCode::SUCCESS;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+void TrigCostMTAuditor::before(StandardEventType evt, const std::string& caller) {
+  if (evt != StandardEventType::Execute) return; // I only care for execution time
+  ATH_MSG_INFO("before (var standard) " << evt << " " << caller);
+  if (m_trigCostSvcHandle->beginAlg(caller).isFailure()) {
+    ATH_MSG_FATAL("Unable to access TrigCostMTSvc to record start time of " << caller);
+    throw std::runtime_error("TrigCostMTAuditor exception");
+  }
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+void TrigCostMTAuditor::before(CustomEventTypeRef evt, const std::string& caller) {
+  // Not monitored
+  ATH_MSG_DEBUG("before (var custom) " << evt << " " << caller);
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+void TrigCostMTAuditor::after(StandardEventType evt, const std::string& caller, const StatusCode& sc) {
+  if (evt != StandardEventType::Execute) return; // I only care for execution time
+  ATH_MSG_INFO("after (var standard) " << evt << " " << caller << " " << sc);
+  if (m_trigCostSvcHandle->endAlg(caller).isFailure()) {
+    ATH_MSG_FATAL("Unable to access TrigCostMTSvc to record end time of " << caller);
+    throw std::runtime_error("TrigCostMTAuditor exception");
+  }
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+void TrigCostMTAuditor::after(CustomEventTypeRef evt, const std::string& caller, const StatusCode& sc) {
+  // Not monitored
+  ATH_MSG_DEBUG("after (var custom) " << evt << " " << caller << " " << sc);
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
new file mode 100644
index 00000000000..13470e0c848
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/TrigCostMTSvc.cxx
@@ -0,0 +1,59 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include <chrono>
+#include <ctime>
+
+#include "TrigCostMonitorMT/TrigCostMTSvc.h"
+
+/////////////////////////////////////////////////////////////////////////////
+
+TrigCostMTSvc::TrigCostMTSvc(const std::string& name, ISvcLocator* pSvcLocator) :
+AthService(name, pSvcLocator) {
+  ATH_MSG_INFO ("regular constructor");
+
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+TrigCostMTSvc::~TrigCostMTSvc() {
+  ATH_MSG_INFO ("destructor()");
+
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTSvc::initialize(){
+  ATH_MSG_INFO ("initialize()");
+
+  return StatusCode::SUCCESS;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTSvc::finalize() {
+  ATH_MSG_INFO ("finalize()");
+
+  return StatusCode::SUCCESS;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTSvc::beginAlg(const std::string& caller) {
+  std::chrono::time_point<std::chrono::system_clock> time_now = std::chrono::system_clock::now();
+  std::time_t time_now_t = std::chrono::system_clock::to_time_t(time_now);
+  ATH_MSG_INFO ("Caller " << caller << " began at " << std::ctime(&time_now_t));
+  return StatusCode::SUCCESS;
+} 
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+StatusCode TrigCostMTSvc::endAlg(const std::string& caller) {
+  std::chrono::time_point<std::chrono::system_clock> time_now = std::chrono::system_clock::now();
+  std::time_t time_now_t = std::chrono::system_clock::to_time_t(time_now);
+  ATH_MSG_INFO ("Caller " << caller << " ended at " << std::ctime(&time_now_t));
+  return StatusCode::SUCCESS;
+}
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
diff --git a/Trigger/TrigMonitoring/TrigCostMonitorMT/src/components/TrigCostMonitorMT_entries.cxx b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/components/TrigCostMonitorMT_entries.cxx
new file mode 100644
index 00000000000..756c91624fb
--- /dev/null
+++ b/Trigger/TrigMonitoring/TrigCostMonitorMT/src/components/TrigCostMonitorMT_entries.cxx
@@ -0,0 +1,9 @@
+/*
+  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+*/
+
+#include "TrigCostMonitorMT/TrigCostMTSvc.h"
+#include "TrigCostMonitorMT/TrigCostMTAuditor.h"
+
+DECLARE_COMPONENT( TrigCostMTSvc )
+DECLARE_COMPONENT( TrigCostMTAuditor )
diff --git a/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py b/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
index e4b5837ae36..cf2255f17db 100644
--- a/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
+++ b/Trigger/TrigValidation/TrigUpgradeTest/share/egamma.withViews.py
@@ -95,7 +95,7 @@ def createFastCaloSequence(rerun=False):
    fastCaloHypo.CaloClusters = clusterMaker.ClustersName
 #   fastCaloHypo.RoIs = fastCaloViewsMaker.InViewRoIs
    fastCaloHypo.HypoOutputDecisions = __prefix+"EgammaCaloDecisions"
-   fastCaloHypo.HypoTools =  [ TrigL2CaloHypoToolFromName( c,c ) for c in testChains ]
+   fastCaloHypo.HypoTools =  [ TrigL2CaloHypoToolFromName( c ) for c in testChains ]
 
    for t in fastCaloHypo.HypoTools:
       t.OutputLevel = DEBUG
@@ -180,7 +180,7 @@ theElectronHypo.Electrons = theElectronFex.ElectronsName
 
 theElectronHypo.OutputLevel = VERBOSE
 
-theElectronHypo.HypoTools = [ TrigL2ElectronHypoToolFromName( c,c ) for c in testChains ]
+theElectronHypo.HypoTools = [ TrigL2ElectronHypoToolFromName( c ) for c in testChains ]
 
 for t in theElectronHypo.HypoTools:
   t.OutputLevel = VERBOSE
@@ -239,18 +239,13 @@ summary.OutputTools = [ egammaViewsMerger ]
 
 summary.OutputLevel = DEBUG
 
-step0filter = parOR("step0filter", [ findAlgorithm( egammaCaloStep, "filterL1RoIsAlg") ] )
-step1filter = parOR("step1filter", [ findAlgorithm(egammaIDStep, "filterCaloRoIsAlg") ] )
-step0rfilter = parOR("step0rfilter", [ findAlgorithm(egammaCaloStepRR, "Rerurn_filterL1RoIsAlg") ] )
-
-
-steps = seqAND("HLTSteps", [ step0filter, step0, step1filter, step1, step0rfilter, step0r ]  )
+steps = seqAND("HLTSteps", [ step0, step1, step0r ]  )
 
 from TrigSteerMonitor.TrigSteerMonitorConf import TrigSignatureMoniMT, DecisionCollectorTool
 mon = TrigSignatureMoniMT()
 mon.FinalDecisions = [ "ElectronL2Decisions", "MuonL2Decisions", "WhateverElse" ]
 from TrigUpgradeTest.TestUtils import MenuTest
-mon.ChainsList = list( set( MenuTest.CTPToChainMapping.keys() ) )
+mon.ChainsList = [ x.split(":")[1] for x in  MenuTest.CTPToChainMapping ]
 mon.OutputLevel = DEBUG
 
 step1Collector = DecisionCollectorTool("Step1Collector")
-- 
GitLab