From 6d089d15fb47f41981ab24d980843365b389f6af Mon Sep 17 00:00:00 2001 From: "Charles D. Burton" Date: Thu, 30 Sep 2021 20:09:24 -0500 Subject: [PATCH 1/2] Add support for formatted string in monitoring histogram aliases --- .../python/ExampleMonitorAlgorithm.py | 3 ++- .../test_unit_ExampleMonitorAlgorithm_online.ref | 4 ++++ .../python/GenericMonitoringTool.py | 14 +++++++++++--- .../test/GenericMonCreation_test.py | 9 +++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py index 9513330bed0..68dea73d728 100644 --- a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py +++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py @@ -138,7 +138,8 @@ def ExampleMonitoringConfig(inputFlags): # Using templates for histogram titles or paths array1D.defineHistogram('c', title='Layer {0}', path='Keys', xmax=3.) - array1D.defineHistogram('c;c_alternate', title='Layer', path='Keys/{0}', xmax=3.) + array1D.defineHistogram('c;c_alternate', path='Keys/{0}', xmax=3.) + array1D.defineHistogram('c;c_{0}_formatted', path='Keys', 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 diff --git a/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref index 6702998ffd7..6e65334f3ac 100644 --- a/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref +++ b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref @@ -14,7 +14,9 @@ TH1F /top/Keys/clusterB/c_layer2_clusterB: 979 uncompressed (hash 1313380230) TH1F /top/Keys/clusterB/c_layer1_clusterB: 979 uncompressed (hash 1105958788) TH1F /top/Keys/c_restricted_layer2_clusterX: 989 uncompressed (hash 255957623) TH1F /top/Keys/c_restricted_layer1_clusterB: 989 uncompressed (hash 457873993) +TH1F /top/Keys/c_layer2_formatted: 962 uncompressed (hash 606965174) TH1F /top/Keys/c_layer2: 952 uncompressed (hash 1161596241) +TH1F /top/Keys/c_layer1_formatted: 962 uncompressed (hash 402230708) TH1F /top/Keys/c_layer1: 952 uncompressed (hash 955944271) TH1F /top/EtaPhi/a_3_1: 578 uncompressed (hash 3580844046) TH1F /top/EtaPhi/a_3_0: 578 uncompressed (hash 3475986445) @@ -48,7 +50,9 @@ TH1F /OneRing/Keys/clusterB/c_layer2_clusterB: 979 uncompressed (hash 1313380230 TH1F /OneRing/Keys/clusterB/c_layer1_clusterB: 979 uncompressed (hash 1105958788) TH1F /OneRing/Keys/c_restricted_layer2_clusterX: 989 uncompressed (hash 255957623) TH1F /OneRing/Keys/c_restricted_layer1_clusterB: 989 uncompressed (hash 457873993) +TH1F /OneRing/Keys/c_layer2_formatted: 962 uncompressed (hash 606965174) TH1F /OneRing/Keys/c_layer2: 952 uncompressed (hash 1161596241) +TH1F /OneRing/Keys/c_layer1_formatted: 962 uncompressed (hash 402230708) TH1F /OneRing/Keys/c_layer1: 952 uncompressed (hash 955944271) TH1F /OneRing/EtaPhi/a_3_1: 578 uncompressed (hash 3580844046) TH1F /OneRing/EtaPhi/a_3_0: 578 uncompressed (hash 3475986445) diff --git a/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py b/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py index 54d1c3f9644..e3bea0db427 100644 --- a/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py +++ b/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py @@ -128,13 +128,21 @@ class GenericMonitoringArray: # assume we have list of strings or ints; convert to list of 1-element tuples pattern = [(_2,) for _2 in pattern] for postfix, tool in self.Tools.items(): - aliased = unAliased+';'+aliasBase+postfix - try: accessors = tuple(self.Accessors[postfix]) if pattern is not None: if accessors not in pattern: continue + # two options for alias formatting, + # a) default convention: (var_0, var_1, etc.) + # b) custom formatting: 'alias{0}custom'.format(*(0, 1)) + aliasBaseFormatted = aliasBase.format(*accessors) + if aliasBaseFormatted==aliasBase: + # if format call did not do anything, use default + aliased = unAliased+';'+aliasBase+postfix + else: + # if format call changed the alias, use custom + aliased = aliasBaseFormatted if title is not None: kwargs['title'] = title.format(*accessors) if path is not None: @@ -142,7 +150,7 @@ class GenericMonitoringArray: except IndexError as e: log.error('In title or path template of histogram {0}, too many positional '\ 'arguments were requested. Title and path templates were "{1}" and "{2}", '\ - 'while only {3} fillers were given: {4}.'.format(aliased, title,\ + 'while only {3} fillers were given: {4}.'.format(aliasBase, title,\ path, len(accessors), accessors)) raise e diff --git a/Control/AthenaMonitoringKernel/test/GenericMonCreation_test.py b/Control/AthenaMonitoringKernel/test/GenericMonCreation_test.py index 6a0040702eb..c38357c9aa0 100644 --- a/Control/AthenaMonitoringKernel/test/GenericMonCreation_test.py +++ b/Control/AthenaMonitoringKernel/test/GenericMonCreation_test.py @@ -106,6 +106,15 @@ class TestGMT(unittest.TestCase): with self.assertRaises(IndexError): gma.defineHistogram('y', path='{1}') + def test_aliasTemplate(self): + gma = GenericMonitoringArray('TestGMA', [['a','b']]) + gma.defineHistogram('x;x-alias-{}-formatted') + d = histogramDictionary(list(gma[0].Histograms)+list(gma[1].Histograms)) + self.assertEqual(d['x-alias-a-formatted']['alias'], 'x-alias-a-formatted') + self.assertEqual(d['x-alias-b-formatted']['alias'], 'x-alias-b-formatted') + with self.assertRaises(IndexError): + gma.defineHistogram('y;y-alias-{1}-formatted') + def test_forwardsHistogramArguments(self): gma = GenericMonitoringArray('TestGMA', [2]) gma.defineHistogram('x,y', type='TH2D', weight='z') -- GitLab From a7562f2af31a47eb65928d28d014c8f6585ac449 Mon Sep 17 00:00:00 2001 From: "Charles D. Burton" Date: Fri, 1 Oct 2021 07:50:04 -0500 Subject: [PATCH 2/2] undo change to formatted path example histogram; update unit tests --- .../AthenaMonitoring/python/ExampleMonitorAlgorithm.py | 2 +- .../share/test_unit_ExampleMonitorAlgorithm_online.ref | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py index 68dea73d728..7bd5f4b5370 100644 --- a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py +++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py @@ -138,7 +138,7 @@ def ExampleMonitoringConfig(inputFlags): # Using templates for histogram titles or paths array1D.defineHistogram('c', title='Layer {0}', path='Keys', xmax=3.) - array1D.defineHistogram('c;c_alternate', path='Keys/{0}', xmax=3.) + array1D.defineHistogram('c;c_alternate', title='Layer', path='Keys/{0}', xmax=3.) array1D.defineHistogram('c;c_{0}_formatted', path='Keys', xmax=3.) array2D.defineHistogram('c', title='Cluster {1}, Layer {0}', path='Keys/{1}', xmax=3.) diff --git a/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref index 6e65334f3ac..9fd794750c3 100644 --- a/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref +++ b/Control/AthenaMonitoring/share/test_unit_ExampleMonitorAlgorithm_online.ref @@ -14,9 +14,9 @@ TH1F /top/Keys/clusterB/c_layer2_clusterB: 979 uncompressed (hash 1313380230) TH1F /top/Keys/clusterB/c_layer1_clusterB: 979 uncompressed (hash 1105958788) TH1F /top/Keys/c_restricted_layer2_clusterX: 989 uncompressed (hash 255957623) TH1F /top/Keys/c_restricted_layer1_clusterB: 989 uncompressed (hash 457873993) -TH1F /top/Keys/c_layer2_formatted: 962 uncompressed (hash 606965174) +TH1F /top/Keys/c_layer2_formatted: 968 uncompressed (hash 2820051072) TH1F /top/Keys/c_layer2: 952 uncompressed (hash 1161596241) -TH1F /top/Keys/c_layer1_formatted: 962 uncompressed (hash 402230708) +TH1F /top/Keys/c_layer1_formatted: 968 uncompressed (hash 2614268030) TH1F /top/Keys/c_layer1: 952 uncompressed (hash 955944271) TH1F /top/EtaPhi/a_3_1: 578 uncompressed (hash 3580844046) TH1F /top/EtaPhi/a_3_0: 578 uncompressed (hash 3475986445) @@ -50,9 +50,9 @@ TH1F /OneRing/Keys/clusterB/c_layer2_clusterB: 979 uncompressed (hash 1313380230 TH1F /OneRing/Keys/clusterB/c_layer1_clusterB: 979 uncompressed (hash 1105958788) TH1F /OneRing/Keys/c_restricted_layer2_clusterX: 989 uncompressed (hash 255957623) TH1F /OneRing/Keys/c_restricted_layer1_clusterB: 989 uncompressed (hash 457873993) -TH1F /OneRing/Keys/c_layer2_formatted: 962 uncompressed (hash 606965174) +TH1F /OneRing/Keys/c_layer2_formatted: 968 uncompressed (hash 2820051072) TH1F /OneRing/Keys/c_layer2: 952 uncompressed (hash 1161596241) -TH1F /OneRing/Keys/c_layer1_formatted: 962 uncompressed (hash 402230708) +TH1F /OneRing/Keys/c_layer1_formatted: 968 uncompressed (hash 2614268030) TH1F /OneRing/Keys/c_layer1: 952 uncompressed (hash 955944271) TH1F /OneRing/EtaPhi/a_3_1: 578 uncompressed (hash 3580844046) TH1F /OneRing/EtaPhi/a_3_0: 578 uncompressed (hash 3475986445) -- GitLab