38from __future__
import print_function
49 header_mapping_dictionary = {
50 'Date/Time' : (
'Datetime' , str) ,
51 'Synchro' : (
'Synchro' , int) ,
52 'Capacity' : (
'Capacitance' , float) ,
53 'Temp.Cold Head' : (
'TempColdHead' , float) ,
54 'Temp. Electrode' : (
'TempElectrode' , float) ,
55 'HV Supply Voltage' : (
'HVSupplyVoltage', float) ,
56 'Electrode 1' : (
'Electrode1' , int) ,
57 'Electrode 2' : (
'Electrode2' , int) ,
58 'Electrode 3' : (
'Electrode3' , int) ,
59 'Electrode 4' : (
'Electrode4' , int) ,
62 type_mapping_dictionary = {
82 header_row =
open(afile).readline().strip().split(
'\t')
84 branch_descriptor =
':'.join([header_mapping_dictionary[row][0]+
'/'+
85 type_mapping_dictionary[header_mapping_dictionary[row][1]]
86 for row
in header_row])
91 output_ROOT_file_name = os.path.splitext(afile)[0] +
'.root'
92 output_file = ROOT.TFile(output_ROOT_file_name,
'recreate')
93 print(
"Outputting %s -> %s" % (afile, output_ROOT_file_name))
95 output_tree = ROOT.TTree(tree_name, tree_name)
96 file_lines =
open(afile).readlines()
104 file_lines = [
'\t'.join([val
if (val.find(
' ') == -1
and val !=
'')
105 else 'empty' for val
in line.split(
'\t')])
106 for line
in file_lines[1:]
if line[0] !=
'#' ]
110 file_as_string = (
'\n'.join(file_lines)).replace(
'NaN', str(0.0))
114 istring = ROOT.istringstream(file_as_string)
117 output_tree.ReadStream(istring, branch_descriptor)
123if __name__ ==
'__main__':
124 if len(sys.argv) < 2:
125 print(
"Usage: %s file_to_parse.dat" % sys.argv[0])