Beispiel #1
0
def run_test_dicts(silent, dicts=[]):
    """Function to run jetdef from a text file containing a single dict"""

    chainDefs = []
    for d in dicts:
        print d
        print d['chainName']
        try:
            cd = _generate(d, silent)
            chainDefs.append(cd)
        except Exception, e:
            print '(Error)ChainDef creation failed: ', str(e)
            print exc2string2()
Beispiel #2
0
def generateHLTChainDef(caller_data):
    """Entrance point to the jet slice configuration code.
    Arguments:
    caller_data [type - dictionary]: data from the caller and returns
                either a ChainDef or an ErrorChainDef object.

    use_atlas_config [type - boolean]: True - instantiate ATLAS configuration
                     objects, which requires the succesful imports of the
                     python classes.
                     False - Use JetDef proxies of the ATLAS configuration
                     objects. These have natural types as attributes,
                     and are suitable for development work."""

    caller_data['test'] = 'JETDEF_TEST' in os.environ
    debug = 'JETDEF_DEBUG' in os.environ
    no_instantiation = 'JETDEF_NO_INSTANTIATION' in os.environ
    use_atlas_config = not no_instantiation

    try:
        # instantiator instantiation can fail if there are
        # ATLAS import errors
        instantiator = instantiatorFactory(use_atlas_config)
    except Exception, e:
        tb = exc2string2()
        msg = 'JetDef Instantiator error: error: %s\n%s' % (str(e), tb)
        chain_name = caller_data['chainName']

        cd = ErrorChainDef(msg, chain_name)
        if debug:
            _debug(caller_data, cd)

        return cd
Beispiel #3
0
class Instantiator(object):

    def __init__(self):
        self.cache = {}
        self.err_hdr = '%s()' % self.__class__.__name__

    def __call__(self, a):
        """__call__ takes the string returned by alg.asString for
        an object alg, and evals it to return an Athena Algorithm instance"""

        try:
            s = a.asString()  # convert alg to a string to be eval'd
        except Exception, e:
            m = '%s() call to asString failed for object %s\n%s ' % (
                self.err_hdr, str(a), str(e))
            raise RuntimeError(m)


        alg = self.cache.get(s)
        if alg:
            return alg

        try:
            alg = eval(s)
        except Exception, e:
            tb = exc2string2()
            m = '%s() Error instantiating  Algorithm: eval(%s) '\
                '%s\nTraceback: \n%s'
            m = m % (self.__class__.__name__, s, str(e), tb)
            try:
                alg = a.alg
            except:
                m += '\nAttempt to retrieve pre-instantiated Algorithm failed'

                raise RuntimeError(m)
Beispiel #4
0
def generateChainDefs(chainDict):
    """Delegate the creation of ChainDef instnaces to JetDEf,
    then add in  the top information."""
    
    jetgroup_chain = True
    chainName = chainDict['chainName']
    #print 'processing chain part 1 start', chainName
    theChainDef = generateHLTChainDef(chainDict)
    #print 'processing chain part 2 end', chainName

    listOfChainDicts = splitChainDict(chainDict)

    topoAlgs = []
    for subCD in listOfChainDicts:  
        allTopoAlgs = subCD['chainParts']['topo']
        for ta in allTopoAlgs:
            topoAlgs.append(ta)

    # test new jet algorithm and configuration PS 15/9/2016
    # now use new jet algorthm TrigHLTJetHypo2 as standard,
    # and have the test chains use th run 1 hypo for comaprison PS 04/10/2016

    if ('muvtx' in topoAlgs) or ('llp' in topoAlgs):

        logJet.info("Adding topo to jet chain")
        try:
            theChainDef = _addTopoInfo(theChainDef, chainDict, topoAlgs)
        except Exception, e:
            tb = exc2string2()
            theChainDef = process_exception(e, tb, chainName)

        jetgroup_chain = False
Beispiel #5
0
def run_all_dicts(silent,
                  use_atlas_config=True,
                  debug=True,
                  printChains=True,
                  chains='',
                  dicts=[]):

    from test_dicts import dicts
    m =  'have [%d] dicts, set $JETDEF_DEBUG, '\
         '$JETDEF_DEBUG_NO_INSTANTIATION'\
         ' to write to disk' % (len(dicts))
    print m

    names = chains.split(':') if chains else []
    if names:
        print 'searching for  %d chains' % len(names)
        dicts = [d for d in dicts if d['chainName'] in names]
        print 'found %d chains' % len(dicts)
    else:
        print 'processsing all %d dicts' % len(dicts)

    # devnull = open(os.devnull, 'w')
    # old_out = sys.stdout
    # old_err = sys.stderr

    result = []
    ndicts = 0
    # toSkip = (
    #     'j30_jes_cleanLLP_PS_llp_noiso_L1TAU8_EMPTY',
    #    'j30_jes_PS_llp_L1TAU8_UNPAIRED_ISO',
    #    )
    for d in dicts:
        # if d['chainName'] in toSkip or '_PS_' in d['chainName']:
        #    print d['chainName']
        #    continue

        if printChains: print ndicts, d['chainName']
        # sys.stdout = devnull
        # sys.stderr = devnull
        try:
            result.append(_generate(d, silent))
        except Exception, e:
            print d['chainName']
            print e
            print exc2string2()
            assert False
        ndicts += 1
