-
Notifications
You must be signed in to change notification settings - Fork 3
/
xRayUpload_KU_Both.py
executable file
·229 lines (190 loc) · 6.79 KB
/
xRayUpload_KU_Both.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#! /usr/bin/env python
"""
Author: John Stupak ([email protected])
Date: 4-9-15
Usage: python xRayUpload.py <input root file>
"""
##############################################################
outputDir='.'
##############################################################
from xml.etree.ElementTree import Element, SubElement, Comment
from xml.etree import ElementTree
from xml.dom import minidom
SE=SubElement
from glob import glob
import os
import subprocess
import sys
import zipfile
import re
import string
from datetime import datetime
DEBUG=False
#if len(sys.argv)<2:
#inputFile='/Users/jstupak/tmp/P-A-3-42.root'
#else:
inputFile=sys.argv[1]
################################################################
################################################################
################################################################
def prettify(elem):
roughString = ElementTree.tostring(elem, 'utf-8')
reparsed = minidom.parseString(roughString)
return reparsed.toprettyxml(indent=" ")
#---------------------------------------------------------------
def attachName(parent):
name=SE(parent,'NAME')
name.text=moduleName
################################################################
def analyze(inputFile, outputDir):
slope = range(16)
offset = range(16)
low_eff_hr = range(16)
low_eff_lr = range(16)
unif_high = range(16)
unif_low = range(16)
qfile = open("SummaryQPlots_XRFResult_" +inputFile+ ".txt",'r')
#qfile = open("SummaryQplots.txt")
line = qfile.readlines()
for l in range(2,len(line)):
values = string.split(line[l])
#slope[l-2] = values[1]+values[2]+values[3]
#offset[l-2] = values[4]+values[5]+values[6].strip('\n')
slope[l-2] = float(values[1])
offset[l-2] = float(values[4])
low98 = []
low95 = []
eff_unif_file = open('hrEfficiency.log', 'r')
eff_unif_lines = eff_unif_file.readlines()
for line in eff_unif_lines:
for i in xrange(0,16):
if 'Lowest DC Eff at High Rate for ROC:'+str(i) in line:
words_low_eff_hr = string.split(line)
low_eff_hr[i] = float(words_low_eff_hr[11])
elif 'Lowest DC Eff at Low Rate for ROC:'+str(i) in line:
words_low_eff_lr = string.split(line)
low_eff_lr[i] = float(words_low_eff_lr[11])
elif 'Highest DC Uni for ROC:'+str(i) in line:
words_unif_high = string.split(line)
unif_high[i] = float(words_unif_high[8])
elif 'Lowest DC Uni for ROC:'+str(i) in line:
words_unif_low = string.split(line)
unif_low[i] = float(words_unif_low[8])
if 'Number DC <= 98% :' in line:
print line
n98s =string.split(line)[5]
print n98s
n98 = n98s.replace(':','')
elif 'Number DC <= 95% :' in line:
print line
n95s =string.split(line)[5]
print n95s
n95 = n95s.replace(':','')
elif 'Number DC >= 1.5 :' in line:
print line
n15 = string.split(line)[5]
print n15
n1p5 = n15.replace(':','')
elif 'Number DC < 0.6 :' in line:
print line
n06 = string.split(line)[5]
print n06
n0p6 = n06.replace(':','')
elif 'Number DC < 0.8 :' in line:
print line
n06 = string.split(line)[5]
print n06
n0p6 = n06.replace(':','')
testtime = SE(top, 'TIME')
testtime.text = str(datetime.now())
test = SE(top, 'TEST')
attachName(test)
n98val = SE(test,'DC_BELOW_98')
n98val.text=str(n98)
n95val = SE(test,'DC_BELOW_95')
n95val.text=str(n95)
n1p5val = SE(test,'DC_ABOVE_150_UNI')
n1p5val.text=str(n1p5)
n0p6val = SE(test,'DC_BELOW_60_UNI')
n0p6val.text=str(n0p6)
xraytested = SE(test,'XRAY_TESTED')
xraytested.text=str(1)
rocs=SE(test, 'ROCS')
for i in range(16):
roc=SE(rocs, 'ROC')
position=SE(roc, 'POSITION')
position.text=str(i)
xray_offset=SE(roc, 'XRAY_OFFSET')
xray_offset.text=str(offset[i])
xray_slope=SE(roc, 'XRAY_SLOPE')
xray_slope.text=str(slope[i])
xray_low_eff_hr=SE(roc, 'LOW_DC_HIGHRATE_EFF')
xray_low_eff_hr.text=str(round(low_eff_hr[i],3))
xray_low_eff_lr=SE(roc,'LOW_DC_LOWRATE_EFF')
xray_low_eff_lr.text=str(round(low_eff_lr[i],3))
xray_unif_low=SE(roc,'LOW_DC_UNI')
xray_unif_low.text=str(round(unif_low[i],3))
xray_unif_high=SE(roc,'HIGH_DC_UNI')
xray_unif_high.text=str(round(unif_high[i],3))
for i in range(16):
pic=SE(top, 'PIC')
attachName(pic)
file=SE(pic, 'FILE')
file.text='Qplot_XRFResult_'+inputFile+'_C' + str(i) +'.png'
part=SE(pic,'PART')
part.text='sidet_p'
pic=SE(top, 'PIC')
attachName(pic)
file=SE(pic, 'FILE')
file.text='Results_Hr_Eff_'+inputFile+'.png'
part=SE(pic,'PART')
part.text='sidet_p'
pic=SE(top, 'PIC')
attachName(pic)
file=SE(pic, 'FILE')
file.text='Results_Hr_Rate_by_DCol_'+inputFile+'.png'
part=SE(pic,'PART')
part.text='sidet_p'
pic=SE(top, 'PIC')
attachName(pic)
file=SE(pic, 'FILE')
file.text='Results_Hr_DC_Uniformity_'+inputFile+'.png'
part=SE(pic,'PART')
part.text='sidet_p'
################################################################
def makeXML(inputFile):
global moduleName
moduleName = string.upper(inputFile[0]+'-'+inputFile[1]+'-'+inputFile[2]+'-'+inputFile[3:5])
global outputDir
outputDir+='/'+inputFile
if os.path.exists(outputDir):
print 'WARNING: outputDir exists'
#exit()
else:
print outputDir
os.makedirs(outputDir)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
global top
top=Element('ROOT')
top.set('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance')
analyze(inputFile, outputDir)
output=open(outputDir+'/master.xml','w')
output.write(prettify(top))
output.close()
#print
#print prettify(top)
#print
os.system ("cp %s %s" % ("Results_Hr_DC_Uniformity_"+inputFile+ ".png", outputDir))
os.system ("cp %s %s" % ("Results_Hr_Eff_"+inputFile+ ".png", outputDir))
os.system ("cp %s %s" % ("Results_Hr_Rate*.png", outputDir))
os.system ("cp %s %s" % ("Qplot_*.png", outputDir))
os.chdir(outputDir)
zip=zipfile.ZipFile('../'+moduleName+'.zip', mode='w')
for file in glob('*'):
zip.write(file)
zip.close()
################################################################
################################################################
################################################################
if __name__=='__main__':
xml=makeXML(inputFile)