Esempio n. 1
0
    def onNeutronExperiment(self, experiment):
        instrument_id = experiment.instrument_id
        if empty_id(instrument_id):
            instrument = None
        else:
            configured_instrument = self.clerk.getConfiguredInstrument(
                instrument_id)
            configure_instrument = self(configured_instrument)
            instrument = configured_instrument
        experiment.instrument = instrument

        sampleassembly_id = experiment.sampleassembly_id
        if empty_id(sampleassembly_id):
            sampleassembly = None
        else:
            sampleassembly = self.clerk.getSampleAssembly(sampleassembly_id)
            sampleassembly = self(sampleassembly)
        experiment.sampleassembly = sampleassembly

        job_id = experiment.job_id
        if empty_id(job_id):
            job = None
        else:
            job = self.clerk.getJob(job_id)
            job = self(job)

        experiment.job = job
        return experiment
Esempio n. 2
0
    def onConfiguredInstrument(self, configured):
        instrument_id = configured.instrument_id
        if empty_id(instrument_id):
            # if instrument is not specified, configuration is not
            # meaningful
            configured.instrument = None
            configured.configuration = None
            return configured

        instrument = self.clerk.getInstrument( instrument_id )
        instrument = self(instrument)

        configuration_id = configured.configuration_id
        if empty_id(configuration_id):
            # if configuration is not explicit,
            # it will be explicitly stored in the instrument table.
            # be sure that this 'instrument' (actually configuration)
            # could contain
            # less components than the original template instrument.
            # it could contain no component too.
            configuration = None
            # create a new instrument record
            #from vnf.dom.Instrument import Instrument
            #instrument = self.clerk.new_ownedobject( Instrument )
            #configuration_id = configured.configuration_id = instrument.id
            #self.clerk.updateRecord( configured )
        else:
            configuration = self.clerk.getInstrumentConfiguration(
                instrument_id, configuration_id )
            configuration = self(configuration)

        configured.instrument = instrument
        configured.configuration = configuration
        return configured
Esempio n. 3
0
    def onScatterer(self, scatterer):
        matter_id =  scatterer.matter_id
        if empty_id( matter_id ):
            matter = None
        else:
            matter = self.clerk.getMatter(matter_id )
            matter = self(matter)

        shape_id = scatterer.shape_id
        if empty_id(shape_id):
            shape = None
        else:
            shape = self.clerk.getShape(shape_id)
            shape = self(shape)
        
        scatterer.shape = shape
        scatterer.matter = matter
    
        try:
            kernels = self.clerk.getScatteringKernels( scatterer.id )
        except:
            import traceback
            self.clerk._debug.log(traceback.format_exc())
            kernels = []
        kernels = [ self(kernel) for kernel in kernels ]
        scatterer.kernels = kernels
        return scatterer
Esempio n. 4
0
    def onNeutronExperiment(self, experiment):
        instrument_id = experiment.instrument_id
        if empty_id( instrument_id ):
            instrument = None
        else:
            configured_instrument = self.clerk.getConfiguredInstrument(
                instrument_id )
            configure_instrument = self(configured_instrument)
            instrument = configured_instrument
        experiment.instrument = instrument

        sampleassembly_id = experiment.sampleassembly_id
        if empty_id(sampleassembly_id):
            sampleassembly = None
        else:        
            sampleassembly = self.clerk.getSampleAssembly( sampleassembly_id )
            sampleassembly = self(sampleassembly)
        experiment.sampleassembly = sampleassembly

        job_id = experiment.job_id
        if empty_id(job_id):
            job = None
        else:
            job = self.clerk.getJob( job_id )
            job = self(job)

        experiment.job = job
        return experiment
Esempio n. 5
0
    def onConfiguredInstrument(self, configured):
        instrument_id = configured.instrument_id
        if empty_id(instrument_id):
            # if instrument is not specified, configuration is not
            # meaningful
            configured.instrument = None
            configured.configuration = None
            return configured

        instrument = self.clerk.getInstrument(instrument_id)
        instrument = self(instrument)

        configuration_id = configured.configuration_id
        if empty_id(configuration_id):
            # if configuration is not explicit,
            # it will be explicitly stored in the instrument table.
            # be sure that this 'instrument' (actually configuration)
            # could contain
            # less components than the original template instrument.
            # it could contain no component too.
            configuration = None
            # create a new instrument record
            #from vnf.dom.Instrument import Instrument
            #instrument = self.clerk.new_ownedobject( Instrument )
            #configuration_id = configured.configuration_id = instrument.id
            #self.clerk.updateRecord( configured )
        else:
            configuration = self.clerk.getInstrumentConfiguration(
                instrument_id, configuration_id)
            configuration = self(configuration)

        configured.instrument = instrument
        configured.configuration = configuration
        return configured
