ATLAS Offline Software
Functions | Variables
python.channel_mapping Namespace Reference

Functions

def convert_channel (name, want_id=True, channel_mapping=channel_mapping)
 
def list_to_channelselection (list_, convert_channel=convert_channel, as_list=False)
 
def make_channelselection (cs, mapping=None)
 
def get_channel_ids_names (folder)
 

Variables

dictionary channel_mapping = {}
 
list channel_names = []
 
 cm_reversed = dict((value, key) for key, value in six.iteritems(channel_mapping))
 

Function Documentation

◆ convert_channel()

def python.channel_mapping.convert_channel (   name,
  want_id = True,
  channel_mapping = channel_mapping 
)
Given a channel, return a name detector or an integer (depending on want_id)

Definition at line 24 of file channel_mapping.py.

24 def convert_channel(name, want_id=True, channel_mapping=channel_mapping):
25  """
26  Given a channel, return a name detector or an integer (depending on want_id)
27  """
28  from builtins import int
29  if isinstance(name, int):
30  if name not in channel_mapping:
31  raise RuntimeError("ChannelID %r is not in channel_mapping" % name)
32  return name if want_id else channel_mapping[name]
33 
34  elif isinstance(name, str):
35  if name not in channel_mapping:
36  raise RuntimeError("ChannelID %r is not in channel_mapping" % name)
37  return name if not want_id else channel_mapping[name]
38 
39  raise RuntimeError("I don't know how to convert %r into "
40  "a ChannelSelection" % name)
41 

◆ get_channel_ids_names()

def python.channel_mapping.get_channel_ids_names (   folder)
Given a `folder` name, retrieve a list of channel ids, names and return a
dictionary which will translate in either direction.

Definition at line 102 of file channel_mapping.py.

102 def get_channel_ids_names(folder):
103  """
104  Given a `folder` name, retrieve a list of channel ids, names and return a
105  dictionary which will translate in either direction.
106  """
107  channel_ids = list(folder.listChannels())
108  channel_names = folder.listChannelsWithNames()
109  channel_names = list(map(channel_names.__getitem__, channel_ids))
110  channel_dict = dict(list(zip(channel_ids, channel_names))
111  +list(zip(channel_names, channel_ids)))
112  return channel_ids, channel_names, channel_dict
113 

◆ list_to_channelselection()

def python.channel_mapping.list_to_channelselection (   list_,
  convert_channel = convert_channel,
  as_list = False 
)
Given a list, return a channelselection.

Does the hard work of merging together adjacent channel numbers. Will also
convert channel names to numbers (if the folder is using DQ channels,
otherwise will give an incorrect result or fail to convert the strings to
channelids.)

Definition at line 42 of file channel_mapping.py.

42 def list_to_channelselection(list_, convert_channel=convert_channel,
43  as_list=False):
44  """
45  Given a list, return a channelselection.
46 
47  Does the hard work of merging together adjacent channel numbers. Will also
48  convert channel names to numbers (if the folder is using DQ channels,
49  otherwise will give an incorrect result or fail to convert the strings to
50  channelids.)
51  """
52  from PyCool import cool
53  if not list_ and as_list: return []
54  if not list_: return cool.ChannelSelection()
55  if set(map(type, list_)) != set([int]) and convert_channel:
56  list_ = map(convert_channel, list_)
57 
58  list_.sort()
59 
60  start = None
61  ranges = []
62  for this, next in zip(list_, list_[1:] + [-1]):
63  if start is None:
64  start = this
65  if next - this != 1:
66  ranges.append((start, this))
67  start = None
68 
69  if as_list:
70  return ranges
71 
72  assert len(ranges) < 50, (
73  "Cool has a 50 channel selection limit (%s selected)" % ranges)
74 
75  selection = cool.ChannelSelection(*ranges.pop(0))
76  for start, end in ranges:
77  selection.addRange(start, end)
78 
79  return selection
80 

◆ make_channelselection()

def python.channel_mapping.make_channelselection (   cs,
  mapping = None 
)
Helper function which can convert a channel id, name, or list of either into
a cool.ChannelSelection. Includes protections for invalid channels.

Definition at line 81 of file channel_mapping.py.

81 def make_channelselection(cs, mapping=None):
82  """
83  Helper function which can convert a channel id, name, or list of either into
84  a cool.ChannelSelection. Includes protections for invalid channels.
85  """
86  from PyCool import cool
87  if mapping is None:
88  mapping = channel_mapping
89  if cs is None or cs == []:
90  return cool.ChannelSelection()
91  elif isinstance(cs, (int, str)):
92  channel_id = convert_channel(cs, channel_mapping=mapping)
93  return cool.ChannelSelection(channel_id, channel_id)
94  elif hasattr(cs, "__iter__"):
95  cc = lambda cs: convert_channel(cs, channel_mapping=mapping)
96  return list_to_channelselection(cs, convert_channel=cc)
97  elif isinstance(cs, cool.ChannelSelection):
98  return cs
99  raise RuntimeError("I don't know how to convert %r into a "
100  "ChannelSelection" % cs)
101 

Variable Documentation

◆ channel_mapping

python.channel_mapping.channel_mapping = {}

Definition at line 14 of file channel_mapping.py.

◆ channel_names

dictionary python.channel_mapping.channel_names = []

Definition at line 15 of file channel_mapping.py.

◆ cm_reversed

python.channel_mapping.cm_reversed = dict((value, key) for key, value in six.iteritems(channel_mapping))

Definition at line 21 of file channel_mapping.py.

python.channel_mapping.make_channelselection
def make_channelselection(cs, mapping=None)
Definition: channel_mapping.py:81
python.channel_mapping.get_channel_ids_names
def get_channel_ids_names(folder)
Definition: channel_mapping.py:102
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
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.channel_mapping.list_to_channelselection
def list_to_channelselection(list_, convert_channel=convert_channel, as_list=False)
Definition: channel_mapping.py:42
python.channel_mapping.convert_channel
def convert_channel(name, want_id=True, channel_mapping=channel_mapping)
Definition: channel_mapping.py:24