11 Update beamspot ntuple for cool for runs that are in the calib loop or have exited in the last 24 hours
14 print (
'Updating COOL ntuple ...')
21 from InDetBeamSpotExample
import COOLUtils
27 oracle = cx_Oracle.connect(dsn=
"ATLAS_COOLPROD",user=
"ATLAS_COOL_READER_U",password=
"XXXXXXX")
29 except Exception
as e:
31 sys.exit(
'ERROR: Unable to connect to ATLAS_COOLPROD database')
36 d = cur.execute(
"SELECT RUN FROM ATLAS_COOL_GLOBAL.NEMOP_RUN WHERE ACTIVE=1 AND RUNTYPE LIKE 'Physics' AND STATE=2")
37 runsCalib = [r[0]
for r
in sorted(d)]
38 except Exception
as e:
40 sys.exit(
'Unable to retrieve runs in calibration loop')
43 curtime =
int(time.time())
44 limit = curtime - 24*3600+30*60
49 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)
50 runsExited = [r[0]
for r
in sorted(d)]
51 except Exception
as e:
53 sys.exit(
'Unable to retrieve runs exiting calibration loop')
56 if not bool(runsExited + runsCalib):
57 sys.exit(
'No runs in calib loop or exited recently so nothing to do')
59 run =
min(
set(runsExited + runsCalib))
64 name =
'/tmp/b7eamspot.' +
str(os.getpid()) +
'.root'
66 stat = os.system(
"beamspotnt.py -q -f %s --status '' --ru %s -s BeamSpotNt merge ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % (name, runMax) )
68 sys.exit(
"Unable to copy previous COOL ntuple")
71 tag = COOLUtils.resolveCurrentBeamSpotFolder()
74 stat = os.system(
"beamspotnt.py -q -f %s --status '%s' --rl %s --fillCOOL -s BeamSpotCOOL merge %s" % (name, status, run, tag) )
76 sys.exit(
"Unable to merge new runs into COOL ntuple")
79 stat = os.system(
"mv ~atlidbs/nt/cool/beamspotnt-COOL-Current.root ~atlidbs/nt/cool/beamspotnt-COOL-Current.previous.root")
81 sys.exit(
"ERROR: Unable to copy COOL ntuple to final location")
83 stat = os.system(
"mv %s ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % name)
85 sys.exit(
"ERROR: Unable to copy COOL ntuple to final location")