ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
python.ids.DefectsDBIDsNamesMixin Class Reference
Inheritance diagram for python.ids.DefectsDBIDsNamesMixin:
Collaboration diagram for python.ids.DefectsDBIDsNamesMixin:

Public Member Functions

None __init__ (self)
 
Set[int] defect_ids (self)
 
Set[strdefect_names (self)
 
MutableMapping[Union[str, int], Union[str, int]] defect_id_map (self)
 
Set[int] virtual_defect_ids (self)
 
Set[strvirtual_defect_names (self)
 
MutableMapping[Union[str, int], Union[str, int]] virtual_defect_id_map (self)
 
int defect_chan_as_id (self, Union[str, int] channel, bool primary_only=False)
 
List[int] defect_names_as_ids (self, Iterable[Union[str, int]] channels)
 
Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]] get_channels (self)
 
Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]] get_virtual_channels (self)
 
MutableMapping[Union[str, int], strget_channel_descriptions (self, Iterable[Union[str, int]] channels)
 
MutableMapping[Union[str, int], strget_virtual_channel_descriptions (self, Iterable[Union[str, int]] channels)
 
Mapping[Union[str, int], strall_defect_descriptions (self)
 
None set_channel_description (self, Union[str, int] channel, str description)
 
bool defect_is_virtual (self, Union[str, int] defect_id)
 
Union[str, List[str]] normalize_defect_names (self, Union[str, Iterable[str]] defect_id)
 

Private Member Functions

None _populate_defect_ids (self)
 
None _populate_virtual_defect_ids (self)
 
None _new_defect (self, int did, str dname)
 
None _new_virtual_defect (self, int did, str dname)
 

Private Attributes

 _initialized
 
 _virtual_initialized
 
 _defect_ids
 
 _defect_names
 
 _defect_id_map
 
 _virtual_defect_names
 
 _virtual_defect_ids
 
 _virtual_defect_id_map
 
 _virtual_defect_map
 
 _virtual_defect_logics
 

Detailed Description

Contains the logic for storing knowledge of which defects exist, and their
channel names and IDs

Definition at line 74 of file ids.py.

Constructor & Destructor Documentation

◆ __init__()

None python.ids.DefectsDBIDsNamesMixin.__init__ (   self)

Definition at line 79 of file ids.py.

79  def __init__(self) -> None:
80  self._initialized = False
81  self._virtual_initialized = False
82  self._defect_id_map: MutableMapping[Union[str,int], Union[str,int]] = {}
83  self._defect_ids: Set[int] = set()
84  self._defect_names: Set[str] = set()
85  self._virtual_defect_id_map: MutableMapping[Union[str,int], Union[str,int]] = {}
86  self._virtual_defect_ids: Set[int] = set()
87  self._virtual_defect_names: Set[str] = set()
88  super(DefectsDBIDsNamesMixin, self).__init__()
89 

Member Function Documentation

◆ _new_defect()

None python.ids.DefectsDBIDsNamesMixin._new_defect (   self,
int  did,
str  dname 
)
private
Internal function used to keep defect IDs/names uptodate.

Definition at line 121 of file ids.py.

121  def _new_defect(self, did: int, dname: str) -> None:
122  """
123  Internal function used to keep defect IDs/names uptodate.
124  """
125  self.defect_ids.add(did)
126  self.defect_names.add(dname)
127  self.defect_id_map[did] = dname
128  self.defect_id_map[dname] = did
129 

◆ _new_virtual_defect()

None python.ids.DefectsDBIDsNamesMixin._new_virtual_defect (   self,
int  did,
str  dname 
)
private
Internal function used to keep defect IDs/names uptodate.

Definition at line 130 of file ids.py.

130  def _new_virtual_defect(self, did: int, dname: str) -> None:
131  """
132  Internal function used to keep defect IDs/names uptodate.
133  """
134  self.virtual_defect_ids.add(did)
135  self.virtual_defect_names.add(dname)
136  self.virtual_defect_id_map[did] = dname
137  self.virtual_defect_id_map[dname] = did
138  # Reset this so we will reload logic later
139  self._virtual_defect_logics = None
140 

◆ _populate_defect_ids()

None python.ids.DefectsDBIDsNamesMixin._populate_defect_ids (   self)
private
Called the first time any of defect_{ids,names,id_map,etc} is called,
and populates internal variables to store the channel ids/names for the
life of the DefectsDB instance.

Definition at line 90 of file ids.py.

90  def _populate_defect_ids(self) -> None:
91  """
92  Called the first time any of defect_{ids,names,id_map,etc} is called,
93  and populates internal variables to store the channel ids/names for the
94  life of the DefectsDB instance.
95  """
96  ids, names, mapping = get_channel_ids_names(self.defects_folder)
97  self._defect_ids = set(ids)
98  self._defect_names = set(names)
99  self._defect_id_map = mapping
100 

◆ _populate_virtual_defect_ids()

None python.ids.DefectsDBIDsNamesMixin._populate_virtual_defect_ids (   self)
private
Called the first time any of virtual_defect_{ids,names,id_map,etc} is called,
and populates internal variables to store the channel ids/names for the
life of the DefectsDB instance.

Definition at line 101 of file ids.py.

101  def _populate_virtual_defect_ids(self) -> None:
102  """
103  Called the first time any of virtual_defect_{ids,names,id_map,etc} is called,
104  and populates internal variables to store the channel ids/names for the
105  life of the DefectsDB instance.
106  """
107  _, _, mapping = get_channel_ids_names(self.defect_logic_folder)
108  try:
109  self._virtual_defect_names = set(self.virtual_defect_logics.keys())
110  self._virtual_defect_ids = set(mapping[name] for name in self._virtual_defect_names)
111  all_defects = self._virtual_defect_names | self._virtual_defect_ids
112  self._virtual_defect_id_map = dict(item for item in mapping.items()
113  if item[0] in all_defects)
114  except InvalidLogicTagError:
115  # Presumably this tag doesn't exist yet, which is ok if we're about
116  # to create some new virtual defects. ?
117  self._virtual_defect_names = set()
118  self._virtual_defect_ids = set()
119  self._virtual_defect_map = {}
120 

◆ all_defect_descriptions()

Mapping[Union[str, int], str] python.ids.DefectsDBIDsNamesMixin.all_defect_descriptions (   self)
A dictionary of all (virtual and primary) defect descriptions

Definition at line 265 of file ids.py.

265  def all_defect_descriptions(self) -> Mapping[Union[str, int], str]:
266  """
267  A dictionary of all (virtual and primary) defect descriptions
268  """
269  result = self.get_channel_descriptions(self.defect_names)
270  gvcd = self.get_virtual_channel_descriptions
271  result.update(gvcd(self.virtual_defect_names))
272  return result
273 

◆ defect_chan_as_id()

int python.ids.DefectsDBIDsNamesMixin.defect_chan_as_id (   self,
Union[str, int]  channel,
bool   primary_only = False 
)
Returns the defect ID for a virtual defect.
Accepts a `channel` as an integer/string and returns it as an integer.

Will raise DefectUnknownError if `channel` is an unknown ID or string.

This function first checks against non-virtual defects, then virutal 
defects. Thus virtual-defects are lazily loaded.        

Definition at line 203 of file ids.py.

203  def defect_chan_as_id(self, channel: Union[str, int], primary_only: bool = False) -> int:
204  """
205  Returns the defect ID for a virtual defect.
206  Accepts a `channel` as an integer/string and returns it as an integer.
207 
208  Will raise DefectUnknownError if `channel` is an unknown ID or string.
209 
210  This function first checks against non-virtual defects, then virutal
211  defects. Thus virtual-defects are lazily loaded.
212  """
213  from builtins import int
214  if isinstance(channel, int):
215  if (channel not in self.defect_ids and
216  (not primary_only and channel not in self.virtual_defect_ids)):
217  raise DefectUnknownError(channel)
218  return channel
219  elif isinstance(channel, six.string_types):
220  if channel in self.defect_names:
221  return self.defect_id_map[channel]
222  if not primary_only and channel in self.virtual_defect_names:
223  return self.virtual_defect_id_map[channel]
224  raise DefectUnknownError(channel)
225  raise RuntimeError("Invalid `channel` type, got %s, expected integer"
226  " or string" % type(channel))
227 

◆ defect_id_map()

MutableMapping[Union[str,int], Union[str,int]] python.ids.DefectsDBIDsNamesMixin.defect_id_map (   self)
Gives the dictionary relating COOL channel ids to defect names and vice
versa, retrieving them from the database if necessary.

Definition at line 163 of file ids.py.

163  def defect_id_map(self) -> MutableMapping[Union[str,int], Union[str,int]]:
164  """
165  Gives the dictionary relating COOL channel ids to defect names and vice
166  versa, retrieving them from the database if necessary.
167  """
168  if not self._initialized:
169  self._populate_defect_ids()
170  self._initialized = True
171  return self._defect_id_map
172 

◆ defect_ids()

Set[int] python.ids.DefectsDBIDsNamesMixin.defect_ids (   self)
Gives the set of defect IDs that exist in COOL

Definition at line 142 of file ids.py.

142  def defect_ids(self) -> Set[int]:
143  """
144  Gives the set of defect IDs that exist in COOL
145  """
146  if not self._initialized:
147  self._populate_defect_ids()
148  self._initialized = True
149  return self._defect_ids
150 

◆ defect_is_virtual()

bool python.ids.DefectsDBIDsNamesMixin.defect_is_virtual (   self,
Union[str, int]  defect_id 
)
Returns True if the `defect_id` represents a virtual defect, False if it 
is not and raises if it doesn't exist

Parameters:
    `defect_id` : defect channel id or name

Definition at line 285 of file ids.py.

285  def defect_is_virtual(self, defect_id: Union[str, int]) -> bool:
286  """
287  Returns True if the `defect_id` represents a virtual defect, False if it
288  is not and raises if it doesn't exist
289 
290  Parameters:
291  `defect_id` : defect channel id or name
292  """
293  from builtins import int
294  if isinstance(defect_id, int):
295  return DefectID(defect_id).is_virtual
296 
297  if not isinstance(defect_id, six.string_types):
298  raise RuntimeError("Invalid defect_id, expected int or string")
299 
300  if defect_id in self.defect_names:
301  return False
302 
303  if defect_id in self.virtual_defect_names:
304  return True
305 
306  raise DefectUnknownError(defect_id)
307 

◆ defect_names()

Set[str] python.ids.DefectsDBIDsNamesMixin.defect_names (   self)
Gives the set of defect names that exist in COOL

Definition at line 152 of file ids.py.

152  def defect_names(self) -> Set[str]:
153  """
154  Gives the set of defect names that exist in COOL
155  """
156  if not self._initialized:
157  self._populate_defect_ids()
158  self._initialized = True
159  assert self._defect_names is not None, self._initialized
160  return self._defect_names
161 

◆ defect_names_as_ids()

List[int] python.ids.DefectsDBIDsNamesMixin.defect_names_as_ids (   self,
Iterable[Union[str, int]]  channels 
)
Returns a list of channels as IDs

Definition at line 228 of file ids.py.

228  def defect_names_as_ids(self, channels: Iterable[Union[str, int]]) -> List[int]:
229  """
230  Returns a list of channels as IDs
231  """
232  return [self.defect_chan_as_id(chan) for chan in channels]
233 

◆ get_channel_descriptions()

MutableMapping[Union[str, int], str] python.ids.DefectsDBIDsNamesMixin.get_channel_descriptions (   self,
Iterable[Union[str, int]]  channels 
)
For the list of channel IDs "channels", return dict mapping ID to
description

Definition at line 246 of file ids.py.

246  def get_channel_descriptions(self, channels: Iterable[Union[str, int]]) -> MutableMapping[Union[str, int], str]:
247  """
248  For the list of channel IDs "channels", return dict mapping ID to
249  description
250  """
251  get_desc = self.defects_folder.channelDescription
252  return {channel: get_desc(self.defect_chan_as_id(channel))
253  for channel in channels}
254 

◆ get_channels()

Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]] python.ids.DefectsDBIDsNamesMixin.get_channels (   self)
Return channel IDs, names, and dict relating the two

Definition at line 234 of file ids.py.

234  def get_channels(self) -> Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]]:
235  """
236  Return channel IDs, names, and dict relating the two
237  """
238  return self.defect_ids, self.defect_names, self.defect_id_map
239 

