ATLAS Offline Software
Loading...
Searching...
No Matches
AtlRunQueryGraphs Namespace Reference

Functions

 execute (fname)

Function Documentation

◆ execute()

AtlRunQueryGraphs.execute ( fname)

Definition at line 7 of file AtlRunQueryGraphs.py.

7def execute( fname ):
8 file = open( fname, 'r' )
9
10 # first count number of lines in file and find run numbers
11 ic = -1
12 minRun = 1e20
13 maxRun = -1
14 for line in file:
15 if '--------------------' in line:
16 if ic<0:
17 ic = 0
18 continue
19 else: break
20 if ic >= 0:
21 # get run number
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
26 ic += 1
27
28 print 'Found: %i runs in file; run range: [%i, %i]' % (ic,minRun, maxRun)
29 maxRun += 1
30 minRun -= 1
31
32 # --- read detectors ----
33
34 print ' '
35 print 'Reading detectors and DQ flags'
36 (dName, NotInAll) = InitDetectorMaskDecoder()
37 dqchans = DQChannels()
38
39 # create graphs and histograms
40 rootfile = TFile.Open( "queryresults.root", "RECREATE" )
41 detgraphs = {}
42 dethists = {}
43 for det in dName:
44 detc = det.strip().replace(' ','_')
45 if 'unknown' in detc: continue
46
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 )
50
51 dqhists = {}
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 )
54
55 # read lines
56 ip = -1
57 file.seek(0)
58 for line in file:
59 # search for start of output block
60 if '--------------------' in line:
61 for line in file:
62 if '--------------------' in line: break
63 # get run number
64 r, sep, line = line.partition(':')
65 ip += 1
66 runno = int(r.strip('run').strip())
67
68 # check detector
69 for det in dName:
70 if 'unknown' in det: continue
71 if det in line: v = 2
72 else: v = 1
73 detgraphs[det].SetPoint( ip, runno, v )
74 dethists[det].SetBinContent( runno - minRun + 1, v )
75
76 # check DQ flag
77 for key, dq in dqchans.items():
78 if not dq in line: v = -1
79 else:
80 word = line[line.find( dq ):line.find( dq )+len(dq)+2]
81 if '=' in word:
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
88 else:
89 print 'ERROR: unknown DQ status: "%s" --> abort' % status
90 sys.exit(1)
91
92 dqhists[dq].SetBinContent( runno - minRun + 1, v )
93 else:
94 print 'ERROR: format error on DQ parsing: "%s" --> abort' % word
95 sys.exit(1)
96
97
98 print 'End of file reading. Found: %i runs' % (ip+1)
99
100 # write all graphs, and finish
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()
104
105 print 'Wrote root file: %s' % rootfile.GetName()
106 rootfile.Close()
107
108
109# command line driver for convenience
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310