File: generate.py

package info (click to toggle)
vecgeom 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,928 kB
  • sloc: cpp: 88,717; ansic: 6,894; python: 1,035; sh: 582; sql: 538; makefile: 29
file content (50 lines) | stat: -rwxr-xr-x 1,382 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import sys

function = "DistanceToIn"
shapes = ["Box", "Orb", "Trapezoid", "Trd1", "Parallelepiped", "Paraboloid", "Tube - no rmin no phi", "Tube - rmin and phi > PI"]
factors = ["ROOT", "Geant4", "Specialized", "Vectorized"]

def fetch(source, factor, shape, func):
    activated = False
    for line in source:
        line = line.split(",")
        if line[0] == shape:
            activated = True
            header = line
        if line[0] == func and activated:
            pos = header.index(factor)
            try:
                val = float(line[pos])
                return val # * 100
            except:
                return 0
    return 0

def print_factor(factor, source):
    values = []
    for shape in shapes:
        if factor == "Geant4" and function == "Contains":
            values += [fetch(source, factor, shape, "Inside")]
        else:
            values += [fetch(source, factor, shape, function)]
    print(",".join([str(x) for x in values]))


def main():
    with open(sys.argv[1]) as f:
        source = f.readlines()
        source = [x.strip() for x in source]

    print(function)
    print("{0},{1}".format(len(shapes), len(factors)))
    print(",".join(shapes))
    print(",".join(factors))

    for factor in factors:
        print_factor(factor, source)

    # print(source)

if __name__ == "__main__":
    main()