ATLAS Offline Software
Functions | Variables
python.main Namespace Reference

Functions

def maketime (n)
 
def print_system_iovs (result)
 
def run_one (system, lbtime, run_iovs)
 
def run_parallel (systems, lbtime, run_iovs, N)
 
def run_sequential (systems, lbtime, run_iovs)
 
def go (iov, systems, db, indb, timewise=False, use_flask=False)
 
def main (argv)
 

Variables

 log
 

Function Documentation

◆ go()

def python.main.go (   iov,
  systems,
  db,
  indb,
  timewise = False,
  use_flask = False 
)
Run the DCS calculator for `run` on the `systems` specified, saving the 
result to the `database`.

Definition at line 93 of file DataQuality/DCSCalculator2/python/main.py.

93 def go(iov, systems, db, indb, timewise=False, use_flask=False):
94  """
95  Run the DCS calculator for `run` on the `systems` specified, saving the
96  result to the `database`.
97  """
98  since, until = iov
99 
100  with timer("Read LBLB"):
101  # fetch lumi block info
102  lblb = fetch_iovs("LBLB", since, until, with_channel=False, database=(indb if indb.startswith('sqlite') else 'COOLONL_TRIGGER/%s' % indb))
103  assert lblb, "No luminosity blocks for desired range. [%s, %s)" % (since, until)
104 
105  # lumi block time info
106  lbtime = inverse_lblb(lblb)
107 
108  # run_iovs is....?
109  if timewise:
110  run_iovs = run_iovs_from_lblb(lbtime)
111  else:
112  run_iovs = run_iovs_from_lblb(lblb)
113 
114  log.debug("Will process %i LBs over %i runs", len(lblb), len(run_iovs))
115 
116  log.info("DCSC2 will run over range: %r %s", tuple(run_iovs.range_iov), "(%i lbs)" % len(lblb))
117 
118  # Initialize the system objects
119  # This changes 'systems' from a list of types to a list of subdetector objects
120  systems = [system() for system in systems
121  if not getattr(system, "__DISABLED__", False)]
122 
123  # Run systems sequentially for this range
124  result_iovs = run_sequential(systems, lbtime, run_iovs)
125 
126  # Run parallel is broken because of the use of closures to implement the
127  # defect translation.
128  #result_iovs = run_parallel(systems, lbtime, run_iovs, parallel)
129 
130  if log.isEnabledFor(logging.DEBUG):
131  pprint_objects(result_iovs)
132 
133  log.info("Calculation complete")
134 
135  if db != "None":
136  try:
137  with timer("write result (%i iovs)" % len(result_iovs)):
138  log.debug("Writing result (%i iovs)", len(result_iovs))
139  defect_iovs = list(filter(lambda iov: isinstance(iov, DefectIOV), result_iovs)) # type: ignore
140  defect_iovs_full = [DefectIOVFull(recoverable=False, user='sys:defectcalculator', **_._asdict())
141  for _ in defect_iovs]
142  defect_iovs_full.append(DefectIOVFull(recoverable=False, user='sys:defectcalculator',
143  channel='GLOBAL_DCS_UNCHECKED', present=False,
144  comment='Calculator did run',
145  since=since, until=until))
146  if len(defect_iovs) > 0:
147  log.warning(f'db {db}, read_only {not use_flask}')
148  ddb = DefectsDB(db, read_only=use_flask, create=not use_flask)
149  defect_names = set(i.channel for i in defect_iovs_full)
150  for defect in defect_names:
151  if defect in ddb.defect_id_map:
152  continue
153  ddb.create_defect(defect, "Created by DCSCalculator2")
154  with ddb.storage_buffer if not use_flask else nullcontext():
155  if use_flask:
156  import os
157  import json
158  secret_path = os.environ.get('COOLFLASK_SECRET', '/afs/cern.ch/user/a/atlasdqm/private/coolflask_secret/coolflask_secret.json')
159  auth = json.loads(open(secret_path).read())
160  else:
161  auth = {}
162  ddb.insert_multiple(defect_iovs_full, use_flask=use_flask, flask_auth=auth)
163  except Exception:
164  log.warning("DCS Calculator failed to upload defects to DB")
165  if config.opts.email_on_failure:
166  from DataQualityUtils.panic import panic
167  from traceback import format_exc
168  runnum = lbtime[0].Run if len(lbtime)>0 else '??????'
169  panicmsg = "DCS Calculator failed to upload defects to database for run %s\n\n%s" % (runnum, format_exc())
170  panic(panicmsg)
171  raise
172 
173 
174  args = len(result_iovs), hash(result_iovs)
175  log.info("Success. Calculated %i iovs. Result hash: 0x%0x8.", *args)
176 

