ATLAS Offline Software
Classes | Functions | Variables
python.KeyStore Namespace Reference

Classes

class  CfgItemList
 
class  CfgKeyStore
 

Functions

def __setattr__ (self, k, v)
 raise AttributeError( "CfgItemList' object has no attribute '%s'" % ( attr ) ) More...
 
def __delattr__ (self, attr)
 
def __bool__ (self)
 
def removeItem (self, item)
 
def removeAllItems (self, item)
 
def remove (self, items)
 
def removeAll (self)
 
def clear (self)
 
def setup (self)
 
def getProperties (self)
 
def _addItem (self, i)
 
def add (self, arg)
 
def has_item (self, item)
 
def allowWildCard (self, allow)
 
def __call__ (self, key=None)
 
def list (self, key=None)
 
def dict (self)
 
def __repr__ (self)
 
def __str__ (self, indent=0, headerLastIndentUnit=Configurable.indentUnit)
 
def name (self)
 
def children (self)
 
def allChildren (self)
 
def items (self)
 for l in self.keys(): yield self[l] More...
 
def clear (self, label=None)
 
def write (self, fileName, label)
 
def read (self, fileName, label)
 
def loadKeyStoreFromPoolFile (keyStore, pool_file, label='transient', items_type='eventdata')
 
def keystore_diff (ref, chk, labels=None, ofile=None)
 

Variables

string __version__ = '$Revision: 1.11 $'
 data More...
 
string __author__ = 'Sebastien Binet <binet@cern.ch>'
 
list __all__
 
 _allowedTriggerKeys = re.compile( r"(?P<KlassName>.*?)#HLTAutoKey.*\*$" )
 
 msg = logging.getLogger( 'CfgItemList' )
 
 _children
 
 _items
 
 _allowWildCard
 

Function Documentation

◆ __bool__()

def python.KeyStore.__bool__ (   self)

Definition at line 206 of file KeyStore.py.

206  def __bool__(self):
207  return True
208 

◆ __call__()

def python.KeyStore.__call__ (   self,
  key = None 
)

Definition at line 302 of file KeyStore.py.

302  def __call__( self, key = None ):
303  if key is not None:
304  items = set( [ i for i in self._items if i.startswith(key+"#") ] )
305  else:
306  items = set( self._items )
307  for c in self._children:
308  try:
309  for i in c.list( key ):
310  items.add( i )
311  except AttributeError as err:
312  msg.warning( err )
313  pass
314  items = [ i for i in items ]
315  items.sort()
316  return items
317 

◆ __delattr__()

def python.KeyStore.__delattr__ (   self,
  attr 
)

Definition at line 201 of file KeyStore.py.

201  def __delattr__( self, attr ):
202  for c in self._children:
203  if c._name == attr:
204  self._children.remove( c )
205 

◆ __repr__()

def python.KeyStore.__repr__ (   self)

Definition at line 329 of file KeyStore.py.

329  def __repr__( self ):
330  return '<%s/%s at %s>' % (self.__class__.__name__,self._name,
331  hex(id(self)))
332 

◆ __setattr__()

def python.KeyStore.__setattr__ (   self,
  k,
  v 
)

raise AttributeError( "CfgItemList' object has no attribute '%s'" % ( attr ) )

Definition at line 190 of file KeyStore.py.

190  def __setattr__( self, k, v ):
191  if k in CfgItemList.__slots__:
192  return super(CfgItemList, self).__setattr__(k, v)
193  for c in self.children():
194  if c.name() == k:
195  return setattr(c, k, v)
196  try:
197  return super(CfgItemList, self).__setattr__(k, v)
198  except AttributeError:
199  pass
200 

◆ __str__()

def python.KeyStore.__str__ (   self,
  indent = 0,
  headerLastIndentUnit = Configurable.indentUnit 
)

Definition at line 333 of file KeyStore.py.

