ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DataQuality
DQDefects
share
dq_defect_copy_virtual_defects.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# This script allows copying of virtual defects from one defect DB to another
4
5
def
parse_channels
(instr):
6
if
instr
is
None
:
return
None
7
return
instr.replace(
' '
,
''
).
split
(
','
)
8
9
if
__name__ ==
'__main__'
:
10
import
optparse, sys, re
11
from
DQUtils.db
import
Databases, fetch_iovs
12
from
DQUtils.sugar
import
RunLumi
13
from
DQUtils.channel_mapping
import
get_channel_ids_names
14
from
DQDefects
import
DefectsDB
15
from
DQDefects.exceptions
import
DefectExistsError
16
17
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"
)
18
parser.add_option(
'--createdb'
, default=
False
, action=
'store_true'
,
19
help=
'Create output database if non-existent; implies --createdefects'
)
20
parser.add_option(
'--createdefects'
, default=
False
, action=
'store_true'
,
21
help=
'Create virtual defects from input database on output if they do not exist'
)
22
parser.add_option(
'--intag'
, default=
'HEAD'
, help=
'Tag to copy from input database'
)
23
parser.add_option(
'--outtag'
, default=
'HEAD'
, help=
'Tag to copy to on output database'
)
24
parser.add_option(
'--defects'
, default=
None
, help=
'Only copy specific virtual defects; give a comma-separated list'
)
25
26
opts, args = parser.parse_args()
27
28
if
len(args) != 2:
29
parser.print_help()
30
sys.exit(1)
31
32
if
opts.createdb:
33
opts.createdefects =
True
34
35
indb = DefectsDB(args[0], read_only=
True
, tag=opts.intag)
36
outdb = DefectsDB(args[1], create=opts.createdb, read_only=
False
,
37
tag=opts.outtag)
38
39
channels =
parse_channels
(opts.defects)
40
41
print
(
'Reading in definitions...'
)
42
inclauses = indb.virtual_defect_logics
43
print
(f
'{len(inclauses)} virtual defects retrieved from input database'
)
44
inchannels =
set
(channels
if
channels
is
not
None
else
inclauses.keys())
45
outchannels =
set
(outdb.virtual_defect_names)
46
missingchannels = inchannels-outchannels
47
with
outdb.storage_buffer:
48
if
len(missingchannels) != 0:
49
if
not
opts.createdefects:
50
print
(
'Missing virtual defect(s) in target database:'
)
51
print
(list(missingchannels))
52
print
(
'Rerun with a restricted virtual defect list (--defects) or with --createdefects'
)
53
sys.exit(1)
54
else
:
55
print
(
'Creating missing virtual defects on output database...'
)
56
descriptions = indb.get_virtual_channel_descriptions(missingchannels)
57
for
channel
in
missingchannels:
58
outdb.new_virtual_defect(channel, descriptions[channel],
59
' '
.join(inclauses[channel].clauses))
60
print
(
'Done'
)
61
62
print
(
'Updating existing virtual defects...'
)
63
for
channel
in
inchannels-missingchannels:
64
outdb.update_virtual_defect(channel,
' '
.join(inclauses[channel].clauses))
65
66
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_virtual_defects.parse_channels
parse_channels(instr)
Definition
dq_defect_copy_virtual_defects.py:5
Generated on
for ATLAS Offline Software by
1.17.0