7 DEPRECATED_PRIMARY_FLAGS = [
'IDPF',
'LCD',
'MET',
'IDBCM',
'TIGB']
9 if __name__ ==
'__main__':
10 import optparse, sys, re
11 from DQUtils.db
import Databases, fetch_iovs
12 from DQUtils.channel_mapping
import get_channel_ids_names
13 from DQDefects
import DefectsDB
14 from DQDefects.exceptions
import DefectExistsError
15 from DetectorStatus.DetStatusLib
import DetStatusNames
17 parser = optparse.OptionParser()
18 parser.add_option(
'--db', default=
'test_defects.db/COMP200',
19 help=
'Set output database')
20 parser.add_option(
'--origpridb', default=
'LBSUMM',
21 help=
'Set input database (connection string format as in DQUtils.db.Databases)')
22 parser.add_option(
'--origvfdb', default=
'VIRTUALFLAGS',
23 help=
'Set input database (connection string format as in DQUtils.db.Databases)')
24 parser.add_option(
'--create', default=
False, action=
'store_true',
25 help=
'If set, will create output database')
26 parser.add_option(
'--vfrun', default=160000, type=
'int',
27 help=
'Set the run number to get virtual flag definitions from')
28 parser.add_option(
'--vftag', default=
'DetStatusVIRTUALFLAGS-03',
29 help=
'Set the tag of the virtual flags folder to copy from')
30 parser.add_option(
'--ignoreold', default=
False, action=
'store_true',
31 help=
'Ignore attempted redefinitions of existing defects')
32 parser.add_option(
'--defecttag', default=
'HEAD',
33 help=
'Set the tag of the virtual defect folder to write to')
35 opts, args = parser.parse_args()
37 db = DefectsDB(opts.db, read_only=
False, tag=opts.defecttag)
39 primary_names = DetStatusNames()
41 with db.storage_buffer:
42 print(
'Populating old primary flags')
43 folder = Databases.get_folder(opts.origpridb, read_only=
True)
46 if defect
in DEPRECATED_PRIMARY_FLAGS:
47 print(
'Skipping', defect,
'as it is deprecated')
50 print(db.new_virtual_defect(defect, defect,
''), defect)
51 except DefectExistsError:
53 print(
'Defect', defect,
'already exists; ignoring')
57 print(
'Populating old virtual flags')
58 folder = Databases.get_folder(opts.origvfdb,
62 iovs =
fetch_iovs(opts.origvfdb, (opts.vfrun, 1), (opts.vfrun, 2),
63 tag=opts.vftag, with_channel=
True)
66 clause = defect.expression
67 clause = clause.replace(
'worst_of(',
'')
68 clause = clause.replace(
')',
'')
69 clause = clause.replace(
', ',
' ')
70 clause = clause.replace(
',',
' ')
71 dname = cdict[defect.channel]
73 print(db.new_virtual_defect(dname, defect.comment, clause), dname,
':', clause)
74 except DefectExistsError:
76 print(
'Defect', dname,
'already exists; ignoring')