333  def __str__( self, indent = 0,
334  headerLastIndentUnit=Configurable.indentUnit ):
335  global msg # to print some info depending on output level
336  indentStr = indent * Configurable.indentUnit
337  # print header
338  title = "%s/%s" % ( self.__class__.__name__, self._name )
339 
340  # print line to easily see start-of-configurable
341  if indent > 0:
342  headerIndent = (indent-1)*Configurable.indentUnit \
343  + headerLastIndentUnit
344  else:
345  headerIndent = ''
346 
347  rep = Configurable._printHeader( headerIndent, title )
348  rep += os.linesep
349 
350  # print own properties
351  props = self.getProperties()
352  if not props:
353  #rep += indentStr + '|-<no output-item-list>' + os.linesep
354  rep += indentStr + '| ' + os.linesep
355  else:
356  # get property name with
357  nameWidth = 0
358  for p in props.keys():
359  nameWidth=max(nameWidth,len(p))
360  for p, v in props.items():
361  # start with indent and property name
362  prefix = indentStr + '|-%-*s' % (nameWidth,p)
363  # add memory address for debugging (not for defaults)
364  if msg.isEnabledFor( logging.DEBUG ):
365  address = ' @%11s' % hex(id(v))
366  prefix += address
367  # add value and default
368  strVal = repr(v)
369  # add the value
370  line = prefix + ' = ' + strVal
371  # add the line to the total string
372  rep += line + os.linesep
373  # print configurables + their properties, or loop over sequence
374  for cfg in self.allChildren():
375  rep += cfg.__str__( indent + 1, '|=' ) + os.linesep
376 
377  # print line to easily see end-of-configurable. Note: No linesep!
378  rep += Configurable._printFooter( indentStr, title )
379  return rep
380 

◆ _addItem()

def python.KeyStore._addItem (   self,
  i 
)
private

Definition at line 259 of file KeyStore.py.

259  def _addItem( self, i ):
260  if i.count( "*" ) <= 0:
261  if i not in self._items:
262  self._items.append( i )
263  elif (self._allowWildCard or _allowedTriggerKeys.match(i)):
264  if i not in self._items:
265  self._items.append( i )
266  else:
267  msg.warning( "Attempt to add an invalid element: '%s'", i )
268  msg.warning( " ==> Ignoring invalid element: '%s'", i )
269  return
270 

◆ add()

def python.KeyStore.add (   self,
  arg 
)

Definition at line 271 of file KeyStore.py.

271  def add( self, arg ):
272  if isinstance(arg, (list, tuple) ):
273  for a in set(arg):
274  self._addItem( a )
275  elif isinstance(arg, str):
276  self._addItem( arg )
277  elif isinstance(arg, dict):
278  new = arg.copy()
279  for k in new.keys():
280  if not isinstance(new[k], (list,tuple)):
281  new[k] = ( new[k], )
282  self.add( [ '%s#%s' % (k,e) for e in new[k] ] )
283  else:
284  msg.error( "Could not add '%r' of type '%s'", arg, type(arg) )
285  return
286 

◆ allChildren()

def python.KeyStore.allChildren (   self)

Definition at line 387 of file KeyStore.py.

387  def allChildren( self ):
388  children = []
389  for c in self._children:
390  children.append( c )
391  children += c.allChildren()
392 
393  return children
394 

◆ allowWildCard()

def python.KeyStore.allowWildCard (   self,
  allow 
)

Definition at line 299 of file KeyStore.py.

299  def allowWildCard( self, allow ):
300  self._allowWildCard = allow
301 

◆ children()

def python.KeyStore.children (   self)

Definition at line 384 of file KeyStore.py.

384  def children( self ):
385  return self._children
386 

◆ clear() [1/2]

def python.KeyStore.clear (   self)

Definition at line 235 of file KeyStore.py.

235  def clear( self ):
236  self.removeAll()
237  self._items = []
238 

◆ clear() [2/2]

def python.KeyStore.clear (   self,
  label = None 
)

Definition at line 527 of file KeyStore.py.

527  def clear(self, label = None):
528  if label is not None:
529  self[label].clear()
530  else:
531  for c in self._items.children():
532  c.clear()
533  return
534 

◆ dict()

def python.KeyStore.dict (   self)

Definition at line 321 of file KeyStore.py.

321  def dict( self ):
322  props = self.getProperties()
323  for c in self._children:
324  props.update( c.dict() )
325  for k in props.keys():
326  props[k] = sorted(props[k])
327  return props
328 

◆ getProperties()

def python.KeyStore.getProperties (   self)

Definition at line 247 of file KeyStore.py.

247  def getProperties( self ):
248  props = {}
249  for item in self._items:
250  cppType = item.split("#")[0]
251  sgKey = item.replace( cppType+"#", '' )
252  if cppType in props:
253  if sgKey not in props[cppType]:
254  props[cppType].append( sgKey )
255  else:
256  props[cppType] = [ sgKey ]
257  return props
258 