◆ get_virtual_channel_descriptions()

MutableMapping[Union[str, int], str] python.ids.DefectsDBIDsNamesMixin.get_virtual_channel_descriptions (   self,
Iterable[Union[str, int]]  channels 
)
For the list of channel IDs "channels", return dict mapping ID to
descriptiondefect_id

Definition at line 255 of file ids.py.

255  def get_virtual_channel_descriptions(self, channels: Iterable[Union[str, int]]) -> MutableMapping[Union[str, int], str]:
256  """
257  For the list of channel IDs "channels", return dict mapping ID to
258  descriptiondefect_id
259  """
260  get_desc = self.defect_logic_folder.channelDescription
261  return {channel: get_desc(self.defect_chan_as_id(channel))
262  for channel in channels}
263 

◆ get_virtual_channels()

Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]] python.ids.DefectsDBIDsNamesMixin.get_virtual_channels (   self)
Return channel IDs, names, and dict relating the two

Definition at line 240 of file ids.py.

240  def get_virtual_channels(self) -> Tuple[Set[int], Set[str], Mapping[Union[str, int], Union[str, int]]]:
241  """
242  Return channel IDs, names, and dict relating the two
243  """
244  return self.virtual_defect_ids, self.virtual_defect_names, self.virtual_defect_id_map
245 

