ATLAS Offline Software
libcore.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2 
3 import logging; log = logging.getLogger("DCSCalculator2.libcore")
4 
5 from DQUtils.iov_arrangement import flatten_channels
6 #from DQUtils.sugar import RunLumi, IOVSet
7 
9  from PyCool import cool
10  ST = cool.StorageType
11  return [("Code", ST.Int32),
12  ("deadFrac", ST.Float),
13  ("Thrust", ST.Float),
14  ("NConfig", ST.Int32),
15  ("NWorking", ST.Int32)]
16 
17 def make_multi_mapping(iterable):
18  """
19  When more than one value can map to the same key, we need
20  {key, [value1, value2]}.
21 
22  This function builds it out of [(key, value1), (key, value2)]
23 
24  Beware, values cannot be lists.
25  """
26 
27  result = {}
28 
29  for key, value in iterable:
30  if key in result and not isinstance(result[key], list):
31  result[key] = [result[key], value]
32  elif key in result:
33  result[key].append(value)
34  else:
35  result[key] = value
36 
37  return result
38 
39 def map_channels(iovs, mapping, folder):
40  """
41  Remap the input channel identifiers. Returns a new IOVSet
42  with the channel number changed according to the provided mapping
43  """
44 
45  # look for unmapped channels
46  bad_channels = set()
47  def has_channel(c):
48  result = c in mapping
49  if not result:
50  bad_channels.add(c)
51  return result
52 
53  IOVSet = iovs.empty
54  iovs = IOVSet(iov._replace(channel=mapping[iov.channel])
55  for iov in iovs if has_channel(iov.channel))
56 
57  if bad_channels:
58  log.debug("WARNING: %s has %i unmapped channels %r",
59  folder, len(bad_channels), repr(bad_channels))
60 
61  # Remove lists from channel field of iovs
62  iovs = flatten_channels(iovs)
63 
64  # Traditional COOL ordering
65  iovs.sort(key=lambda iov: (iov.channel, iov.since))
66 
67  return IOVSet(iovs)
68 
70  previous = None
71  for iov in generator:
72  if (previous and previous.connected_to(iov) and
73  previous.comment==iov.comment and previous.channel==iov.channel and
74  previous.present==iov.present):
75  previous = previous._replace(until=iov.until)
76  else:
77  if previous:
78  yield previous
79  previous = iov
80  if previous:
81  yield previous
82 
python.libcore.map_channels
def map_channels(iovs, mapping, folder)
Definition: libcore.py:39
python.libcore.make_multi_mapping
def make_multi_mapping(iterable)
Definition: libcore.py:17
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
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.libcore.connect_adjacent_iovs_defect
def connect_adjacent_iovs_defect(generator)
Definition: libcore.py:69
python.libcore.dcsofl_cool_record
def dcsofl_cool_record()
Definition: libcore.py:8
python.iov_arrangement.flatten_channels
def flatten_channels(iovs)
Definition: iov_arrangement.py:79