Skip to content
Snippets Groups Projects
Commit e466eb40 authored by Charles Burton's avatar Charles Burton Committed by Frank Winklmeier
Browse files

Formatted strings in histogram aliases

parent 1098192a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment