ATLAS Offline Software
Functions
dq_defect_compare_tags Namespace Reference

Functions

def DEFECTSET_VAL (defects)
 
def DEFECTDIFF_VAL (tag1, tag2)
 
def make_defectset_iovs (range_iovs, defect_iovs)
 
def make_defectdiff_iovs (defects1, defects2, system_only, ignore_not_considered)
 
def pretty (defects)
 
def main ()
 

Function Documentation

◆ DEFECTDIFF_VAL()

def dq_defect_compare_tags.DEFECTDIFF_VAL (   tag1,
  tag2 
)

Definition at line 13 of file dq_defect_compare_tags.py.

13 def DEFECTDIFF_VAL(tag1, tag2):
14  "Lists of defects only present in one tag or the other"
15 

◆ DEFECTSET_VAL()

def dq_defect_compare_tags.DEFECTSET_VAL (   defects)

Definition at line 9 of file dq_defect_compare_tags.py.

9 def DEFECTSET_VAL(defects):
10  "A set of defect names present for each IoV"
11 
12 @define_iov_type

◆ main()

def dq_defect_compare_tags.main ( )

Definition at line 60 of file dq_defect_compare_tags.py.

60 def main():
61  import sys
62  from argparse import ArgumentParser, FileType
63 
64  p = ArgumentParser(description="Compute differences in the defects "
65  "database between tags")
66  arg = p.add_argument
67  arg("tags", metavar="DetStatus-Tag", nargs=2, type=str,
68  help="Two tags to show the difference between")
69  arg("-p", "--project", default=None,
70  help="Limit considered runs to those in project")
71  arg("-P", "--period", default=None, help="Data period")
72  arg("-r", "--run", type=int, help="Run number to process")
73  arg("-R", "--range", help="Run range: e.g. 150000-151000")
74  arg("-d", "--defect", action="append", dest="defects", default=None,
75  help="Defects to show the difference between. "
76  "(If empty, show all. -d can be specified multiple times.)")
77  arg("-i", "--ignore-not-considered", action="store_true",
78  help="Ignore ranges in which GLOBAL_NOTCONSIDERED is set for either tag")
79  arg("--output", default=sys.stdout, type=FileType("w"),
80  help="Place to out the output (Default stdout)")
81  arg("-s", "--by-system", action="store_true",
82  help="If specified, show systems which differ, not defects")
83  arg("-v", "--virtual", action="store_true",
84  help="If specified, show virtual defect differences as well as primary"
85  " (produces a lot of output)")
86 
87  args = p.parse_args()
88 
89  # tags
90  tag1, tag2 = args.tags
91 
92  # range to process
93  since, until = None, None
94  #since, until = (200804, 0), (200804, 50)
95  range_iovs = IOVSet()
96 
97  # if specifying run, only use that run, and it's easy
98  if args.run:
99  since, until = (args.run, 0), (args.run+1, 0)
100  range_iovs = IOVSet.from_runs([args.run])
101  elif args.range:
102  run1, run2 = map(int, args.range.split("-"))
103  since, until = (run1, 0), (run2, 0)
104  range_iovs = IOVSet([ RANGEIOV_VAL(RunLumi(since), RunLumi(until)) ])
105 
106  # if specifying project, use that to build the range_iovs
107  # TODO: what if period is specified but not project?
108  # shouldn't I define a default project in that case?
109  elif args.project:
110 
111  # fetch the project:period:runs dictionary
112  project_dict = fetch_project_period_runs()
113  period_dict = project_dict[args.project]
114 
115  # if specifying period, use those runs
116  runs = set()
117  if args.period:
118  runs = set(period_dict[args.period])
119  else:
120  #runs = set([ run for run in runs for (period, runs) in period_dict.iteritems() ])
121  for period, period_runs in period_dict.iteritems():
122  runs.update(period_runs)
123 
124  since, until = (min(runs), 0), (max(runs)+1, 0)
125  range_iovs = IOVSet.from_runs(runs)
126 
127  # debugging
128  print('range to process:')
129  print('since, until =', since, until)
130  #print 'range_iovs:'
131  #range_iovs.pprint()
132 
133  # arguments for fetching defects
134  kwargs = dict(primary_only=not args.virtual, channels=args.defects, since=since, until=until)
135 
136  def fetch_defects(tag):
137  iovs = make_defectset_iovs(range_iovs, DefectsDB(tag=tag).retrieve(**kwargs))
138  return iovs
139 
140  print("Retrieving defects..")
141  defects1, defects2 = fetch_defects(tag1), fetch_defects(tag2)
142  #defects1.pprint()
143 
144  print("Computing diff..")
145  diff_iovs = make_defectdiff_iovs(defects1, defects2, args.by_system, args.ignore_not_considered)
146  for since, until, t1, t2 in diff_iovs:
147  print(since, until, "tag1:(%s)" % pretty(t1), "tag2:(%s)" % pretty(t2))
148 