◆ normalize_defect_names()

Union[str, List[str]] python.ids.DefectsDBIDsNamesMixin.normalize_defect_names (   self,
Union[str, Iterable[str]]  defect_id 
)
Returns correct name(s) of defects, given name(s) that possibly differ
from the correct ones by case.  Raises if an input name doesn't map to
any existing defect.  You can pass either a string or an iterable
object as `defect_id`.

Definition at line 308 of file ids.py.

308  def normalize_defect_names(self, defect_id: Union[str, Iterable[str]]) -> Union[str, List[str]]:
309  """
310  Returns correct name(s) of defects, given name(s) that possibly differ
311  from the correct ones by case. Raises if an input name doesn't map to
312  any existing defect. You can pass either a string or an iterable
313  object as `defect_id`.
314  """
315  wasstring = False
316  if isinstance(defect_id, six.string_types):
317  defect_id = [defect_id]
318  wasstring = True
319  if any(not isinstance(i, six.string_types) for i in defect_id):
320  raise ValueError('All input values must be strings')
321 
322  uppered_defects = dict((i.upper(), i) for i in self.defect_names)
323  uppered_defects.update(dict((i.upper(), i) for i in self.virtual_defect_names))
324 
325  rv = []
326  for i in defect_id:
327  up = i.upper()
328  if up in uppered_defects:
329  rv.append(uppered_defects[up])
330  else:
331  raise DefectUnknownError(i)
332 
333  if wasstring:
334  return rv[0]
335  else:
336  return rv

