From 672dbb19e2b2b7743787eb715b36cdf5a366c056 Mon Sep 17 00:00:00 2001
From: Peter Onyisi <ponyisi@utexas.edu>
Date: Mon, 20 Apr 2020 01:14:50 +0200
Subject: [PATCH] Improve AthenaMonitoring unit test

---
 Control/AthenaMonitoring/CMakeLists.txt       |  3 +-
 .../python/ExampleMonitorAlgorithm.py         |  3 +
 .../test_unit_ExampleMonitorAlgorithm.ref     | 58 +++++++++++++++++++
 .../test/test_unit_ExampleMonitorAlgorithm.sh |  9 +++
 4 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm.ref
 create mode 100755 Control/AthenaMonitoring/test/test_unit_ExampleMonitorAlgorithm.sh

diff --git a/Control/AthenaMonitoring/CMakeLists.txt b/Control/AthenaMonitoring/CMakeLists.txt
index 0e9cbe51b16..0ba48dbf69d 100644
--- a/Control/AthenaMonitoring/CMakeLists.txt
+++ b/Control/AthenaMonitoring/CMakeLists.txt
@@ -80,8 +80,9 @@ atlas_install_python_modules( python/*.py
                               POST_BUILD_CMD ${ATLAS_FLAKE8} )
 atlas_install_joboptions( share/*.py )
 atlas_install_scripts( share/Run3DQTestingDriver.py share/hist_file_dump.py share/hist_diff.sh )
+atlas_install_runtime( share/test_unit_ExampleMonitorAlgorithm.ref )
 
 # Example monitor algorithm test
 atlas_add_test( ExampleMonitorAlgorithm_test
-    SCRIPT python -m AthenaMonitoring.ExampleMonitorAlgorithm
+    SCRIPT test/test_unit_ExampleMonitorAlgorithm.sh
 )
diff --git a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py
index 14150102bef..2f3f2ca3451 100644
--- a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py
+++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py
@@ -138,6 +138,9 @@ def ExampleMonitoringConfig(inputFlags):
         array1D.defineHistogram('c;c_alternate', title='Layer', path='Keys/{0}', xmax=3.)
         array2D.defineHistogram('c', title='Cluster {1}, Layer {0}', path='Keys/{1}', xmax=3.)
 
+        # Making a histogram only for certain elements of the array
+        array2D.defineHistogram('c;c_restricted', path='Keys', pattern=[('layer1', 'clusterB'), ('layer2', 'clusterX')])
+
     ### STEP 6 ###
     # Finalize. The return value should be a tuple of the ComponentAccumulator
     # and the sequence containing the created algorithms. If we haven't called
diff --git a/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm.ref b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm.ref
new file mode 100644
index 00000000000..83ea1ea17cf
--- /dev/null
+++ b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm.ref
@@ -0,0 +1,58 @@
+TH1F /run_311321/top/run: 4000554 uncompressed, 17768 on file (hash -1637422341)
+TEfficiency /run_311321/OneRing/AndInTheDarkness/random_vs_pT_vs_pT_passed: 21034 uncompressed, 1551 on file (hash -1415546040)
+TTree /run_311321/OneRing/BindThem/testtree: 2979 uncompressed, 860 on file (hash -1367424522)
+TEfficiency /run_311321/OneRing/AndInTheDarkness/pT_vs_pT_passed: 2965 uncompressed, 684 on file (hash -94247922)
+TH2F /run_311321/OneRing/ToBringThemAll/pT_vs_random: 909 uncompressed, 426 on file (hash 151299293)
+TH1F /run_311321/OneRing/ToFindThem/lb: 12574 uncompressed, 387 on file (hash -1115607720)
+TH1F /run_311321/OneRing/AndInTheDarkness/pT_with_cut: 759 uncompressed, 356 on file (hash 1766687537)
+TH1F /run_311321/OneRing/ToBringThemAll/random: 667 uncompressed, 322 on file (hash -1985709482)
+TH1F /run_311321/OneRing/ToRuleThemAll/lumiPerBCID_merge: 748 uncompressed, 304 on file (hash 1780646662)
+TH1F /run_311321/OneRing/ToRuleThemAll/lumiPerBCID: 742 uncompressed, 297 on file (hash 1977778327)
+TH1F /run_311321/top/Keys/clusterX/c_layer2_clusterX: 979 uncompressed, 254 on file (hash 356947890)
+TH1F /run_311321/top/Keys/clusterX/c_layer1_clusterX: 979 uncompressed, 254 on file (hash 297768880)
+TH1F /run_311321/top/Keys/clusterB/c_layer2_clusterB: 979 uncompressed, 254 on file (hash -953182330)
+TH1F /run_311321/top/Keys/clusterB/c_layer1_clusterB: 979 uncompressed, 254 on file (hash -1012361340)
+TH1F /run_311321/OneRing/Keys/clusterX/c_layer2_clusterX: 979 uncompressed, 254 on file (hash 356947890)
+TH1F /run_311321/OneRing/Keys/clusterX/c_layer1_clusterX: 979 uncompressed, 254 on file (hash 297768880)
+TH1F /run_311321/OneRing/Keys/clusterB/c_layer2_clusterB: 979 uncompressed, 254 on file (hash -953182330)
+TH1F /run_311321/OneRing/Keys/clusterB/c_layer1_clusterB: 979 uncompressed, 254 on file (hash -1012361340)
+TH1F /run_311321/top/Keys/c_restricted_layer2_clusterX: 989 uncompressed, 252 on file (hash -9069961)
+TH1F /run_311321/top/Keys/c_restricted_layer1_clusterB: 989 uncompressed, 252 on file (hash 1652922953)
+TH1F /run_311321/OneRing/Keys/c_restricted_layer2_clusterX: 989 uncompressed, 252 on file (hash -9069961)
+TH1F /run_311321/OneRing/Keys/c_restricted_layer1_clusterB: 989 uncompressed, 252 on file (hash 1652922953)
+TH1F /run_311321/top/Keys/layer2/c_alternate_layer2: 955 uncompressed, 243 on file (hash 1644728065)
+TH1F /run_311321/top/Keys/layer1/c_alternate_layer1: 955 uncompressed, 243 on file (hash 1598131968)
+TH1F /run_311321/OneRing/Keys/layer2/c_alternate_layer2: 955 uncompressed, 243 on file (hash 1644728065)
+TH1F /run_311321/OneRing/Keys/layer1/c_alternate_layer1: 955 uncompressed, 243 on file (hash 1598131968)
+TH1F /run_311321/top/LayerCluster/c_layer2_clusterX: 590 uncompressed, 237 on file (hash -1351655145)
+TH1F /run_311321/top/LayerCluster/c_layer2_clusterB: 590 uncompressed, 237 on file (hash 1925406977)
+TH1F /run_311321/top/LayerCluster/c_layer1_clusterX: 590 uncompressed, 237 on file (hash -1398513386)
+TH1F /run_311321/top/LayerCluster/c_layer1_clusterB: 590 uncompressed, 237 on file (hash 1878548736)
+TH1F /run_311321/OneRing/LayerCluster/c_layer2_clusterX: 590 uncompressed, 237 on file (hash -1351655145)
+TH1F /run_311321/OneRing/LayerCluster/c_layer2_clusterB: 590 uncompressed, 237 on file (hash 1925406977)
+TH1F /run_311321/OneRing/LayerCluster/c_layer1_clusterX: 590 uncompressed, 237 on file (hash -1398513386)
+TH1F /run_311321/OneRing/LayerCluster/c_layer1_clusterB: 590 uncompressed, 237 on file (hash 1878548736)
+TH1F /run_311321/top/Keys/c_layer2: 952 uncompressed, 236 on file (hash -1735029423)
+TH1F /run_311321/top/Keys/c_layer1: 952 uncompressed, 236 on file (hash -1792438961)
+TH1F /run_311321/OneRing/Keys/c_layer2: 952 uncompressed, 236 on file (hash -1735029423)
+TH1F /run_311321/OneRing/Keys/c_layer1: 952 uncompressed, 236 on file (hash -1792438961)
+TH2F /run_311321/top/Eta/b_vs_a_1: 1148 uncompressed, 231 on file (hash 1811263699)
+TH2F /run_311321/top/Eta/b_vs_a_0: 1148 uncompressed, 231 on file (hash 1762701522)
+TH2F /run_311321/OneRing/Eta/b_vs_a_1: 1148 uncompressed, 231 on file (hash 1811263699)
+TH2F /run_311321/OneRing/Eta/b_vs_a_0: 1148 uncompressed, 231 on file (hash 1762701522)
+TH1F /run_311321/top/Layer/c_layer2: 581 uncompressed, 228 on file (hash 1180196190)
+TH1F /run_311321/top/Layer/c_layer1: 581 uncompressed, 228 on file (hash 1133927773)
+TH1F /run_311321/OneRing/Layer/c_layer2: 581 uncompressed, 228 on file (hash 1180196190)
+TH1F /run_311321/OneRing/Layer/c_layer1: 581 uncompressed, 228 on file (hash 1133927773)
+TH1F /run_311321/top/Eta/c_1: 576 uncompressed, 222 on file (hash 2129681261)
+TH1F /run_311321/top/Eta/c_0: 576 uncompressed, 222 on file (hash 2083412844)
+TH1F /run_311321/OneRing/Eta/c_1: 576 uncompressed, 222 on file (hash 2129681261)
+TH1F /run_311321/OneRing/Eta/c_0: 576 uncompressed, 222 on file (hash 2083412844)
+TH1F /run_311321/top/EtaPhi/a_1_1: 578 uncompressed, 218 on file (hash 1174035080)
+TH1F /run_311321/top/EtaPhi/a_1_0: 578 uncompressed, 218 on file (hash 1127766663)
+TH1F /run_311321/top/EtaPhi/a_0_1: 578 uncompressed, 218 on file (hash 1127635591)
+TH1F /run_311321/top/EtaPhi/a_0_0: 578 uncompressed, 218 on file (hash 1081367174)
+TH1F /run_311321/OneRing/EtaPhi/a_1_1: 578 uncompressed, 218 on file (hash 1174035080)
+TH1F /run_311321/OneRing/EtaPhi/a_1_0: 578 uncompressed, 218 on file (hash 1127766663)
+TH1F /run_311321/OneRing/EtaPhi/a_0_1: 578 uncompressed, 218 on file (hash 1127635591)
+TH1F /run_311321/OneRing/EtaPhi/a_0_0: 578 uncompressed, 218 on file (hash 1081367174)
diff --git a/Control/AthenaMonitoring/test/test_unit_ExampleMonitorAlgorithm.sh b/Control/AthenaMonitoring/test/test_unit_ExampleMonitorAlgorithm.sh
new file mode 100755
index 00000000000..35ba7c07809
--- /dev/null
+++ b/Control/AthenaMonitoring/test/test_unit_ExampleMonitorAlgorithm.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+echo $PWD
+python -m AthenaMonitoring.ExampleMonitorAlgorithm
+# Grep to avoid RooFit lines
+hist_file_dump.py --hash ExampleMonitorOutput.root | grep '^T' | tee hist-content
+get_files -symlink test_unit_ExampleMonitorAlgorithm.ref
+diff hist-content test_unit_ExampleMonitorAlgorithm.ref
+exit $?
\ No newline at end of file
-- 
GitLab