ATLAS Offline Software
test_dcsc.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 from __future__ import with_statement
3 
4 from DCSCalculator2.subdetectors import LAr, Lucid, MDT, Pixels, RPC, SCT, TDQ, Tile, TGC, TRT
5 
6 from DQUtils.general import timer, kgrind_profile
7 
8 from DQUtils.db import fetch_iovs
9 from DQUtils.iov_arrangement import inverse_lblb
10 from DQUtils.utils import pprint_objects
11 from DQUtils.sugar import RunLumi
12 
13 from DQUtils.iov_differences import emit_iov_differences
14 
15 def sum_lbs(iovs):
16  """
17  Sum the number of luminosity blocks spanned by a run
18  """
19  return sum(iov.until - iov.since for iov in iovs)
20 
21 def print_diff_lumi(diff):
22  before, after = diff
23  assert (before.since, before.until) == (after.since, after.until)
24  assert before._fields == after._fields
25 
26  if not hasattr(type(before), "_is_empty"): type(before)._is_empty = False
27  if not hasattr(type(after), "_is_empty"): type(after)._is_empty = False
28 
29  print " ", before.since, before.until,
30 
31  if before._is_empty:
32  print " Empty -> Filled"
33  elif after._is_empty:
34  print " Filled -> Empty"
35  else:
36  for field, val_before, val_after in zip(before._fields, before, after):
37  if val_before != val_after:
38  print field, val_before, "->", val_after,
39  print
40 
41 def compare_iovs(a, b):
42 
43  a = a.by_channel
44  b = b.by_channel
45 
46  for output_channel in sorted(set(a.keys() + b.keys())):
47  A = a[output_channel]
48  B = b[output_channel]
49 
50  diff = emit_iov_differences(A, B)
51  print " [BAD] diff iovs =", len(diff), "lbs =", sum_lbs(zip(*diff)[0])
52  print " First ten diffs:"
53  for i in diff[:10]:
54  #print i
56  print
57 
58 def main():
59  run = 144247 # Recent run where CSC gas state was bad.
60  run = 136379
61  run = 155112 # Recent long run (Sat May 15th, 11am -> Sun 16th 8am), 632 lbs
62  run = 156463
63  #run = 155669 # MDT NConfig goes below 600
64  from sys import argv
65  args = argv[1:]
66  if args:
67  run = int(args[0])
68  since, until = RunLumi(run, 0), RunLumi(run+1, 0)
69 
70  with timer("Read LBLB"):
71  lblb = fetch_iovs("LBLB", since, until, with_channel=False)
72  lbtime = inverse_lblb(lblb)
73 
74  #system = SCT() # Works, very slightly discrepant for the config.
75  #system = Pixels() # Works
76  #system = Tile() # Works
77  #system = TDQ() # Works, needs further testing
78  #system = RPC() # Works
79  #system = LAr() # Works, but produces slightly different result. Original gives:
80  # DCSOFL_VAL(since=(155112: 167), until=(155112: 176), channel=215, Code=2L)
81 
82  #system = TRT() # Unresolved discrepancies: Wrong NConfig, NWorking off by one in run 155112.
83 
84  system = MDT() # Seems to work
85  #system = Magnets() # Needs to be finished
86  #system = Lucid() # Needs to be written
87 
88  #print system.mapping.keys()
89 
90  with timer("Calculate result for %s" % system):
91  result = system.run(lbtime)
92 
93  print "Done."
94  print
95  #print result[0]
96 
97  print "Run range:", since, "to", until
98  print "DCSC2 intervals of validity:"
99  pprint_objects(result[:30])
100  print
101 
102  output_channels = system.mapping.keys()
103  iovs = fetch_iovs("DCSOFL", since, until, output_channels)
104 
105  #print hex(hash(tuple(iovs))), hex(hash(tuple(result)))
106 
107  print "Original DCSC intervals of validity:"
108  pprint_objects(iovs[:30])
109 
110  return
111 
112  compare_iovs(iovs, result)
113 
114  #for calc_iov, ref_iov in zip(result, iovs):
115  #print calc_iov.since, calc_iov.until, ref_iov.since, ref_iov.until
116  #pprint_objects(result)
117 
118 if __name__ == "__main__":
119 
120  from IPython.Shell import IPShellEmbed
121  ipython_instance = IPShellEmbed(["-pdb"], rc_override=dict(quiet=True))
122 
123  from DQUtils.logger import init_logging
124  init_logging()
125 
126  main()
python.iov_arrangement.inverse_lblb
def inverse_lblb(iovs)
Definition: iov_arrangement.py:34
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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
test_dcsc.print_diff_lumi
def print_diff_lumi(diff)
Definition: test_dcsc.py:21
test_dcsc.sum_lbs
def sum_lbs(iovs)
Definition: test_dcsc.py:15
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
test_dcsc.compare_iovs
def compare_iovs(a, b)
Definition: test_dcsc.py:41
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:131
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
python.utils.pprint_objects
def pprint_objects(objects, where=stdout)
Definition: DataQuality/DQUtils/python/utils.py:129
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
test_dcsc.main
def main()
Definition: test_dcsc.py:58
MDT
@ MDT
Definition: RegSelEnums.h:31