◆ has_item()

def python.KeyStore.has_item (   self,
  item 
)

Definition at line 287 of file KeyStore.py.

287  def has_item( self, item ):
288  from fnmatch import fnmatchcase as match
289  for i in self._items:
290  if match(i, item):
291  return True
292 
293 
294  for c in self._children:
295  if c.has_item( item ):
296  return True
297  return False
298 

◆ items()

def python.KeyStore.items (   self)

for l in self.keys(): yield self[l]

Definition at line 524 of file KeyStore.py.

524  def items(self):
525  return zip( self.keys(), self.values() )
526 

◆ keystore_diff()

def python.KeyStore.keystore_diff (   ref,
  chk,
  labels = None,
  ofile = None 
)
Helper function to print the 'diff' of two KeyStores `ref` and `chk` into
the file-like object `ofile` (default value: sys.stdout)
 `ref` and `chk` can either be :
   - @c KeyStore.CfgKeyStore instances or,
   - strings being the names of the _already created_
     @c KeyStore.CfgKeyStore instances
 @param `labels` the list of labels (default: CfgKeyStore.Labels) to compare
        between the two CfgKeyStores

Definition at line 637 of file KeyStore.py.

637 def keystore_diff (ref, chk, labels=None, ofile=None):
638  """
639  Helper function to print the 'diff' of two KeyStores `ref` and `chk` into
640  the file-like object `ofile` (default value: sys.stdout)
641  `ref` and `chk` can either be :
642  - @c KeyStore.CfgKeyStore instances or,
643  - strings being the names of the _already created_
644  @c KeyStore.CfgKeyStore instances
645  @param `labels` the list of labels (default: CfgKeyStore.Labels) to compare
646  between the two CfgKeyStores
647  """
648  if isinstance (ref, str):
649  if ref not in CfgKeyStore.instances:
650  raise ValueError \
651  ('invalid `ref` argument (non existing instance name [%s])'%\
652  ref)
653  ref = CfgKeyStore.instances [ref]
654 
655  if isinstance (chk, str):
656  if chk not in CfgKeyStore.instances:
657  raise ValueError \
658  ('invalid `chk` argument (non existing instance name [%s])'%\
659  chk)
660  chk = CfgKeyStore.instances [chk]
661 
662  if labels is None:
663  labels = CfgKeyStore.__slots__['Labels']
664  elif isinstance (labels, str):
665  labels = [l.strip() for l in labels.split() if l.strip() != '']
666 
667  if ofile is None:
668  import sys
669  ofile = sys.stdout
670 
671  diff = []
672  if ref is chk or ref == chk:
673  return ""
674 
675  for label in labels:
676  ref_content = sorted (ref[label].list())
677  chk_content = sorted (chk[label].list())
678  if len(ref_content) != len(chk_content):
679  diff.append ("- len(ref[%s]) == %i" % (label,len(ref_content)))
680  diff.append ("+ len(chk[%s]) == %i" % (label,len(chk_content)))
681  for r in ref_content:
682  if r not in chk_content:
683  diff.append ("- ref[%s] : %s" % (label, r))
684  for c in chk_content:
685  if c not in ref_content:
686  diff.append ("+ chk[%s] : %s" % (label, c))
687  if len(diff) == 0:
688  return ""
689 
690  diff.append ("")
691  map (ofile.writelines, (d for d in os.linesep.join(diff)))
692  ofile.flush()
693  diff = "".join(diff)
694  return diff

◆ list()

def python.KeyStore.list (   self,
  key = None 
)

Definition at line 318 of file KeyStore.py.

318  def list( self, key = None ):
319  return self( key )
320 

◆ loadKeyStoreFromPoolFile()

def python.KeyStore.loadKeyStoreFromPoolFile (   keyStore,
  pool_file,
  label = 'transient',
  items_type = 'eventdata' 
)
Helper function to create a CfgKeyStore of name `keyStore` from the
content of the POOL file `pool_file` (a python string).
The content of the POOL file will be stored into the label `label`

Definition at line 609 of file KeyStore.py.

