From d47b797a22668cc46085d29e23ab13b7b997a76d Mon Sep 17 00:00:00 2001
From: scott snyder <snyder@bnl.gov>
Date: Wed, 16 Oct 2024 22:07:26 +0200
Subject: [PATCH] DataModelTestDataRead: Update to support tests reading and
 writing to RNTuple.

Make ViewVector tests optional.
---
 .../src/xAODTestReadHVec.cxx                  | 45 +++--------------
 .../src/xAODTestReadHVec.h                    | 30 ++++--------
 .../src/xAODTestTypelessRead.cxx              | 48 +++++--------------
 .../src/xAODTestTypelessRead.h                | 44 +++++++----------
 4 files changed, 43 insertions(+), 124 deletions(-)

diff --git a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.cxx b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.cxx
index bdf4fa7bcd2..7d713479d2f 100644
--- a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.cxx
+++ b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.cxx
@@ -1,8 +1,6 @@
 /*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
-
-// $Id$
 /**
  * @file  DataModelTestDataRead/src/xAODTestReadHVec.cxx
  * @author snyder@bnl.gov
@@ -25,38 +23,15 @@
 namespace DMTest {
 
 
-/**
- * @brief Constructor.
- * @param name The algorithm name.
- * @param svc The service locator.
- */
-xAODTestReadHVec::xAODTestReadHVec (const std::string &name,
-                                    ISvcLocator *pSvcLocator)
-  : AthReentrantAlgorithm (name, pSvcLocator),
-    m_hvecKey ("hvec"),
-    m_hviewKey ("hview"),
-    m_vecWriteKey (""),
-    m_viewWriteKey ("")
-{
-  declareProperty ("HVecKey", m_hvecKey);
-  declareProperty ("HViewKey", m_hviewKey);
-  declareProperty ("VecWriteKey", m_vecWriteKey);
-  declareProperty ("ViewWriteKey", m_viewWriteKey);
-}
-  
-
 /**
  * @brief Algorithm initialization; called at the beginning of the job.
  */
 StatusCode xAODTestReadHVec::initialize()
 {
   ATH_CHECK( m_hvecKey.initialize() );
-  if (!m_hviewKey.key().empty())
-    ATH_CHECK( m_hviewKey.initialize() );
-  if (!m_vecWriteKey.key().empty())
-    ATH_CHECK( m_vecWriteKey.initialize() );
-  if (!m_viewWriteKey.key().empty())
-    ATH_CHECK( m_viewWriteKey.initialize() );
+  ATH_CHECK( m_hviewKey.initialize(SG::AllowEmpty) );
+  ATH_CHECK( m_vecWriteKey.initialize(SG::AllowEmpty) );
+  ATH_CHECK( m_viewWriteKey.initialize(SG::AllowEmpty) );
   return StatusCode::SUCCESS;
 }
 
@@ -73,7 +48,8 @@ StatusCode xAODTestReadHVec::execute (const EventContext& ctx) const
     ost1 << " " << h->aFloat();
   ATH_MSG_INFO (ost1.str());
 
-  if (const DMTest::HVec* hview = SG::get (m_hviewKey, ctx)) {
+  if (!m_hviewKey.empty()) {
+    const DMTest::HVec* hview = SG::get (m_hviewKey, ctx);
     std::ostringstream ost2;
     ost2 << m_hviewKey.key() << ":";
     for (const H* h : *hview)
@@ -105,14 +81,5 @@ StatusCode xAODTestReadHVec::execute (const EventContext& ctx) const
 }
 
 
-/**
- * @brief Algorithm finalization; called at the end of the job.
- */
-StatusCode xAODTestReadHVec::finalize()
-{
-  return StatusCode::SUCCESS;
-}
-
-
 } // namespace DMTest
 
diff --git a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.h b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.h
index e6dc370b7bb..50f9792e53e 100644
--- a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.h
+++ b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestReadHVec.h
@@ -1,10 +1,7 @@
 // This file's extension implies that it's C, but it's really -*- C++ -*-.
-
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
-
-// $Id$
 /**
  * @file src/xAODTestReadHVec.h
  * @author scott snyder <snyder@bnl.gov>
@@ -34,12 +31,7 @@ class xAODTestReadHVec
   : public AthReentrantAlgorithm
 {
 public:
-  /**
-   * @brief Constructor.
-   * @param name The algorithm name.
-   * @param svc The service locator.
-   */
-  xAODTestReadHVec (const std::string &name, ISvcLocator *pSvcLocator);
+  using AthReentrantAlgorithm::AthReentrantAlgorithm;
   
 
   /**
@@ -54,17 +46,15 @@ public:
   virtual StatusCode execute (const EventContext& ctx) const override;
 
 
-  /**
-   * @brief Algorithm finalization; called at the end of the job.
-   */
-  virtual StatusCode finalize() override;
-
-
 private:
-  SG::ReadHandleKey<DMTest::HVec> m_hvecKey;
-  SG::ReadHandleKey<DMTest::HVec> m_hviewKey;
-  SG::WriteHandleKey<DMTest::HVec> m_vecWriteKey;
-  SG::WriteHandleKey<DMTest::HView> m_viewWriteKey;
+  SG::ReadHandleKey<DMTest::HVec> m_hvecKey
+  { this, "HVecKey", "hvec" };
+  SG::ReadHandleKey<DMTest::HVec> m_hviewKey
+  { this, "HViewKey", "hview" };
+  SG::WriteHandleKey<DMTest::HVec> m_vecWriteKey
+  { this, "VecWriteKey", "" };
+  SG::WriteHandleKey<DMTest::HView> m_viewWriteKey
+  { this, "ViewWriteKey", "" };
 };
 
 
