ATLAS Offline Software
Loading...
Searching...
No Matches
python.ids.DefectsDBIDsNamesMixin Class Reference
Inheritance diagram for python.ids.DefectsDBIDsNamesMixin:
Collaboration diagram for python.ids.DefectsDBIDsNamesMixin:

Public Types

typedef HLT::TypeInformation::for_each_type_c< typenameEDMLIST::map, my_functor, my_result<>, my_arg< HLT::TypeInformation::get_cont, CONTAINER > >::type result

Public Member Functions

None __init__ (self)
Set[int] defect_ids (self)
Set[str] defect_names (self)
MutableMapping[Union[str, int], Union[str, int]] defect_id_map (self)
Set[int] virtual_defect_ids (self)
Set[str] virtual_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], str] get_channel_descriptions (self, Iterable[Union[str, int]] channels)
MutableMapping[Union[str, int], str] get_virtual_channel_descriptions (self, Iterable[Union[str, int]] channels)
Mapping[Union[str, int], str] all_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)

Public Attributes

 virtual_defect_ids
 defect_names
 virtual_defect_names
 defect_ids

Protected 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)

Protected Attributes

bool _initialized = False
bool _virtual_initialized = False
dict _defect_id_map = {}
Set[int] _defect_ids = set()
Set[str] _defect_names = set()
dict _virtual_defect_id_map = {}
Set[int] _virtual_defect_ids = set()
Set[str] _virtual_defect_names = set()
dict _virtual_defect_map = {}
 _virtual_defect_logics = None

Detailed Description

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

Definition at line 73 of file ids.py.

Member Typedef Documentation

◆ result

Definition at line 90 of file EDM_MasterSearch.h.

Constructor & Destructor Documentation

◆ __init__()

None python.ids.DefectsDBIDsNamesMixin.__init__ ( self)

Definition at line 78 of file ids.py.

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

Member Function Documentation

◆ _new_defect()

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

Definition at line 120 of file ids.py.

120 def _new_defect(self, did: int, dname: str) -> None:
121 """
122 Internal function used to keep defect IDs/names uptodate.
123 """
124 self.defect_ids.add(did)
125 self.defect_names.add(dname)
126 self.defect_id_map[did] = dname
127 self.defect_id_map[dname] = did
128
bool add(const std::string &hname, TKey *tobj)
Definition fastadd.cxx:55

◆ _new_virtual_defect()

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

Definition at line 129 of file ids.py.

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

◆ _populate_defect_ids()

None python.ids.DefectsDBIDsNamesMixin._populate_defect_ids ( self)
protected
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 89 of file ids.py.

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

◆ _populate_virtual_defect_ids()

None python.ids.DefectsDBIDsNamesMixin._populate_virtual_defect_ids ( self)
protected
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 100 of file ids.py.

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

◆ 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 264 of file ids.py.

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

◆ 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 202 of file ids.py.

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

◆ 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 162 of file ids.py.

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

◆ defect_ids()

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

Definition at line 141 of file ids.py.

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

◆ 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 284 of file ids.py.

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

◆ defect_names()

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

Definition at line 151 of file ids.py.

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

◆ 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 227 of file ids.py.

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

◆ 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 245 of file ids.py.

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

◆ 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 233 of file ids.py.

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

◆ 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 254 of file ids.py.

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

◆ 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 239 of file ids.py.

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

◆ 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 307 of file ids.py.

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

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

◆ 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 193 of file ids.py.

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

◆ virtual_defect_ids()

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

Definition at line 173 of file ids.py.

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

◆ virtual_defect_names()

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

Definition at line 183 of file ids.py.

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

Member Data Documentation

◆ _defect_id_map

dict python.ids.DefectsDBIDsNamesMixin._defect_id_map = {}
protected

Definition at line 81 of file ids.py.

◆ _defect_ids

Set[int] python.ids.DefectsDBIDsNamesMixin._defect_ids = set()
protected

Definition at line 82 of file ids.py.

◆ _defect_names

Set[str] python.ids.DefectsDBIDsNamesMixin._defect_names = set()
protected

Definition at line 83 of file ids.py.

◆ _initialized

bool python.ids.DefectsDBIDsNamesMixin._initialized = False
protected

Definition at line 79 of file ids.py.

◆ _virtual_defect_id_map

dict python.ids.DefectsDBIDsNamesMixin._virtual_defect_id_map = {}
protected

Definition at line 84 of file ids.py.

◆ _virtual_defect_ids

Set[int] python.ids.DefectsDBIDsNamesMixin._virtual_defect_ids = set()
protected

Definition at line 85 of file ids.py.

◆ _virtual_defect_logics

python.ids.DefectsDBIDsNamesMixin._virtual_defect_logics = None
protected

Definition at line 138 of file ids.py.

◆ _virtual_defect_map

dict python.ids.DefectsDBIDsNamesMixin._virtual_defect_map = {}
protected

Definition at line 118 of file ids.py.

◆ _virtual_defect_names

Set[str] python.ids.DefectsDBIDsNamesMixin._virtual_defect_names = set()
protected

Definition at line 86 of file ids.py.

◆ _virtual_initialized

bool python.ids.DefectsDBIDsNamesMixin._virtual_initialized = False
protected

Definition at line 80 of file ids.py.

◆ defect_ids

python.ids.DefectsDBIDsNamesMixin.defect_ids

Definition at line 237 of file ids.py.

◆ defect_names

python.ids.DefectsDBIDsNamesMixin.defect_names

Definition at line 219 of file ids.py.

◆ virtual_defect_ids

python.ids.DefectsDBIDsNamesMixin.virtual_defect_ids

Definition at line 215 of file ids.py.

◆ virtual_defect_names

python.ids.DefectsDBIDsNamesMixin.virtual_defect_names

Definition at line 221 of file ids.py.


The documentation for this class was generated from the following file: