Exemple #1
0
def storeJobOptionsCatalogue(cfg_fname):
    """Inspect the 'configured' JobOptionsSvc and existing services,
   then dump the properties of each component into a pickle file.
   """

    from collections import defaultdict
    jocat = defaultdict(dict)
    jocfg = defaultdict(dict)

    def _fillCfg(client, props):
        for p in props:
            n, v = p
            if hasattr(v, 'toStringProperty'):
                v = str(v.toStringProperty())
            elif hasattr(v, 'toString'):
                v = str(v.toString())
            elif type(v) == float:
                # str(1.8e12) will give '1.8e+12' in py2
                # and `1800000000000.0' in py3.
                # Convert floats like this for consistency.
                v = '%g' % v
            else:
                v = str(v)
            jocfg[client][n] = v

    from AthenaCommon.AppMgr import theApp
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    from AthenaCommon.Configurable import Configurable as C

    # tickle the Gaudi C++ side and configure the ApplicationMgr
    theApp.setup(recursive=True)

    app_props = [(k, v.value())
                 for k, v in six.iteritems(theApp.getHandle().properties())]
    _fillCfg('ApplicationMgr', app_props)

    # get all services that now already exist, as they require special treatment;
    # the appmgr handle talks directly to the ServiceManager and services() returns
    # a copy of the services names
    svcs = theApp.getHandle().services()

    # now assume that if these services carry configuration, then they should exist
    # on the service manager configurable
    for svcname in svcs:
        svc = getattr(svcMgr, svcname, None)
        if svc:
            _fillCfg(svcname, svc.getValuedProperties().items())

# make sure to propagate the EventLoop properties through the josvc
    try:
        evLoopName = theApp.EventLoop.split('/')[-1]
        evLoop = getattr(svcMgr, evLoopName)

        props = []
        for k, v in six.iteritems(evLoop.properties()):
            if v != C.propertyNoValue:
                props.append((k, v))
        _fillCfg(evLoopName, props)

    except AttributeError:
        pass  # no properties defined for EventLoop type

# get the values for all other components (these may contain duplicates of
# the ones above in svcs, and there may even be conflicts)
    import AthenaPython.PyAthena as PyAthena
    josvc = PyAthena.py_svc('JobOptionsSvc',
                            iface="Gaudi::Interfaces::IOptionsSvc")
    allProps = josvc.items()  #a std::tuple<string,string>
    for prop in allProps:
        cn = str(prop._0).split(".")
        v = str(prop._1)
        client = ".".join(cn[:-1])
        n = cn[-1]
        jocat[client][n] = v

# take care of some ancient history
    for k in ('Go', 'Exit'):
        if k in jocfg['ApplicationMgr']:
            del jocfg['ApplicationMgr'][k]

# workaround for pycomps
    pycomps = []
    for c in six.itervalues(C.allConfigurables):
        if not isinstance(
                c,
            (PyAthena.Alg, PyAthena.AlgTool, PyAthena.Svc, PyAthena.Aud)):
            continue
    # FIXME: should check if the component is still 'active'
    #        ie: is it in one of the TopAlg,SvcMgr,ToolSvc and children ?
        try:
            delattr(c, 'msg')
        except AttributeError:
            pass

        pycomps.append(c)

# write out all parts; start with the jocat, so that it can be loaded by
# itself only, if need be

    cfg = open(cfg_fname, 'wb')  # output pickle file

    pickle.dump(jocat, cfg)  # jobopt catalogue contents
    pickle.dump(jocfg, cfg)  # special services' properties
    pickle.dump(pycomps, cfg)  # python components workaround

    cfg.close()

    return cfg_fname
