ATLAS Offline Software
Loading...
Searching...
No Matches
libcore.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3import logging; log = logging.getLogger("DCSCalculator2.libcore")
4
5from 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
17def 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
39def 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
STL class.
map_channels(iovs, mapping, folder)
Definition libcore.py:39
dcsofl_cool_record()
Definition libcore.py:8
make_multi_mapping(iterable)
Definition libcore.py:17
connect_adjacent_iovs_defect(generator)
Definition libcore.py:69