609 def loadKeyStoreFromPoolFile(keyStore, pool_file,
610  label='transient',
611  items_type='eventdata'):
612  """
613  Helper function to create a CfgKeyStore of name `keyStore` from the
614  content of the POOL file `pool_file` (a python string).
615  The content of the POOL file will be stored into the label `label`
616  """
617  if not isinstance(keyStore, str):
618  raise ValueError("argument 0 (`keyStore`) should be string")
619  if not isinstance(pool_file, str):
620  raise ValueError("argument 1 (`pool_file`) should be string")
621  if not isinstance(label, str):
622  raise ValueError("argument 2 (`label`) should be string")
623 
624  from PyUtils.PoolFile import extract_items
625  item_list = ['%s#%s'%(name,key)
626  for name,key in extract_items(pool_file,
627  verbose=False,
628  items_type=items_type)
629  ]
630  ks = CfgKeyStore(keyStore)
631  ks_label = getattr(ks, label)
632 
633  ks_label.add (item_list)
634 
635  return ks
636 

◆ name()

def python.KeyStore.name (   self)

Definition at line 381 of file KeyStore.py.

381  def name( self ):
382  return self._name
383 

◆ read()

def python.KeyStore.read (   self,
  fileName,
  label 
)

Definition at line 588 of file KeyStore.py.

588  def read( self, fileName, label ):
589  item = self[label]
590  import imp, inspect
591  from AthenaCommon.Include import FindFile,optionsPath
592  osp = os.path
593  name = osp.expanduser( osp.expandvars( fileName ) )
594  name = FindFile( name, optionsPath, os.R_OK )
595  if not name:
596  name = FindFile( osp.basename(fileName), optionsPath, os.R_OK )
597  uri = open( name, 'r' )
598  mod = imp.load_source( uri.name[:-3], uri.name, uri )
599  uri.close()
600 
601  fill = inspect.getmembers(
602  mod, lambda o: inspect.isfunction(o) and (o.__name__ == '_fill')
603  )[0][1]
604  fill( item )
605  return
606 

◆ remove()

def python.KeyStore.remove (   self,
  items 
)

Definition at line 226 of file KeyStore.py.

226  def remove( self, items ):
227  if not type(items) in ( type([]), type(()) ):
228  items = [ items ]
229 
230  self._children = [ e for e in self._children if e not in items ]
231 

◆ removeAll()

def python.KeyStore.removeAll (   self)

Definition at line 232 of file KeyStore.py.

232  def removeAll( self ):
233  self.remove( self._children )
234 

◆ removeAllItems()

def python.KeyStore.removeAllItems (   self,
  item 
)

Definition at line 220 of file KeyStore.py.

220  def removeAllItems( self, item ):
221  self.removeItem( item )
222  for c in self._children:
223  c.removeAllItems( item )
224  return
225 

◆ removeItem()

def python.KeyStore.removeItem (   self,
  item 
)

Definition at line 209 of file KeyStore.py.

209  def removeItem( self, item ):
210  if not type(item) in ( type([]), type(()) ):
211  items = ( item, )
212  else:
213  items = item
214  for item in items:
215  for i in self._items:
216  if i == item:
217  self._items.remove( i )
218  return
219 

◆ setup()

def python.KeyStore.setup (   self)

Definition at line 239 of file KeyStore.py.

239  def setup( self ):
240  msg.debug( 'setup of Output ItemList: %s', self._name )
241  if msg.isEnabledFor( logging.VERBOSE ):
242  msg.verbose( 'layout of sequence: %s\n%s', self._name, str(self) )
243 
244  for child in self.children():
245  child.setup()
246 

◆ write()

def python.KeyStore.write (   self,
  fileName,
  label 
)

Definition at line 562 of file KeyStore.py.

562  def write( self, fileName, label ):
563  item = self[label]
564  try:
565  from pprint import pprint
566  from datetime import datetime
567  from io import StringIO
568  buf = StringIO()
569  pprint( item.dict(), stream = buf )
570 
571  out = open( os.path.expanduser(os.path.expandvars(fileName)), 'w' )
572  out.writelines( os.linesep.join( [
573  "## autogenerated at [%s]" % str(datetime.now()),
574  "",
575  "## method filling an item-list with some data",
576  "def _fill( item ):",
577  " item.add(","%s )" % buf.getvalue(),
578  " return",
579  "",
580  "## EOF ##",
581  ] ) )
582  out.close()
583  except Exception as e:
584  print ("Py:Error :",e)
585  raise e
586  return
587 

Variable Documentation

◆ __all__

list python.KeyStore.__all__
private
Initial value:
1 = [ "CfgItemList", "CfgKeyStore",
2  "loadKeyStoreFromPoolFile",
3  "keystore_diff" ]