diff --git a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.cxx b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.cxx
index b73a8927ed9..3bf9b996ad4 100644
--- a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.cxx
+++ b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.cxx
@@ -47,29 +47,6 @@
 namespace DMTest {
 
 
-/**
- * @brief Constructor.
- * @param name The algorithm name.
- * @param svc The service locator.
- */
-xAODTestTypelessRead::xAODTestTypelessRead (const std::string &name,
-                                            ISvcLocator *pSvcLocator)
-  : AthAlgorithm (name, pSvcLocator),
-    m_count(0)
-{
-  declareProperty ("WritePrefix", m_writePrefix);
-}
-  
-
-/**
- * @brief Algorithm initialization; called at the beginning of the job.
- */
-StatusCode xAODTestTypelessRead::initialize()
-{
-  return StatusCode::SUCCESS;
-}
-
-
 namespace {
 
 
@@ -341,7 +318,7 @@ void copy (DMTest::PLinks& to, const DMTest::PLinks& from)
 
 template <class OBJ, class AUX>
 StatusCode
-xAODTestTypelessRead::testit (const char* key)
+xAODTestTypelessRead::testit (const std::string& key)
 {
   const OBJ* obj = nullptr;
   CHECK( evtStore()->retrieve (obj, key) );
@@ -380,7 +357,7 @@ xAODTestTypelessRead::testit (const char* key)
 
 template <class OBJ>
 StatusCode
-xAODTestTypelessRead::testit_view (const char* key)
+xAODTestTypelessRead::testit_view (const std::string& key)
 {
   const OBJ* obj = nullptr;
   CHECK( evtStore()->retrieve (obj, key) );
@@ -413,10 +390,16 @@ StatusCode xAODTestTypelessRead::execute()
   CHECK(( testit<C,    CInfoAuxContainer> ("cinfo") ));
   CHECK(( testit<CVec, CTrigAuxContainer> ("ctrig") ));
   CHECK(( testit<CVecWithData, CAuxContainer> ("cvecWD") ));
-  CHECK(( testit_view<CView> ("cview") ));
-  CHECK(( testit<PVec, PAuxContainer>     ("pvec") ));
+  if (!m_cviewKey.empty()) {
+    CHECK(( testit_view<CView> (m_cviewKey) ));
+  }
+  if (!m_pvecKey.empty()) {
+    CHECK(( testit<PVec, PAuxContainer>     (m_pvecKey) ));
+  }
   CHECK(( testit<HVec, HAuxContainer>     ("hvec") ));
-  CHECK(( testit_view<HView> ("hview") ));
+  if (!m_hviewKey.empty()) {
+    CHECK(( testit_view<HView> (m_hviewKey) ));
+  }
   CHECK(( testit<JVecContainer, JVecAuxContainer> ("jvecContainer") ));
   CHECK(( testit<JVec, JVecAuxInfo> ("jvecInfo") ));
   CHECK(( testit<PLinksContainer, PLinksAuxContainer> ("plinksContainer") ));
@@ -426,14 +409,5 @@ StatusCode xAODTestTypelessRead::execute()
 }
 
 
-/**
- * @brief Algorithm finalization; called at the end of the job.
- */
-StatusCode xAODTestTypelessRead::finalize()
-{
-  return StatusCode::SUCCESS;
-}
-
-
 } // namespace DMTest
 
diff --git a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.h b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.h
index 4a9aa3130a8..cf35cac1dff 100644
--- a/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.h
+++ b/Control/DataModelTest/DataModelTestDataRead/src/xAODTestTypelessRead.h
@@ -1,10 +1,7 @@
 // This file's extension implies that it's C, but it's really -*- C++ -*-.
-
 /*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
 */
-
-// $Id$
 /**
  * @file src/xAODTestTypelessRead.h
  * @author scott snyder <snyder@bnl.gov>
@@ -30,18 +27,7 @@ class xAODTestTypelessRead
   : public AthAlgorithm
 {
 public:
-  /**
-   * @brief Constructor.
-   * @param name The algorithm name.
-   * @param svc The service locator.
-   */
-  xAODTestTypelessRead (const std::string &name, ISvcLocator *pSvcLocator);
-  
-
-  /**
-   * @brief Algorithm initialization; called at the beginning of the job.
-   */
-  virtual StatusCode initialize();
+  using AthAlgorithm::AthAlgorithm;
 
 
   /**
@@ -50,24 +36,26 @@ public:
   virtual StatusCode execute(); 
 
 
-  /**
-   * @brief Algorithm finalization; called at the end of the job.
-   */
-  virtual StatusCode finalize();
-
-
 private:
   template <class OBJ, class AUX>
-  StatusCode testit (const char* key);
+  StatusCode testit (const std::string& key);
 
   template <class OBJ>
-  StatusCode testit_view (const char* key);
-
-  /// Parameter: Prefix for names written to SG.  Null for no write.
-  std::string m_writePrefix;
+  StatusCode testit_view (const std::string& key);
 
   /// Event counter.
-  int m_count;
+  int m_count = 0;
+
+  /// Prefix for names written to SG.  Null for no write.
+  StringProperty m_writePrefix
+    { this, "WritePrefix", "cview", "" };
+
+  StringProperty m_cviewKey
+    { this, "CViewKey", "cview", "" };
+  StringProperty m_pvecKey
+    { this, "PVecKey", "pvec", "" };
+  StringProperty m_hviewKey
+    { this, "HViewKey", "hview", "" };
 };
 
 
-- 
GitLab