8 from __future__
import print_function
12 Update beamspot ntuple for cool for runs that are in the calib loop or have exited in the last 24 hours
15 print (
'Updating COOL ntuple ...')
22 from InDetBeamSpotExample
import COOLUtils
28 oracle = cx_Oracle.connect(dsn=
"ATLAS_COOLPROD",user=
"ATLAS_COOL_READER_U",password=
"XXXXXXX")
30 except Exception
as e:
32 sys.exit(
'ERROR: Unable to connect to ATLAS_COOLPROD database')
37 d = cur.execute(
"SELECT RUN FROM ATLAS_COOL_GLOBAL.NEMOP_RUN WHERE ACTIVE=1 AND RUNTYPE LIKE 'Physics' AND STATE=2")
38 runsCalib = [r[0]
for r
in sorted(d)]
39 except Exception
as e:
41 sys.exit(
'Unable to retrieve runs in calibration loop')
44 curtime =
int(time.time())
45 limit = curtime - 24*3600+30*60
50 d = cur.execute(
"SELECT RUN FROM ATLAS_COOL_GLOBAL.NEMOP_RUN WHERE ACTIVE=1 AND RUNTYPE LIKE 'Physics' AND STATE=4 AND UTIME>%s" % limit)
51 runsExited = [r[0]
for r
in sorted(d)]
52 except Exception
as e:
54 sys.exit(
'Unable to retrieve runs exiting calibration loop')
57 if not bool(runsExited + runsCalib):
58 sys.exit(
'No runs in calib loop or exited recently so nothing to do')
60 run =
min(
set(runsExited + runsCalib))
65 name =
'/tmp/b7eamspot.' +
str(os.getpid()) +
'.root'
67 stat = os.system(
"beamspotnt.py -q -f %s --status '' --ru %s -s BeamSpotNt merge ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % (name, runMax) )
69 sys.exit(
"Unable to copy previous COOL ntuple")
72 tag = COOLUtils.resolveCurrentBeamSpotFolder()
75 stat = os.system(
"beamspotnt.py -q -f %s --status '%s' --rl %s --fillCOOL -s BeamSpotCOOL merge %s" % (name, status, run, tag) )
77 sys.exit(
"Unable to merge new runs into COOL ntuple")
80 stat = os.system(
"mv ~atlidbs/nt/cool/beamspotnt-COOL-Current.root ~atlidbs/nt/cool/beamspotnt-COOL-Current.previous.root")
82 sys.exit(
"ERROR: Unable to copy COOL ntuple to final location")
84 stat = os.system(
"mv %s ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % name)
86 sys.exit(
"ERROR: Unable to copy COOL ntuple to final location")