Definition at line 10 of file KeyStore.py.

◆ __author__

string python.KeyStore.__author__ = 'Sebastien Binet <binet@cern.ch>'
private

Definition at line 8 of file KeyStore.py.

◆ __version__

string python.KeyStore.__version__ = '$Revision: 1.11 $'
private

data

Definition at line 7 of file KeyStore.py.

◆ _allowedTriggerKeys

python.KeyStore._allowedTriggerKeys = re.compile( r"(?P<KlassName>.*?)#HLTAutoKey.*\*$" )
private

Definition at line 19 of file KeyStore.py.

◆ _allowWildCard

python.KeyStore._allowWildCard
private

Definition at line 300 of file KeyStore.py.

◆ _children

python.KeyStore._children
private

Definition at line 230 of file KeyStore.py.

◆ _items

python.KeyStore._items
private

Definition at line 237 of file KeyStore.py.

◆ msg

python.KeyStore.msg = logging.getLogger( 'CfgItemList' )

Definition at line 26 of file KeyStore.py.

read
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
Definition: openCoraCool.cxx:569
python.KeyStore.children
def children(self)
Definition: KeyStore.py:384
max
#define max(a, b)
Definition: cfImp.cxx:41
python.KeyStore.__call__
def __call__(self, key=None)
Definition: KeyStore.py:302
python.KeyStore.__repr__
def __repr__(self)
Definition: KeyStore.py:329
python.KeyStore.__str__
def __str__(self, indent=0, headerLastIndentUnit=Configurable.indentUnit)
Definition: KeyStore.py:333
python.KeyStore.__setattr__
def __setattr__(self, k, v)
raise AttributeError( "CfgItemList' object has no attribute '%s'" % ( attr ) )
Definition: KeyStore.py:190
python.KeyStore.has_item
def has_item(self, item)
Definition: KeyStore.py:287
python.KeyStore.clear
def clear(self, label=None)
Definition: KeyStore.py:527
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:94
python.KeyStore.items
def items(self)
for l in self.keys(): yield self[l]
Definition: KeyStore.py:524
python.KeyStore.allChildren
def allChildren(self)
Definition: KeyStore.py:387
python.KeyStore.removeAllItems
def removeAllItems(self, item)
Definition: KeyStore.py:220
python.KeyStore.__delattr__
def __delattr__(self, attr)
Definition: KeyStore.py:201
python.Utils.unixtools.FindFile
def FindFile(filename, pathlist, access)
helper -------------------------------------------------------------------—
Definition: unixtools.py:20
python.KeyStore.dict
def dict(self)
Definition: KeyStore.py:321
python.KeyStore.__bool__
def __bool__(self)
Definition: KeyStore.py:206
python.KeyStore.write
def write(self, fileName, label)
Definition: KeyStore.py:562
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
add
bool add(const std::string &hname, TKey *tobj)
Definition: fastadd.cxx:55
python.KeyStore.removeItem
def removeItem(self, item)
Definition: KeyStore.py:209
python.KeyStore.keystore_diff
def keystore_diff(ref, chk, labels=None, ofile=None)
Definition: KeyStore.py:637
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.KeyStore.remove
def remove(self, items)
Definition: KeyStore.py:226
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
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
python.KeyStore.loadKeyStoreFromPoolFile
def loadKeyStoreFromPoolFile(keyStore, pool_file, label='transient', items_type='eventdata')
Definition: KeyStore.py:609
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Trk::open
@ open
Definition: BinningType.h:40
python.KeyStore.getProperties
def getProperties(self)
Definition: KeyStore.py:247
lumiFormat.fill
fill
Definition: lumiFormat.py:111
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.KeyStore.list
def list(self, key=None)
Definition: KeyStore.py:318
str
Definition: BTagTrackIpAccessor.cxx:11
python.PoolFile.extract_items
def extract_items(pool_file, verbose=True, items_type='eventdata')
Definition: PoolFile.py:446
python.KeyStore._addItem
def _addItem(self, i)
Definition: KeyStore.py:259
python.setup
def setup()
Definition: Control/Hephaestus/python/__init__.py:9
python.KeyStore.removeAll
def removeAll(self)
Definition: KeyStore.py:232
python.KeyStore.allowWildCard
def allowWildCard(self, allow)
Definition: KeyStore.py:299
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356