Esempio n. 6
0
    def onScatterer(self, scatterer):
        matter_id = scatterer.matter_id
        if empty_id(matter_id):
            matter = None
        else:
            matter = self.clerk.getMatter(matter_id)
            matter = self(matter)

        shape_id = scatterer.shape_id
        if empty_id(shape_id):
            shape = None
        else:
            shape = self.clerk.getShape(shape_id)
            shape = self(shape)

        scatterer.shape = shape
        scatterer.matter = matter

        try:
            kernels = self.clerk.getScatteringKernels(scatterer.id)
        except:
            import traceback
            self.clerk._debug.log(traceback.format_exc())
            kernels = []
        kernels = [self(kernel) for kernel in kernels]
        scatterer.kernels = kernels
        return scatterer
Esempio n. 7
0
    def processUserInputs(self, commit = True):
        '''process user inputs and save them to db
        commit: if true, commit to database record. 
        '''

        # prepare a record to accept user inputs
        if self.inventory.id == '':
            record = self.createRecord()
        else:
            record = self.getRecord( )

        # transfer user inputs to db record
        for prop in self.parameters:
            setattr(
                record, prop,
                self.inventory.getTraitValue( prop ) )
            continue

        # commit if requested
        if commit:
            director = self.director
            if empty_id(record.id):
                #if record is new, create a new db record
                id = new_id( director )
                record.id = id
                director.clerk.insertRecord( record )
            else:
                #otherwise, update the record
                director.clerk.updateRecord( record )
            pass # endif
        return record
Esempio n. 8
0
 def getRecord(self):
     'get DB record'
     id = self.inventory.id
     if empty_id(id): return
     director = self.director
     clerk = director.clerk
     return clerk.getRecordByID( self.DBTable, id )
Esempio n. 9
0
    def processUserInputs(self, commit=True):
        '''process user inputs and save them to db
        commit: if true, commit to database record. 
        '''

        # prepare a record to accept user inputs
        if self.inventory.id == '':
            record = self.createRecord()
        else:
            record = self.getRecord()

        # transfer user inputs to db record
        for prop in self.parameters:
            setattr(record, prop, self.inventory.getTraitValue(prop))
            continue

        # commit if requested
        if commit:
            director = self.director
            if empty_id(record.id):
                #if record is new, create a new db record
                id = new_id(director)
                record.id = id
                director.clerk.newRecord(record)
            else:
                #otherwise, update the record
                director.clerk.updateRecord(record)
            pass  # endif
        return record
Esempio n. 10
0
    def onConfiguredScatterer(self, configured):
        scatterer_id = configured.scatterer_id
        if empty_id(scatterer_id):
            scatterer = None
        else:
            scatterer = self.clerk.getScatterer( scatterer_id )
            scatterer = self(scatterer)
        configured.scatterer = scatterer

        configuration_id = configured.configuration_id
        if empty_id( configuration_id ): configuration = None
        else:
            configuration = self.clerk.getScatterer( configuration_id )
            configuration = self(configuration)
            pass # endif
        configured.configuration = configuration
        return configured
Esempio n. 11
0
    def onConfiguredScatterer(self, configured):
        scatterer_id = configured.scatterer_id
        if empty_id(scatterer_id):
            scatterer = None
        else:
            scatterer = self.clerk.getScatterer(scatterer_id)
            scatterer = self(scatterer)
        configured.scatterer = scatterer

        configuration_id = configured.configuration_id
        if empty_id(configuration_id): configuration = None
        else:
            configuration = self.clerk.getScatterer(configuration_id)
            configuration = self(configuration)
            pass  # endif
        configured.configuration = configuration
        return configured
Esempio n. 12
0
 def onJob(self, job):
     server = job.server
     if empty_id(server):
         computation_server= None
     else:
         computation_server = self.clerk.getServer( server )
         computation_server = self(computation_server)
     job.computation_server = computation_server
     job.short_description = job.jobName
     return job
Esempio n. 13
0
 def onJob(self, job):
     server = job.server
     if empty_id(server):
         computation_server = None
     else:
         computation_server = self.clerk.getServer(server)
         computation_server = self(computation_server)
     job.computation_server = computation_server
     job.short_description = job.jobName
     return job
    def apply(self, configuration):
        scatterer = self.scatterer

        # scatterer is a container of matter and shape
        matter = scatterer.matter.realmatter
        shape = scatterer.shape.realshape
        
        # the configuration is also a container of matter and shape
        # if it exists
        if configuration is None: return

        matter_id = configuration.matter_id
        if not empty_id(matter_id):
            # need implementation here
            pass

        
        return
    def _checkstatus(self, director):
        experiment = director.clerk.getNeutronExperiment(
            self.inventory.id )
        self.name_assigned = experiment.short_description not in [None, '']

        instrument_id = experiment.instrument_id
        if not empty_id( instrument_id ):
            configured = director.clerk.getConfiguredInstrument(instrument_id)
            self.instrument_configured = not empty_id( configured.instrument_id )
            pass

        sampleenvironment_id = experiment.sampleenvironment_id
        self.sample_environment_configured = not empty_id( sampleenvironment_id )
        
        sampleassembly_id = experiment.sampleassembly_id
        
        if not empty_id( sampleassembly_id ):
            sampleassembly = director.clerk.getSampleAssembly(
                sampleassembly_id )
            
            scatterers = director.clerk.getConfiguredScatterers(
                sampleassembly_id)
            samples = filter(
                lambda scatterer: scatterer.label == 'sample',
                scatterers)
            if len(samples) == 0: return
            if len(samples) > 1: raise RuntimeError, "more than 1 sample"
            
            sample = samples[0]
            self.sample_prepared = not empty_id(sample.scatterer_id)
            # need to test if kernel is configured
            # ...
            # probably need a canned solution here for the demo...
            self.kernel_configured = True
            pass

        if not self.kernel_configured: return

        if experiment.ncount <=0 : return
        if empty_id(experiment.job_id): return
        job = director.clerk.getJob( experiment.job_id )

        self.allconfigured = True

        # the last is to check if all files for this experiment
        # are generated
        return        