◆ main()

def python.main.main (   argv)

Definition at line 177 of file DataQuality/DCSCalculator2/python/main.py.

177 def main(argv):
178 
179  optp, opts, args = config.parse_options(argv)
180 
181  init_logger(opts.verbose)
182 
183  log.debug("Commandline arguments: %s", argv)
184  log.debug("Current configuration: %s", (opts))
185 
186  if opts.shell_on_exception:
187  import sys
188  from IPython.core import ultratb
189  sys.excepthook = ultratb.FormattedTB(call_pdb=True)
190  #from IPython.Shell import IPShellEmbed
191  #ipython_instance = IPShellEmbed(["-pdb"], rc_override=dict(quiet=True))
192 
193  if opts.systems is None:
194  systems = ALL_SYSTEMS
195 
196  else:
197  systems = []
198  invalid_systems = []
199  for system in opts.systems:
200  if system not in SYSTEM_MAP:
201  invalid_systems.append(system)
202  else:
203  systems.append(SYSTEM_MAP[system])
204 
205  if invalid_systems:
206  optp.error("Invalid system(s) specified: {0}. "
207  "Available systems: {1}".format(invalid_systems, SYSTEM_MAP.keys()))
208 
209 
210  if (opts.run and opts.range) or (not opts.run and not opts.range):
211  optp.error("Specify either -r or -R")
212  elif opts.run:
213  since, until = opts.run, opts.run
214  elif opts.range:
215  since, until = map(int, opts.range.split("-"))
216 
217  if opts.lbs:
218  if opts.range:
219  optp.error("--lbs and --range are incompatible. "
220  "Use --lbs with --run")
221  sincelb, untillb = map(int, opts.lbs.split("-"))
222  iov = RunLumi(since, sincelb), RunLumi(until, untillb)
223  else:
224  iov = RunLumi(since, 0), RunLumi(until+1, 0)
225 
226  go(iov, systems, opts.output_database, opts.input_database, opts.timewise, opts.flask)
227 

◆ maketime()

def python.main.maketime (   n)

Definition at line 25 of file DataQuality/DCSCalculator2/python/main.py.

25 def maketime(n):
26  if n < 1000000:
27  # Probably an LB.
28  return n
29  seconds = n / 1e9
30  hours = seconds / 3600; seconds %= 3600
31  minutes = seconds / 60; seconds %= 60
32  return "%ih%im%is" % (hours, minutes, seconds)
33 

◆ print_system_iovs()

def python.main.print_system_iovs (   result)

Definition at line 34 of file DataQuality/DCSCalculator2/python/main.py.

34 def print_system_iovs(result):
35  if not result:
36  log.info("Empty Result.")
37  return
38  #print result
39 
42 
43 
45 

◆ run_one()

def python.main.run_one (   system,
  lbtime,
  run_iovs 
)

Definition at line 46 of file DataQuality/DCSCalculator2/python/main.py.

