3 from __future__
import print_function
22 from MuonFixedIdUnpack
import *
26 if caller.debug ==
True:
28 if isinstance(exc,cx_Oracle.Error):
30 if isinstance(error,str):
33 self.
args += error.message,
35 if isinstance(exc,str):
38 if isinstance(exc,Exception):
54 service_re = re.compile(
'\(SERVICE_NAME\s*\=\s*([A-Za-z.]+)\)+')
56 unixts = re.compile(
'[0-9]{10,11}')
58 def __init__(self,head_id=None,impl=None,lr=None,ur=None,lt=None,ut=None,luminosity=None,rootfile=None,statusflag=None):
67 self.
dbtime = {
'wtime': 0,
'ptime': 0 }
69 self.
timer = {
'wtime':0,
'ptime': 0 }
96 lt =
"19700101 00:00:00"
98 ut =
"20690721 00:37:33"
104 lt = lt.replace(
"-",
"")
105 lowtime_converted = time.strptime(lt,
"%Y%m%d %H:%M:%S")
106 self.
lowtime = calendar.timegm(lowtime_converted)
113 ut = ut.replace(
"-",
"")
114 uptime_converted = time.strptime(ut,
"%Y%m%d %H:%M:%S")
115 self.
uptime = calendar.timegm(uptime_converted)
118 if luminosity ==
None:
128 if statusflag ==
None:
167 self.
setdb(CalibDbInfo.calibdb)
185 if self.
dconn !=
None:
186 if self.
debug ==
True:
187 print(
"Closing calibration database connection")
190 if self.
debug ==
True:
191 print(
"Closing metadata database connection")
194 except cx_Oracle.InterfaceError
as exc:
197 if exc ==
'not connected':
202 if self.
debug ==
True:
203 traceback.print_exc()
208 dblist =
'%-10s %-28s %-28s \n' % (
"ID",
"SERVICE",
"SCHEMA")
209 dblist +=
'---------------------------------------------------------------\n'
210 for ldb
in CalibDbInfo.databases.keys():
211 if ldb == CalibDbInfo.calibdb:
212 isdefault =
"(Default)"
215 if ldb
not in CalibDbInfo.db.keys():
218 schema = CalibDbInfo.db[ldb]
219 dblist +=
"%-10s %-28s %-28s %s \n" % (ldb,CalibData.service_re.search(CalibDbInfo.databases[ldb]).
group(1),schema,isdefault)
223 if dbid
in CalibDbInfo.databases:
231 raise Exception(
"SERVICE_NAME not found in databases[%s]" % dbid)
233 raise Exception(
"Tried to set CalibData object to unknown database %s" % (dbid))
237 print (output +
'\n')
241 required = dict( (name,getattr(self,name))
for name
in checkvars)
242 for varname,var
in required.items():
248 var = {
'write':
'dbw',
'read':
'dbr' }
251 passattr = var[access] +
'_password'
252 proxyattr = var[access] +
'_proxy'
253 obj = getattr(CalibDbInfo,attr)
254 passobj = getattr(CalibDbInfo,passattr)
255 proxyobj = getattr(CalibDbInfo,proxyattr)
256 rval[
'password'] = passobj[self.
database]
258 if schema ==
'meta' or (schema ==
'data' and access ==
'read'):
261 rval[
'user'] +=
'[' + proxyobj[self.
database] +
']'
286 def connect(self,access='read',schema='meta'):
289 userstring = userinfo[
'user']
290 userpass = userinfo[
'password']
291 cstring = userstring +
"/" + userpass +
"@" + self.
tnsname
293 dbname = CalibDbInfo.db[self.
database]
if schema ==
'meta' else 'queried data schema'
295 dbgstring =
'%s %s connection to %s requested - doing nothing and keeping existing open' % (access,schema,dbname)
296 dbgstring2 =
'New connection required - closing %s schema database connection' % schema
297 dbgstring3 =
'Opening connection with connection information: %s' % cstring
300 if self.
mconn !=
None:
308 self.
mconn = cx_Oracle.connect(cstring)
314 elif schema ==
'data':
321 if self.
dconn !=
None:
329 self.
dconn = cx_Oracle.connect(cstring)
333 except Exception
as exc:
334 output =
"There was an error connecting to the database "
335 if self.
mschema !=
None and schema ==
"meta":
336 output +=
"Schema: %s" % self.
mschema
337 if self.
dschema !=
None and schema ==
"data":
338 output +=
"Schema: %s" % self.
dschema
340 if isinstance(exc,cx_Oracle.Error):
342 output += error.message
343 elif isinstance(exc,KeyError):
344 output +=
"There is configuration missing for database identifier '%s' - check CalibDbInfo.py" % self.
database
346 output += exc.args[0]
352 schema_sql = self.
mschema +
'.MDT_DATA_SCHEMA'
353 sql =
"select WRITER_ACCOUNT,SCHEMA_NAME from %s where ACTIVE = 1 " % (schema_sql)
356 self.
dbgout(
"SQL in set_active_db: %s" % sql)
358 except Exception
as exc:
361 result = self.
mcursor.fetchone()
369 self.
timer[
'wtime'] = time.time()
370 self.
timer[
'ptime'] = time.clock()
374 raise Exception(
"Called timestop without calling timestart")
376 welap = time.time() - self.
timer[
'wtime']
377 pelap = time.clock() - self.
timer[
'ptime']
378 self.
dbtime[
'wtime'] += welap
379 self.
dbtime[
'ptime'] += pelap
388 if self.
limit ==
True:
389 sql_del_limit =
" AND ROWNUM < %s" % (self.
maxops + 1)
393 esql = sql + sql_del_limit
394 self.
dbgout(
"SQL executed in exec_delete: %s" % esql)
399 rowcount = self.
dcursor.rowcount
400 elif ctype ==
"meta":
404 rowcount = self.
mcursor.rowcount
419 elif ctype ==
"meta":
431 print (
"Ready to commit %s operations" % self.
opcount)
432 confirm = raw_input(
"Enter 'y' or 'yes' if you wish to continue with operation: ")
433 if confirm
not in (
"y",
"yes",
"Y"):
434 raise Exception(
"User cancelled operation")
448 if self.
dconn !=
None:
458 except Exception
as exc:
463 if self.
mconn !=
None:
469 if self.
dconn !=
None:
474 except cx_Oracle.InterfaceError
as exc:
476 if exc ==
'not open':
480 except Exception
as exc:
509 linkid = service + lb
511 dblink_sql =
"CREATE DATABASE LINK %s CONNECT TO %s identified by %s using '%s'" % (linkid, CalibDbInfo.dbr[srcdb],CalibDbInfo.dbr_password[srcdb],CalibDbInfo.databases[srcdb])
512 check_sql =
"SELECT DB_LINK from USER_DB_LINKS where lower(DB_LINK) like '%s%s'" % (linkid,
'%');
517 self.
dbgout (
"SQL in setup_dblink: %s" % check_sql)
522 self.
dbgout(
"SQL in setup_dblink: %s" % dblink_sql)
525 except Exception
as exc:
530 drop_sql =
"DROP DATABASE LINK %s" % self.
linkid
531 self.
dbgout(
"Deleting database link")
534 self.
dbgout(
"SQL in drop_dblink: %s" % drop_sql)
536 except Exception
as exc:
543 info +=
"Lower Run IOV: %s \n" % self.
lowrun
544 info +=
"Upper Run IOV: %s \n" % self.
uprun
546 info +=
"Rootfile: %s \n" % self.
rootfile
547 info +=
"Sitename: %s \n" % self.
sitename
549 info +=
"Status Flag: %s \n" % self.
statusflag
557 hardware_tubestring = mid.online_re.search(fullstring)
558 software_tubestring = mid.offline_re.search(fullstring)
559 numeric_tubestring = mid.numeric_re.search(fullstring)
561 if (hardware_tubestring):
562 return hardware_tubestring.group()
563 if (software_tubestring):
564 return software_tubestring.group()
565 if (numeric_tubestring):
567 datematch = re.compile(
'(19|20)\d\d(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])')
568 if not datematch.search(fullstring):
569 return numeric_tubestring.group()
575 exepath = sys.path[0] +
"/muonfixedid"
576 retval = subprocess.Popen([exepath,tube], stdout=subprocess.PIPE).stdout.read()
577 if "ERROR" in retval:
586 return mid.identifier
592 string =
"%s_%s_%s" % (mid.stationNameString(),mid.stationPhi(),mid.stationEta())
601 sql =
"select head.head_id, head.implementation, head.data_schema, sh.SCHEMA_NAME, head.lowrun,head.uprun,head.lowtime,head.uptime, head.luminosity, head.rootfile, head.site_name, head.insert_time, head.status_flag, sh.WRITER_ACCOUNT, sh.ACTIVE, sh.ARCHIVED, sh.ARCHIVE_CONNECTION_STRING from %s.MDT_HEAD head, %s.MDT_DATA_SCHEMA sh where head.DATA_SCHEMA = sh.SCHEMA_NAME AND " % (self.
mschema,self.
mschema)
603 sql +=
"head.HEAD_ID = %s " % self.
head_id
605 sql +=
"ORDER BY head.head_id DESC"
607 self.
dbgout(
"SQL from get_head_info: %s" % sql)
611 except Exception
as exc:
614 result = self.
mcursor.fetchone()
621 self.
uprun = result[5]
636 if result[16] ==
None:
651 if isinstance(dtobj,datetime.datetime):
652 return dtobj.strftime(
'%d-%b-%y %I.%M.%S.%f %p %z').
upper()
654 raise Exception(
"Not a datetime object")
656 def get_t0(self,tube_id=None,chamber_id=None):
659 sql =
"SELECT T.chamber, T.tube_id, T.P4, T.ADC_1, T.validflag, T.nhits_above_adc_cut, V.algo_flag,V.chisquare_1,V.P4_err,V.P5,V.P5_err,V.P0,C.P0_ERR,V.P6,V.p6_err, V.tube_grouping from"+self.
dschema +
".MDT_TUBE T, " + self.
dschema +
".MDT_TUBE_V V," + self.
dschema +
".MDT_TUBE_C C where T.head_id = :hid AND C.head_id = :hid AND V.head_id = :hid"
660 if chamber_id !=
None:
661 sql +=
" AND t.chamber = :cid AND C.tube_id IN (SELECT tube_id from %s.MDT_TUBE T WHERE T.chamber = :cid) AND V.tube_id IN (SELECT tube_id from %s.MDT_TUBE T WHERE T.chamber = :cid)"
663 sql +=
" AND T.tube_id = :tid AND C.tube_id = :tid AND V.tube_id = :tid"
665 self.
dbgout(
"SQL in get_tzero: %s" % sql)
669 except Exception
as exc:
673 for r
in self.cursor.fetchall():
679 sql =
"SELECT HEAD_ID, REGION_ID,CALIBFLAG,LOWRUN,UPRUN,HISTOGRAM,N_SEGS,AVER_ANGLE,DELTA_AVER_ANGLE,AVER_SPREAD,DELTA_AVER_SPREAD,CONVERGENCE,B_AVER,T_AVER,HV,CURR,GAS,VALIDFLAG,ALGO_FLAG,BINSFROM %s.MDT_RT" % (self.
dschema )
680 if chamber_id !=
None:
681 sql +=
" AND region_id = :rid"
684 except Exception
as exc:
687 for r
in self.cursor.fetchall():
688 self.rt[rowcount] = r
692 if not isinstance(sourceobj,CalibData):
693 raise Exception(
"Called %s without providing copy source CalibData object" % fn)
694 if sourceobj.mschema ==
None:
695 raise Exception(
"CalibData object passed to %s not initialized with get_head_info() method" % fn)
702 sql_exists =
"SELECT SCHEMA_NAME from %s.MDT_DATA_SCHEMA WHERE SCHEMA_NAME = '%s'" % (self.
mschema, self.
dschema)
706 self.
dbgout(
"SQL from write_data_schema: %s" % sql_exists)
713 raise Exception(self,
"Tried to write new MDT_DATA SCHEMA %s but SCHEMA_NAME exists" % self.
dschema)
716 except Exception
as e:
720 self.
dbgout(
"SQL from write_data_schema: %s" % sql_insert)
724 except Exception
as exc:
725 raise HeadInsertError(self,
"Unable to insert into MDT_DATA_SCHEMA: %s" % exc)
730 required = dict( (name,getattr(self,name))
for name
in [
'implementation',
'lowrun',
'uprun',
'lowtime',
'uptime',
'luminosity',
'rootfile',
'sitename' ])
731 for varname,var
in required.items():
733 raise HeadInsertError(self,
"Write head ID - %s was not set, cannot create new id" % varname)
736 raise HeadInsertError(self,
"Cannot insert new meta information into replica database because self.head_id is not set")
749 sql =
"INSERT INTO %s.MDT_HEAD(HEAD_ID,IMPLEMENTATION, LOWRUN, UPRUN, LOWTIME, UPTIME, LUMINOSITY, ROOTFILE, SITE_NAME, DATA_SCHEMA,INSERT_TIME,STATUS_FLAG) VALUES(%s,'%s',%s,%s,%s,%s,%s,'%s','%s'," % (self.
mschema, self.
head_id, self.
implementation, self.
lowrun, self.
uprun, self.
lowtime, self.
uptime, self.
luminosity, self.
rootfile,self.
sitename)
756 sql +=
"%s) RETURNING head_id,data_schema into :newid,:schema" % (self.
statusflag)
760 sql =
"UPDATE %s.MDT_HEAD SET IMPLEMENTATION='%s', LOWRUN=%s, UPRUN=%s, LOWTIME=%s, UPTIME=%s, LUMINOSITY=%s,ROOTFILE='%s',SITE_NAME='%s', INSERT_TIME = '%s', STATUS_FLAG=%s WHERE HEAD_ID=%s" % (self.
mschema, self.
implementation,self.
lowrun,self.
uprun,self.
lowtime,self.
uptime,self.
luminosity,self.
rootfile,self.
sitename,self.
insert_time,self.status_flag, self.
head_id)
763 self.
dbgout(
"SQL from write_headid: %s" % sql)
776 self.
dschema = schema.getvalue()
777 except Exception
as exc:
783 fromid = sourceobj.head_id
784 srcdb_id = sourceobj.database
788 self.
head_id = sourceobj.head_id
793 self.
lowrun = sourceobj.lowrun
794 self.
uprun = sourceobj.uprun
795 self.
lowtime = sourceobj.lowtime
796 self.
uptime = sourceobj.uptime
816 raise HeadInsertError(self,
"Destination is configured as 'replica' but got new head_id %s from insert when expecting id %s - cannot replicate head_id from source. Check your CalibDbInfo.py configuration." % (self.
head_id, sourceobj.head_id))
818 def copy_rt(self,sourceobj,chamber=None,ignore_missing=False):
821 fromid = sourceobj.head_id
822 srcdb_id = sourceobj.database
828 raise Exception(
"Cannot copy RT in same database without setting head_id for CalibData object")
832 id_select =
"head_id"
834 schema_sql =
"%s.MDT_RT" % sourceobj.dschema
835 schema_sql_map = schema_sql +
"_MAP"
838 schema_sql +=
"@%s" % self.
linkid
839 schema_sql_map +=
"@%s" % self.
linkid
841 sql_rt =
"INSERT INTO %s.MDT_RT (HEAD_ID, REGION_ID,CALIBFLAG,LOWRUN,UPRUN,HISTOGRAM,N_SEGS,AVER_ANGLE,DELTA_AVER_ANGLE,AVER_SPREAD,DELTA_AVER_SPREAD,CONVERGENCE,B_AVER,T_AVER,HV,CURR,GAS,VALIDFLAG,ALGO_FLAG,BINS) SELECT %s,REGION_ID,CALIBFLAG,LOWRUN,UPRUN,HISTOGRAM,N_SEGS,AVER_ANGLE,DELTA_AVER_ANGLE,AVER_SPREAD,DELTA_AVER_SPREAD,CONVERGENCE,B_AVER,T_AVER,HV,CURR,GAS,VALIDFLAG,ALGO_FLAG,BINS FROM %s WHERE HEAD_ID = %s" % (self.
dschema, id_select, schema_sql, fromid)
843 sql_rt_map =
"INSERT INTO %s.MDT_RT_MAP(HEAD_ID, REGION_ID,CALIBFLAG,POINT_NR,S,T,R) SELECT %s,REGION_ID,CALIBFLAG,POINT_NR,S,T,R FROM %s WHERE HEAD_ID = %s" % (self.
dschema, id_select, schema_sql_map, fromid)
847 chamber_sql =
" AND region_id = %s" % chamber_id
848 sql_rt += chamber_sql
849 sql_rt_map += chamber_sql
851 self.
dbgout(
"SQL in copy_rt: %s" % sql_rt_map)
854 self.
dbgout(
"SQL in copy_rt: %s" % sql_rt)
856 self.
dbgout(
"SQL in copy_rt: %s" % sql_rt_map)
858 if self.
dcursor.rowcount == 0
and ignore_missing ==
False:
859 raise DataCopyError(self,
"There is no RT data in the source head id")
860 except cx_Oracle.IntegrityError
as exc:
862 except HeadInsertError:
864 except Exception
as exc:
868 def copy_tzero(self,sourceobj=None,chamber=None,tube=None,ignore_missing=False):
872 fromid = sourceobj.head_id
873 srcdb_id = sourceobj.database
879 raise Exception(
"Cannot copy tzero in same database without setting head_id for CalibData object")
883 id_select =
"head_id"
885 schema_sql =
"%s.MDT_TUBE" % sourceobj.dschema
886 schema_sql_tv = schema_sql +
"_V"
887 schema_sql_tc = schema_sql +
"_C"
890 schema_sql +=
"@%s" % self.
linkid
891 schema_sql_tv +=
"@%s" % self.
linkid
892 schema_sql_tc +=
"@%s" % self.
linkid
894 mdt_tube_sql =
"INSERT INTO %s.MDT_TUBE SELECT tube_id,%s,chamber,calibflag,validflag,nhits,nhits_above_adc_cut,p4,adc_0,adc_1,adc_2,adc_3,insert_time FROM %s WHERE head_id = %s" % (self.
dschema,id_select,schema_sql,fromid)
896 mdt_tube_v_sql =
"INSERT INTO %s.MDT_TUBE_V (head_id,tube_id,calibflag, chisquare_1, chisquare_2, p0, p1, p2, p3, p5, p6, p7, p8, p9, p4_err, p5_err, p6_err, algo_flag, entries, tube_grouping) SELECT %s, tube_id,calibflag, chisquare_1, chisquare_2, p0, p1, p2, p3, p5, p6, p7, p8, p9, p4_err, p5_err, p6_err, algo_flag, entries, tube_grouping FROM %s WHERE head_id = %s" % (self.
dschema,id_select,schema_sql_tv,fromid)
898 mdt_tube_c_sql =
"INSERT INTO %s.MDT_TUBE_C (head_id, tube_id,calibflag, p0_err, p1_err, p2_err, p3_err, p7_err, p8_err, p9_err, cov_1, cov_2, cov_3, cov_4, adc_0_err, adc_1_err, adc_2_err, adc_3_err, adc_chisquare, adc_pedestal, adc_pedestal_width) SELECT %s,tube_id,calibflag, p0_err, p1_err, p2_err, p3_err, p7_err, p8_err, p9_err, cov_1, cov_2, cov_3, cov_4, adc_0_err, adc_1_err, adc_2_err, adc_3_err, adc_chisquare, adc_pedestal, adc_pedestal_width FROM %s WHERE head_id = %s" % (self.
dschema,id_select,schema_sql_tc,fromid)
900 if chamber !=
None and tube ==
None:
902 chamber_sql =
" AND chamber = %s" % chamber_id
903 chamber_tube_sql =
" AND tube_id IN (SELECT tube_id FROM %s WHERE chamber=%s)" % (schema_sql,chamber_id)
904 mdt_tube_sql += chamber_sql
905 mdt_tube_v_sql += chamber_tube_sql
906 mdt_tube_c_sql += chamber_tube_sql
907 elif tube !=
None and chamber ==
None:
909 tube_sql =
" AND tube_id = %s" % tube_id
910 mdt_tube_sql += tube_sql
911 mdt_tube_v_sql += tube_sql
912 mdt_tube_c_sql += tube_sql
913 elif tube !=
None and chamber !=
None:
914 raise DataCopyError(self,
"Cannot operate on both chamber and single tube")
916 self.
dbgout(
"SQL in copy_tzero: %s" % mdt_tube_sql)
917 self.
dbgout(
"SQL in copy_tzero: %s" % mdt_tube_c_sql)
918 self.
dbgout(
"SQL in copy_tzero: %s" % mdt_tube_v_sql)
924 if self.
dcursor.rowcount == 0
and ignore_missing ==
False:
925 raise DataCopyError(self,
"There is no T0 data in the source head id")
928 except cx_Oracle.IntegrityError
as exc:
930 except HeadInsertError:
932 except cx_Oracle.Error
as exc:
937 sql_map =
"INSERT INTO %s.MDT_RT_MAP(HEAD_ID, REGION_ID,CALIBFLAG,POINT_NR,S,T,R) VALUES (%s,%s,%s,%s,%s,%s,%s)" % ( self.
dschema, self.
head_id,self.
regionid,self.
calibflag,point_nr,s,t,r)
938 if self.
debug ==
True:
939 self.
dbgout(
"SQL from insert_rt_map: %s" % sql_map)
941 if point_nr == 99
or point_nr == 199:
943 if tmax > 800.
or tmax < 700.:
944 raise Exception(
"Tmax value %s: Tmax must be in range 700 to 800 ns" % t)
946 except cx_Oracle.IntegrityError
as exc:
948 except Exception
as exc:
952 if self.
type ==
None:
953 raise RTInsertError(self,
"Cannot insert RT until you set object 'type' variable")
956 sql_rt =
"INSERT INTO %s.MDT_RT (HEAD_ID, REGION_ID,CALIBFLAG,LOWRUN,UPRUN,HISTOGRAM,N_SEGS,AVER_ANGLE,DELTA_AVER_ANGLE,AVER_SPREAD,DELTA_AVER_SPREAD,CONVERGENCE,B_AVER,T_AVER,HV,CURR,GAS,VALIDFLAG,ALGO_FLAG,BINS) VALUES (%s,%s,%s,%s,%s,'%s',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,'%s',%s)" % (self.
dschema,self.
head_id,regionid,self.
calibflag,self.
lowrun,self.
uprun,self.
histogram,self.
n_segs,self.
aver_angle,self.
delta_aver_angle,self.
aver_spread,self.
delta_aver_spread,self.
convergence,self.
b_aver,self.
t_aver,self.
hv,self.
curr,self.
gas,self.
validflag,self.
type,self.
bins)
958 self.
dbgout(
"SQL from insert_rt: %s" % sql_rt)
963 except cx_Oracle.IntegrityError
as exc:
965 except Exception
as exc:
968 def insert_adc(self,tube_id,chamber_id,nhits,adc_0,adc_0_err,adc_1,adc_1_err,adc_2,adc_2_err,adc_3,adc_3_err,adc_chisquare):
970 sql_tube =
'INSERT INTO %s.MDT_TUBE (HEAD_ID,TUBE_ID,CHAMBER,VALIDFLAG,NHITS,NHITS_ABOVE_ADC_CUT,P4,ADC_0,ADC_1,ADC_2,ADC_3) VALUES (%s,%s,%s,0,%s,%s,%s,%s,%s,%s,%s)' % (self.
dschema,self.
head_id,tube_id,chamber_id,self.
validflag,nhits,nhits,adc_0,adc_1,adc_2,adc_3)
971 sql_tube_c =
"INSERT INTO %s.MDT_TUBE_C (HEAD_ID,TUBE_ID,ADC_0_ERR,ADC_1_ERR,ADC_2_ERR,ADC_3_ERR,ADC_CHISQUARE) VALUES (%s,%s,%s,%s,%s,%s,%s)" % (self.
dschema,self.
head_id,tube_id, adc_0_err, adc_1_err, adc_2_err, adc_3_err, adc_chisquare)
973 if self.
debug ==
True:
974 self.
dbgout(
"SQL from insert_adc: %s" % sql_tube)
975 self.
dbgout(
"SQL from insert_adc: %s" % sql_tube_c)
980 except cx_Oracle.IntegrityError
as exc:
982 except Exception
as exc:
985 def insert_t0(self,tube_id,chamber_id, tzero,avg_adc,calibflag,stats,chi2,t0err,tmax,tmax_err,noise,noise_err,slope,slope_err):
989 sql_tube =
"INSERT INTO %s.MDT_TUBE (HEAD_ID,TUBE_ID,CALIBFLAG,CHAMBER,P4,ADC_1,VALIDFLAG,NHITS,NHITS_ABOVE_ADC_CUT) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)" % (self.
dschema,self.
head_id,tube_id,calibflag,chamber_id,tzero,avg_adc,self.
validflag,stats,stats)
992 sql_tube_c =
"INSERT INTO %s.MDT_TUBE_C (HEAD_ID,TUBE_ID,CALIBFLAG,P0_ERR) VALUES (%s,%s,%s,%s)" % (self.
dschema,self.
head_id,tube_id,calibflag,noise_err)
993 sql_tube_v =
"INSERT INTO %s.MDT_TUBE_V (HEAD_ID,TUBE_ID,CALIBFLAG,CHISQUARE_1,P4_ERR,P5,P5_ERR,P0,P6,P6_ERR,ALGO_FLAG,TUBE_GROUPING) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,'%s','%s')" % (self.
dschema,self.
head_id,tube_id,calibflag,chi2,t0err,tmax,tmax_err,noise,slope,slope_err,self.
type,self.
t0_tube_grouping)
995 if self.
debug ==
True:
996 self.
dbgout(
"SQL from insert_t0: %s" % sql_tube)
997 self.
dbgout(
"SQL from insert_t0: %s" % sql_tube_c)
998 self.
dbgout(
"SQL from insert_t0: %s" % sql_tube_v)
1004 except cx_Oracle.IntegrityError
as exc:
1006 except Exception
as exc:
1015 self.
dbgout(
"SQL from delete_head_id: %s" % sql)
1019 except Exception
as exc:
1024 sql_rt_map =
"DELETE FROM %s.MDT_RT_MAP WHERE HEAD_ID=%s" % (self.
dschema, self.
head_id)
1025 sql_rt =
"DELETE FROM %s.MDT_RT WHERE HEAD_ID=%s" % (self.
dschema, self.
head_id)
1030 sql_rt_map +=
" AND REGION_ID=%s" % region_id
1031 sql_rt +=
" AND REGION_ID=%s" % region_id
1035 except Exception
as exc:
1040 sql_tube_v =
"DELETE FROM %s.MDT_TUBE_V WHERE HEAD_ID=%s" % (self.
dschema, self.
head_id)
1041 sql_tube_c =
"DELETE FROM %s.MDT_TUBE_C WHERE HEAD_ID=%s" % (self.
dschema, self.
head_id)
1042 sql_tube =
"DELETE FROM %s.MDT_TUBE WHERE HEAD_ID=%s" % (self.
dschema, self.
head_id)
1045 sql_tube +=
" AND CHAMBER=%s" % chamber_id
1046 chamber_tube_sql =
" AND tube_id IN (SELECT tube_id FROM %s.MDT_TUBE WHERE chamber=%s)" % (self.
dschema,chamber_id)
1047 sql_tube_v += chamber_tube_sql
1048 sql_tube_c += chamber_tube_sql
1049 elif tube !=
None and chamber ==
None:
1051 sql_tube_v +=
" AND TUBE_ID=%s" % tube_id
1052 sql_tube_c +=
" AND TUBE_ID=%s" % tube_id
1053 sql_tube +=
" AND TUBE_ID=%s" % tube_id
1055 self.
dbgout(
"SQL from delete_t0: %s" % sql_tube_v)
1056 self.
dbgout(
"SQL from delete_t0: %s" % sql_tube_c)
1057 self.
dbgout(
"SQL from delete_t0: %s" % sql_tube)
1063 except Exception
as exc:
1068 sql_valid =
"UPDATE %s.MDT_RT SET VALIDFLAG=3 WHERE HEAD_ID=%s " % (self.
dschema, self.
head_id)
1070 sql_valid +=
"AND REGION_ID=%s" % tube
1072 self.
dbgout(
"SQL from set_rt_valid: %s" % sql_valid)
1076 except Exception
as exc:
1081 sql_valid =
"UPDATE %s.MDT_TUBE SET VALIDFLAG=3 WHERE HEAD_ID=%s " % (self.
dschema, self.
head_id)
1083 sql_valid +=
"AND TUBE_ID=%s" % tube
1085 self.
dbgout(
"SQL from set_t0_valid: %s" % sql_valid)
1089 except Exception
as exc:
1094 sql =
"SELECT HEAD_ID,IMPLEMENTATION,LOWRUN,UPRUN,LOWTIME,UPTIME,LUMINOSITY,SITE_NAME,INSERT_TIME FROM %s.MDT_HEAD ORDER BY HEAD_ID DESC" % (self.
mschema)
1096 self.
dbgout(
"SQL from fetch_head_data: %s" % sql)
1100 except Exception
as exc:
1107 head_data_rows.append(head_row)
1108 head_row = self.
mcursor.fetchone()
1109 return head_data_rows
1112 text =
"%-10s%-35s%-10s%-10s%-12s%-12s%-5s%-6s%-30s\n" % (
'HEAD_ID',
'IMPLEMENTATION',
'LOWRUN',
'UPRUN',
'LOWTIME',
'UPTIME',
'LUM',
'SITE',
'INSERT TIME')
1113 for data
in head_data_rows:
1114 text +=
"%-10s%-35s%-10s%-10s%-12s%-12s%-5s%-6s%-30s\n" % (data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7],data[8])