4 from argparse
import ArgumentParser
6 parser = ArgumentParser()
7 parser.add_argument(
"--inFile", help=
"Input file to be translated",
8 default=
"TGC_Digitization_timejitter.dat")
9 parser.add_argument(
"--outFile", help=
"Output JSON file",
10 default=
"TGC_Digitization_timejitter.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))
24 with open (resolvedInFile,
'r')
as inStream:
26 tokens = [x.strip()
for x
in line.split(
" ")
if len(x.strip())]
30 timeJitters= tokens[2:]
31 jitterEntry =
"\n".
join([
" {",
32 " \"angle\" : {angle},".
format(angle = angle),
33 " \"nBins\" : {nBins},".
format(nBins = nBins),
34 " \"values\" : [{timeJitters}]".
format(timeJitters =
",".
join(timeJitters)),
36 logging.debug(jitterEntry)
37 jitterFields+=[jitterEntry]
39 with open(args.outFile,
'w')
as outStream:
40 outStream.write(
"[\n")
41 for num, jitter
in enumerate(jitterFields, 1):
42 outStream.write(jitter)
43 if num != len(jitterFields): outStream.write(
",")
45 outStream.write(
"]\n")