Commit 12afed8c authored by Alex Pearce's avatar Alex Pearce
Browse files

added PhysSel/PhysSelPython from Phys (Phys/v22r1)

parent a1117e57
......@@ -43,3 +43,6 @@
[lb-checkout "Analysis.Phys/AnalysisConf"]
base = 952b64dd00ad765681114d8feb395aaadca223dc
imported = 501800938971bb57ca1cd42020d5912b45bce927
[lb-checkout "Phys.PhysSel/PhysSelPython"]
base = 8896a4b01a63c578dfd2102c22ebbaa4bdb4eb87
imported = a7c275f30404f33968419a46de8912cca9490444
################################################################################
# Package: PhysSelPython
################################################################################
gaudi_subdir(PhysSelPython v9r11)
gaudi_depends_on_subdirs(GaudiConf
GaudiConfUtils
GaudiPython
Phys/SelPy)
find_package(pytools)
gaudi_install_python_modules()
gaudi_add_test(QMTest QMTEST)
#$Id$
#============================================================================
# Created : 2009-07-13
# Maintainer : Juan PALACIOS
#============================================================================
package PhysSelPython
version v9r11
#============================================================================
# Structure, i.e. directories to process.
#============================================================================
branches cmt doc python
#============================================================================
# Used packages. Specify the version, * at the end specifies 'any revision'
# Put as many lines as needed, with all packages, without the '#'
#============================================================================
use GaudiPython v*
use GaudiConfUtils v* -no_auto_imports
use GaudiConf v* -no_auto_imports
use SelPy v* Phys -no_auto_imports
use pytools v* LCG_Interfaces -no_auto_imports
#============================================================================
apply_pattern install_python_modules
#============================================================================
apply_pattern QMTest
#============================================================================
This diff is collapsed.
"""Module with all kinds of tools to cure the sick, sick Configurables.
"""
from GaudiKernel.Configurable import Configurable
from GaudiConfUtils import isIterable
from GaudiConfUtils import isConfigurable
from GaudiConfUtils import getConfigurablesFromModule
from GaudiConfUtils import configurableExists
import inspect
__author__ = 'Juan Palacios palacios@physik.uzh.ch'
__all__ = ('SaneConfigurable',
'sanitise')
_originalCloner = Configurable.clone
def _saneClone(obj, name, **kwargs) :
print 'Try to clone to a new configurable', name
if configurableExists(name) :
raise ValueError('Configurable '+ name + ' already exists. Pick a new name')
else :
print 'Configurable', name, 'does not exist. Proceed with cloning.'
return _originalCloner(obj, name, **kwargs)
class SaneConfigurable(object) :
def __init__(self, configurableType) :
if not isConfigurable(configurableType) :
raise TypeError('SaneConfigurable only works for Configurables!')
configurableType.clone = _saneClone
self.configurableType = configurableType
self.name = type(configurableType).__name__
self.__name__ = self.name
def __call__(self, name='', **kwargs) :
if name == '' :
name = self.name
print 'Try to instantiate a new configurable', name
if configurableExists(name) :
raise ValueError('Configurable '+ name + ' already exists. Pick a new name')
else :
print 'Configurable', name, 'does not exist. Build it.'
saneConfig = self.configurableType(name, **kwargs)
return saneConfig
import Configurables as _crazyConfigurables
class memoized_sanitise(object) :
"""
Take a list consisting of Configurables, Configurable names, or Configurable modules,
and replace each Configurable by their sane counterpart in the Configurables module.
List can contain any mix of Configurable types, their string counterparts, of modules
containing Configurables.
"""
_cache = []
def __init__(self, sourceModule, targetModule) :
self._source = sourceModule
self._target = targetModule
def __call__(self, algs) :
if not isIterable(algs) :
if inspect.ismodule(algs) :
print 'Dealing with a module'
algs = getConfigurablesFromModule(algs)
else :
'dealing with a single instance'
algs = [algs]
self.processAlgs(algs)
def processAlgs(self, algs) :
for alg in algs :
print 'Bringing sanity to', alg
if inspect.ismodule(alg) :
'Deal with module'
self.processAlgs(getConfigurablesFromModule(alg))
else :
'not module', alg
if alg in memoized_sanitise._cache or issubclass(type(alg), SaneConfigurable) :
pass
else :
memoized_sanitise._cache += [alg]
crazyAlg = alg
if type(alg) == str :
crazyAlg = self._source.__getattr__(alg)
elif isConfigurable(alg) :
alg = alg.__name__
saneAlg = SaneConfigurable(crazyAlg)
self._target.__setattr__(alg, saneAlg)
sanitise = memoized_sanitise(_crazyConfigurables, _crazyConfigurables)
"""Module containing a list of important, crazy configurables that should be cured in the Configurable Hospital.
Exports configurables as list via method configurables().
Add a configurable to list with method addConfigurable(arg).
"""
__author__ = 'Juan Palacios juan.palacios@physik.uzh.ch'
__all__ = ('parientList')
import DaVinciTools.DaVinciToolsConf
import LoKiCore.LoKiCoreConf
import LoKiHlt.LoKiHltConf
import LoKiArrayFunctors.LoKiArrayFunctorsConf
import DecayTreeTuple.DecayTreeTupleConf
import ParticleMaker.ParticleMakerConf
import TisTosTobbing.TisTosTobbingConf
from Configurables import DeterministicPrescaler, GaudiSequencer
from PhysSelPython.ConfigurableHospital import memoized_sanitise
_configurableList = [DaVinciTools.DaVinciToolsConf,
LoKiCore.LoKiCoreConf,
LoKiArrayFunctors.LoKiArrayFunctorsConf,
LoKiHlt.LoKiHltConf,
LoKiArrayFunctors.LoKiArrayFunctorsConf,
DecayTreeTuple.DecayTreeTupleConf,
ParticleMaker.ParticleMakerConf,
TisTosTobbing.TisTosTobbingConf,
GaudiSequencer,
DeterministicPrescaler]
def configurables() :
return _configurableList
def addConfigurable(conf) :
if not conf in _configurableList :
_configurableList += [conf]
"""Set of utilities for creating StrippingLine Like objects from selection-type objects.
"""
__all__ = ('MockStrippingLine')
__author__ = 'Juan Palacios palacios@physik.uzh.ch'
from copy import copy
from SelPy.selection import flatAlgorithmList
from PhysSelPython.Wrappers import MergedSelection
def _getAlgoList(sel) :
return copy(flatAlgorithmList(sel))
def _cloneSelection(sel, name) :
return sel.clone(name=name)
def _mergedSelection(sel, name) :
return MergedSelection(name, RequiredSelections = [sel])
def _eventSelection(sel, name) :
if sel.outputLocation() == '' :
return sel
else :
return _mergedSelection(sel, name)
class MockStrippingLine(object) :
"""
This class should return a list of configurables and an output location.
Usage:
>>> sel = Selection('Fred', ....)
>>> print sel.name(), sel.outputLocation()
Fred Phys/Fred
>>> mockStrippingLineComponents = MockStrippingLine('StrippingLineFred', sel)
>>> srtippingSel = mockStrippingLineComponents.selection()
>>> print strippingSel.name(), strippingSel.outputLocation()
StrippingLineFred, Phys/StrippingLineFred
>>> # get the configurables
>>> configs = mockStrippingLineComponents.members()
"""
_getMemberAlgs = {'MergedSelection' : lambda x : [x.algorithm()] }
_getSelectionAlgs = { 'Selection' : _cloneSelection,
'MergedSelection' : _cloneSelection,
'EventSelection' : _eventSelection,
'VoidEventSelection' : _eventSelection,
'PassThroughSelection' : _eventSelection,
'AutomaticData' : _mergedSelection }
def __init__(self, name, selection) :
self._sel = self._getSelection(selection, name)
self._members = self._getMembers(self._sel)
self._outputLocation = self._sel.outputLocation()
self._name = 'Stripping' + name
def _getMembers(self, selection) :
selTypeName = type(selection).__name__
return MockStrippingLine._getMemberAlgs.get(selTypeName, _getAlgoList)(selection)
def _getSelection(self, selection, name) :
selTypeName = type(selection).__name__
return MockStrippingLine._getSelectionAlgs.get(selTypeName, lambda x : x)(selection, name)
def name(self) :
return self._name
def outputLocation(self) :
return self._outputLocation
def members(self) :
return copy(self._members)
def selection(self) :
return self._sel
def clone ( self , name , selection) :
return MockStrippingLine(name, selection)
def configurable(self) :
return GaudiSequencer(self._name, Members = self.members())
"""Module containing fixed versions of insane configurables.
"""
__author__ = 'Juan Palacios palacios@physik.uzh.ch'
from ConfigurableHospital import memoized_sanitise
from CrazyConfigurables import configurables
def addConfigurables(configurables) :
sanitise(configurables)
from sys import modules
this = modules[__name__]
import Configurables as _crazyConfigurables
sanitise = memoized_sanitise(_crazyConfigurables, this)
sanitise( configurables() )
def cureConfigurables(configurables) :
"""
Take configurables, cure them, and add them to this module.
"""
sanitise(configurables)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# =============================================================================
# $Id$
# =============================================================================
## @file PhysSelPython/Selections.py
# Collection of high-level blocks for ``Seelctions''-framework
#
# Basic blocks:
# - AutomaticData : selection that gets data from TES (or Datra-On-Demand)
# - MergedSelection : merge several selections into one ('OR'-mode)
# - SelectionSequence : create the selection sequence
# - MultiSelectionSequence : create the sequence for several selections
#
# Derived blocks:
# - SimpleSelection : create 1-step selection
# - FilterSelection : selection with FilterDesktop algorithm
# - CombineSelection : selection with CombineParticles algorithm
# - Combine3BodySelection : selection with DaVinci::N3BodyDecays algorithm
# - Combine4BodySelection : selection with DaVinci::N4BodyDecays algorithm
# - TupleSelection : selection with DecayTreeTuple algorithm
# - PrintSelection : helper selection for debugging purposes
# - LimitSelection : limit selection
# - CheckPVSelection : embed CheckPV algorithm into selectiton sequence
# - MomentumScaling : insert momentum scaling into selectiton sequence
#
# @author Juan PALACIOS
# @author Vanya BELYAEV Ivan.Belyaev@itep.ru
#
# $Revision$
# Last modification $Date$
# by $Author$
# =============================================================================
""" Collection of high-level blocks for ``Selections''-framework:
Basic blocks:
- AutomaticData : selection that gets data from TES (or Datra-On-Demand)
- MergedSelection : merge several selections into one ('OR'-mode)
- SelectionSequence : create the selection sequence
- MultiSelectionSequence : create the sequence for several selections
Derived blocks:
- SimpleSelection : create 1-step selection
- FilterSelection : selection with FilterDesktop algorithm
- CombineSelection : selection with CombineParticles algorithm
- Combine3BodySelection : selection with DaVinci::N3BodyDecays algorithm
- Combine4BodySelection : selection with DaVinci::N4BodyDecays algorithm
- TupleSelection : selection with DecayTreeTuple algorithm
- PrintSelection : helper selection for debugging purposes
- LimitSelection : limit selection
- CheckPVSelection : embed CheckPV algorithm into selectiton sequence
- MomentumScaling : insert momentum scaling into selectiton sequence
"""
# =============================================================================
__author__ = 'Juan PALACIOS, Vanya BELYAEV'
__version__ = '$Revision$'
__date__ = '2016-03-12'
__all__ = ( 'AutomaticData' ,
'Selection' ,
'MergedSelection' ,
'SelectionSequence' ,
'MultiSelectionSequence' ,
#
'SimpleSelection' ,
'FilterSelection' ,
'PrintSelection' ,
'LimitSelection' ,
'CombineSelection' ,
'Combine3BodySelection' ,
'Combine4BodySelection' ,
'TupleSelection' ,
##
'CheckPVSelection' ,
##
'MomentumScaling'
)
# =============================================================================
## import all blocks from wrappers
from PhysSelPython.Wrappers import *
# =============================================================================
# =============================================================================
if '__main__' == __name__ :
print 80*'*'
print __doc__
print ' Author : %s ' % __author__
print ' Version : %s ' % __version__
print ' Date : %s ' % __date__
print ' Symbols : %s ' % list ( __all__ )
print 80*'*'
# =============================================================================
# The END
# =============================================================================
"""Set of utilities for handling and general manipulation of Configurables.
"""
__all__ = ('configurableExists',
'isConfigurable')
__author__ = 'Juan Palacios palacios@physik.uzh.ch'
from GaudiConfUtils import configurableExists
from GaudiConfUtils import isConfigurable
print "Warning: PhysSelPython.Utils deprecated! Use GaudiConfUtils."
This diff is collapsed.
import DaVinciTools.DaVinciToolsConf
import LoKiCore.LoKiCoreConf
import LoKiHlt.LoKiHltConf
import LoKiArrayFunctors.LoKiArrayFunctorsConf
import DecayTreeTuple.DecayTreeTupleConf
import ParticleMaker.ParticleMakerConf
import TisTosTobbing.TisTosTobbingConf
from Configurables import DeterministicPrescaler, GaudiSequencer
from ConfigurableHospital import sanitise
from CrazyConfigurables import configurables
sanitise( configurables() )
print '#Warning: PhysSelPython.selection deprecated. Use SelPy.selection'
from SelPy.selection import *
<?xml version="1.0" ?>
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program">
<text>py.test</text>
</argument>
<argument name="args">
<set>
<text>../test_import_wrappers.py</text>
<text>--verbose</text>
</set>
</argument>
</extension>
<?xml version="1.0" ?>
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program">
<text>py.test</text>
</argument>
<argument name="args">
<set>
<text>$PHYSSELPYTHONROOT/tests/test_import_wrappers_star.py</text>
<text>--verbose</text>
</set>
</argument>
</extension>
<?xml version="1.0" ?>
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program">
<text>py.test</text>
</argument>
<argument name="args"><set>
<text>../test_multi_selection_sequence.py</text>
<text>--verbose</text>
</set>
</argument>
</extension>
<?xml version="1.0" ?>
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program">
<text>py.test</text>
</argument>
<argument name="args">
<set>
<text>../test_selection.py</text>
<text>--verbose</text>
</set>
</argument>
</extension>
<?xml version="1.0" ?>
<!DOCTYPE extension PUBLIC '-//QM/2.3/Extension//EN' 'http://www.codesourcery.com/qm/dtds/2.3/-//qm/2.3/extension//en.dtd'>
<extension class="GaudiTest.GaudiExeTest" kind="test">
<argument name="program">
<text>py.test</text>
</argument>
<argument name="args">
<set>
<text>../test_selection_sequence.py</text>
<text>--verbose</text>
</set>
</argument>
</extension>
#!/usr/bin/env python
'''
Test loading of modules
'''
import sys
sys.path.append('../python')
def test_import_physselpython_wrappers() :
import PhysSelPython.Wrappers
def test_import_physselpython_selection() :
import PhysSelPython.selection
if '__main__' == __name__ :
import sys
test_names = filter(lambda k : k.count('test_') > 0, locals().keys())
__tests = filter( lambda x : x[0] in test_names, locals().items())
message = ''
summary = '\n'
length = len(sorted(test_names,
cmp = lambda x,y : cmp(len(y),len(x)))[0]) +2
for test in __tests :
try :
test[1]()
message = 'PASS'
except :
message = "FAIL"
summary += test[0].ljust(length) + ':' + message.rjust(10) + '\n'
if summary.count('FAIL') > 0 :
message = 'FAIL'
wr = sys.stderr.write
else :
message = 'PASS'
wr = sys.stdout.write
summary += 'Global'.ljust(length) + ':' + message.rjust(10) + '\n\n'
wr(summary)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment