6 if instr
is None:
return None
7 return instr.replace(
' ',
'').
split(
',')
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
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')
26 opts, args = parser.parse_args()
33 opts.createdefects =
True
35 indb = DefectsDB(args[0], read_only=
True, tag=opts.intag)
36 outdb = DefectsDB(args[1], create=opts.createdb, read_only=
False,
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:')
52 print(
'Rerun with a restricted virtual defect list (--defects) or with --createdefects')
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))
62 print(
'Updating existing virtual defects...')
63 for channel
in inchannels-missingchannels:
64 outdb.update_virtual_defect(channel,
' '.
join(inclauses[channel].clauses))