Beispiel #6
0
def generateHLTChainDef(caller_data):
    """Entrance point to the jet slice configuration code.
    Arguments:
    caller_data [type - dictionary]: data from the caller and returns
                either a ChainDef or an ErrorChainDef object.

    Debug and testing actions are controlled by environment variables.
    See commnets in usage()."""

    # selected_chains = ('j85_lcw',)
    # chain_name = caller_data['chainName']
    # if chain_name not in selected_chains:
    #    return ErrorChainDef('Not a selected chain', chain_name)

    # maintain a copy of the incoming dictionary - to be used
    # for debugging, will not be overwritten.

    caller_data_copy = copy.deepcopy(caller_data)
    
    caller_data_copy['run_rtt_diags'] = 'JETDEF_TEST' in os.environ
    debug = 'JETDEF_DEBUG' in os.environ
    no_instantiation_flag = 'JETDEF_NO_INSTANTIATION' in os.environ
    use_atlas_config = not no_instantiation_flag
    chain_name = caller_data_copy['chainName']
    # if 'inv' in chain_name:
    #    dump_chaindef(caller_data, None, None, no_instantiation_flag)
    #    return
        
    chain_config = None
    if 'test2' in caller_data['chainName']:
        msg = 'Chain name error: test2 chains not currently supported'
        cd = ErrorChainDef(msg, chain_name)
        if debug:
            # for debugging, output the original incoming dictionary
            dump_chaindef(caller_data, cd, chain_config, no_instantiation_flag)

        return cd
        
    try:
        # instantiator instantiation can fail if there are
        # ATLAS import errors
        instantiator = instantiatorFactory(use_atlas_config)
    except Exception, e:
        tb = exc2string2()
        msg = 'JetDef Instantiator error: error: %s\n%s' % (str(e), tb)
        cd = ErrorChainDef(msg, chain_name)
        if debug:
            # for debugging, output the original incoming dictionary
            dump_chaindef(caller_data, cd, chain_config, no_instantiation_flag)

        return cd
Beispiel #7
0
        instantiator = instantiatorFactory(use_atlas_config)
    except Exception, e:
        tb = exc2string2()
        msg = 'JetDef Instantiator error: error: %s\n%s' % (str(e), tb)
        chain_name = caller_data['chainName']

        cd = ErrorChainDef(msg, chain_name)
        if debug:
            _debug(caller_data, cd)

        return cd
            
    try:
        cd = _make_chaindef(caller_data, instantiator)
    except Exception, e:
        tb = exc2string2()
        chain_name = caller_data['chainName']
        msg = 'JetDef error: error: %s\n%s' % (str(e), tb)
        cd = ErrorChainDef(msg, chain_name)
        if logger:
            logger.warning(str(cd))

    if debug:
        _debug(caller_data, cd)
    return cd

def _debug(caller_data, cd):
    """Dump incoming dictionaly and outfgoing(Error)ChainDef to a file."""

    chain_name = caller_data['chainName']
    ddir = os.path.join('/tmp/', os.environ['USER'])
Beispiel #8
0
        # ATLAS import errors
        instantiator = instantiatorFactory(use_atlas_config)
    except Exception, e:
        tb = exc2string2()
        msg = 'JetDef Instantiator error: error: %s\n%s' % (str(e), tb)
        cd = ErrorChainDef(msg, chain_name)
        if debug:
            # for debugging, output the original incoming dictionary
            dump_chaindef(caller_data, cd, chain_config, no_instantiation_flag)

        return cd

    try:
        cd, chain_config = _make_chaindef(caller_data_copy, instantiator)
    except Exception, e:
        tb = exc2string2()
        msg = 'JetDef error: error: %s\n%s' % (str(e), tb)
        cd = ErrorChainDef(msg, chain_name)
        if logger:
            logger.warning(str(cd))

    if debug:
        # for debugging, output the original incoming dictionary
        dump_chaindef(caller_data, cd, chain_config, no_instantiation_flag)

    return cd

def dump_chaindef(caller_data, cd, chain_config, no_instantiation_flag):
    """Dump incoming dictionaly and outfgoing(Error)ChainDef to a file."""

    chain_name = caller_data['chainName']