test_timing_histo_file.py 1.93 KB
Newer Older
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Check the content of the ROOT file generated by the test 'gaudiexamples.timing_histos'.

The file must contain a directory called 'TIMER.TIMER' with 3 well defined histograms inside.
"""
import sys

Marco Clemencic's avatar
Marco Clemencic committed
10

11
12
13
14
15
16
17
18
19
def test():
    import ROOT

    filename = 'timing_histos.root'

    toolname = 'TIMER.TIMER'

    histograms = ['ElapsedTime', 'CPUTime', 'Count']

Gitlab CI's avatar
Gitlab CI committed
20
21
22
23
24
25
26
27
28
29
30
31
    labels = [
        'EVENT LOOP                    ', ' ParentAlg                    ',
        '  SubAlg1                     ', '  SubAlg2                     ',
        ' StopperAlg                   ', ' TopSequence                  ',
        '  Sequence1                   ', '   Prescaler1                 ',
        '   HelloWorld                 ', '   Counter1                   ',
        '  Sequence2                   ', '   Prescaler2                 ',
        '   Counter2                   ', ' ANDSequence                  ',
        '  AND                         ', '  ANDCounter                  ',
        ' ORSequence                   ', '  OR                          ',
        '  ORCounter                   '
    ]
32
33
34
35
36
37
38
39
40
41
42

    f = ROOT.TFile.Open(filename)
    assert f, 'Cannot open file %r' % filename

    d = f.Get(toolname)
    assert d, 'Missing directory %r' % toolname

    for name in histograms:
        h = d.Get(name)
        assert h, 'Missing histogram %r' % name
        l = list(h.GetXaxis().GetLabels())
Gitlab CI's avatar
Gitlab CI committed
43
44
45
        assert len(l) == len(
            labels
        ), 'Wrong number of labels in histogram %r (found: %d, exp: %d)' % (
Marco Clemencic's avatar
Marco Clemencic committed
46
            name, len(l), len(labels))
47
        for i, (expected, found) in enumerate(zip(labels, l)):
Marco Clemencic's avatar
Marco Clemencic committed
48
49
50
            assert found == expected, 'Wrong label at position %d in histogram %r (found: %r, exp: %r)' % (
                i, name, found, expected)

51
52
53
54

if __name__ == '__main__':
    try:
        test()
55
    except AssertionError as a:
56
57
58
        print "FAILURE:", a
        sys.exit(1)
    print "SUCCESS"