◆ set_channel_description()

None python.ids.DefectsDBIDsNamesMixin.set_channel_description (   self,
Union[str, int]  channel,
str  description 
)
Set a defect description

Definition at line 274 of file ids.py.

274  def set_channel_description(self, channel: Union[str, int], description: str) -> None:
275  """
276  Set a defect description
277  """
278  chan_id = self.defect_chan_as_id(channel)
279  if self.defect_is_virtual(chan_id):
280  folder = self.defect_logic_folder
281  else:
282  folder = self.defects_folder
283  folder.setChannelDescription(chan_id, description.encode('utf-8'))
284 

◆ virtual_defect_id_map()

MutableMapping[Union[str,int], Union[str,int]] python.ids.DefectsDBIDsNamesMixin.virtual_defect_id_map (   self)
Returns a dict() mapping virtual defect names to IDs and vice-versa.

Definition at line 194 of file ids.py.

194  def virtual_defect_id_map(self) -> MutableMapping[Union[str,int], Union[str,int]]:
195  """
196  Returns a dict() mapping virtual defect names to IDs and vice-versa.
197  """
198  if not self._virtual_initialized:
199  self._populate_virtual_defect_ids()
200  self._virtual_initialized = True
201  return self._virtual_defect_id_map
202 

◆ virtual_defect_ids()

