def test2(self):
        'mcni.pyre_support: findcomponentfactory'
        from mcni.pyre_support import findcomponentfactory
        f = findcomponentfactory('MonochromaticSource')
        from mcni.pyre_components.MonochromaticSource import MonochromaticSource
        self.assertEqual(f, MonochromaticSource)

        f1 = findcomponentfactory('Source_simple')
        import mcstas2.pyre_support
        f1a = mcstas2.pyre_support.componentfactory('sources', 'Source_simple')
        self.assertEqual(f1, f1a)
        return
示例#2
0
    def test2(self):
        'mcni.pyre_support: findcomponentfactory'
        from mcni.pyre_support import findcomponentfactory
        f = findcomponentfactory('MonochromaticSource' )
        from mcni.pyre_components.MonochromaticSource import MonochromaticSource
        self.assertEqual( f, MonochromaticSource )

        f1 = findcomponentfactory('Source_simple')
        import mcstas2.pyre_support 
        f1a = mcstas2.pyre_support.componentfactory( 'sources', 'Source_simple' )
        self.assertEqual( f1, f1a )
        return
    def _createNeutronComponent(self, component_specifier):
        '''create a pyre neutron component from the given name
        
        the name could be
         * <componenttype>
           eg. MonochromaticSource
         * <componentcategory>/<componenttype>
           eg. sources/MonochromaticSource
         * <supplier>://<componenttype>
           eg. mcni://MonochromaticSource
         * <supplier>://<componentcategory>/<componenttype>
           eg. mcni://sources/MonochromaticSource
         * <supplier>://<componentcategory>/<componenttypefactory>(*args)
           eg. mcni://sources/NDMonitor(x, y)
        '''
        component_specifier = str(component_specifier)
        supplier, category, type, args = _decode(component_specifier)
        
        # component factory
        from mcni.pyre_support import findcomponentfactory
        try:
            factory = findcomponentfactory(type, category, supplier)
        except:
            import journal, traceback
            tb = traceback.format_exc()
            journal.error('pyre.inventory').log('failed to find component factory %r. \n%s' % (
                    component_specifier, tb))
            return None, None
        
        # error handling
        if not factory:
            import journal
            journal.error("mcvine.component").log(
                "could not bind facility '%s': component factory '%s' not found." % (
                self.name, component_specifier)
                )
            return None, None

        # component type factory ?
        if args:
            factory = factory(*args)
        
        # instantiate the component
        component = factory(self.name)

        # uri
        uri = _encode(factory.supplier, factory.category, factory.type, args)
        component.uri = uri
        # locator
        locator = '<mcvine.componentfactory>'
        #
        return component, locator