Esempio n. 16
0
    def _checkstatus(self, director):
        experiment = director.clerk.getNeutronExperiment(self.inventory.id)
        self.name_assigned = experiment.short_description not in [None, '']

        instrument_id = experiment.instrument_id
        if not empty_id(instrument_id):
            configured = director.clerk.getConfiguredInstrument(instrument_id)
            self.instrument_configured = not empty_id(configured.instrument_id)
            pass

        sampleenvironment_id = experiment.sampleenvironment_id
        self.sample_environment_configured = not empty_id(sampleenvironment_id)

        sampleassembly_id = experiment.sampleassembly_id

        if not empty_id(sampleassembly_id):
            sampleassembly = director.clerk.getSampleAssembly(
                sampleassembly_id)

            scatterers = director.clerk.getConfiguredScatterers(
                sampleassembly_id)
            samples = filter(lambda scatterer: scatterer.label == 'sample',
                             scatterers)
            if len(samples) == 0: return
            if len(samples) > 1: raise RuntimeError, "more than 1 sample"

            sample = samples[0]
            self.sample_prepared = not empty_id(sample.scatterer_id)
            # need to test if kernel is configured
            # ...
            # probably need a canned solution here for the demo...
            self.kernel_configured = True
            pass

        if not self.kernel_configured: return

        if experiment.ncount <= 0: return
        if empty_id(experiment.job_id): return
        job = director.clerk.getJob(experiment.job_id)

        self.allconfigured = True

        # the last is to check if all files for this experiment
        # are generated
        return
        # run button
        submit = form.control(name="submit", type="submit", value="Run")
            
        return page


    def run(self, director):
        try:
            page = director.retrieveSecurePage( 'neutronexperiment' )
        except AuthenticationError, err:
            return err.page

        experiment = director.clerk.getNeutronExperiment(
            self.inventory.id)
        job_id = experiment.job_id
        if empty_id(job_id):
            raise RuntimeError, "job not yet established"
        
        job_id  = experiment.job_id
        job = director.clerk.getJob( job_id )
        
        try:
            Scheduler.schedule(job, director)
            experiment.status = 'submitted'
        except Exception, err:
            raise
            import traceback
            experiment.status = 'submissionfailed'
            job.error = traceback.format_exc()

        # update db
            page = director.retrieveSecurePage( 'neutronexperimentwizard' )
        except AuthenticationError, err:
            return err.page
        
        try:
            self.processFormInputs( director )
        except InputProcessingError, err:
            errors = err.errors
            self.form_received = None
            director.routine = 'configure_instrument'
            return self.configure_instrument( director, errors = errors )

        experiment = director.clerk.getNeutronExperiment(
            self.inventory.id )
        # make sure instrument is configured
        if empty_id( experiment.instrument_id ):
            director.routine = 'select_instrument'
            return self.select_instrument( director )
        # get configured instrument
        configured_instrument = director.clerk.getConfiguredInstrument(
            experiment.instrument_id )
        # make sure it has a instrument and it is configured
        if empty_id( configured_instrument.instrument_id ) or \
           empty_id( configured_instrument.configuration_id ):
            director.routine = 'select_instrument'
            return self.select_instrument( director )

        # update experiment status
        director.clerk.updateRecord( experiment )
        
        director.routine = 'sample_environment'
Esempio n. 19
0
        try:
            page = director.retrieveSecurePage('neutronexperimentwizard')
        except AuthenticationError, err:
            return err.page

        try:
            self.processFormInputs(director)
        except InputProcessingError, err:
            errors = err.errors
            self.form_received = None
            director.routine = 'configure_instrument'
            return self.configure_instrument(director, errors=errors)

        experiment = director.clerk.getNeutronExperiment(self.inventory.id)
        # make sure instrument is configured
        if empty_id(experiment.instrument_id):
            director.routine = 'select_instrument'
            return self.select_instrument(director)
        # get configured instrument
        configured_instrument = director.clerk.getConfiguredInstrument(
            experiment.instrument_id)
        # make sure it has a instrument and it is configured
        if empty_id( configured_instrument.instrument_id ) or \
           empty_id( configured_instrument.configuration_id ):
            director.routine = 'select_instrument'
            return self.select_instrument(director)

        # update experiment status
        director.clerk.updateRecord(experiment)

        director.routine = 'sample_environment'