7 from datetime
import datetime, timedelta
8 from time
import strftime, strptime
16 datapath =
'/scratch/nearline/NDOS/'+softrel+
'/000'+run[0:3]+
'/'+run+
'/cosmic/' 19 if os.path.exists(datapath):
20 dcfiles = [f
for f
in sorted(os.listdir(datapath))
if (f.startswith(
'reco_')
and f.endswith(
'_hist.root'))]
23 print run,
"has not been processed" 27 print run,
"has no reco files" 31 dbpswfile = os.environ.get(
'NOVADBPWDFILE')
33 pfile =
open(dbpswfile,
'r') 40 query =
'SELECT MIN(firstnonemptyeventtime), MAX(lastnonemptyeventtime) FROM ndos.nearline_metrics' 41 query+=
" WHERE triggertype = 2 AND softwarerelease='"+softrel+
"' AND run ="+run+
" AND firstnonemptyeventtime > TIMESTAMP'2010-01-01' " 42 query+=
" GROUP BY run;" 44 db= TSQLServer.Connect(
"pgsql://ifdbprod.fnal.gov:5433/nova_prod",
"nova_reader", dbpsw)
46 print "Cannot connect to database" 49 stmt = db.Statement(query,1000)
52 while stmt.NextResultRow():
53 start = stmt.GetString(0)
54 end = stmt.GetString(1)
56 print "Problem with Statement" 71 if os.path.getsize(datapath+file)<1000:
73 errors+=file+
' '+
'Is broken, filesize too small\n' 77 rootfile = TFile(datapath+file,
'READ')
78 if rootfile.TestBit(TFile.kRecovered):
80 errors+=file+
' '+
'has recovered keys\n' 84 if not rootfile.cd(
"DataCheck"):
86 errors+=file+
' '+
'Does not have DataCheck subdirectory\n' 91 hists.append(rootfile.Get(
"DataCheck/fDCM1_1_FebVEvent"))
92 hists.append(rootfile.Get(
"DataCheck/fDCM1_2_FebVEvent"))
93 hists.append(rootfile.Get(
"DataCheck/fDCM1_3_FebVEvent"))
94 hists.append(rootfile.Get(
"DataCheck/fDCM2_1_FebVEvent"))
95 hists.append(rootfile.Get(
"DataCheck/fDCM2_2_FebVEvent"))
96 hists.append(rootfile.Get(
"DataCheck/fDCM2_3_FebVEvent"))
97 hists.append(rootfile.Get(
"DataCheck/fDCM3_1_FebVEvent"))
98 hists.append(rootfile.Get(
"DataCheck/fDCM3_2_FebVEvent"))
99 hists.append(rootfile.Get(
"DataCheck/fDCM3_3_FebVEvent"))
100 hists.append(rootfile.Get(
"DataCheck/fDCM4_1_FebVEvent"))
101 hists.append(rootfile.Get(
"DataCheck/fDCM4_2_FebVEvent"))
106 for feb
in range(1,65):
107 integral=hist.Integral(1,hist.GetNbinsX(),feb,feb)
117 day = timedelta(days=1)
118 hour = timedelta(hours=1)
119 minute = timedelta(minutes=1)
121 startdt = datetime.strptime(start,
"%Y-%m-%d %H:%M:%S")
123 dstoff = datetime(startdt.year,11,1,1,30,0)
124 while dstoff.weekday()<6:
127 dston = datetime(startdt.year,3,8,3,0,0)
128 while dston.weekday()<6:
131 if startdt < dstoff
and startdt > dston:
136 startutc = (startdt+hoffset).strftime(
"%Y-%m-%d %H:%M:%S")
137 partutc = (startdt+6*minute+hoffset).strftime(
"%Y-%m-%d %H:%M:%S")
138 endutc = (datetime.strptime(end,
"%Y-%m-%d %H:%M:%S")+hoffset).strftime(
"%Y-%m-%d %H:%M:%S")
144 hdb = TSQLServer.Connect(
"pgsql://ifdbprod.fnal.gov/nova_hardware",
"nova_reader", dbpsw)
146 print "Cannot connect to hardware database" 150 query1=
"select hw_id, coating, dcm_name, dcm_port " 151 query1+=
"from hardware_position where hw_type = 'APD' and (remove_date is null or remove_date > TIMESTAMP'"+end+
"') " 152 query1+=
"order by dcm_name, dcm_port, install_date desc;" 154 hstmt = hdb.Statement(query1,1000)
161 while hstmt.NextResultRow():
162 id.append(hstmt.GetString(0))
163 coat.append(hstmt.GetString(1))
164 hdcm.append(hstmt.GetString(2))
165 hfeb.append(hstmt.GetString(3))
168 print "Problem with Hardware Statement" 178 for i
in range(len(hdcm)):
179 if '01-01' in hdcm[i]:
181 elif '01-02' in hdcm[i]:
183 elif '01-03' in hdcm[i]:
185 elif '02-01' in hdcm[i]:
187 elif '02-02' in hdcm[i]:
189 elif '02-03' in hdcm[i]:
191 elif '03-01' in hdcm[i]:
193 elif '03-02' in hdcm[i]:
195 elif '03-03' in hdcm[i]:
197 elif '04-01' in hdcm[i]:
199 elif '04-02' in hdcm[i]:
202 print "DCM name in Hardware Database is out of range", hdcm[i]
208 coat[i]=
'New Parylene' 210 coat[i]=
'Used Parylene' 216 print "Coating type in Hardware Database is out of range", coat[i]
220 apd.append(hdcm[i]+
':'+hfeb[i])
225 query2 =
'SELECT channel_name, value FROM ndos.dcs_report' 226 query2+=
" WHERE channel_name LIKE '%_tecc.RVAL' AND time_stamp in" 227 query2+=
" (SELECT MIN(time_stamp) FROM ndos.dcs_report " 228 query2+=
" WHERE channel_name LIKE '%_tecc.RVAL' AND time_stamp > TIMESTAMP'"+startutc+
"'" 229 query2+=
" AND time_stamp < TIMESTAMP'"+partutc+
"'" 230 query2+=
" GROUP BY channel_name)" 231 query2+=
" ORDER BY channel_name;" 238 stmt2 = db.Statement(query2,1000)
245 while stmt2.NextResultRow():
246 chan = stmt2.GetString(0)[:-10]
247 port.append(chan[12:])
250 elif '01-02' in chan:
252 elif '01-03' in chan:
254 elif '02-01' in chan:
256 elif '02-02' in chan:
258 elif '02-03' in chan:
260 elif '03-01' in chan:
262 elif '03-02' in chan:
264 elif '03-03' in chan:
266 elif '04-01' in chan:
268 elif '04-02' in chan:
272 print "DCM name in Production Database is out of range", chan
275 capd.append(cdcm[-1]+
':'+port[-1])
279 cooled.append(
'Uninstrumented')
281 cooled.append(
'Not Cooled')
282 elif val>2000
and val != 4095:
283 cooled.append(
'Cooled')
285 cooled.append(
'Error')
287 print "Problem with Cooling Statement" 297 for i
in range(len(dcm[0])):
299 for j
in range(len(dcm[0][i])):
300 prevstat[i].
append(dcm[0][i][j])
302 dcmlist=[
'1-1',
'1-2',
'1-3',
'2-1',
'2-2',
'2-3',
'3-1',
'3-2',
'3-3',
'4-1',
'4-2']
305 outfile =
open(
'/home/nearline/jancode/results/'+run+
'febshutoff_auto.txt',
'w')
308 outfile.write(
"Run: "+run+
'\n')
309 outfile.write(
"From: "+start+
'\n')
310 outfile.write(
"To: "+end+
'\n')
311 outfile.write(
"Subruns: "+
str(len(dcm))+
'\n')
315 for i
in range(1,len(dcm)):
319 for a
in range(len(dcm[i])):
320 afebs+=
sum(dcm[i][a])
322 errors+=
'The run died in subrun '+
str(i-1)+
'\n' 324 for j
in range(len(dcm[i])):
325 for k
in range(len(dcm[i][j])):
326 prev = prevstat[j][k]
332 coating = coat[apd.index(dcmlist[j]+
':'+
str(k))]
333 coolstat= cooled[capd.index(dcmlist[j]+
':'+
str(k))]
335 outfile.write(
'FEB'+dcmlist[j]+
':'+
str(k)+
' shutoff in subrun '+
str(i-1)+
' is '+coating+
' coated and was '+coolstat+
'\n')
337 outfile.write(
'FEB'+dcmlist[j]+
':'+
str(k)+
' came back in subrun '+
str(i)+
' is '+coating+
' coated and was '+coolstat+
'\n')
338 prevstat[j][k]=dcm[i][j][k]
342 outfile.write(
"There were no shutoffs in this run\n")
343 outfile.write(errors)
procfile open("FD_BRL_v0.txt")