def visit(self, new_visit = None): if new_visit: Finder.getInstance().find("GDAMetadata").setMetadataValue("visit", new_visit) Finder.getInstance().find("GDAMetadata").setMetadataValue("defaultVisit", new_visit) if not os.path.exists(self.getVisitDirectory()): print "!!! Warning !!! The directory '%s' does NOT exist! (pointing to it anyway though)" %self.getVisitDirectory() self.setDetectorDirectories() return Finder.getInstance().find("GDAMetadata").getMetadataValue("visit")
def __init__(self, stageName): self.name=stageName self.calibrant_file_name=None self.stage_x=Finder.getInstance().find(stageName+"x") self.stage_y=Finder.getInstance().find(stageName+"y") self.stage_rot=Finder.getInstance().find(stageName+"rot") self.lookup_table = readLookupTable(LocalProperties.get("gda.function.lookupTable.dir")+os.path.sep+"lde_stages_home_positions.txt") self.samples=[] self.calibration_required=True self.pixium=Finder.getInstance().find('pixium_hdf')
def visit(self, new_visit=None): if new_visit: Finder.getInstance().find("GDAMetadata").setMetadataValue( "visit", new_visit) Finder.getInstance().find("GDAMetadata").setMetadataValue( "defaultVisit", new_visit) if not os.path.exists(self.getVisitDirectory()): print "!!! Warning !!! The directory '%s' does NOT exist! (pointing to it anyway though)" % self.getVisitDirectory( ) self.setDetectorDirectories() return Finder.getInstance().find("GDAMetadata").getMetadataValue( "visit")
def doCalibration(self, calibrant='Si', calibrant_x=0, calibrant_y=0, calibrant_exposure=1.0): if self.calibration_required: mycalibrant=Finder.getInstance().find("calibrant_name") mycalibrant.moveTo(calibrant) dummyScannable=DummyScannable("dummyScannable") #additional_plugin_list = pixium.getAdditionalPluginList()[0] #Detector calibration if self.calibration_required: self.stage_x.moveTo(calibrant_x) self.stage_y.moveTo(calibrant_y) scan([dummyScannable, 1, 1, 1, self.pixium, calibrant_exposure]) #TODO GDA .nxs file, not EPICS h5 file scan_data_point_provider = InterfaceProvider.getScanDataPointProvider() self.calibrant_file_name = scan_data_point_provider.getLastScanDataPoint().getCurrentFilename() #calibrant_file_name = additional_plugin_list.getFullFileName() #do detector calibration on cluster serevrs builder = OSCommandRunnerBuilder.defaults() builder=builder.command([LocalProperties.get("org.opengda.lde.pixium.data.reduction.script","/dls_sw/apps/i11-scripts/bin/LDE-RunFromGDAAtEndOfScan.sh")]) builder=builder.keepOutput(True) builder = builder.inputFilename(self.calibrant_file_name) builder = builder.outputFilename(os.path.splitext(self.calibrant_file_name)[0]+"_output.log") builder=builder.noTimeout() builder.build() self.calibration_required=False
def __init__(self, name, tfg, fg, adc, pe, detector): self.name=name self.tfg=tfg self.fg=fg self.adc=adc self.pedata=pe self.detector=detector self.fastshutter=Finder.getInstance().find("fastshutter") self.numGates=1 self.numCycles=1 self.numFrames=1 self.livetime=0.0 self.deadtime=0.0 self.boundaryFrequency=0.1 self.func = 2 self.bncycle=1 self.freq=0.1 self.adcStreamerCompleted=True self.gateDetectorCompleted=True self.numDefinedSequency=1 self.filename="" self.directory="" self.scanNumber=0 self.preConditioning=True self.startCycleNumber=0 self.startSeqNumber=0
def Assemble(self): nameList=Finder.getInstance().listAllNames('Scannable') nameList=['ab__a', 'ab__b', 'xyz__x', 'xyz__y', 'xyz__z', 'blarghh'] # Filter out those containing __ groupComponentList=[] for name in nameList: if name.__contains__('__'): groupComponentList.append(name) # Create a dictionary with one key for each group, each key pointing to a list of component strings" groupDict={} for name in groupComponentList: group, component = name.split('__') if not(groupDict.has_key(group)): groupDict[group]=[] groupDict[group].append(component) # Create the group scannables and pass back as list (STUB) toReturn = [] groupNameList = groupDict.keys() for groupName in groupNameList: tmp=groupName for componentName in groupDict[groupName]: tmp += "." + componentName toReturn += [tmp] return toReturn
def getUserOptionsManager(): manager = Finder.getInstance().findSingleton(UserOptionsManager) if not manager: manager = UserOptionsManager() manager.configure() return manager
def setProperty(propertyName, propertyValue): LocalProperties.set(propertyName, propertyValue) eventAdmin=Finder.getInstance().find("eventadmin") if eventAdmin is None: print "Cannot find 'eventAdmin' on the GDA server. Please create a Spring bean using 'Scriptcontroller' Java class" else: eventAdmin.update(propertyName, propertyValue)
def Assemble(self): nameList = Finder.getInstance().listAllNames('Scannable') nameList = ['ab__a', 'ab__b', 'xyz__x', 'xyz__y', 'xyz__z', 'blarghh'] # Filter out those containing __ groupComponentList = [] for name in nameList: if name.__contains__('__'): groupComponentList.append(name) # Create a dictionary with one key for each group, each key pointing to a list of component strings" groupDict = {} for name in groupComponentList: group, component = name.split('__') if not (groupDict.has_key(group)): groupDict[group] = [] groupDict[group].append(component) # Create the group scannables and pass back as list (STUB) toReturn = [] groupNameList = groupDict.keys() for groupName in groupNameList: tmp = groupName for componentName in groupDict[groupName]: tmp += "." + componentName toReturn += [tmp] return toReturn
def meta_add( farg, *vargs): """ Command to add a scannable to the items to be put into the scan metadata """ metashop=Finder.getInstance().find("metashop") if metashop == None: return metashop.add([farg]+list(vargs))
def __init__(self, name, scannableX, scannableY, deviceFun): """constructor parameters: name: Name of the new device scannableX: Name of the scannable on X-axis (for example: "energy") scannableY: Name of the scannable on Y-axis (for example: "mac15") deviceFun: Name of the function to calculate the new position based on scannableX and scannableY positions""" self.setName(name) self.setInputNames([name]) # self.Units=[strUnit] # self.setOutputFormat([strFormat]) # self.setLevel(8); self.x1 = 0.0 self.x2 = 0.0 self.y = 0.0 self.refObj1 = Finder.getInstance().find(scannableX) self.refObj2 = Finder.getInstance().find(scannableY) self.deviceFun = deviceFun
def meta_rm(farg, *vargs): """ Command to remove items to be put into the scan metadata. """ metashop=Finder.getInstance().find("metashop") if metashop == None: return metashop.remove([farg]+list(vargs))
def meta_rm(farg, *vargs): """ Command to remove items to be put into the scan metadata. """ metashop = Finder.getInstance().find("metashop") if metashop == None: return metashop.remove([farg] + list(vargs))
def meta_add(farg, *vargs): """ Command to add a scannable to the items to be put into the scan metadata """ metashop = Finder.getInstance().find("metashop") if metashop == None: return metashop.add([farg] + list(vargs))
def runExperiment(self): print "I am now running the experiment using parameters in the bean",str(self.bean),"..." time.sleep(2) print "...and now the experiment is over." scriptController = Finder.getInstance().find("MyExperimentScriptController") if scriptController != None: print "Broadcasting experiment complete message..." scriptController.update("MyExperiment Script", "Experiment Complete!")
def _createHeaderStringForScannables(self, fmt='%s=%s\n'): s = "" metascannables = Finder.getInstance().find("metashop").getMetaScannables() \ if self.readFromNexus else self.scannables_to_read for scn in metascannables: pairs = self._createNamePositionPairs(scn) for key, value in pairs: s += fmt % (key, value) return s
def reloadLookupTables(): """reloads all lookup tables on the ObjectServer""" controller = None prefix = "reloadLookupTables:" update(controller, prefix, " - started.") finder = Finder.getInstance() converters = finder.listAllObjects("IReloadableQuantitiesConverter") for converter in converters: update(controller, prefix, "..." + converter.getName() ) converter.reloadConverter() update(controller, prefix, " - completed")
def runExperiment(self): print "I am now running the experiment using parameters in the bean", str( self.bean), "..." time.sleep(2) print "...and now the experiment is over." scriptController = Finder.getInstance().find( "MyExperimentScriptController") if scriptController != None: print "Broadcasting experiment complete message..." scriptController.update("MyExperiment Script", "Experiment Complete!")
def __init__(self, name, lutObj='energytable', objType=0, rootNameSpace={}): '''Constructor - Only succeed if it find the lookup table, otherwise raise exception.''' self.finder=Finder.getInstance() self.lut=self.finder.find(lutObj) if self.lut==None: raise Exception, "Can not find the Lookup Table object" self.rootNameSpace=rootNameSpace self.scannableNames=self.lut.getScannableNames() self._busy=0 self.scannables=[self.rootNameSpace[x] for x in self.scannableNames] self.setName(name) self.setLevel(3) self.objType=objType self.inputNames=['energy']
def jobs(): """ Print a string showing the threads running in the command server. Only shows the live threads. """ command_server = Finder.getInstance().find(Jython.SERVER_NAME) logger.debug("jobs() called") s = "%-10s %-12s %-8s %-11s %s\n" % ('DATE', 'TIME', 'TYPE', 'INTERRUPTED', 'COMMAND') thread_infos = command_server.getCommandThreadInfo() for t in thread_infos: date = t.getDate() time = t.getTime() thread_type = t.getCommandThreadType() cmd = t.getCommand(); intrpt = ' X ' if t.isInterrupted() else '' s += "%(date)-10s %(time)-12s %(thread_type)-8s %(intrpt)-11s %(cmd)s\n" % locals() print s
def jobs(): """ Print a string showing the threads running in the command server. Only shows the live threads. """ command_server = Finder.getInstance().find(Jython.SERVER_NAME) logger.debug("jobs() called") s = "%-10s %-12s %-8s %-11s %s\n" % ('DATE', 'TIME', 'TYPE', 'INTERRUPTED', 'COMMAND') thread_infos = command_server.getCommandThreadInfo() for t in thread_infos: date = t.getDate() time = t.getTime() thread_type = t.getCommandThreadType() cmd = t.getCommand() intrpt = ' X ' if t.isInterrupted() else '' s += "%(date)-10s %(time)-12s %(thread_type)-8s %(intrpt)-11s %(cmd)s\n" % locals( ) print s
def reload_tables(logInfo=True): """reloads all lookup tables on the ObjectServer""" ok = True controller = None prefix = "reload_tables:" if( logInfo ): handle_messages.log(controller, prefix + " - started") finder = Finder.getInstance() converters = finder.listAllObjects("IReloadableQuantitiesConverter") for converter in converters: try: if( logInfo ): handle_messages.log(controller, prefix + "..." + converter.getName() ) converter.reloadConverter() except: type1, exception, traceback = sys.exc_info() handle_messages.log(controller, prefix + " - ", type1, exception, traceback, False) ok = False if( logInfo ): handle_messages.log(controller, prefix + " - completed") if( not ok): print "reload_tables completed with error" return ok
def meta_clear_alldynamical(): metashop = Finder.getInstance().find("metashop") if metashop is None: return metashop.clearDynamicScannableMetadata() return metashop.list(False)
def ls(self): metascannables = Finder.getInstance().find("metashop").getMetaScannables() \ if self.readFromNexus else self.scannables_to_read # meta_ls and meta_ll enforce their own formatting, so return their # list of metadata scannables in our format. return ' '.join([scn.name for scn in metascannables])
def testMCA(): beamline = Finder.getInstance().find("Beamline") return plotY( "Point", "Counts", beamline.getValue(ReturnType.DBR_NATIVE, "", "-EA-DET-01:MCA-01:mca3"))
ANY CHANGES WILL BE OVERWRITTEN WITHOUT WARNING ''' # generation-time attributes __beamline__ = 'EXAMPLE' __gdaversion__ = '9.9.0pre' __xmlfile__ = '/home/pi/server_20180710-1656_linux64/rpi-config/rpi-config/servers/main/dummy/server.xml' __pid__ = '803' __hostname__ = 'raspberrypi' __timestamp__ = '2018-09-13 09:05:15.862' # get function (finder.find for now) from gda.factory import Finder get = Finder.getInstance().find del Finder # not executed so types not in: dir(gdaserver) if False: # fake imports for fake assignments below from gda.data import ObservablePathConstructor from gda.data.metadata import GdaMetadata from gda.data.metadata import NXMetaDataProvider from gda.device.detector import DummyMandelbrotMappingDetector from gda.device.detector import NXDetector from gda.device.motor import DummyMotor from gda.device.scannable import ScannableMotor from gda.device.scannable import TwoJawSlitGap from gda.device.scannable import TwoJawSlitPosition
def _meta_ll(): """ Command to list the items to be put into the scan metadata. The value of the items will also be listed """ metashop=Finder.getInstance().find("metashop") return metashop.list(True)
def setTitle(title): """ Command to set the title that is recorded in the scan file """ Finder.getInstance().find("GDAMetadata").setMetadataValue("title", title)
def __init__(self, finder=None): if finder == None: finder = Finder.getInstance() self.reload(finder)
"""Utility script to help manage BSL file conversion""" from gda.configuration.properties import LocalProperties from gda.factory import Finder from gda.observable import IObserver from uk.ac.diamond.daq.persistence.jythonshelf import LocalParameters from gda.data.metadata import GDAMetadataProvider BSL_CONVERSION_CONFIGURED = 'gda.scan.processing.bsl.configured' RUNNER = Finder.getInstance().find('bslConversion') class BslConversionUpdater(IObserver): def update(self, source, arg): print 'Visit changed to ' + str(arg) restore() if not LocalProperties.contains(BSL_CONVERSION_CONFIGURED): LocalProperties.set(BSL_CONVERSION_CONFIGURED, 'True') for meta in GDAMetadataProvider.getInstance().getMetadataEntries(): if meta.name == 'visit': break if meta: meta.addIObserver(BslConversionUpdater()) CONFIGURATION_FILE = 'bslUsers' DEFAULT = False STORE = LocalParameters.getXMLConfiguration(CONFIGURATION_FILE)
def _meta_ls(): """ Command to list the items to be put into the scan metadata. """ metashop = Finder.getInstance().find("metashop") return metashop.list(False)
def pescan(self, frequency=0.1,exposure=0.5,amplitude=5.0,numPoints=40, function=2, bncycle=1): self.directory=PathConstructor.createFromDefaultProperty() self.scanNumber=scanNumTracker.incrementNumber() self.filename=self.directory+(str(self.scanNumber)) print self.filename if self.adc.getMode()=="Gate": self.setupADC2() elif self.adc.getMode()=="Trigger": self.configADC(200, self.adcClockRate(frequency)) self.calculateExperimentParameters(frequency, exposure, numPoints) self.setupFG(freq=frequency,amp=amplitude,bncycle=self.numGates, func=function) # must in following order if self.isSampleConditioning(): self.sampleConditioning(func=6, bncycle=1) self.configTFG(frequency) self.setupDataCapturer(self.filename, self.numGates) print "open fast shutter %d" % time() self.fastshutter.moveTo("OPEN") try: if frequency <= self.boundaryFrequency: for i in range(self.numCycles): GeneralCommands.pause() self.pedata.reset() self.pedata.setCollectionNumber(i) print "\ncollecting %d frames, %d gates per frame, Scan number %d, Collection number %d" % (self.numFrames*self.numDefinedSequency, self.numGates, self.scanNumber, i) Thread(target=self.gateDetector, name="MythenGatedCollection", args=(self.numFrames, self.numGates, self.scanNumber, i), kwargs={}).start() sleep(1) #self.startDetector(frequency, self.scanNumber, i) if self.adc.getMode()=="Trigger": print "enable adc sampling" self.adc.enable() #elif self.adc.getMode()=="Continuous": self.startPEDataStreamer(self.filename+"_pe_"+str(i)+".h5", 1/frequency+TIME_FUDGE_FACTOR_IN_SECONDS) self.tfg.start() sleep(1/frequency+GDAPROCESSTIME) else: finder=Finder.getInstance() print "\nPlease start PSD collection from Mythen QT client ..." print " 1. select 'Gated' option in the 'Runs' box first" print " 2. then set 'Acquisition time' to %d, 'Repetitions' to %d" % (self.numGates, self.numFrames * self.numDefinedSequency*self.numCycles) print " 3. set 'Output Directory' to subdirector %s under 'processing' directory, 'File name root' to %d, 'Start index' to %d" % (finder.find("GDAMetadata").getMetadataValue("subdirectory"), self.scanNumber, 0) target = requestInput("Is PSD ready, Yes or No?") print str(target) if str(target)!="Yes": raise "Exiting program" for j in range(self.startCycleNumber,self.numCycles): self.pedata.reset() self.pedata.setCollectionNumber(j) #self.startDetector(frequency, self.scanNumber, j) for i in range(self.startSeqNumber, self.numDefinedSequency): GeneralCommands.pause() sleep(4.0) self.tfg.config_cycle_for_seq(i, self.numGates, 1) sleep(4.0) if self.adc.getMode()=="Trigger": print "enable adc sampling" self.adc.enable() #elif self.adc.getMode()=="Continuous": self.startPEDataStreamer(self.filename+"_pe_"+str(i)+".h5", 1/frequency*self.numGates+TIME_FUDGE_FACTOR_IN_SECONDS) self.tfg.start() sleep(1/frequency*self.numGates+GDAPROCESSTIME) except: self.stop() raise finally: print "close fast shutter %d" % time() self.fastshutter.moveTo("CLOSE") self.pedata.removeMonitors() print "collection completed at %d" % time()
def _meta_ls(): """ Command to list the items to be put into the scan metadata. """ metashop=Finder.getInstance().find("metashop") return metashop.list(False)
def getMeta(self): return Finder.getInstance().find("metashop").getMetaScannables() \ if self.readFromNexus else self.scannables_to_read
def getTitle(): """ Command to get the title that is recorded in the scan file """ return Finder.getInstance().find("GDAMetadata").getMetadataValue("title")
from gda.data import PathConstructor from gda.factory import Finder import sys import gda.device.scannable.DummyScannable from gda.configuration.properties import LocalProperties import subprocess from gda.device import Scannable from gda.jython.commands.GeneralCommands import ls_names, vararg_alias from time import sleep from gda.jython.commands import GeneralCommands from gda.epics import CAClient from epics_scripts.pv_scannable_utils import caputStringAsWaveform # set up a nice method for getting the latest file path i11NumTracker = NumTracker("i11"); finder = Finder.getInstance() ca=CAClient() def wd(): dir = PathConstructor.createFromDefaultProperty() return dir # function to find the last file path def pwd(): dir = PathConstructor.createFromDefaultProperty() filenumber = i11NumTracker.getCurrentFileNumber(); return os.path.join(dir, str(filenumber))
def __init__(self): resistrarDict = Finder.getInstance().getFindablesOfType(IFileRegistrar) self.registrars = resistrarDict.values()
"""Utility script to help manage BSL file conversion""" from gda.configuration.properties import LocalProperties from gda.factory import Finder from gda.observable import IObserver from uk.ac.diamond.daq.persistence.jythonshelf import LocalParameters from gda.data.metadata import GDAMetadataProvider BSL_CONVERSION_CONFIGURED = 'gda.scan.processing.bsl.configured' RUNNER = Finder.getInstance().find('bslConversion') class BslConversionUpdater(IObserver): def update(self, source, arg): print 'Visit changed to ' + str(arg) restore() if not LocalProperties.contains(BSL_CONVERSION_CONFIGURED): LocalProperties.set(BSL_CONVERSION_CONFIGURED, 'True') for meta in GDAMetadataProvider.getInstance().getMetadataEntries(): if meta.name == 'visit': break if meta: meta.addIObserver(BslConversionUpdater()) CONFIGURATION_FILE = 'bslUsers' DEFAULT = False STORE = LocalParameters.getXMLConfiguration(CONFIGURATION_FILE) def isConvertingOn(): """Check whether new files will be converted automatically"""
def _meta_ll(): """ Command to list the items to be put into the scan metadata. The value of the items will also be listed """ metashop = Finder.getInstance().find("metashop") return metashop.list(True)
def testMCA(): beamline = Finder.getInstance().find("Beamline") return plotY("Point","Counts",beamline.getValue(ReturnType.DBR_NATIVE,"","-EA-DET-01:MCA-01:mca3"))
def __init__(self, name): self.tfg = Finder.getInstance().find("tfg") self.daserver = Finder.getInstance().find("daserver") # to support showArmed status self.tfg.setShowArmed(True)
''' Created on 10 Oct 2014 @author: fy65 ''' from gda.device import Detector from gda.device.scannable import DummyScannable from gda.factory import Finder from gda.jython.commands.ScannableCommands import scan ds1=DummyScannable("ds1") NDR=0 CAL=1 calName=Finder.getInstance().find("calibrantName") dr=Finder.getInstance().find("datareduction") def ldescan(*args): MUSTADDDATAREDUCTIONATEND=False newargs=[] i=0 #processing 1st argument if (args[i] == NDR): i=1 if (isinstance(args[i], Detector)) : newargs.append(ds1) # @UndefinedVariable newargs.append(1.0) newargs.append(1.0) newargs.append(1.0) while i<len(args): newargs.append(args[i]) i=i+1