ATLAS Offline Software
bsCompare.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 """
8 Compare beamspot DQ defects between various databases and tags
9 """
10 __author__ = 'Carl Gwilliam'
11 __version__ = ''
12 __usage__ = '''%prog [options] [database1] [database2]
13 
14 Database can be either connection string or db file:
15 
16  e.g COOLOFL_INDET/CONDBR2 (default)
17  beamspot.db/BEAMSPOT
18 
19 Example:
20 
21  dqCompare.py --rl 190236 ~atlidbs/jobs/data11_7TeV.00190236.express_express/DB_BEAMSPOT.x155_c779/data11_7TeV.00190236.express_express-DB_BEAMSPOT.x155_c779.AveBeamSpot-beamspot.db/BEAMSPOT
22 
23 '''
24 
25 from DQUtils import fetch_iovs, process_iovs
26 from DQUtils.sugar import IOVSet,RANGEIOV_VAL,RunLumiType
27 
28 from optparse import OptionParser
29 parser = OptionParser(usage=__usage__, version=__version__)
30 parser.add_option('-f', '--folder', dest='folder', default='/Indet/Beampos', help='Folder name (default: /Indet/Beampos)')
31 parser.add_option('', '--tag1', dest='tag1', default='nominal', help='Tag to compare (default: nominal)')
32 parser.add_option('', '--tag2', dest='tag2', default='IndetBeampos-ES1-UPD2-03', help='Tag to compare to (default: IndetBeampos-ES1-UPD2-03)')
33 parser.add_option('', '--rl', dest='runMin', type='int', default=None, help='Start run number (default: None)')
34 parser.add_option('', '--ru', dest='runMax', type='int', default=None, help='Start run number (default: None)')
35 parser.add_option('', '--statusonly', dest='statusonly', action='store_true', default=False, help='only show runs with differences in status (default: False)')
36 parser.add_option('-s', '--summary', dest='summary', action='store_true', default=False, help='only show summary of runs with differences (default: False)')
37 parser.add_option('', '--span', dest='span', action='store_true', default=False, help='Allows IoVs spanning run boundaries (default: False)')
38 (options,args) = parser.parse_args()
39 
40 db1 = args[0] if len(args)==1 else 'COOLOFL_INDET/CONDBR2'
41 db2 = args[1] if len(args)==2 else 'COOLOFL_INDET/CONDBR2'
42 
43 def main():
44  f1 = "%s::%s" % (db1, options.folder)
45  f2 = "%s::%s" % (db2, options.folder)
46 
47  print ("="*100)
48  print ("Comparing: ")
49  print (" * ", f1, options.tag1)
50  print (" * ", f2, options.tag2)
51  print ("="*100)
52 
53  if options.runMin is not None:
54  runs = options.runMin
55  if options.runMax is not None:
56  runs = options.runMin, options.runMax
57 
58  tag1iovs = fetch_iovs(f1, runs=runs, tag=options.tag1)
59  tag2iovs = fetch_iovs(f2, runs=runs, tag=options.tag2)
60 
61  affected_runs = set()
62  ar2 = set()
63 
64  #runiovs = IOVSet()
65  #runiovs.add(RunLumiType((runs << 32)+0), RunLumiType((runs << 32)+(1 << 32)-1))
66 
67  # Loop over iovs in the two tags
68  # for since, until, (t1, t2, r) in process_iovs(tag1iovs, tag2iovs, runiovs.solidify(RANGEIOV_VAL)):
69  for since, until, (t1, t2) in process_iovs(tag1iovs, tag2iovs):
70 
71  # Ignore IoVs spanning runs
72  if not options.span and since.run != until.run: continue
73 
74  # Make sure run exists in both
75  #if not t1.since or not t2.since: continue
76 
77  # Only consider runs in the range interested in
78  # if not r: continue
79 
80  # Check for IOVs with different status (one of which is non-zero)
81  if (t1.status == 0 or t2.status == 0) and (t1.status != t2.status):
82  if options.statusonly and not options.summary:
83  print (since, until, t1.status, t2.status)
84  ar2.add(since.run)
85 
86  # Check for differences in all fields
87  if not options.statusonly:
88  for i, field in enumerate(t1._fields):
89  if t1[i] != t2[i]:
90  #if field in ['posX', 'posY'] and abs(t1[i]-t2[i]) > 0.1e-3:
91  #if field not in ['status'] and t1[i] != 0 and abs(t1[i]-t2[i])/t1[i] > 0.001:
92  #if field in ['posZ'] and t1[i] != 0 and abs(t1[i]-t2[i])/t1[i] > 0.05:
93  #if field in ['sigmaX', 'sigmaY'] and abs(t1[i]-t2[i]) > 0.2e-3:
94  #if field in ['sigmaZ'] and abs(t1[i]-t2[i])/t1[i] > 0.002:
95  if not options.summary:
96  print (since, until, field, t1[i], t2[i])
97  affected_runs.add(since.run)
98 
99  # Print results
100  if not options.statusonly:
101  print ("Runs with differences (%s):" % len(affected_runs), ", ".join(map(str, sorted(affected_runs))))
102 
103  print ("Runs with different status (and one non-zero):", ", ".join(map(str, sorted(ar2))))
104 
105 if __name__ == "__main__":
106  main()
bsCompare.main
def main()
Definition: bsCompare.py:43
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.events.process_iovs
def process_iovs(*iovsets)
Definition: events.py:30
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
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10