4 from argparse
import ArgumentParser
6 parser = ArgumentParser()
7 parser.add_argument(
"--inFile", help=
"Input file to be translated",
8 default=
"TGC_Digitization_energyThreshold.dat")
9 parser.add_argument(
"--outFile", help=
"Output JSON file",
10 default=
"TGC_Digitization_energyThreshold.json")
13 if __name__ ==
"__main__":
15 from ROOT
import PathResolver
16 resolver = PathResolver()
18 resolvedInFile = resolver.find_file(args.inFile,
"DATAPATH")
19 if not resolvedInFile
or len(resolvedInFile) == 0:
20 logging.error(
"Failed to find file {fileName}".
format(fileName = args.inFile))
23 stationNameDict = {41:
"T1F", 42:
"T1E", 43:
"T2F", 44:
"T2E", 45:
"T3F", 46:
"T3E", 47:
"T4F", 48:
"T4E"}
25 with open (resolvedInFile,
'r')
as inStream:
27 line = line[0 : line.find(
"#")]
28 tokens = [x.strip()
for x
in line.split(
" ")
if len(x.strip())]
29 stationName = stationNameDict[
int(tokens[0])]
30 stationEta = tokens[1][tokens[1].
find(
"+")+1: ]
31 stationPhi = tokens[2]
35 threshEntry =
"\n".
join([
" {",
36 " \"station\" : \"{name}\",".
format(name = stationName),
37 " \"eta\" : {eta},".
format(eta = stationEta),
38 " \"phi\" : {phi},".
format(phi = stationPhi),
39 " \"gasGap\" : {gap},".
format(gap = gasGap),
40 " \"isStrip\" : {strip},".
format(strip = isStrip),
41 " \"threshold\": {threshold}".
format(threshold=threshold),
43 logging.debug(threshEntry)
44 threshChambers+=[threshEntry]
45 with open(args.outFile,
'w')
as outStream:
46 outStream.write(
"[\n")
47 for num, thresh
in enumerate(threshChambers, 1):
48 outStream.write(thresh)
49 if num != len(threshChambers): outStream.write(
",")
51 outStream.write(
"]\n")