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