ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetExample
InDetBeamSpotExample
bin
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
"""
11
Update beamspot ntuple for cool for runs that are in the calib loop or have exited in the last 24 hours
12
"""
13
14
print
(
'Updating COOL ntuple ...'
)
15
16
import
cx_Oracle
17
import
time
18
import
os
19
import
sys
20
21
from
InDetBeamSpotExample
import
COOLUtils
22
23
# Connect to ATLAS_COOLPROD DB for NEMO folders
24
try
:
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()
29
except
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)
35
try
:
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:
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).
43
curtime = int(time.time())
44
limit = curtime - 24*3600+30*60
45
46
# List all active runs exiting calib loop (STATE=4) within this time interval
47
try
:
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)]
51
except
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
56
if
not
bool(runsExited + runsCalib):
57
sys.exit(
'No runs in calib loop or exited recently so nothing to do'
)
58
59
run =
min
(
set
(runsExited + runsCalib))
60
runMax = run - 1
# Since ru is inclusive
61
status =
"59,83"
62
63
# Merge previous COOL ntuple into new one excluding runs abve this (which might have been in calib loop last time)
64
name =
'/tmp/b7eamspot.'
+ str(os.getpid()) +
'.root'
65
66
stat = os.system(
"beamspotnt.py -q -f %s --status '' --ru %s -s BeamSpotNt merge ~atlidbs/nt/cool/beamspotnt-COOL-Current.root"
% (name, runMax) )
67
if
stat:
68
sys.exit(
"Unable to copy previous COOL ntuple"
)
69
70
# Add in new info from cool tag for runs above this
71
tag = COOLUtils.resolveCurrentBeamSpotFolder()
72
# Fit status included in ntuple
73
74
stat = os.system(
"beamspotnt.py -q -f %s --status '%s' --rl %s --fillCOOL -s BeamSpotCOOL merge %s"
% (name, status, run, tag) )
75
if
stat:
76
sys.exit(
"Unable to merge new runs into COOL ntuple"
)
77
78
# Copy ntuple back (backing up previous version)
79
stat = os.system(
"mv ~atlidbs/nt/cool/beamspotnt-COOL-Current.root ~atlidbs/nt/cool/beamspotnt-COOL-Current.previous.root"
)
80
if
stat:
81
sys.exit(
"ERROR: Unable to copy COOL ntuple to final location"
)
82
83
stat = os.system(
"mv %s ~atlidbs/nt/cool/beamspotnt-COOL-Current.root"
% name)
84
if
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
min
#define min(a, b)
Definition
cfImp.cxx:40
set
STL class.
Generated on
for ATLAS Offline Software by
1.17.0