8 if instr
is None:
return None
10 from DQUtils.sugar
import RunLumi
11 m = re.match(
'\((\d+),(\d+)\)', instr.replace(
' ',
''))
13 raise ValueError(
'Unable to parse ' + instr +
'; please specify the limits in the form (run, lb)')
17 if instr
is None:
return None
18 return instr.replace(
' ',
'').
split(
',')
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
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')
41 opts, args = parser.parse_args()
48 opts.createdefects =
True
50 indb = DefectsDB(args[0], read_only=
True, tag=opts.intag)
51 outdb = DefectsDB(args[1], create=opts.createdb, read_only=
False,
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))
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:')
69 print(
'Rerun with a restricted defect list (--defects) or with --createdefects')
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])
77 with outdb.storage_buffer:
78 print(
'Writing out IOVs...')
80 outdb.insert(iov.channel, iov.since, iov.until, iov.comment,
81 iov.user, iov.present, iov.recoverable)