Exemple #2
0
def store_configuration(cfg_fname=None):
    """helper function to inspect the 'configured' JobOptionsSvc and dump
    the properties of each component into a (sqlite) shelve.
    it will eventually dump the properties of py-components too.
    """
    jobo_cfg = defaultdict(dict)
    if cfg_fname is None:
        import tempfile
        tmpfile = tempfile.NamedTemporaryFile(suffix='-jobo.pkl')
        cfg_fname = tmpfile.name
        tmpfile.close()
        import os
        if os.path.exists(cfg_fname):
            os.remove(cfg_fname)

    assert cfg_fname

    from AthenaCommon.AppMgr import theApp

    def _fill_cfg(client, props):
        for p in props:
            n = p[0]
            v = p[1]
            if hasattr(v, 'toStringProperty'):
                v = str(v.toStringProperty().toString())
            elif hasattr(v, 'toString'):
                v = str(v.toString())
            else:
                v = str(v)
            jobo_cfg[client][n] = v

    from AthenaCommon.AppMgr import ServiceMgr as svcMgr

    # special cases: joboptionsvc and messagesvc
    def _fill_props(svcname):
        if not hasattr(svcMgr, svcname):
            return
        svc = getattr(svcMgr, svcname)
        props = []
        for k, v in svc.properties().iteritems():
            if v == svc.propertyNoValue:
                v = svc.getDefaultProperty(k)
            props.append((k, v))
        _fill_cfg(svcname, props)

    _fill_props('JobOptionsSvc')
    _fill_props('MessageSvc')

    # tickle C++ and configure the whole app
    theApp.setup()

    app_props = [(k, v.value())
                 for k, v in theApp.getHandle().properties().iteritems()]
    _fill_cfg(theApp.name(), app_props)

    import AthenaPython.PyAthena as PyAthena
    josvc = PyAthena.py_svc('JobOptionsSvc', iface='IJobOptionsSvc')
    assert josvc is not None

    clients = list(josvc.getClients())
    for client in clients:
        props = josvc.getProperties(client)
        for prop in props:
            n = prop.name()
            v = prop.toString()
            jobo_cfg[client][n] = v

    cfg = dbs.open(cfg_fname, 'w')
    cfg['jobopts'] = jobo_cfg

    pycomps = []
    import sys
    from .AppMgr import ServiceMgr as svcMgr

    # all other pycomps
    from .Configurable import Configurable as C
    for c in C.allConfigurables.itervalues():
        if not isinstance(
                c,
            (PyAthena.Alg, PyAthena.AlgTool, PyAthena.Svc, PyAthena.Aud)):
            continue
        # FIXME: should check if the component is still 'active'
        #        ie: is it in one of the TopAlg,SvcMgr,ToolSvc and children ?
        if hasattr(c, 'msg'):
            delattr(c, 'msg')
        pycomps.append(c)
        pass

    # folder for the pyathena-components
    cfg['pycomps'] = pycomps
    cfg.close()

    return cfg_fname
    print " | Execute command after jobOptions script START. | "
    print " +------------------------------------------------+ "
    print " ---> Command = ", PscConfig.optmap['POSTCOMMAND']
    try:
        exec PscConfig.optmap['POSTCOMMAND']
    except Exception, e:
        if isinstance(e, IncludeError):
            print sys.exc_type, e
            theApp._exitstate = ExitCodes.INCLUDE_ERROR
            sys.exit(ExitCodes.INCLUDE_ERROR)
        elif isinstance(e, ImportError):
            print sys.exc_type, e
            theApp._exitstate = ExitCodes.IMPORT_ERROR
            sys.exit(ExitCodes.IMPORT_ERROR)
        raise
    print " +------------------------------------------------+ "
    print " | Execute command after jobOptions script END.   | "
    print " +------------------------------------------------+ "
    print "\n"

### final tweaks -------------------------------------------------------------

from TriggerJobOpts.TriggerFlags import TriggerFlags
if TriggerFlags.Online.doValidation():
    theApp.StatusCodeCheck = True

del TriggerFlags

### setup everything ---------------------------------------------------------
theApp.setup()
Exemple #4
0
def store_configuration(cfg_fname=None):
    """helper function to inspect the 'configured' JobOptionsSvc and dump
    the properties of each component into a (sqlite) shelve.
    it will eventually dump the properties of py-components too.
    """
    jobo_cfg = defaultdict(dict)
    if cfg_fname is None:
        import tempfile
        tmpfile = tempfile.NamedTemporaryFile(suffix='-jobo.pkl')
        cfg_fname = tmpfile.name
        tmpfile.close()
        import os
        if os.path.exists(cfg_fname):
            os.remove(cfg_fname)

    assert cfg_fname

    from AthenaCommon.AppMgr import theApp

    def _fill_cfg(client, props):
        for p in props:
            n = p[0]
            v = p[1]
            if hasattr(v, 'toStringProperty'):
                v = str(v.toStringProperty().toString())
            elif hasattr(v, 'toString'):
                v = str(v.toString())
            else:
                v = str(v)
            jobo_cfg[client][n] = v
    
    from AthenaCommon.AppMgr import ServiceMgr as svcMgr
    
    # special cases: joboptionsvc and messagesvc
    def _fill_props(svcname):
        if not hasattr(svcMgr, svcname):
            return
        svc = getattr(svcMgr, svcname)
        props = []
        for k,v in svc.properties().iteritems():
            if v == svc.propertyNoValue:
                v = svc.getDefaultProperty(k)
            props.append((k,v))
        _fill_cfg(svcname, props)
    _fill_props('JobOptionsSvc')
    _fill_props('MessageSvc')
    
    # tickle C++ and configure the whole app
    theApp.setup()
    
    app_props = [(k,v.value())
                 for k,v in theApp.getHandle().properties().iteritems()]
    _fill_cfg(theApp.name(), app_props)

    import AthenaPython.PyAthena as PyAthena
    josvc = PyAthena.py_svc('JobOptionsSvc', iface='IJobOptionsSvc')
    assert josvc is not None

    clients = list(josvc.getClients())
    for client in clients:
        props = josvc.getProperties(client)
        for prop in props:
            n = prop.name()
            v = prop.toString()
            jobo_cfg[client][n] = v

    cfg = dbs.open(cfg_fname, 'w')
    cfg['jobopts'] = jobo_cfg

    pycomps = []
    import sys
    from .AppMgr import ServiceMgr as svcMgr
        
    # all other pycomps
    from .Configurable import Configurable as C
    for c in C.allConfigurables.itervalues():
        if not isinstance(c, (PyAthena.Alg,
                              PyAthena.AlgTool,
                              PyAthena.Svc,
                              PyAthena.Aud)):
            continue
        # FIXME: should check if the component is still 'active'
        #        ie: is it in one of the TopAlg,SvcMgr,ToolSvc and children ?
        if hasattr(c, 'msg'):
            delattr(c, 'msg')
        pycomps.append(c)
        pass
    
    # folder for the pyathena-components
    cfg['pycomps'] = pycomps
    cfg.close()

    return cfg_fname