diff --git a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py index 9513330bed0af67459ebc5a5b055b8707cb91a7f..7bd5f4b5370b9821cf7e098d056b9f9d66bb89b4 100644 --- a/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py +++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py @@ -139,6 +139,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', 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.) # 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 6702998ffd7ffeea801d15ae374a62dc8d0caa45..9fd794750c3c316f92782a7b1b1c264b0405fe23 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: 968 uncompressed (hash 2820051072) TH1F /top/Keys/c_layer2: 952 uncompressed (hash 1161596241) +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) @@ -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: 968 uncompressed (hash 2820051072) TH1F /OneRing/Keys/c_layer2: 952 uncompressed (hash 1161596241) +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) diff --git a/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py b/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py index 4c615119d9bc1d65dda837bce4e16d348c3ab04a..c651b28bda19f38207c7d372a28560b1c1d55a07 100644 --- a/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py +++ b/Control/AthenaMonitoringKernel/python/GenericMonitoringTool.py @@ -130,13 +130,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: @@ -144,7 +152,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 6a0040702eb48b39e5177354cb9922bb40b5b593..c38357c9aa078dad8eeb83b66c267b0c82fcc95c 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')