4 from CoolRunQuery.utils.AtlRunQueryLookup
import InitDetectorMaskDecoder, DQChannels
5 from ROOT
import TFile, TGraph, TH1I
8 file =
open( fname,
'r' )
15 if '--------------------' in line:
22 r, sep, line = line.partition(
':')
23 runno =
int(r.strip(
'run').strip())
24 if runno > maxRun: maxRun = runno
25 if runno < minRun: minRun = runno
28 print 'Found: %i runs in file; run range: [%i, %i]' % (ic,minRun, maxRun)
35 print 'Reading detectors and DQ flags'
40 rootfile = TFile.Open(
"queryresults.root",
"RECREATE" )
44 detc = det.strip().
replace(
' ',
'_')
45 if 'unknown' in detc:
continue
47 detgraphs[det] = TGraph( ic )
48 detgraphs[det].SetName(
'Det_%s_vs_run_graph' % detc )
49 dethists[det] = TH1I(
'Det_%s_vs_run_hist' % detc,
'Det_%s_vs_run_hist' % detc, maxRun-minRun+1, minRun, maxRun )
52 for key, dq
in dqchans.items():
53 dqhists[dq] = TH1I(
'DQ_%s_vs_run_hist' % dq,
'DQ_%s_vs_run_hist' % dq, maxRun-minRun+1, minRun, maxRun )
60 if '--------------------' in line:
62 if '--------------------' in line:
break
64 r, sep, line = line.partition(
':')
66 runno =
int(r.strip(
'run').strip())
70 if 'unknown' in det:
continue
73 detgraphs[det].SetPoint( ip, runno, v )
74 dethists[det].SetBinContent( runno - minRun + 1, v )
77 for key, dq
in dqchans.items():
78 if not dq
in line: v = -1
80 word = line[line.find( dq ):line.find( dq )+len(dq)+2]
82 w, sep, status = word.partition(
'=')
83 status = status.strip().lower()
84 if status ==
'u': v = 0
85 elif status ==
'g': v = 3
86 elif status ==
'y': v = 2
87 elif status ==
'r': v = 1
89 print 'ERROR: unknown DQ status: "%s" --> abort' % status
92 dqhists[dq].SetBinContent( runno - minRun + 1, v )
94 print 'ERROR: format error on DQ parsing: "%s" --> abort' % word
98 print 'End of file reading. Found: %i runs' % (ip+1)
101 for key, g
in detgraphs.items(): g.Write()
102 for key, h
in dethists.items() : h.Write()
103 for key, h
in dqhists.items() : h.Write()
105 print 'Wrote root file: %s' % rootfile.GetName()
110 if __name__==
'__main__':
112 if len(sys.argv) <= 1:
113 print 'ERROR: Need to give input filename as argument --> abort'