46 def run_one(system, lbtime, run_iovs):
47  try:
48  with timer("Run DCS calculator 2 for %s" % system):
49  return system.run(lbtime, run_iovs)
50  except Exception:
51  log.warning("DCS Calculator failed to run for %s.", system)
52  if config.opts.dont_ignore_system_exceptions:
53  raise
54  log.exception("Continuing. Use -e -X commandline to investigate")
55  if config.opts.email_on_failure:
56  from DataQualityUtils.panic import panic
57  from traceback import format_exc
58  runnum = lbtime[0].Run if len(lbtime)>0 else '??????'
59  panicmsg = "DCS Calculator failed to execute in run %s for system %s.\n\n%s" % (runnum, system, format_exc())
60  panic(panicmsg)
61  return None
62  except (KeyboardInterrupt, SystemExit):
63  raise
64 

◆ run_parallel()

def python.main.run_parallel (   systems,
  lbtime,
  run_iovs,
  N 
)

Definition at line 65 of file DataQuality/DCSCalculator2/python/main.py.

65 def run_parallel(systems, lbtime, run_iovs, N):
66  pool = Pool(N if N > 0 else len(systems))
67  results = []
68  for system in systems:
69  result = pool.apply_async(run_one, (system, lbtime, run_iovs))
70  results.append(result)
71 
72  all_results = IOVSet()
73  for system, result in zip(systems, map(lambda x: x.get(), results)):
74  log.info(" -- result for %s", system)
75  print_system_iovs(result)
76  if result:
77  all_results.extend(result)
78 
79  return all_results
80 

◆ run_sequential()

def python.main.run_sequential (   systems,
  lbtime,
  run_iovs 
)

Definition at line 81 of file DataQuality/DCSCalculator2/python/main.py.

81 def run_sequential(systems, lbtime, run_iovs):
82  result_iovs = IOVSet()
83 
84  for system in systems:
85  log.info(" -- running for %s", system)
86  system_result = run_one(system, lbtime, run_iovs)
87  print_system_iovs(system_result)
88  if system_result:
89  result_iovs.extend(system_result)
90 
91  return result_iovs
92 

Variable Documentation

◆ log

python.main.log

Definition at line 7 of file DataQuality/DCSCalculator2/python/main.py.

read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
python.main.maketime
def maketime(n)
Definition: DataQuality/DCSCalculator2/python/main.py:25
python.iov_arrangement.inverse_lblb
def inverse_lblb(iovs)
Definition: iov_arrangement.py:34
vtune_athena.format
format
Definition: vtune_athena.py:14
python.main.run_sequential
def run_sequential(systems, lbtime, run_iovs)
Definition: DataQuality/DCSCalculator2/python/main.py:81
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.panic.panic
def panic(msg)
Definition: panic.py:5
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
covarianceTool.filter
filter
Definition: covarianceTool.py:514
python.sugar.runlumi.RunLumi
RunLumi
Definition: runlumi.py:131
python.main.print_system_iovs
def print_system_iovs(result)
Definition: DataQuality/DCSCalculator2/python/main.py:34
python.iov_arrangement.run_iovs_from_lblb
def run_iovs_from_lblb(lblb)
Definition: iov_arrangement.py:14
python.utils.pprint_objects
def pprint_objects(objects, where=stdout)
Definition: DataQuality/DQUtils/python/utils.py:129
python.main.run_one
def run_one(system, lbtime, run_iovs)
Definition: DataQuality/DCSCalculator2/python/main.py:46
python.variable.DefectIOVFull
def DefectIOVFull(channel, present, comment, recoverable=False, user='sys:defectcalculator')
Definition: variable.py:30
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.main.run_parallel
def run_parallel(systems, lbtime, run_iovs, N)
Definition: DataQuality/DCSCalculator2/python/main.py:65
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
python.logger.init_logger
def init_logger(verbose=False, quiet=False)
Definition: logger.py:113
python.main.main
def main(argv)
Definition: DataQuality/DCSCalculator2/python/main.py:177
python.main.go
def go(iov, systems, db, indb, timewise=False, use_flask=False)
Definition: DataQuality/DCSCalculator2/python/main.py:93
Trk::open
@ open
Definition: BinningType.h:40
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109