ATLAS Offline Software
dq_defect_create_virtual_defects.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # This script populates the virtual defect folder with
4 # 1. the old primary DQ flags, set to have empty clauses
5 # 2. the old virtual flags (with definitions as per the iov/tag specified)
6 
7 DEPRECATED_PRIMARY_FLAGS = ['IDPF', 'LCD', 'MET', 'IDBCM', 'TIGB']
8 
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
16 
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')
34 
35  opts, args = parser.parse_args()
36 
37  db = DefectsDB(opts.db, read_only=False, tag=opts.defecttag)
38 
39  primary_names = DetStatusNames()
40 
41  with db.storage_buffer:
42  print('Populating old primary flags')
43  folder = Databases.get_folder(opts.origpridb, read_only=True)
44  ids, names, cdict = get_channel_ids_names(folder)
45  for defect in names:
46  if defect in DEPRECATED_PRIMARY_FLAGS:
47  print('Skipping', defect, 'as it is deprecated')
48  continue
49  try:
50  print(db.new_virtual_defect(defect, defect, ''), defect)
51  except DefectExistsError:
52  if opts.ignoreold:
53  print('Defect', defect, 'already exists; ignoring')
54  else:
55  raise
56 
57  print('Populating old virtual flags')
58  folder = Databases.get_folder(opts.origvfdb,
59  read_only=True)
60 
61  ids, names, cdict = get_channel_ids_names(folder)
62  iovs = fetch_iovs(opts.origvfdb, (opts.vfrun, 1), (opts.vfrun, 2),
63  tag=opts.vftag, with_channel=True)
64 
65  for defect in iovs:
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]
72  try:
73  print(db.new_virtual_defect(dname, defect.comment, clause), dname, ':', clause)
74  except DefectExistsError:
75  if opts.ignoreold:
76  print('Defect', dname, 'already exists; ignoring')
77  else:
78  raise
python.db.fetch_iovs
def fetch_iovs(folder_name, since=None, until=None, channels=None, tag="", what="all", max_records=-1, with_channel=True, loud=False, database=None, convert_time=False, named_channels=False, selection=None, runs=None, with_time=False, unicode_strings=False)
Definition: DQUtils/python/db.py:67
python.channel_mapping.get_channel_ids_names
def get_channel_ids_names(folder)
Definition: channel_mapping.py:102
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25