ATLAS Offline Software
dq_defect_virtual_defect_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 def truncate_iovs_to_runs(iovs, runends):
4  for iov in iovs:
5  if iov.since.run not in runends:
6  print('Missing run', iov.since.run, 'from EOR_Params')
7 
8  rv = filter(None, [iov.intersect(runends[iov.since.run])
9  for iov in iovs if iov.since.run in runends])
10  rv = filter(lambda x: not(x.until.lumi-x.since.lumi == 0),
11  rv)
12  return rv
13 
15  from DQUtils.db import fetch_iovs
16  from DQUtils.sugar import RunLumi
17  eor_params = fetch_iovs('EOR_Params',
18  with_channel=False, what=[])
19  runends = {}
20  for iov in eor_params:
21  if iov.since.lumi == 0: iov = iov._replace(since=RunLumi(iov.since.run, 1))
22  runends[iov.since.run] = iov
23  return runends
24 
25 def do_compact(iovs):
26  iovs = sorted(iovs)
27  rv = []
28  pos = 0
29  while pos < len(iovs):
30  tiov = iovs[pos]
31  pos += 1
32  while pos < len(iovs):
33  niov = iovs[pos]
34  if niov.since != tiov.until:
35  break
36  tiov = tiov._replace(until=niov.until)
37  pos += 1
38  rv.append(tiov)
39  return rv
40 
41 if __name__ == '__main__':
42  import optparse
43 
44  parser = optparse.OptionParser()
45  parser.add_option('--defectdb', default='defectstest.db/COMP200',
46  help='Set defect database')
47  parser.add_option('--vfdb', default='LBSUMM',
48  help='Set DQ flag database (connection string format as in DQUtils.db.Databases)')
49 
50  opts, args = parser.parse_args()
51 
52  # get virtual flag IOVs
53  import VirtualFlags, DQUtils
54  from DQDefects import DefectsDB
55  print('Getting virtual flag information...', end='')
56  vfdb = DQUtils.db.Databases.get_folder(opts.vfdb)
57  vff = VirtualFlags.VirtualFlagFolder(vfdb)
58  mapping = vff.get_flag_name_id_mapping()
59  print('done')
60 
61  print('Getting virtual defect information...', end='')
62  ddb = DefectsDB(opts.defectdb, read_only=True)
63  defectids, defectnames, defectdict = ddb.get_virtual_channels()
64  print('done')
65 
66  print('Retrieving run ends...', end='')
67  runends = get_runends()
68  print('done')
69 
70  for key in mapping:
71  if not isinstance(key, str): continue
72  #if '_' in key: continue
73  if key not in defectdict or key in ['IDPF', 'LCD', 'MET', 'IDBCM', 'TIGB']:
74  print('MISSING:', key)
75  continue
76  print(key, end='')
77  vfiovs = do_compact(vff.browseObjects((152166,0), (167845,0), [key], 'DetStatus-v03-repro05-01', selection=lambda x: x.Code < 3))
78  #print vfiovs
79  d1 = set([((x.since.run, x.since.lumi), (x.until.run, x.until.lumi)) for x in truncate_iovs_to_runs(vfiovs, runends) if x.since.run != 152220])
80  diovs = do_compact(ddb.retrieve((152166,0), (167845,0), [key]))
81  d2 = set([((x.since.run, x.since.lumi), (x.until.run, x.until.lumi)) for x in truncate_iovs_to_runs(diovs, runends) if x.since.run != 152220])
82  print(d1 == d2)
83  if d1 != d2:
84  #print d1
85  d1a = dict([(((x.since.run, x.since.lumi), (x.until.run, x.until.lumi)), x.Comment) for x in truncate_iovs_to_runs(vfiovs, runends)])
86  d2a = dict([(((x.since.run, x.since.lumi), (x.until.run, x.until.lumi)), x.comment) for x in truncate_iovs_to_runs(diovs, runends)])
87 
88  print('In VF but not defects:', [(x, d1a[x]) for x in d1-d2])
89  print('In defects but not VF:', [(x, d2a[x]) for x in d2-d1])
90 
dq_defect_virtual_defect_validation.do_compact
def do_compact(iovs)
Definition: dq_defect_virtual_defect_validation.py:25
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
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:131
dq_defect_virtual_defect_validation.truncate_iovs_to_runs
def truncate_iovs_to_runs(iovs, runends)
Definition: dq_defect_virtual_defect_validation.py:3
dq_defect_virtual_defect_validation.get_runends
def get_runends()
Definition: dq_defect_virtual_defect_validation.py:14
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25