ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DQDefects
share
dq_defect_copy_defect_database.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# This script allows copying from one defect DB to another, where the defects
4
# are matched by name (not channel number).
5
# Script does NOT copy virtual defects! Use copy_virtual_defects.py for that.
6
7
def
parse_runlumi
(instr):
8
if
instr
is
None
:
return
None
9
import
re
10
from
DQUtils.sugar
import
RunLumi
11
m = re.match(
r'\((\d+),(\d+)\)'
, instr.replace(
' '
,
''
))
12
if
m
is
None
:
13
raise
ValueError(
'Unable to parse '
+ instr +
'; please specify the limits in the form (run, lb)'
)
14
return
RunLumi(int(m.group(1)), int(m.group(2)))
15
16
def
parse_channels
(instr):
17
if
instr
is
None
:
return
None
18
return
instr.replace(
' '
,
''
).
split
(
','
)
19
20
if
__name__ ==
'__main__'
:
21
import
optparse, sys, re
22
from
DQUtils.db
import
Databases, fetch_iovs
23
from
DQUtils.sugar
import
RunLumi
24
from
DQUtils.channel_mapping
import
get_channel_ids_names
25
from
DQDefects
import
DefectsDB
26
from
DQDefects.exceptions
import
DefectExistsError
27
28
parser = optparse.OptionParser(usage=
"usage: %prog [options] indb outdb\n\nindb and outdb can be COOL connection strings or \"filename/dbname\", e.g. mydb.db/COMP200"
)
29
parser.add_option(
'--createdb'
, default=
False
, action=
'store_true'
,
30
help=
'Create output database if non-existent; implies --createdefects'
)
31
parser.add_option(
'--createdefects'
, default=
False
, action=
'store_true'
,
32
help=
'Create defects from input database on output if they do not exist'
)
33
parser.add_option(
'--intag'
, default=
'HEAD'
, help=
'Tag to copy from input database'
)
34
parser.add_option(
'--outtag'
, default=
'HEAD'
, help=
'Tag to copy to on output database'
)
35
parser.add_option(
'--since'
, default=
None
, help=
'Start run/lb: specify as "(run, lb)"'
)
36
parser.add_option(
'--until'
, default=
None
, help=
'End run/lb: specify as "(run, lb)"'
)
37
parser.add_option(
'--defects'
, default=
None
, help=
'Only copy specific defects; give a comma-separated list'
)
38
parser.add_option(
'--noabsent'
, default=
False
, action=
'store_true'
,
39
help=
'Do not copy absent defects'
)
40
41
opts, args = parser.parse_args()
42
43
if
len(args) != 2:
44
parser.print_help()
45
sys.exit(1)
46
47
if
opts.createdb:
48
opts.createdefects =
True
49
50
indb = DefectsDB(args[0], read_only=
True
, tag=opts.intag)
51
outdb = DefectsDB(args[1], create=opts.createdb, read_only=
False
,
52
tag=opts.outtag)
53
54
since =
parse_runlumi
(opts.since)
55
until =
parse_runlumi
(opts.until)
56
channels =
parse_channels
(opts.defects)
57
58
print
(
'Reading in IOVs...'
)
59
iniovs = indb.retrieve(since=since, until=until, channels=channels, primary_only=
True
, nonpresent=(
not
opts.noabsent))
60
print
(
'%d IOVs retrieved from input database'
% len(iniovs))
61
#inchannels = set((x.channel for x in iniovs))
62
inchannels =
set
(channels
if
channels
is
not
None
else
indb.defect_names)
63
outchannels =
set
(outdb.defect_names)
64
missingchannels = inchannels-outchannels
65
if
len(missingchannels) != 0:
66
if
not
opts.createdefects:
67
print
(
'Missing defect(s) in target database:'
)
68
print
(list(missingchannels))
69
print
(
'Rerun with a restricted defect list (--defects) or with --createdefects'
)
70
sys.exit(1)
71
else
:
72
print
(
'Creating missing channels on output database'
)
73
descriptions = indb.get_channel_descriptions(missingchannels)
74
for
channel
in
missingchannels:
75
outdb.create_defect(channel, descriptions[channel])
76
77
with
outdb.storage_buffer:
78
print
(
'Writing out IOVs...'
)
79
for
iov
in
iniovs:
80
outdb.insert(iov.channel, iov.since, iov.until, iov.comment,
81
iov.user, iov.present, iov.recoverable)
82
83
print
(
'Done.'
)
print
void print(char *figname, TCanvas *c1)
Definition
TRTCalib_StrawStatusPlots.cxx:26
set
STL class.
split
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition
hcg.cxx:179
dq_defect_copy_defect_database.parse_runlumi
parse_runlumi(instr)
Definition
dq_defect_copy_defect_database.py:7
dq_defect_copy_defect_database.parse_channels
parse_channels(instr)
Definition
dq_defect_copy_defect_database.py:16
Generated on
for ATLAS Offline Software by
1.17.0