◆ make_defectdiff_iovs()

def dq_defect_compare_tags.make_defectdiff_iovs (   defects1,
  defects2,
  system_only,
  ignore_not_considered 
)
Return a list of IoVs containing the set of defects only present in 
defects1 or defects2

Definition at line 30 of file dq_defect_compare_tags.py.

30 def make_defectdiff_iovs(defects1, defects2, system_only, ignore_not_considered):
31  """
32  Return a list of IoVs containing the set of defects only present in
33  defects1 or defects2
34  """
35  result = IOVSet()
36  defectset = ((since, until,
37  (t1.defects if t1 else set(), t2.defects if t2 else set()))
38  for since, until, (t1, t2) in process_iovs(defects1, defects2))
39  for since, until, (t1defects, t2defects) in defectset:
40  if t1defects == t2defects:
41  continue
42 
43  diff = t1defects.symmetric_difference(t2defects)
44  if ignore_not_considered and "GLOBAL_NOTCONSIDERED" in diff:
45  continue
46 
47  tag1only, tag2only = t1defects & diff, t2defects & diff
48 
49  if system_only:
50  tag1only = set(x.split("_")[0] for x in tag1only)
51  tag2only = set(x.split("_")[0] for x in tag2only)
52 
53  result.add(since, until, tag1only, tag2only)
54 
55  return result.solidify(DEFECTDIFF_VAL)
56 

◆ make_defectset_iovs()

def dq_defect_compare_tags.make_defectset_iovs (   range_iovs,
  defect_iovs 
)
Return a list of iovs with a set for each IoV containing the present defects

Definition at line 16 of file dq_defect_compare_tags.py.

16 def make_defectset_iovs(range_iovs, defect_iovs):
17  """
18  Return a list of iovs with a set for each IoV containing the present defects
19  """
20  chans, iovsets = defect_iovs.chans_iovsets
21 
22  result = IOVSet()
23  for since, until, states in process_iovs(range_iovs, *iovsets):
24  in_range, defects = states[0], states[1:]
25  if in_range:
26  result.add(since, until, set(d.channel for d in defects if d))
27 
28  return result.solidify(DEFECTSET_VAL)
29 

◆ pretty()

def dq_defect_compare_tags.pretty (   defects)

Definition at line 57 of file dq_defect_compare_tags.py.

57 def pretty(defects):
58  return ", ".join(sorted(defects))
59 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
dq_defect_compare_tags.make_defectdiff_iovs
def make_defectdiff_iovs(defects1, defects2, system_only, ignore_not_considered)
Definition: dq_defect_compare_tags.py:30
max
#define max(a, b)
Definition: cfImp.cxx:41
dq_defect_compare_tags.pretty
def pretty(defects)
Definition: dq_defect_compare_tags.py:57
python.sugar.iovtype.RANGEIOV_VAL
def RANGEIOV_VAL()
Definition: iovtype.py:153
dq_defect_compare_tags.main
def main()
Definition: dq_defect_compare_tags.py:60
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:131
python.periods.fetch_project_period_runs
def fetch_project_period_runs()
Definition: periods.py:64
dq_defect_compare_tags.DEFECTDIFF_VAL
def DEFECTDIFF_VAL(tag1, tag2)
Definition: dq_defect_compare_tags.py:13
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:224
min
#define min(a, b)
Definition: cfImp.cxx:40
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
dq_defect_compare_tags.make_defectset_iovs
def make_defectset_iovs(range_iovs, defect_iovs)
Definition: dq_defect_compare_tags.py:16
dq_defect_compare_tags.DEFECTSET_VAL
def DEFECTSET_VAL(defects)
Definition: dq_defect_compare_tags.py:9
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28