ATLAS Offline Software
Loading...
Searching...
No Matches
updateCoolNtuple.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5# !!! UNTESTED !!!
6
7
8
9
10"""
11Update beamspot ntuple for cool for runs that are in the calib loop or have exited in the last 24 hours
12"""
13
14print ('Updating COOL ntuple ...')
15
16import cx_Oracle
17import time
18import os
19import sys
20
21from InDetBeamSpotExample import COOLUtils
22
23# Connect to ATLAS_COOLPROD DB for NEMO folders
24try:
25 #oracle = cx_Oracle.connect(dsn="ATLAS_COOLREADER_U",user="ATLAS_COOL_GLOBAL_W")
26 #immediate removal; should use the autorization xml
27 oracle = cx_Oracle.connect(dsn="ATLAS_COOLPROD",user="ATLAS_COOL_READER_U",password="XXXXXXX")
28 cur = oracle.cursor()
29except Exception as e:
30 print (e)
31 sys.exit('ERROR: Unable to connect to ATLAS_COOLPROD database')
32
33
34# List of all active runs currently in calib loop (STATE=2)
35try:
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)]
38except Exception as e:
39 print (e)
40 sys.exit('Unable to retrieve runs in calibration loop')
41
42# Look back 24 hours (+ half hour safety) from now (last time cron ran).
43curtime = int(time.time())
44limit = curtime - 24*3600+30*60
45
46# List all active runs exiting calib loop (STATE=4) within this time interval
47try:
48 cur = oracle.cursor()
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)]
51except Exception as e:
52 print (e)
53 sys.exit('Unable to retrieve runs exiting calibration loop')
54
55# Get lowest run in calib loop or having left since last cron
56if not bool(runsExited + runsCalib):
57 sys.exit('No runs in calib loop or exited recently so nothing to do')
58
59run = min(set(runsExited + runsCalib))
60runMax = run - 1 # Since ru is inclusive
61status = "59,83"
62
63# Merge previous COOL ntuple into new one excluding runs abve this (which might have been in calib loop last time)
64name = '/tmp/b7eamspot.' + str(os.getpid()) + '.root'
65
66stat = os.system("beamspotnt.py -q -f %s --status '' --ru %s -s BeamSpotNt merge ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % (name, runMax) )
67if stat:
68 sys.exit("Unable to copy previous COOL ntuple")
69
70# Add in new info from cool tag for runs above this
71tag = COOLUtils.resolveCurrentBeamSpotFolder()
72# Fit status included in ntuple
73
74stat = os.system("beamspotnt.py -q -f %s --status '%s' --rl %s --fillCOOL -s BeamSpotCOOL merge %s" % (name, status, run, tag) )
75if stat:
76 sys.exit("Unable to merge new runs into COOL ntuple")
77
78# Copy ntuple back (backing up previous version)
79stat = os.system("mv ~atlidbs/nt/cool/beamspotnt-COOL-Current.root ~atlidbs/nt/cool/beamspotnt-COOL-Current.previous.root")
80if stat:
81 sys.exit("ERROR: Unable to copy COOL ntuple to final location")
82
83stat = os.system("mv %s ~atlidbs/nt/cool/beamspotnt-COOL-Current.root" % name)
84if stat:
85 sys.exit("ERROR: Unable to copy COOL ntuple to final location")
86
87# Bonus: Can we somehow check if resolved tag has changed since last time and if so regenerate from scratch
88# Can we fill type of run into ntuple (e.g. pp vs Hi) - can get project tag from SOR_Params -> projects
89
90# Version for by time
#define min(a, b)
Definition cfImp.cxx:40
STL class.