From 6e98f813b02029451494d17f7a601f44ffff3c9c Mon Sep 17 00:00:00 2001
From: Tobias Boeckh <tobias.boeckh@cern.ch>
Date: Wed, 6 Jul 2022 12:17:56 +0200
Subject: [PATCH] added FaserSCT_ConditionsSummaryTool

---
 .../ISCT_ConditionsSummaryTool.h              | 33 +++++++++++++
 .../src/FaserSCT_ConditionsSummaryTool.cxx    | 49 +++++++++++++++++++
 .../src/FaserSCT_ConditionsSummaryTool.h      | 38 ++++++++++++++
 .../FaserSCT_ConditionsTools_entries.cxx      |  2 +
 4 files changed, 122 insertions(+)
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_ConditionsSummaryTool.h
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.cxx
 create mode 100644 Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.h

diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_ConditionsSummaryTool.h b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_ConditionsSummaryTool.h
new file mode 100644
index 00000000..8fdc8ebc
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/FaserSCT_ConditionsTools/ISCT_ConditionsSummaryTool.h
@@ -0,0 +1,33 @@
+/*
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+*/
+
+#ifndef ISCT_CONDITIONSSUMMARYTOOL_H
+#define ISCT_CONDITIONSSUMMARYTOOL_H
+
+#include "GaudiKernel/IInterface.h"
+#include "Identifier/IdContext.h"
+
+#include "InDetConditionsSummaryService/InDetHierarchy.h"
+
+class Identifier;
+class IdentifierHash;
+
+/**
+ * @class ISCT_ConditionsSummaryTool
+ * Interface class for service providing summary of status of a detector element
+**/
+
+class ISCT_ConditionsSummaryTool: virtual public IInterface, virtual public IAlgTool {
+public:
+  virtual ~ISCT_ConditionsSummaryTool() = default;
+  /// Creates the InterfaceID and interfaceID() method
+  DeclareInterfaceID(ISCT_ConditionsSummaryTool, 1, 0);
+
+  virtual bool isGood(const Identifier& elementId, const InDetConditions::Hierarchy h) const =0;
+  virtual bool isGood(const Identifier& elementId, const EventContext& ctx, const InDetConditions::Hierarchy h) const =0;
+  virtual bool isGood(const IdentifierHash& elementHash) const =0;
+  virtual bool isGood(const IdentifierHash& elementHash, const EventContext& ctx) const =0;
+};
+
+#endif //ISCT_CONDITIONSSUMMARYTOOL_H
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.cxx b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.cxx
new file mode 100644
index 00000000..afa40853
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.cxx
@@ -0,0 +1,49 @@
+/*
+  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+*/
+
+
+#include "FaserSCT_ConditionsSummaryTool.h"
+#include "FaserSCT_ConditionsTools/ISCT_ConditionsTool.h"
+
+
+FaserSCT_ConditionsSummaryTool::FaserSCT_ConditionsSummaryTool(const std::string& type, const std::string& name, const IInterface* parent) :
+  base_class(type, name, parent), m_toolHandles{this} {
+  declareProperty("ConditionsTools", m_toolHandles);
+}
+
+StatusCode FaserSCT_ConditionsSummaryTool::initialize() {
+  ATH_CHECK(m_toolHandles.retrieve());
+  m_noReports = m_toolHandles.empty();
+  return StatusCode::SUCCESS;
+}
+
+bool FaserSCT_ConditionsSummaryTool::isGood(const Identifier& elementId, const EventContext& ctx, const InDetConditions::Hierarchy h) const {
+  if (not m_noReports) {
+    for (const ToolHandle<ISCT_ConditionsTool>& tool: m_toolHandles) {
+      if (tool->canReportAbout(h) and (not tool->isGood(elementId, ctx, h))) return false;
+    }
+  }
+  return true;
+}
+
+bool FaserSCT_ConditionsSummaryTool::isGood(const Identifier& elementId, const InDetConditions::Hierarchy h) const {
+  return isGood(elementId, Gaudi::Hive::currentContext(), h);
+}
+
+bool FaserSCT_ConditionsSummaryTool::isGood(const IdentifierHash& elementHash, const EventContext& ctx) const {
+  if (not m_noReports) {
+    for (const ToolHandle<ISCT_ConditionsTool>& tool: m_toolHandles) {
+      if ((tool->canReportAbout(InDetConditions::SCT_SIDE) or
+           tool->canReportAbout(InDetConditions::SCT_MODULE)) and
+          (not tool->isGood(elementHash, ctx))) {
+        return false;
+      }
+    }
+  }
+  return true;
+}
+
+bool FaserSCT_ConditionsSummaryTool::isGood(const IdentifierHash& elementHash) const {
+  return isGood(elementHash, Gaudi::Hive::currentContext());
+}
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.h b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.h
new file mode 100644
index 00000000..681ac2be
--- /dev/null
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/FaserSCT_ConditionsSummaryTool.h
@@ -0,0 +1,38 @@
+#ifndef FASERSCT_CONDITIONSSUMMARYTOOL_H
+#define FASERSCT_CONDITIONSSUMMARYTOOL_H
+
+#include "AthenaBaseComps/AthAlgTool.h"
+#include "InDetConditionsSummaryService/InDetHierarchy.h"
+#include "FaserSCT_ConditionsTools/ISCT_ConditionsSummaryTool.h"
+
+#include "GaudiKernel/ToolHandle.h"
+#include "GaudiKernel/EventContext.h"
+
+#include <string>
+#include <vector>
+
+class ISCT_ConditionsTool;
+
+/**
+ * @class FaserSCT_ConditionsSummaryTool
+ * Interface class for tool providing summary of status of an SCT detector element
+**/
+class FaserSCT_ConditionsSummaryTool: public extends<AthAlgTool, ISCT_ConditionsSummaryTool> {
+public:
+  FaserSCT_ConditionsSummaryTool(const std::string& type, const std::string& name, const IInterface* parent); //!< Tool constructor
+  virtual ~FaserSCT_ConditionsSummaryTool() = default;
+  virtual StatusCode initialize() override;
+
+  virtual bool isGood(const Identifier& elementId, const InDetConditions::Hierarchy h) const override;
+  virtual bool isGood(const Identifier& elementId, const EventContext& ctx, const InDetConditions::Hierarchy h) const override;
+  virtual bool isGood(const IdentifierHash& elementHash) const override;
+  virtual bool isGood(const IdentifierHash& elementHash, const EventContext& ctx) const override;
+
+private:
+  StringArrayProperty m_reportingTools; //!< list of tools to be used
+  ToolHandleArray<ISCT_ConditionsTool> m_toolHandles;
+  bool m_noReports{true};
+};
+
+
+#endif // FASERSCT_CONDITIONSSUMMARYTOOL_H
diff --git a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
index adad7ee3..2d1e5111 100644
--- a/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
+++ b/Tracker/TrackerConditions/FaserSCT_ConditionsTools/src/components/FaserSCT_ConditionsTools_entries.cxx
@@ -21,6 +21,7 @@
 // #include "../SCT_TdaqEnabledTool.h"
 #include "../FaserSCT_CableMappingTool.h"
 #include "../FaserSCT_NoisyStripTool.h"
+#include "../FaserSCT_ConditionsSummaryTool.h"
 
 // DECLARE_COMPONENT( SCT_ByteStreamErrorsTool )
 // DECLARE_COMPONENT( SCT_ChargeTrappingTool )
@@ -45,3 +46,4 @@ DECLARE_COMPONENT( FaserSCT_SiliconConditionsTool )
 // DECLARE_COMPONENT( SCT_TdaqEnabledTool )
 DECLARE_COMPONENT( FaserSCT_CableMappingTool )
 DECLARE_COMPONENT( FaserSCT_NoisyStripTool )
+DECLARE_COMPONENT( FaserSCT_ConditionsSummaryTool )
-- 
GitLab