Set[int] python.ids.DefectsDBIDsNamesMixin.virtual_defect_ids (   self)
Returns the set of existing virtual defect IDs

Definition at line 174 of file ids.py.

174  def virtual_defect_ids(self) -> Set[int]:
175  """
176  Returns the set of existing virtual defect IDs
177  """
178  if not self._virtual_initialized:
179  self._populate_virtual_defect_ids()
180  self._virtual_initialized = True
181  return self._virtual_defect_ids
182 

◆ virtual_defect_names()

Set[str] python.ids.DefectsDBIDsNamesMixin.virtual_defect_names (   self)
Returns the set of existing virtual defect names

Definition at line 184 of file ids.py.

184  def virtual_defect_names(self) -> Set[str]:
185  """
186  Returns the set of existing virtual defect names
187  """
188  if not self._virtual_initialized:
189  self._populate_virtual_defect_ids()
190  self._virtual_initialized = True
191  return self._virtual_defect_names
192 

Member Data Documentation

◆ _defect_id_map

python.ids.DefectsDBIDsNamesMixin._defect_id_map
private

Definition at line 99 of file ids.py.

◆ _defect_ids

python.ids.DefectsDBIDsNamesMixin._defect_ids
private

Definition at line 97 of file ids.py.

◆ _defect_names

python.ids.DefectsDBIDsNamesMixin._defect_names
private

Definition at line 98 of file ids.py.

◆ _initialized

python.ids.DefectsDBIDsNamesMixin._initialized
private

Definition at line 80 of file ids.py.

◆ _virtual_defect_id_map

python.ids.DefectsDBIDsNamesMixin._virtual_defect_id_map
private

Definition at line 112 of file ids.py.

◆ _virtual_defect_ids

python.ids.DefectsDBIDsNamesMixin._virtual_defect_ids
private

Definition at line 110 of file ids.py.

◆ _virtual_defect_logics

python.ids.DefectsDBIDsNamesMixin._virtual_defect_logics
private

Definition at line 139 of file ids.py.

◆ _virtual_defect_map

python.ids.DefectsDBIDsNamesMixin._virtual_defect_map
private

Definition at line 119 of file ids.py.

◆ _virtual_defect_names

python.ids.DefectsDBIDsNamesMixin._virtual_defect_names
private

Definition at line 109 of file ids.py.

◆ _virtual_initialized

python.ids.DefectsDBIDsNamesMixin._virtual_initialized
private

Definition at line 81 of file ids.py.


The documentation for this class was generated from the following file:
python.channel_mapping.get_channel_ids_names
def get_channel_ids_names(folder)
Definition: channel_mapping.py:102
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
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.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790