Modified BSCAcquisition, so that the Cache is an argument of the function _acquire
This commit is contained in:
@ -90,13 +90,13 @@ class Dispersion:
|
|||||||
# adjustable
|
# adjustable
|
||||||
self.adjSV = 'SATCB01-RSYS:SET-BEAM-PHASE'
|
self.adjSV = 'SATCB01-RSYS:SET-BEAM-PHASE'
|
||||||
self.adjRB = 'SATCB01-RSYS:GET-BEAM-PHASE'
|
self.adjRB = 'SATCB01-RSYS:GET-BEAM-PHASE'
|
||||||
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1)
|
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1,ID = self.adjSV, name = "SATCB01-Linac")
|
||||||
self.amp = 30 # the amplitude of the scan, which can be scaled
|
self.amp = 30 # the amplitude of the scan, which can be scaled
|
||||||
# acquisition
|
# acquisition
|
||||||
sensor1 = getBSChannels('SATBD02-DBPM.*:Y2$')
|
sensor1 = getBSChannels('SATBD02-DBPM.*:Y2$')
|
||||||
sensor2 = getBSChannels('SATCB.*-RLLE-DSP:.*-VS$')
|
sensor2 = getBSChannels('SATCB.*-RLLE-DSP:.*-VS$')
|
||||||
self.sensor = sensor1+sensor2
|
self.sensor = sensor1+sensor2
|
||||||
self.acq = [BSCAcquisition(".",pgroup, default_channels=self.sensor)]
|
self.acq = [BSAcquisition(".",pgroup, default_channels=self.sensor)]
|
||||||
# auxiliar data to be read one
|
# auxiliar data to be read one
|
||||||
self.aux = self.getRFCalibrationChannels(sensor2,'SATCL01-MBND100:ENERGY-OP')
|
self.aux = self.getRFCalibrationChannels(sensor2,'SATCL01-MBND100:ENERGY-OP')
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class Dispersion:
|
|||||||
# adjustable
|
# adjustable
|
||||||
self.adjSV = 'S30:SET-E-GAIN-OP'
|
self.adjSV = 'S30:SET-E-GAIN-OP'
|
||||||
self.adjRB = 'S30:GET-E-GAIN-OP'
|
self.adjRB = 'S30:GET-E-GAIN-OP'
|
||||||
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1)
|
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1,ID = self.adjSV, name = "Linac3")
|
||||||
self.amp = 20 # the amplitude of the scan, which can be scaled
|
self.amp = 20 # the amplitude of the scan, which can be scaled
|
||||||
# acquisition
|
# acquisition
|
||||||
sensor1 = getBSChannels('SAR.*DBPM.*:[XY]1$')
|
sensor1 = getBSChannels('SAR.*DBPM.*:[XY]1$')
|
||||||
@ -142,7 +142,7 @@ class Dispersion:
|
|||||||
# adjustable
|
# adjustable
|
||||||
self.adjSV = 'S20:SET-E-GAIN-OP'
|
self.adjSV = 'S20:SET-E-GAIN-OP'
|
||||||
self.adjRB = 'S20:GET-E-GAIN-OP'
|
self.adjRB = 'S20:GET-E-GAIN-OP'
|
||||||
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1)
|
self.adj = PVAdjustable(self.adjSV,pvname_readback = self.adjRB, accuracy = 0.1,ID = self.adjSV, name = "Linac 2 and 3")
|
||||||
# self.adj2SV = 'S30:SET-E-GAIN-OP'
|
# self.adj2SV = 'S30:SET-E-GAIN-OP'
|
||||||
# self.adj2RB = 'S30:GET-E-GAIN-OP'
|
# self.adj2RB = 'S30:GET-E-GAIN-OP'
|
||||||
# self.adj2 = PVAdjustable(self.adj2SV,pvname_readback = self.adj2RB, accuracy = 0.1)
|
# self.adj2 = PVAdjustable(self.adj2SV,pvname_readback = self.adj2RB, accuracy = 0.1)
|
||||||
@ -159,7 +159,7 @@ class Dispersion:
|
|||||||
|
|
||||||
def setup(self,scl = 1, Nsteps=5, Nsamples=5):
|
def setup(self,scl = 1, Nsteps=5, Nsamples=5):
|
||||||
val = self.adj.get_current_value(readback=False)
|
val = self.adj.get_current_value(readback=False)
|
||||||
dval = self.amp*scl
|
# dval = self.amp*scl
|
||||||
dval = 0 ######## edit this
|
dval = 0 ######## edit this
|
||||||
self.N = Nsteps
|
self.N = Nsteps
|
||||||
self.Ns= Nsamples
|
self.Ns= Nsamples
|
||||||
@ -180,10 +180,10 @@ class Dispersion:
|
|||||||
self.sc=self.scanner.ascan_list(self.adj,self.values,
|
self.sc=self.scanner.ascan_list(self.adj,self.values,
|
||||||
filename=self.branch,start_immediately = False,
|
filename=self.branch,start_immediately = False,
|
||||||
n_pulses=self.Ns,return_to_initial_values=True)
|
n_pulses=self.Ns,return_to_initial_values=True)
|
||||||
# self.preaction() ######
|
# self.preaction() ######
|
||||||
self.sc.run()
|
self.sc.run()
|
||||||
self.auxdata = getAux(self.aux)
|
# self.auxdata = getAux(self.aux)
|
||||||
# self.postaction() #######
|
# self.postaction() #######
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
@ -1,42 +1,40 @@
|
|||||||
import zmq
|
|
||||||
import h5py
|
import h5py
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
from bstrd import BSCache
|
|
||||||
from slic.core.acquisition.acquisition import Acquisition
|
from slic.core.acquisition.acquisition import Acquisition
|
||||||
from slic.core.acquisition import BSAcquisition, PVAcquisition
|
|
||||||
|
|
||||||
# class using the BSQueue to avoid to reestablish a stream for each step.
|
# class using the BSQueue to avoid to reestablish a stream for each step.
|
||||||
|
|
||||||
class BSCAcquisition(Acquisition):
|
class BSCAcquisition(Acquisition):
|
||||||
|
|
||||||
def release(self):
|
|
||||||
if not self.queue == None:
|
|
||||||
del self.queue
|
|
||||||
self.queue = None
|
|
||||||
|
|
||||||
def _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
|
def _acquire(self, filename, channels=None, data_base_dir=None, scan_info=None, n_pulses=100, **kwargs):
|
||||||
if not hasattr(self,'queue'):
|
|
||||||
self.queue = getStream(channels)
|
queue =channels[0] # abusing interface since BSAcquisition assume a list of channels
|
||||||
elif not self.queue:
|
|
||||||
self.queue = getStream(channels)
|
# allocating space
|
||||||
|
data={}
|
||||||
self.queue.flush()
|
chns = queue.channels
|
||||||
print('Acquiring',n_pulses,'samples')
|
for chn in chns:
|
||||||
data = []
|
data[chn]={'data':np.zeros((n_pulses))}
|
||||||
|
data['pulse_id']=np.zeros((n_pulses))
|
||||||
|
|
||||||
|
# clear the queue
|
||||||
|
queue.flush()
|
||||||
for i in range(n_pulses):
|
for i in range(n_pulses):
|
||||||
data.append(self.queue.__next__())
|
msg = queue.__next__() # pull data from cache
|
||||||
|
for chn in chns:
|
||||||
|
data[chn]['data'][i] = msg[chn]
|
||||||
|
data['pulse_id'][i]=msg['pid']
|
||||||
|
|
||||||
|
# write out the data file
|
||||||
hid = h5py.File(filename,'w')
|
hid = h5py.File(filename,'w')
|
||||||
gid = hid.create_group(channels[0])
|
hid.create_dataset('pulse_id', data = data['pulse_id'])
|
||||||
for key in data[0].keys():
|
for chn in chns:
|
||||||
gid.create_dataset(key, data = [rec[key].value for rec in data])
|
gid = hid.create_group(chn)
|
||||||
|
for key in data[chn].keys():
|
||||||
|
gid.create_dataset(key, data = data[chn][key])
|
||||||
hid.close()
|
hid.close()
|
||||||
|
|
||||||
|
|
||||||
def getStream(channels):
|
|
||||||
print('Generating stream with channels:',channels)
|
|
||||||
bs = BSCache(100000,10000) # 1 second time out, capazity for 100 second.
|
|
||||||
bs.get_vars(channels)
|
|
||||||
return bs
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user