commit 0defe64bda3c8ab6a3b6584b8948526a60769e2c Author: gac-x07mb Date: Fri Mar 4 14:28:28 2022 +0100 Configuration change: Context diff --git a/config/config.properties b/config/config.properties new file mode 100644 index 0000000..875c0d3 --- /dev/null +++ b/config/config.properties @@ -0,0 +1,54 @@ +#Fri Mar 04 14:28:28 CET 2022 +autoSaveScanData=true +simulation=false +dataScanSaveOutput=false +userAuthenticator= +dataScanSaveScript=false +notifiedTasks=null +parallelInitialization=false +dataTransferPath=null +scanStreamingPort=-1 +saveConsoleSessionFiles=false +devicePoolFile={config}/devices.properties +hostName=null +disableEmbeddedAttributes=false +serverPort=8080 +versionTrackingEnabled=true +dataPath={data}/{year}/{month}/{day}/{year}_{month}{day}_{time}_{name} +serverEnabled=true +depthDimension=0 +logLevel=Info +dataLayout=fda +disableDataFileLogs=false +sessionHandling=Off +deviceUpdateStrategyFile={config}/update.properties +terminalEnabled=false +notificationLevel=Off +terminalPort=3579 +dataTransferUser=null +versionTrackingLogin={context}/svcusr-hlapp_robot +noBytecodeFiles=false +versionTrackingRemote=git@git.psi.ch\:pshell_config/x07mb.git +commandExecutionEvents=false +logDaysToLive=30 +logLevelConsole=Off +filePermissionsConfig=Default +scanStreamerPort=-1 +dataScanSaveSetpoints=false +versionTrackingManual=true +dataTransferMode=Off +userManagement=false +instanceName= +dataServerPort=-1 +hideServerMessages=false +dataScanReleaseRecords=true +dataScanPreserveTypes=true +dataScanFlushRecords=true +logPath={logs}/{date}_{time} +filePermissionsLogs=Default +filePermissionsScripts=Default +tasksFile={config}/tasks.properties +filePermissionsData=Default +createSessionFiles=false +dataProvider=fda +saveCommandStatistics=false diff --git a/config/devices.properties b/config/devices.properties new file mode 100644 index 0000000..17cf67f --- /dev/null +++ b/config/devices.properties @@ -0,0 +1,28 @@ +current=ch.psi.pshell.epics.ChannelDouble|ARIDI-PCT:CURRENT|Read||true +ROT=ch.psi.pshell.epics.Motor|X07MB-ES-MA1:ROT|||true +TRSCANH=ch.psi.pshell.epics.Motor|X07MA-ES3-MA1:TRSCAN||| +TRSCANH_RBV=ch.psi.pshell.epics.ChannelDouble|X07MB-ES3-MA1:TRSCANH.RBV|||true +ScanX=ch.psi.pshell.epics.Motor|X07MB-ES-MA1:ScanX|||true +ScanX_RBV=ch.psi.pshell.epics.ChannelDouble|X07MB-ES-MA1:ScanX.RBV||| +channel=ch.psi.pshell.epics.ChannelDouble|X07MB-OP2-SAI_03:CUR-MEAN|||true +ScanY=ch.psi.pshell.epics.Motor|X07MB-ES-MA1:ScanY|||true +ScanY_RBV=ch.psi.pshell.epics.ChannelDouble|X07MB-ES-MA1:ScanY.RBV||| +keith_1=ch.psi.pshell.epics.ChannelDouble|X07MB-OP2-SAI_07:MEAN|||true +keith_2=ch.psi.pshell.epics.ChannelDouble|X07MB-OP2-SAI_08:MEAN|||true +keith_3=ch.psi.pshell.epics.ChannelDouble|X07MB-OP2-SAI_06:MEAN|||true +mca_1=ch.psi.pshell.epics.ChannelIntegerArray|X07MB-XMAP:mca1|||true +trigger=ch.psi.pshell.epics.ChannelInteger|X07MB-OP2:INTR-COUNT|||true +pol_mode=ch.psi.pshell.epics.DiscretePositioner|X07MA-ID:MODE|||true +pol_offset=ch.psi.pshell.epics.ChannelDouble|X07MA-ID:ENERGY-OFFS|||true +pol_angle=ch.psi.pshell.epics.ChannelDouble|X07MA-ID:ALPHA|||true +pol_done=ch.psi.pshell.epics.ChannelString|X07MA-ID:DONE|Read||true +energy_ma=ch.psi.pshell.epics.ChannelDouble|X07MA-PHS-E:GO.A|||true +energy_ma_rbv=ch.psi.pshell.epics.ChannelDouble|X07MA-PGM:CERBK|Read||true +energy_ma_done=ch.psi.pshell.epics.ChannelInteger|X07MA-PHS:alldone|Read||true +cadc1=ch.psi.pshell.epics.ChannelDouble|X07MA-ES1-AI:SIGNAL0|Read||true +cadc2=ch.psi.pshell.epics.ChannelDouble|X07MA-ES1-AI:SIGNAL1|Read||true +cadc3=ch.psi.pshell.epics.ChannelDouble|X07MA-ES1-AI:SIGNAL2|Read||true +cadc4=ch.psi.pshell.epics.ChannelDouble|X07MA-ES1-AI:SIGNAL3|Read||true +cadc5=ch.psi.pshell.epics.ChannelDouble|X07MA-ES1-AI:SIGNAL4|Read||true +beam_status=ch.psi.pshell.epics.DiscretePositioner|ACOAU-ACCU:OP-MODE|Read||true +id_error=ch.psi.pshell.epics.ChannelInteger|X07MA-ID-PLC:ERROR|||true diff --git a/config/jcae.properties b/config/jcae.properties new file mode 100644 index 0000000..20cf111 --- /dev/null +++ b/config/jcae.properties @@ -0,0 +1,16 @@ +#Fri Jul 31 16:19:42 CEST 2020 +ch.psi.jcae.ContextFactory.maxArrayBytes=20000000 +ch.psi.jcae.impl.DefaultChannelService.timeout=1000 +ch.psi.jcae.ChannelFactory.timeout=3000 +ch.psi.jcae.ContextFactory.maxSendArrayBytes= +ch.psi.jcae.ChannelFactory.retries=1 +ch.psi.jcae.ContextFactory.useShellVariables=true +ch.psi.jcae.ContextFactory.addLocalBroadcastInterfaces=false +ch.psi.jcae.ContextFactory.addressList= +ch.psi.jcae.ContextFactory.serverPort= +ch.psi.jcae.impl.DefaultChannelService.retries=4 +ch.psi.jcae.ContextFactory.autoAddressList=false +ch.psi.jcae.ChannelBeanFactory.timeout=10000 +ch.psi.jcae.ChannelBeanFactory.waitTimeout=1800000 +ch.psi.jcae.ChannelBeanFactory.waitRetryPeriod=60000 +ch.psi.jcae.ChannelBeanFactory.retries=4 diff --git a/config/mail.properties b/config/mail.properties new file mode 100644 index 0000000..42cffd1 --- /dev/null +++ b/config/mail.properties @@ -0,0 +1,9 @@ +#Thu Nov 09 14:48:45 CET 2017 +auth=None +from= +host= +port=0 +pwd= +smsSuffix=@sms.switch.ch +to= +usr= diff --git a/config/plugins.properties b/config/plugins.properties new file mode 100644 index 0000000..832fff6 --- /dev/null +++ b/config/plugins.properties @@ -0,0 +1 @@ +PersonalizedTheme.java=enabled diff --git a/config/settings.properties b/config/settings.properties new file mode 100644 index 0000000..3f77598 --- /dev/null +++ b/config/settings.properties @@ -0,0 +1,2 @@ +#Fri Mar 04 14:27:17 CET 2022 +FdaBrowser=true diff --git a/config/setup.properties b/config/setup.properties new file mode 100644 index 0000000..4d01278 --- /dev/null +++ b/config/setup.properties @@ -0,0 +1,23 @@ +#Wed May 19 14:35:09 CEST 2021 +scriptPath={home}/script +sessionsPath={outp}/sessions +pluginsPath={home}/plugins +configFileDevices={config}/devices.properties +consoleSessionsPath={sessions}/console +libraryPath={script}; {script}/Lib +configFilePlugins={config}/plugins.properties +contextPath={outp}/context +extensionsPath={home}/extensions +configPath={home}/config +configFileSessions={config}/sessions.properties +userSessionsPath={sessions}/user +dataPath={outp}/data +devicesPath={home}/devices +configFileVariables={config}/variables.properties +configFileSettings={config}/settings.properties +logPath={outp}/log +wwwPath={home}/www +configFile={config}/config.properties +imagesPath={outp}/images +scriptType=py +configFileTasks={config}/tasks.properties diff --git a/config/variables.properties b/config/variables.properties new file mode 100644 index 0000000..af46ff7 --- /dev/null +++ b/config/variables.properties @@ -0,0 +1,4 @@ +#Fri Mar 04 14:16:42 CET 2022 +LastRunDate=220304 +FileSequentialNumber=582 +DaySequentialNumber=7 diff --git a/devices/ROT.properties b/devices/ROT.properties new file mode 100644 index 0000000..b9af399 --- /dev/null +++ b/devices/ROT.properties @@ -0,0 +1,18 @@ +#Thu Sep 19 10:34:01 CEST 2019 +defaultSpeed=1.5 +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=95.5 +minSpeed=0.75 +minValue=-41.0 +monitorByPosition=false +offset=0.0 +precision=6 +resolution=0.002 +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=deg diff --git a/devices/ScanX.properties b/devices/ScanX.properties new file mode 100644 index 0000000..c1ca55d --- /dev/null +++ b/devices/ScanX.properties @@ -0,0 +1,18 @@ +#Thu Sep 19 10:34:01 CEST 2019 +defaultSpeed=1.0 +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=30.0 +minSpeed=0.001 +minValue=-32.0 +monitorByPosition=false +offset=0.0 +precision=6 +resolution=0.001 +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=mm diff --git a/devices/ScanY.properties b/devices/ScanY.properties new file mode 100644 index 0000000..9b940fa --- /dev/null +++ b/devices/ScanY.properties @@ -0,0 +1,18 @@ +#Thu Sep 19 10:34:01 CEST 2019 +defaultSpeed=0.5 +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=1.6999999999999993 +minSpeed=1.0E-4 +minValue=-23.3 +monitorByPosition=false +offset=0.0 +precision=6 +resolution=0.2 +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=mm diff --git a/devices/ScanY_RBV.properties b/devices/ScanY_RBV.properties new file mode 100644 index 0000000..0eb2bd7 --- /dev/null +++ b/devices/ScanY_RBV.properties @@ -0,0 +1,16 @@ +#Wed Feb 28 15:37:17 CET 2018 +defaultSpeed=0.4 +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=22.0 +minSpeed=0.0050000000000000044 +minValue=-17.0 +offset=0.0 +precision=8 +resolution=0.00125 +rotation=false +scale=1.0 +startRetries=1 +unit=mm diff --git a/devices/TRSCANH.properties b/devices/TRSCANH.properties new file mode 100644 index 0000000..4f3df64 --- /dev/null +++ b/devices/TRSCANH.properties @@ -0,0 +1,18 @@ +#Thu Sep 19 10:34:01 CEST 2019 +defaultSpeed=0.4 +estbilizationDelay=0 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=22.0 +minSpeed=0.001 +minValue=-17.0 +monitorByPosition=false +offset=0.0 +precision=8 +resolution=0.01 +rotation=false +scale=1.0 +sign_bit=0 +startRetries=1 +unit=mm diff --git a/devices/dp1.properties b/devices/dp1.properties new file mode 100644 index 0000000..49a76db --- /dev/null +++ b/devices/dp1.properties @@ -0,0 +1,11 @@ +#Mon Mar 21 10:29:45 CET 2016 +motor1=0.0|4.0|8.0|0.0 +motor2=0.0|5.0|3.0|NaN +motor3=null +motor4=null +motor5=null +motor6=null +motor7=null +motor8=null +positions=Park|Ready|Out|Clear +precision=-1 diff --git a/devices/energy_ma.properties b/devices/energy_ma.properties new file mode 100644 index 0000000..b8bb77d --- /dev/null +++ b/devices/energy_ma.properties @@ -0,0 +1,10 @@ +#Thu Mar 03 14:39:23 CET 2022 +offset=0.0 +maxValue=2000.0 +rotation=false +precision=3 +scale=1.0 +resolution=0.01 +minValue=300.0 +unit=eV +sign_bit=0 diff --git a/devices/m1.properties b/devices/m1.properties new file mode 100644 index 0000000..e4a30d8 --- /dev/null +++ b/devices/m1.properties @@ -0,0 +1,16 @@ +#Wed Jul 22 10:07:25 CEST 2020 +offset=0.0 +maxValue=10.0 +precision=2 +rotation=false +scale=1.0 +estbilizationDelay=0 +maxSpeed=10.0 +resolution=NaN +startRetries=1 +minValue=-10.0 +unit=mm +defaultSpeed=1.0 +sign_bit=0 +monitorByPosition=false +minSpeed=0.1 diff --git a/devices/m2.properties b/devices/m2.properties new file mode 100644 index 0000000..e4a30d8 --- /dev/null +++ b/devices/m2.properties @@ -0,0 +1,16 @@ +#Wed Jul 22 10:07:25 CEST 2020 +offset=0.0 +maxValue=10.0 +precision=2 +rotation=false +scale=1.0 +estbilizationDelay=0 +maxSpeed=10.0 +resolution=NaN +startRetries=1 +minValue=-10.0 +unit=mm +defaultSpeed=1.0 +sign_bit=0 +monitorByPosition=false +minSpeed=0.1 diff --git a/devices/p1.properties b/devices/p1.properties new file mode 100644 index 0000000..e6cb79e --- /dev/null +++ b/devices/p1.properties @@ -0,0 +1,10 @@ +#Wed Jul 22 10:07:25 CEST 2020 +minValue=0.0 +unit=mm +offset=0.0 +maxValue=1000.0 +precision=-1 +rotation=false +sign_bit=0 +scale=1.0 +resolution=NaN diff --git a/devices/scan_y.properties b/devices/scan_y.properties new file mode 100644 index 0000000..60dc096 --- /dev/null +++ b/devices/scan_y.properties @@ -0,0 +1,16 @@ +#Thu Nov 09 14:48:45 CET 2017 +defaultSpeed=0.5 +estbilizationDelay=100 +hasEnable=false +homingType=None +maxSpeed=NaN +maxValue=1.6999999999999993 +minSpeed=0.05 +minValue=-23.3 +offset=0.0 +precision=6 +resolution=5.0E-4 +rotation=false +scale=1.0 +startRetries=1 +unit=mm diff --git a/devices/src1.properties b/devices/src1.properties new file mode 100644 index 0000000..921ed69 --- /dev/null +++ b/devices/src1.properties @@ -0,0 +1,25 @@ +#Wed Jul 22 10:07:25 CEST 2020 +spatialCalOffsetY=NaN +spatialCalOffsetX=NaN +colormapLogarithmic=false +scale=1.0 +grayscale=false +spatialCalScaleX=NaN +spatialCalScaleY=NaN +colormapMax=255.0 +rescaleOffset=0.0 +roiWidth=-1 +colormap=Temperature +invert=false +colormapMin=0.0 +rotation=0.0 +rotationCrop=false +rescaleFactor=1.0 +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +flipHorizontally=false +colormapAutomatic=true +roiY=0 +roiX=0 +transpose=false diff --git a/devices/src2.properties b/devices/src2.properties new file mode 100644 index 0000000..91efeb5 --- /dev/null +++ b/devices/src2.properties @@ -0,0 +1,25 @@ +#Wed Jul 22 10:07:25 CEST 2020 +spatialCalOffsetY=NaN +spatialCalOffsetX=NaN +colormapLogarithmic=false +scale=1.0 +grayscale=false +spatialCalScaleX=NaN +spatialCalScaleY=NaN +colormapMax=255.0 +rescaleOffset=0.0 +roiWidth=-1 +colormap=Grayscale +invert=false +colormapMin=0.0 +rotation=0.0 +rotationCrop=false +rescaleFactor=1.0 +spatialCalUnits=mm +flipVertically=false +roiHeight=-1 +flipHorizontally=false +colormapAutomatic=true +roiY=0 +roiX=0 +transpose=false diff --git a/plugins/EnergyScan.form b/plugins/EnergyScan.form new file mode 100644 index 0000000..d3bd992 --- /dev/null +++ b/plugins/EnergyScan.form @@ -0,0 +1,467 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java new file mode 100644 index 0000000..db4bb67 --- /dev/null +++ b/plugins/EnergyScan.java @@ -0,0 +1,714 @@ +/* + * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. + */ + +import java.awt.Component; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.logging.Level; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JLabel; +import ch.psi.utils.State; +import ch.psi.utils.swing.DsvEditor; +import ch.psi.utils.swing.Editor.EditorDialog; +import ch.psi.pshell.data.PlotDescriptor; +import ch.psi.pshell.ui.Panel; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.io.File; +import java.util.logging.Logger; + +/** + * + */ +public class EnergyScan extends Panel { + + public EnergyScan() { + initComponents(); + buttonDefaultsActionPerformed(null); + setBackgroundUpdate(true); + } + double[] offsets = new double[4]; + + @Override + public void onInitialize(int runCount) { + super.onInitialize(runCount); + + loadConfig(); + } + + @Override + public void onStateChange(State state, State former) { + setEnabled(state == State.Ready); + } + + @Override + public void onExecutedFile(String fileName, Object result) { + } + + void stopScan() { + try{ + getLogger().info("Stopping scan"); + evalAsync("caput('START', 'STOP')"); + } catch (Exception ex){ + getLogger().log(Level.WARNING, null, ex); + } + } + + Path getConfigFile() { + return Paths.get(getContext().getSetup().getConfigPath(), "energy_scan.properties"); + } + + enum Mode { + + plus, + minus, + lh, + lv + } + + Mode[] batch; + int batchIndex; + + @Override + public void setEnabled(boolean value) { + super.setEnabled(value); + buttonExecute.setEnabled(value); + comboSetup.setEnabled(value); + comboRunType.setEnabled(value); + buttonConfigure.setEnabled(value); + textFile.setEnabled(value); + buttonDefaults.setEnabled(value); + checkParameterControls(); + } + + void checkParameterControls() { + boolean enabled = isEnabled() && (comboRunType.getSelectedIndex() == 0); + for (Component c : panelParameters.getComponents()) { + if (!(c instanceof JLabel)) { + c.setEnabled(enabled); + } + } + spinnerAlpha.setEnabled(enabled && comboMode.getSelectedItem().equals("LINEAR")); + spinnerOffset.setEnabled(checkSetOffset.isSelected() && enabled); + } + + + void loadConfig() { + DefaultComboBoxModel model = (DefaultComboBoxModel) comboSetup.getModel(); + model.removeAllElements(); + try { + for (String line : Files.readAllLines(getConfigFile())) { + if ((line != null) && (!line.trim().isEmpty())) { + String[] tokens = line.split("="); + if (tokens.length > 0) { + model.addElement(tokens[0].trim()); + } + } + } + } catch (Exception ex) { + } + } + + String expandPath(String path) { + long time = System.currentTimeMillis(); + String mode; + if (comboMode.getSelectedIndex() == 0) { + mode = "plus"; + } else if (comboMode.getSelectedIndex() == 1) { + mode = "minus"; + } else { + mode = "lin_" + String.format("%1.0f", (Double) spinnerAlpha.getValue()); + } + path = getContext().getSetup().expandPath(path); + path = path.replaceAll("\\{el\\}", String.valueOf(comboSetup.getSelectedItem())); + path = path.replaceAll("\\{mode\\}", mode); + return path; + } + + void setMode(Mode mode) { + switch (mode) { + case plus: + comboMode.setSelectedIndex(0); + spinnerOffset.setValue(offsets[0]); + return; + case minus: + comboMode.setSelectedIndex(1); + spinnerOffset.setValue(offsets[1]); + return; + case lh: + comboMode.setSelectedIndex(2); + spinnerOffset.setValue(offsets[2]); + spinnerAlpha.setValue(0.0); + return; + case lv: + comboMode.setSelectedIndex(2); + spinnerOffset.setValue(offsets[3]); + spinnerAlpha.setValue(90.0); + return; + } + } + + boolean isManualRun() { + return (comboRunType.getSelectedIndex() == 0); + } + + void setElement() throws Exception { + String selection = comboSetup.getSelectedItem().toString(); + for (String line : Files.readAllLines(getConfigFile())) { + if ((line != null) && (!line.trim().isEmpty())) { + String[] tokens = line.split("="); + if (tokens.length < 2) { + throw new Exception("Invalid file format"); + } + if (tokens[0].equals(selection)) { + tokens = tokens[1].trim().split(";"); + if (tokens.length != 8) { + throw new Exception("Invalid file format"); + } + spinnerE1.setValue(Double.valueOf(tokens[0].trim())); + spinnerE2.setValue(Double.valueOf(tokens[1].trim())); + spinnerTime.setValue(Double.valueOf(tokens[2].trim())); + spinnerDelay.setValue(Double.valueOf(tokens[3].trim())); + + offsets[0] = Double.valueOf(tokens[4].trim()); + offsets[1] = Double.valueOf(tokens[5].trim()); + offsets[2] = Double.valueOf(tokens[6].trim()); + offsets[3] = Double.valueOf(tokens[7].trim()); + break; + } + } + } + } + + void setRunType() throws Exception { + switch (comboRunType.getSelectedIndex()) { + case 0: //Manual + break; + case 1: //+ + setMode(Mode.plus); + break; + case 2: //- + setMode(Mode.minus); + break; + case 3: //LH + setMode(Mode.lh); + break; + case 4: //LV + setMode(Mode.lv); + break; + case 5: //+/- + setMode(Mode.plus); + break; + case 6: //+/-/-/+ + setMode(Mode.plus); + break; + case 7: //LH/LV + setMode(Mode.lh); + break; + case 8: //LH/LV/LV/LH + setMode(Mode.lh); + break; + } + checkParameterControls(); + } + + void run() throws Exception { + HashMap args = new HashMap(); + Double e1 = (Double) spinnerE1.getValue(); + Double e2 = (Double) spinnerE2.getValue(); + args.put("E1", e1); + args.put("E2", e2); + args.put("TIME", (Double) spinnerTime.getValue()); + args.put("DELAY", (Double) spinnerDelay.getValue()); + args.put("MODE", comboMode.getSelectedItem().toString()); + args.put("OFFSET", checkSetOffset.isSelected() ? (Double) spinnerOffset.getValue() : null); + args.put("ALPHA", (Double) spinnerAlpha.getValue()); + + String file = expandPath(textFile.getText()); + args.put("NAME", file); + buttonAbort.setEnabled(true); + + runAsync("EnergyScan_ma", args).handle((ok, ex) -> { + try{ + buttonAbort.setEnabled(false); + if (ex != null) { + stopScan(); + throw ex; + } else { + if (batch != null) { + batchIndex++; + if (batchIndex >= batch.length) { + batch = null; + } else { + setMode(batch[batchIndex]); + run(); + } + } + } + } catch (Throwable t){ + batch = null; + getLogger().log(Level.WARNING, null, ex); + //showException((Exception)ex); + } + return ok; + }); + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonGroupPlot = new javax.swing.ButtonGroup(); + panelParameters = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + spinnerE1 = new javax.swing.JSpinner(); + jLabel2 = new javax.swing.JLabel(); + spinnerE2 = new javax.swing.JSpinner(); + jLabel3 = new javax.swing.JLabel(); + spinnerTime = new javax.swing.JSpinner(); + jLabel4 = new javax.swing.JLabel(); + spinnerDelay = new javax.swing.JSpinner(); + jLabel5 = new javax.swing.JLabel(); + comboMode = new javax.swing.JComboBox(); + jLabel8 = new javax.swing.JLabel(); + spinnerOffset = new javax.swing.JSpinner(); + jLabel9 = new javax.swing.JLabel(); + spinnerAlpha = new javax.swing.JSpinner(); + checkSetOffset = new javax.swing.JCheckBox(); + jPanel1 = new javax.swing.JPanel(); + comboSetup = new javax.swing.JComboBox(); + buttonConfigure = new javax.swing.JButton(); + jLabel10 = new javax.swing.JLabel(); + jLabel11 = new javax.swing.JLabel(); + comboRunType = new javax.swing.JComboBox(); + panelData = new javax.swing.JPanel(); + buttonDefaults = new javax.swing.JButton(); + jLabel6 = new javax.swing.JLabel(); + textFile = new javax.swing.JTextField(); + jPanel3 = new javax.swing.JPanel(); + buttonExecute = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + + panelParameters.setBorder(javax.swing.BorderFactory.createTitledBorder((String)null)); + + jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel1.setText("E1:"); + + spinnerE1.setModel(new javax.swing.SpinnerNumberModel(690.0d, 0.0d, 9999.0d, 1.0d)); + + jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel2.setText("E2:"); + + spinnerE2.setModel(new javax.swing.SpinnerNumberModel(755.0d, 0.0d, 9999.0d, 1.0d)); + + jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel3.setText("Time(min):"); + + spinnerTime.setModel(new javax.swing.SpinnerNumberModel(3.0d, 0.0d, 60.0d, 1.0d)); + + jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel4.setText("Delay(s):"); + + spinnerDelay.setModel(new javax.swing.SpinnerNumberModel(10.0d, 0.0d, 600.0d, 1.0d)); + + jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel5.setText("Mode:"); + + comboMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CIRC +", "CIRC -", "LINEAR" })); + comboMode.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboModeActionPerformed(evt); + } + }); + + jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel8.setText("Offset:"); + + spinnerOffset.setModel(new javax.swing.SpinnerNumberModel(0.0d, -20.0d, 20.0d, 1.0d)); + spinnerOffset.setEnabled(false); + + jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel9.setText("Alpha:"); + + spinnerAlpha.setModel(new javax.swing.SpinnerNumberModel(0.0d, 0.0d, 90.0d, 1.0d)); + + checkSetOffset.setText("Set Offset"); + checkSetOffset.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + checkSetOffsetActionPerformed(evt); + } + }); + + javax.swing.GroupLayout panelParametersLayout = new javax.swing.GroupLayout(panelParameters); + panelParameters.setLayout(panelParametersLayout); + panelParametersLayout.setHorizontalGroup( + panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelParametersLayout.createSequentialGroup() + .addContainerGap() + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) + .addGroup(panelParametersLayout.createSequentialGroup() + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerE1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerTime, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboMode, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addComponent(checkSetOffset)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParametersLayout.createSequentialGroup() + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(spinnerE2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerDelay, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerAlpha, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParametersLayout.createSequentialGroup() + .addComponent(jLabel8) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(spinnerOffset, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboMode, spinnerE1, spinnerTime}); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel2, jLabel4, jLabel8, jLabel9}); + + panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerAlpha, spinnerDelay, spinnerE2, spinnerOffset}); + + panelParametersLayout.setVerticalGroup( + panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelParametersLayout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(spinnerE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel2) + .addComponent(spinnerE2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel3) + .addComponent(spinnerTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel4) + .addComponent(spinnerDelay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel5) + .addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(spinnerAlpha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel9)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel8) + .addComponent(spinnerOffset, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(checkSetOffset)) + .addContainerGap()) + ); + + jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder((String)null)); + + comboSetup.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboSetupActionPerformed(evt); + } + }); + + buttonConfigure.setText("Configure"); + buttonConfigure.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonConfigureActionPerformed(evt); + } + }); + + jLabel10.setText("Element:"); + + jLabel11.setText("Run Type:"); + + comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Manual", "+", "-", "LH", "LV", "+/-", "+/-/-/+", "LH/LV", "LH/LV/LV/LH" })); + comboRunType.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboRunTypeActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap(22, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING) + .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonConfigure))) + .addContainerGap(22, Short.MAX_VALUE)) + ); + + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {comboRunType, comboSetup}); + + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(4, 4, 4) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel10) + .addComponent(buttonConfigure)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel11) + .addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + panelData.setBorder(javax.swing.BorderFactory.createTitledBorder((String)null)); + + buttonDefaults.setText("Default"); + buttonDefaults.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDefaultsActionPerformed(evt); + } + }); + + jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); + jLabel6.setText("File:"); + + javax.swing.GroupLayout panelDataLayout = new javax.swing.GroupLayout(panelData); + panelData.setLayout(panelDataLayout); + panelDataLayout.setHorizontalGroup( + panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelDataLayout.createSequentialGroup() + .addContainerGap() + .addComponent(jLabel6) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textFile) + .addGap(18, 18, 18) + .addComponent(buttonDefaults) + .addContainerGap()) + ); + panelDataLayout.setVerticalGroup( + panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(panelDataLayout.createSequentialGroup() + .addGroup(panelDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel6) + .addComponent(textFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonDefaults, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap()) + ); + + jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder((String)null)); + + buttonExecute.setText("Start"); + buttonExecute.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonExecuteActionPerformed(evt); + } + }); + + buttonAbort.setText("Abort"); + buttonAbort.setEnabled(false); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); + jPanel3.setLayout(jPanel3Layout); + jPanel3Layout.setHorizontalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() + .addContainerGap(22, Short.MAX_VALUE) + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonExecute, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(22, Short.MAX_VALUE)) + ); + jPanel3Layout.setVerticalGroup( + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() + .addGap(4, 4, 4) + .addComponent(buttonExecute) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonAbort) + .addContainerGap()) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, 0) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(panelData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(panelParameters, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(0, 0, 0)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(16, 16, 16) + .addComponent(panelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(panelData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jPanel1, jPanel3}); + + }// //GEN-END:initComponents + + private void buttonExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecuteActionPerformed + try { + batchIndex = 0; + switch (comboRunType.getSelectedIndex()) { + case 5: + batch = new Mode[]{Mode.plus, Mode.minus}; + break; + case 6: + batch = new Mode[]{Mode.plus, Mode.minus, Mode.minus, Mode.plus}; + break; + case 7: + batch = new Mode[]{Mode.lh, Mode.lv}; + break; + case 8: + batch = new Mode[]{Mode.lh, Mode.lv, Mode.lv, Mode.lh}; + break; + default: + batch = null; + } + run(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonExecuteActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + batch = null; + try { + abort(); + } catch (InterruptedException ex) { + } + }//GEN-LAST:event_buttonAbortActionPerformed + + private void comboSetupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboSetupActionPerformed + try { + if (comboSetup.getSelectedItem() != null) { + setElement(); + if (!isManualRun()) { + setRunType(); + } + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_comboSetupActionPerformed + + EditorDialog dlgConfig; + private void buttonConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigureActionPerformed + try { + //Desktop.getDesktop().open(getConfigFile().toFile()); + if ((dlgConfig == null) || (!dlgConfig.isShowing())) { + String[] columns = new String[]{"Element", "E1", "E2", "Time", "Delay", "OffPlus", "OffMinus", "OffLH", "OffLV"}; + Class[] types = new Class[]{String.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class}; + DsvEditor editor = new DsvEditor(columns, types, ";"); + dlgConfig = editor.getDialog(getView(), false); + editor.load(getConfigFile().toString()); + editor.setTitle("Energy Scan Configuration"); + dlgConfig.addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent e) { + if (System.currentTimeMillis() - new File(dlgConfig.getEditor().getFileName()).lastModified() < 5000) { + loadConfig(); + } + } + }); + } + dlgConfig.setSize(680, 320); + showWindow(dlgConfig); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonConfigureActionPerformed + + private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed + checkParameterControls(); + }//GEN-LAST:event_comboModeActionPerformed + + private void comboRunTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboRunTypeActionPerformed + try { + if (!isManualRun()) { + setElement(); + } + setRunType(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_comboRunTypeActionPerformed + + private void buttonDefaultsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDefaultsActionPerformed + textFile.setText("{el}_{mode}"); + }//GEN-LAST:event_buttonDefaultsActionPerformed + + private void checkSetOffsetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkSetOffsetActionPerformed + spinnerOffset.setEnabled(checkSetOffset.isSelected()); + }//GEN-LAST:event_checkSetOffsetActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonConfigure; + private javax.swing.JButton buttonDefaults; + private javax.swing.JButton buttonExecute; + private javax.swing.ButtonGroup buttonGroupPlot; + private javax.swing.JCheckBox checkSetOffset; + private javax.swing.JComboBox comboMode; + private javax.swing.JComboBox comboRunType; + private javax.swing.JComboBox comboSetup; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel10; + private javax.swing.JLabel jLabel11; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; + private javax.swing.JLabel jLabel4; + private javax.swing.JLabel jLabel5; + private javax.swing.JLabel jLabel6; + private javax.swing.JLabel jLabel8; + private javax.swing.JLabel jLabel9; + private javax.swing.JPanel jPanel1; + private javax.swing.JPanel jPanel3; + private javax.swing.JPanel panelData; + private javax.swing.JPanel panelParameters; + private javax.swing.JSpinner spinnerAlpha; + private javax.swing.JSpinner spinnerDelay; + private javax.swing.JSpinner spinnerE1; + private javax.swing.JSpinner spinnerE2; + private javax.swing.JSpinner spinnerOffset; + private javax.swing.JSpinner spinnerTime; + private javax.swing.JTextField textFile; + // End of variables declaration//GEN-END:variables +} diff --git a/plugins/PersonalizedTheme.java b/plugins/PersonalizedTheme.java new file mode 100644 index 0000000..c32c20d --- /dev/null +++ b/plugins/PersonalizedTheme.java @@ -0,0 +1,64 @@ + +import ch.psi.pshell.ui.Plugin; +import ch.psi.pshell.ui.Preferences; +import ch.psi.pshell.swing.ScriptEditor; +import ch.psi.utils.swing.SwingUtils; +import java.awt.Font; +import java.util.logging.Level; +import javax.swing.UIManager; + +public class PersonalizedTheme implements Plugin { + + @Override + public void onStart() { + try { + Font font = new Font("Verdana", Font.PLAIN, 16); + UIManager.put("Button.font", font); + UIManager.put("ToggleButton.font", font); + UIManager.put("RadioButton.font", font); + UIManager.put("CheckBox.font", font); + UIManager.put("ColorChooser.font", font); + UIManager.put("ComboBox.font", font); + UIManager.put("Label.font", font); + UIManager.put("List.font", font); + UIManager.put("MenuBar.font", font); + UIManager.put("MenuItem.font", font); + UIManager.put("RadioButtonMenuItem.font", font); + UIManager.put("CheckBoxMenuItem.font", font); + UIManager.put("Menu.font", font); + UIManager.put("PopupMenu.font", font); + UIManager.put("OptionPane.font", font); + UIManager.put("Panel.font", font); + UIManager.put("ProgressBar.font", font); + UIManager.put("ScrollPane.font", font); + UIManager.put("Viewport.font", font); + UIManager.put("TabbedPane.font", font); + UIManager.put("Table.font", font); + UIManager.put("TableHeader.font", font); + UIManager.put("TextField.font", font); + UIManager.put("PasswordField.font", font); + UIManager.put("TextArea.font", font); + UIManager.put("TextPane.font", font); + UIManager.put("EditorPane.font", font); + UIManager.put("TitledBorder.font", font); + UIManager.put("ToolBar.font", font); + UIManager.put("ToolTip.font", font); + UIManager.put("Tree.font", font); + + SwingUtils.updateAllFrames(); + + + SwingUtils.invokeDelayed( ()->{ + Preferences preferences = getView().getPreferences(); + for (ScriptEditor editor : getView().getEditors()){ + editor.setTextPaneFont(preferences.fontEditor); + } + }, 250); + + } catch (Exception ex) { + getLogger().log(Level.WARNING, null, ex); + } + + } + +} diff --git a/script/2018_0905_090323_BeamMovementsMicroscope.py b/script/2018_0905_090323_BeamMovementsMicroscope.py new file mode 100644 index 0000000..630013c --- /dev/null +++ b/script/2018_0905_090323_BeamMovementsMicroscope.py @@ -0,0 +1,425 @@ +#Script imported from: 2018_0905_090323_BeamMovementsMicroscope.xml + +#Pre-actions +caput('X07MB-OP2:START-CSMPL', '0') +sleep(0.1) +caput('X07MB-XMAP:StopAll', '1') +sleep(0.1) +caput('X07MB-XMAP:CollectMode', '0') +sleep(0.2) +caput('X07MB-XMAP:Apply', '1') +sleep(0.1) +caput('X07MB-XMAP:PresetReal', '0') +sleep(0.1) +caput('X07MB-OP2:TOTAL-CYCLES', '5') +sleep(0.1) +caput('X07MB-ES1-PP2:VO5', '0') +sleep(0.1) +caput('X07MB-OP-WV1:WT_SET', '1') +sleep(0.1) + +#TODO: Set the diplay names of positioners and detectors +scan = ManualScan(['Energy'], ['ScanX_set', 'ScanY_set', 'ROT_set', 'TRX1_set', 'TRZ1_set', 'DET_set', 'Energy_set', 'Mono_offset', 'I_SLS', 'I0_KEITHLEY1', 'KEITHLEY1_GAIN', 'I1_KEITHLEY2', 'KEITHLEY2_GAIN', 'KEITHLEY3', 'KEITHLEY3_GAIN', 'XBPM3_GAIN', 'XBPM3_SAI14_CUR_MEAN', 'XBPM3_SAI15_CUR_MEAN', 'XBPM3_SAI16_CUR_MEAN', 'XBPM3_SAI17_CUR_MEAN', 'XBPM3_POSX', 'XBPM3_POSY', 'XBPM4_GAIN', 'XBPM4_SAI19_CUR_MEAN', 'XBPM4_SAI20_CUR_MEAN', 'XBPM4_SAI21_CUR_MEAN', 'XBPM4_SAI22_CUR_MEAN', 'XBPM4_POSX', 'XBPM4_POSY', 'D1_Si', 'D1_ICR', 'D1_OCR', 'DD1_ELTM', 'DD1_ERTM', 'DD1_DTIM', 'Spec_1[2048]', 'MONO_THETA_TC1', 'MONO_TRX_TC1', 'MONO_C2_TC_Z', 'MONO_C2_TC_Y', 'MONO_TC1', 'MONO_TC2', 'MONO_TC3', 'MONO_TC4', 'MONO_TC5', 'MONO_TC6', 'MONO_TC7', 'MONO_TC8', 'MONO_TC9', 'MONO_TC10', 'MONO_TC11', 'MONO_TC12', 'MONO_TC13', 'MONO_TC14', 'MONO_TC15', 'MONO_TC16', 'ES1MF1', 'ES1MC1', 'OPKBMF1', 'OPSL2MF1', 'Mic_X', 'Mic_Y', 'Mic_sigma_X', 'Mic_Sigma_Y', 'Theta', 'Pitch', 'Roll', 'D1_Si_corr', 'Si_sum_cps'] , [3900.0], [5000.0], [220]) +scan.start() + +#Creating channels: dimension 1 +#RegionPositioner Energy +Energy = Channel('X07MB-OP-MO:E-SET', type = 'd') +EnergyReadback = Channel('X07MB-OP-MO:E-GET', type = 'd') +#ScalarDetector ScanX_set +ScanX_set = Channel('X07MB-ES-MA1:ScanX.VAL', type = 'd') +#ScalarDetector ScanY_set +ScanY_set = Channel('X07MB-ES-MA1:ScanY.VAL', type = 'd') +#ScalarDetector ROT_set +ROT_set = Channel('X07MB-ES-MA1:ROT.VAL', type = 'd') +#ScalarDetector TRX1_set +TRX1_set = Channel('X07MB-ES-MA1:TRX1.VAL', type = 'd') +#ScalarDetector TRZ1_set +TRZ1_set = Channel('X07MB-ES-MA1:TRZ1.VAL', type = 'd') +#ScalarDetector DET_set +DET_set = Channel('X07MB-ES-RONTEC:TRX.VAL', type = 'd') +#ScalarDetector Energy_set +Energy_set = Channel('X07MB-OP-MO:E-SET', type = 'd') +#ScalarDetector Mono_offset +Mono_offset = Channel('X07MB-OP-MO:BEAM-OFS', type = 'd') +#ScalarDetector I_SLS +I_SLS = Channel('ARIDI-PCT:CURRENT', type = 'd') +#ScalarDetector I0_KEITHLEY1 +I0_KEITHLEY1 = Channel('X07MB-OP2-SAI_07:MEAN', type = 'd') +#ScalarDetector KEITHLEY1_GAIN +KEITHLEY1_GAIN = Channel('X07MB-OP-KEITH1:setGain', type = 'd') +#ScalarDetector I1_KEITHLEY2 +I1_KEITHLEY2 = Channel('X07MB-OP2-SAI_08:MEAN', type = 'd') +#ScalarDetector KEITHLEY2_GAIN +KEITHLEY2_GAIN = Channel('X07MB-OP-KEITH2:setGain', type = 'd') +#ScalarDetector KEITHLEY3 +KEITHLEY3 = Channel('X07MB-OP2-SAI_06:MEAN', type = 'd') +#ScalarDetector KEITHLEY3_GAIN +KEITHLEY3_GAIN = Channel('X07MB-OP-KEITH3:setGain', type = 'd') +#ScalarDetector XBPM3_GAIN +XBPM3_GAIN = Channel('X07MB-OP2:LCAD3-GAIN', type = 'd') +#ScalarDetector XBPM3_SAI14_CUR_MEAN +XBPM3_SAI14_CUR_MEAN = Channel('X07MB-OP2-SAI_14:CUR-MEAN', type = 'd') +#ScalarDetector XBPM3_SAI15_CUR_MEAN +XBPM3_SAI15_CUR_MEAN = Channel('X07MB-OP2-SAI_15:CUR-MEAN', type = 'd') +#ScalarDetector XBPM3_SAI16_CUR_MEAN +XBPM3_SAI16_CUR_MEAN = Channel('X07MB-OP2-SAI_16:CUR-MEAN', type = 'd') +#ScalarDetector XBPM3_SAI17_CUR_MEAN +XBPM3_SAI17_CUR_MEAN = Channel('X07MB-OP2-SAI_17:CUR-MEAN', type = 'd') +#ScalarDetector XBPM3_POSX +XBPM3_POSX = Channel('X07MB-OP-BPM3:POSX', type = 'd') +#ScalarDetector XBPM3_POSY +XBPM3_POSY = Channel('X07MB-OP-BPM3:POSY', type = 'd') +#ScalarDetector XBPM4_GAIN +XBPM4_GAIN = Channel('X07MB-OP2:LCAD3-GAIN', type = 'd') +#ScalarDetector XBPM4_SAI19_CUR_MEAN +XBPM4_SAI19_CUR_MEAN = Channel('X07MB-OP2-SAI_19:CUR-MEAN', type = 'd') +#ScalarDetector XBPM4_SAI20_CUR_MEAN +XBPM4_SAI20_CUR_MEAN = Channel('X07MB-OP2-SAI_20:CUR-MEAN', type = 'd') +#ScalarDetector XBPM4_SAI21_CUR_MEAN +XBPM4_SAI21_CUR_MEAN = Channel('X07MB-OP2-SAI_21:CUR-MEAN', type = 'd') +#ScalarDetector XBPM4_SAI22_CUR_MEAN +XBPM4_SAI22_CUR_MEAN = Channel('X07MB-OP2-SAI_22:CUR-MEAN', type = 'd') +#ScalarDetector XBPM4_POSX +XBPM4_POSX = Channel('X07MB-OP-BPM4:POSX', type = 'd') +#ScalarDetector XBPM4_POSY +XBPM4_POSY = Channel('X07MB-OP-BPM4:POSY', type = 'd') +#ScalarDetector D1_Si +D1_Si = Channel('X07MB-XMAP:mca1.R0', type = 'd') +#ScalarDetector D1_ICR +D1_ICR = Channel('X07MB-XMAP:dxp1:InputCountRate', type = 'd') +#ScalarDetector D1_OCR +D1_OCR = Channel('X07MB-XMAP:dxp1:OutputCountRate', type = 'd') +#ScalarDetector DD1_ELTM +DD1_ELTM = Channel('X07MB-XMAP:mca1.ELTM', type = 'd') +#ScalarDetector DD1_ERTM +DD1_ERTM = Channel('X07MB-XMAP:mca1.ERTM', type = 'd') +#ScalarDetector DD1_DTIM +DD1_DTIM = Channel('X07MB-XMAP:mca1.DTIM', type = 'd') +#ArrayDetector Spec_1 +Spec_1 = Channel('X07MB-XMAP:mca1.VAL', type = '[d', size = 2048) +#ScalarDetector MONO_THETA_TC1 +MONO_THETA_TC1 = Channel('X07MB-OP-MOTHETA:TC1', type = 'd') +#ScalarDetector MONO_TRX_TC1 +MONO_TRX_TC1 = Channel('X07MB-OP-MOTRX:TC1', type = 'd') +#ScalarDetector MONO_C2_TC_Z +MONO_C2_TC_Z = Channel('X07MB-OP-MOC2:TC_Z', type = 'd') +#ScalarDetector MONO_C2_TC_Y +MONO_C2_TC_Y = Channel('X07MB-OP-MOC2:TC_Y', type = 'd') +#ScalarDetector MONO_TC1 +MONO_TC1 = Channel('X07MB-OP-MO:TC1', type = 'd') +#ScalarDetector MONO_TC2 +MONO_TC2 = Channel('X07MB-OP-MO:TC2', type = 'd') +#ScalarDetector MONO_TC3 +MONO_TC3 = Channel('X07MB-OP-MO:TC3', type = 'd') +#ScalarDetector MONO_TC4 +MONO_TC4 = Channel('X07MB-OP-MO:TC4', type = 'd') +#ScalarDetector MONO_TC5 +MONO_TC5 = Channel('X07MB-OP-MO:TC5', type = 'd') +#ScalarDetector MONO_TC6 +MONO_TC6 = Channel('X07MB-OP-MO:TC6', type = 'd') +#ScalarDetector MONO_TC7 +MONO_TC7 = Channel('X07MB-OP-MO:TC7', type = 'd') +#ScalarDetector MONO_TC8 +MONO_TC8 = Channel('X07MB-OP-MO:TC8', type = 'd') +#ScalarDetector MONO_TC9 +MONO_TC9 = Channel('X07MB-OP-MO:TC9', type = 'd') +#ScalarDetector MONO_TC10 +MONO_TC10 = Channel('X07MB-OP-MO:TC10', type = 'd') +#ScalarDetector MONO_TC11 +MONO_TC11 = Channel('X07MB-OP-MO:TC11', type = 'd') +#ScalarDetector MONO_TC12 +MONO_TC12 = Channel('X07MB-OP-MO:TC12', type = 'd') +#ScalarDetector MONO_TC13 +MONO_TC13 = Channel('X07MB-OP-MO:TC13', type = 'd') +#ScalarDetector MONO_TC14 +MONO_TC14 = Channel('X07MB-OP-MO:TC14', type = 'd') +#ScalarDetector MONO_TC15 +MONO_TC15 = Channel('X07MB-OP-MO:TC15', type = 'd') +#ScalarDetector MONO_TC16 +MONO_TC16 = Channel('X07MB-OP-MO:TC16', type = 'd') +#ScalarDetector ES1MF1 +ES1MF1 = Channel('X07MB-ES1-MF1:PRESSURE', type = 'd') +#ScalarDetector ES1MC1 +ES1MC1 = Channel('X07MB-ES1-MC1:PRESSURE', type = 'd') +#ScalarDetector OPKBMF1 +OPKBMF1 = Channel('X07MB-OP-KBMF1:PRESSURE', type = 'd') +#ScalarDetector OPSL2MF1 +OPSL2MF1 = Channel('X07MB-OP-SL2MF1:PRESSURE', type = 'd') +#ScalarDetector Mic_X +Mic_X = Channel('X07MB-PC-PSCAN:CAM1-BEAMPOS_X', type = 'd') +#ScalarDetector Mic_Y +Mic_Y = Channel('X07MB-PC-PSCAN:CAM1-BEAMPOS_Y', type = 'd') +#ScalarDetector Mic_sigma_X +Mic_sigma_X = Channel('X07MB-PC-PSCAN:CAM1-SIGMA_X', type = 'd') +#ScalarDetector Mic_Sigma_Y +Mic_Sigma_Y = Channel('X07MB-PC-PSCAN:CAM1-SIGMA_Y', type = 'd') +#ScalarDetector Theta +Theta = Channel('X07MB-OP-MO:THETA.RBV', type = 'd') +#ScalarDetector Pitch +Pitch = Channel('X07MB-OP-MO:C2-ROX.RBV', type = 'd') +#ScalarDetector Roll +Roll = Channel('X07MB-OP-MO:C2-ROZ.RBV', type = 'd') + +#Dimension 1 +#RegionPositioner Energy +for setpoint1 in frange(3900.0, 5000.0, 5.0, True): + #Region 1 pre-actions + if setpoint1 == 3900.0: + caput('X07MB-OP2:TOTAL-CYCLES', '5') + sleep(5.0) + Energy.put(setpoint1, timeout=None) # TODO: Set appropriate timeout + readback1 = EnergyReadback.get() + if abs(readback1 - setpoint1) > 2.5 : # TODO: Check accuracy + raise Exception('Actor Energy could not be set to the value ' + str(setpoint1)) + sleep( 3.0 ) # Settling time + #Dimension Actions + caputq('X07MB-XMAP:EraseStart', '1') + sleep(0.1) + caput('X07MB-OP2:SMPL', '1') + sleep(0.1) + cawait('X07MB-OP2:SMPL-DONE', 1, type = 'l') + sleep(0.1) + caput('X07MB-XMAP:StopAll', '1') + sleep(0.1) + #Detector ScanX_set + detector1 = ScanX_set.get() + #Detector ScanY_set + detector2 = ScanY_set.get() + #Detector ROT_set + detector3 = ROT_set.get() + #Detector TRX1_set + detector4 = TRX1_set.get() + #Detector TRZ1_set + detector5 = TRZ1_set.get() + #Detector DET_set + detector6 = DET_set.get() + #Detector Energy_set + detector7 = Energy_set.get() + #Detector Mono_offset + detector8 = Mono_offset.get() + #Detector I_SLS + detector9 = I_SLS.get() + #Detector I0_KEITHLEY1 + detector10 = I0_KEITHLEY1.get() + #Detector KEITHLEY1_GAIN + detector11 = KEITHLEY1_GAIN.get() + #Detector I1_KEITHLEY2 + detector12 = I1_KEITHLEY2.get() + #Detector KEITHLEY2_GAIN + detector13 = KEITHLEY2_GAIN.get() + #Detector KEITHLEY3 + detector14 = KEITHLEY3.get() + #Detector KEITHLEY3_GAIN + detector15 = KEITHLEY3_GAIN.get() + #Detector XBPM3_GAIN + detector16 = XBPM3_GAIN.get() + #Detector XBPM3_SAI14_CUR_MEAN + detector17 = XBPM3_SAI14_CUR_MEAN.get() + #Detector XBPM3_SAI15_CUR_MEAN + detector18 = XBPM3_SAI15_CUR_MEAN.get() + #Detector XBPM3_SAI16_CUR_MEAN + detector19 = XBPM3_SAI16_CUR_MEAN.get() + #Detector XBPM3_SAI17_CUR_MEAN + detector20 = XBPM3_SAI17_CUR_MEAN.get() + #Detector XBPM3_POSX + detector21 = XBPM3_POSX.get() + #Detector XBPM3_POSY + detector22 = XBPM3_POSY.get() + #Detector XBPM4_GAIN + detector23 = XBPM4_GAIN.get() + #Detector XBPM4_SAI19_CUR_MEAN + detector24 = XBPM4_SAI19_CUR_MEAN.get() + #Detector XBPM4_SAI20_CUR_MEAN + detector25 = XBPM4_SAI20_CUR_MEAN.get() + #Detector XBPM4_SAI21_CUR_MEAN + detector26 = XBPM4_SAI21_CUR_MEAN.get() + #Detector XBPM4_SAI22_CUR_MEAN + detector27 = XBPM4_SAI22_CUR_MEAN.get() + #Detector XBPM4_POSX + detector28 = XBPM4_POSX.get() + #Detector XBPM4_POSY + detector29 = XBPM4_POSY.get() + #Detector D1_Si + detector30 = D1_Si.get() + #Detector D1_ICR + detector31 = D1_ICR.get() + #Detector D1_OCR + detector32 = D1_OCR.get() + #Detector DD1_ELTM + detector33 = DD1_ELTM.get() + #Detector DD1_ERTM + detector34 = DD1_ERTM.get() + #Detector DD1_DTIM + detector35 = DD1_DTIM.get() + #Detector Spec_1 + detector36 = Spec_1.get() + #Detector MONO_THETA_TC1 + detector37 = MONO_THETA_TC1.get() + #Detector MONO_TRX_TC1 + detector38 = MONO_TRX_TC1.get() + #Detector MONO_C2_TC_Z + detector39 = MONO_C2_TC_Z.get() + #Detector MONO_C2_TC_Y + detector40 = MONO_C2_TC_Y.get() + #Detector MONO_TC1 + detector41 = MONO_TC1.get() + #Detector MONO_TC2 + detector42 = MONO_TC2.get() + #Detector MONO_TC3 + detector43 = MONO_TC3.get() + #Detector MONO_TC4 + detector44 = MONO_TC4.get() + #Detector MONO_TC5 + detector45 = MONO_TC5.get() + #Detector MONO_TC6 + detector46 = MONO_TC6.get() + #Detector MONO_TC7 + detector47 = MONO_TC7.get() + #Detector MONO_TC8 + detector48 = MONO_TC8.get() + #Detector MONO_TC9 + detector49 = MONO_TC9.get() + #Detector MONO_TC10 + detector50 = MONO_TC10.get() + #Detector MONO_TC11 + detector51 = MONO_TC11.get() + #Detector MONO_TC12 + detector52 = MONO_TC12.get() + #Detector MONO_TC13 + detector53 = MONO_TC13.get() + #Detector MONO_TC14 + detector54 = MONO_TC14.get() + #Detector MONO_TC15 + detector55 = MONO_TC15.get() + #Detector MONO_TC16 + detector56 = MONO_TC16.get() + #Detector ES1MF1 + detector57 = ES1MF1.get() + #Detector ES1MC1 + detector58 = ES1MC1.get() + #Detector OPKBMF1 + detector59 = OPKBMF1.get() + #Detector OPSL2MF1 + detector60 = OPSL2MF1.get() + #Detector Mic_X + detector61 = Mic_X.get() + #Detector Mic_Y + detector62 = Mic_Y.get() + #Detector Mic_sigma_X + detector63 = Mic_sigma_X.get() + #Detector Mic_Sigma_Y + detector64 = Mic_Sigma_Y.get() + #Detector Theta + detector65 = Theta.get() + #Detector Pitch + detector66 = Pitch.get() + #Detector Roll + detector67 = Roll.get() + #Manipulation D1_Si_corr + #Variable Mappings + a = detector30 + b = detector31 + c = detector32 + d = detector33 + #TODO: Move, if needed, this import to the file header: import math + DeadTime = 1.182e-7 + ICR = b + OCR = c + + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test > DeadTime) and (n < 30)): + TrueICR = ICR * math.exp(TestICR * DeadTime) + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + D1_Si_corr = a * TrueICR / OCR / d + #Manipulation Si_sum_cps + #Variable Mappings + detector30_corr = detector33 + detector33 = detector33 + #TODO: Move, if needed, this import to the file header: import math + DeadTime = 1.182e-7 + SUM_DET = 0. + SUM_DET = SUM_DET + detector30_corr + Si_sum_cps = SUM_DET + scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, detector9, detector10, detector11, detector12, detector13, detector14, detector15, detector16, detector17, detector18, detector19, detector20, detector21, detector22, detector23, detector24, detector25, detector26, detector27, detector28, detector29, detector30, detector31, detector32, detector33, detector34, detector35, detector36, detector37, detector38, detector39, detector40, detector41, detector42, detector43, detector44, detector45, detector46, detector47, detector48, detector49, detector50, detector51, detector52, detector53, detector54, detector55, detector56, detector57, detector58, detector59, detector60, detector61, detector62, detector63, detector64, detector65, detector66, detector67, D1_Si_corr, Si_sum_cps]) + +#Closing channels +Energy.close() +EnergyReadback.close() +ScanX_set.close() +ScanY_set.close() +ROT_set.close() +TRX1_set.close() +TRZ1_set.close() +DET_set.close() +Energy_set.close() +Mono_offset.close() +I_SLS.close() +I0_KEITHLEY1.close() +KEITHLEY1_GAIN.close() +I1_KEITHLEY2.close() +KEITHLEY2_GAIN.close() +KEITHLEY3.close() +KEITHLEY3_GAIN.close() +XBPM3_GAIN.close() +XBPM3_SAI14_CUR_MEAN.close() +XBPM3_SAI15_CUR_MEAN.close() +XBPM3_SAI16_CUR_MEAN.close() +XBPM3_SAI17_CUR_MEAN.close() +XBPM3_POSX.close() +XBPM3_POSY.close() +XBPM4_GAIN.close() +XBPM4_SAI19_CUR_MEAN.close() +XBPM4_SAI20_CUR_MEAN.close() +XBPM4_SAI21_CUR_MEAN.close() +XBPM4_SAI22_CUR_MEAN.close() +XBPM4_POSX.close() +XBPM4_POSY.close() +D1_Si.close() +D1_ICR.close() +D1_OCR.close() +DD1_ELTM.close() +DD1_ERTM.close() +DD1_DTIM.close() +Spec_1.close() +MONO_THETA_TC1.close() +MONO_TRX_TC1.close() +MONO_C2_TC_Z.close() +MONO_C2_TC_Y.close() +MONO_TC1.close() +MONO_TC2.close() +MONO_TC3.close() +MONO_TC4.close() +MONO_TC5.close() +MONO_TC6.close() +MONO_TC7.close() +MONO_TC8.close() +MONO_TC9.close() +MONO_TC10.close() +MONO_TC11.close() +MONO_TC12.close() +MONO_TC13.close() +MONO_TC14.close() +MONO_TC15.close() +MONO_TC16.close() +ES1MF1.close() +ES1MC1.close() +OPKBMF1.close() +OPSL2MF1.close() +Mic_X.close() +Mic_Y.close() +Mic_sigma_X.close() +Mic_Sigma_Y.close() +Theta.close() +Pitch.close() +Roll.close() + +scan.end() + +#Post-actions +caput('X07MB-OP2:START-CSMPL', '1') +sleep(0.1) diff --git a/script/CPython/GaussFit.py b/script/CPython/GaussFit.py new file mode 100644 index 0000000..a33058f --- /dev/null +++ b/script/CPython/GaussFit.py @@ -0,0 +1,31 @@ +import numpy as np +import scipy.optimize + + +# Profile statistics #### +def profile_gauss_stats(x, y, off=None, amp=None, com=None, sigma=None): + if off is None: + off = y.min() # good enough starting point for offset + + if com is None: + com = x[y.argmax()] + + if amp is None: + amp = y.max() - off + + # For normalised gauss curve sigma=1/(amp*sqrt(2*pi)) + if sigma is None: + surface = np.trapz((y-off), x=x) + sigma = surface / (amp * np.sqrt(2 * np.pi)) + try: + popt, pcov = scipy.optimize.curve_fit(gauss_fn, x, y, p0=[off, amp, com, sigma], method='lm') + popt[3] = abs(popt[3]) # sigma should be returned as positive + except Exception as e: + print("Gauss fitting not successful.\n" + str(e)) + popt = [off, amp, com, abs(sigma)] + + return popt + + +def gauss_fn(x, a, b, c, d): + return a + b * np.exp(-(np.power((x - c), 2) / (2 * np.power(d, 2)))) \ No newline at end of file diff --git a/script/CPython/GaussFit_wrapper.py b/script/CPython/GaussFit_wrapper.py new file mode 100644 index 0000000..7e4fc38 --- /dev/null +++ b/script/CPython/GaussFit_wrapper.py @@ -0,0 +1,9 @@ +from jeputils import * + +MODULE = "CPython/GaussFit" + +def profile_gauss_stats(x, y, off=None, amp=None, com=None, sigma=None): + ret = call_jep(MODULE, "profile_gauss_stats", [to_npa(x), to_npa(y), off, amp, com, sigma]) + return ret if ret is None or is_list(ret) else ret.data + + diff --git a/script/EnergyScan_ma.py b/script/EnergyScan_ma.py new file mode 100644 index 0000000..cbf0cb4 --- /dev/null +++ b/script/EnergyScan_ma.py @@ -0,0 +1,96 @@ +#Debugging +if get_exec_pars().args is None: + E1 = 974 + E2 = 978 + TIME = 1 #min + DELAY = 0.0 #s + MODE = None #'LINEAR' #'CIRC +' + OFFSET = None + NAME = 'Test' + ALPHA= None #0 + +print "\nStart energy scan..." +print E1,"eV ->",E2,"eV,",TIME,"min duration,",DELAY,"sec delay,",str(MODE),(str(ALPHA)+"deg") if (MODE=="LINEAR") else "" + + +set_exec_pars(reset=True, name= NAME) + +#Pre-actions +wait_beam() +wait_id_ok() + +set_pol(MODE, ALPHA, OFFSET) +set_energy_ma(float(E1)) +caput(energy_ma_rbv.channelName+".N", 10) # set energy readback averaging to 10 pts + +print "Setup OTF" +caput('E1', E1) +caput('E2', E2) +caput('TIME', TIME) +caput('FOLDER', "OTF/" + get_context().setup.expandPath("OTF/{year}_{month}/{date}")) +caput('FILE', NAME) + +time.sleep(max(DELAY, 0.1)) + +#Scan +print "Start OTF" +scan_completed = False +try: + while True: + caput('START', '1') + waiting = True + + class Time(Readable): + def __init__(self): + self.start = time.time() + def read(self): + return time.time()-self.start + tm = Time() + + class norm_tey(Readable): + def read(self): + return float(cadc1.take())/float(cadc2.take()) + + class norm_diode(Readable): + def read(self): + return float(cadc3.take())/float(cadc2.take()) + + snaps = (pol_mode, pol_angle,pol_offset) + diags = (current.cache) #Must use cache because mscan evensts are called from monitor callback tread (or else async=False). Sensors are automatically handled. + sensors = [energy_ma_rbv, cadc1, cadc2, cadc3, cadc4, cadc5, norm_tey(), norm_diode(), tm] + + tm.setAlias("time") + cadc1.setAlias("tey_raw") + cadc2.setAlias("i0") + cadc3.setAlias("diode_raw") + + def monitoring_task(): + global scan_completed + time.sleep(1.0) + wait_channel('START', 'STOP', type = 's') + scan_completed = True + get_exec_pars().currentScan.abort() + + monitoring_future = fork(monitoring_task)[0] + + print "Scanning...", + try: + mscan( energy_ma_rbv, sensors, -1, None, \ + range="auto",domain_axis=energy_ma_rbv.name, \ + enabled_plots=["norm_tey", "norm_diode", cadc1, cadc3, cadc2], \ + snaps=snaps, diags=diags) + finally: + monitoring_future.cancel(True) + + print "Finished Energy scan." + if after_sample(): #Repeat if id error and not ABORT_ON_ID_ERROR: + break + +except: + if not scan_completed: + print sys.exc_info() + print("Aborting...") + while caget('START') == 'START': + caput('START', '0') + time.sleep(0.1) + raise diff --git a/script/Mono_pitch.py b/script/Mono_pitch.py new file mode 100644 index 0000000..2ed383d --- /dev/null +++ b/script/Mono_pitch.py @@ -0,0 +1,139 @@ +#Script imported from: Mono_pitch.xml + +#Pre-actions +caput('X07MB-OP2:START-CSMPL', '0') +sleep(0.1) +caput('X07MB-XMAP:StopAll', '1') +sleep(0.1) +caput('X07MB-XMAP:PresetMode', '0') +sleep(0.1) +caput('X07MB-XMAP:PresetReal', '0') +sleep(0.1) +caput('X07MB-OP2:TOTAL-CYCLES', '1') +sleep(0.1) +print('dd') + +#TODO: Set the diplay names of positioners and detectors +scan = ManualScan(['Pitch'], ['bm3', 'bm4', 'Filter_RY', 'Harmonic', 'TC_Y', 'TC_Z', 'T_THETA', 'Id_OFF', 'Id_energy', 'E_Mono', 'Bragg_Id_theo', 'Theta_rbv', 'Theta_offset', 'Delta_E', 'Delta_theta', 'XX'] , [-10700.0], [-10750.0], [25]) +scan.start() + +#Creating channels: dimension 1 +#LinearPositioner Pitch +Pitch = Channel('X07MB-OP-MO:C2-ROX.VAL', type = 'd') +PitchReadback = Channel('X07MB-OP-MO:C2-ROX.RBV', type = 'd') +#ScalarDetector bm3 +bm3 = Channel('X07MB-OP2-SAI_03:MEAN', type = 'd') +#ScalarDetector bm4 +bm4 = Channel('X07MB-OP2-SAI_04:MEAN', type = 'd') +#ScalarDetector Filter_RY +Filter_RY = Channel('X07MB-OP-FI:ROY.VAL', type = 'd') +#ScalarDetector Harmonic +Harmonic = Channel('X07MA-ID:HARMONIC', type = 'd') +#ScalarDetector TC_Y +TC_Y = Channel('X07MB-OP-MOC2:TC_Y', type = 'd') +#ScalarDetector TC_Z +TC_Z = Channel('X07MB-OP-MOC2:TC_Z', type = 'd') +#ScalarDetector T_THETA +T_THETA = Channel('X07MB-OP-MOTHETA:TC1', type = 'd') +#ScalarDetector Id_OFF +Id_OFF = Channel('X07MA-ID:ENERGY-OFFS', type = 'd') +#ScalarDetector Id_energy +Id_energy = Channel('X07MA-ID:ENERGY', type = 'd') +#ScalarDetector E_Mono +E_Mono = Channel('X07MB-OP-MO:E-GET', type = 'd') +#ScalarDetector Bragg_Id_theo +Bragg_Id_theo = Channel('X07MB-OP-MO:BRAGG-CALC', type = 'd') +#ScalarDetector Theta_rbv +Theta_rbv = Channel('X07MB-OP-MO:THETA.RBV', type = 'd') +#ScalarDetector Theta_offset +Theta_offset = Channel('X07MB-OP-MO:THETA.OFF', type = 'd') + +#Dimension 1 +#Dimension Guard +cawait('ACOAU-ACCU:OP-MODE', 6, type = 'l') +#LinearPositioner Pitch +for setpoint1 in frange(-10700.0, -10750.0, -2.0, True): + if setpoint1 > -10700.0 or setpoint1 < -10750.0: + break + Pitch.put(setpoint1, timeout=None) # TODO: Set appropriate timeout + readback1 = PitchReadback.get() + if abs(readback1 - setpoint1) > 10.0 : # TODO: Check accuracy + print readback1, setpoint1 + raise Exception('Actor Pitch could not be set to the value ' + str(setpoint1)) + #Detector bm3 + #Detector X07MB-OP2-SAI_03:MEAN pre-actions + caput('X07MB-OP2:SMPL', '1') + sleep(0.1) + cawait('X07MB-OP2:SMPL-DONE', 1, type = 'l') + detector1 = bm3.get() + #Detector bm4 + detector2 = bm4.get() + #Detector Filter_RY + detector3 = Filter_RY.get() + #Detector Harmonic + detector4 = Harmonic.get() + #Detector TC_Y + detector5 = TC_Y.get() + #Detector TC_Z + detector6 = TC_Z.get() + #Detector T_THETA + detector7 = T_THETA.get() + #Detector Id_OFF + detector8 = Id_OFF.get() + #Detector Id_energy + detector9 = Id_energy.get() + #Detector E_Mono + detector10 = E_Mono.get() + #Detector Bragg_Id_theo + detector11 = Bragg_Id_theo.get() + #Detector Theta_rbv + detector12 = Theta_rbv.get() + #Detector Theta_offset + detector13 = Theta_offset.get() + #Manipulation Delta_E + #Variable Mappings + a = detector10 + b = detector9 + Delta_E = a-b + #Manipulation Delta_theta + #Variable Mappings + a = detector11 + b = detector12 + Delta_theta = a-b + #Manipulation XX + #Variable Mappings + a = detector11 + b = detector12 + XX = a*b + print(XX) + scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, detector9, detector10, detector11, detector12, detector13, Delta_E, Delta_theta, E_Mono, XX]) + +#Closing channels +Pitch.close() +PitchReadback.close() +bm3.close() +bm4.close() +Filter_RY.close() +Harmonic.close() +TC_Y.close() +TC_Z.close() +T_THETA.close() +Id_OFF.close() +Id_energy.close() +E_Mono.close() +Bragg_Id_theo.close() +Theta_rbv.close() +Theta_offset.close() + +scan.end() + + +#Post-actions +caput('X07MB-OP2:START-CSMPL', '1') +sleep(0.1) +caput('X07MB-OP2:START-CSMPL', '1') +sleep(0.3) +caput('X07MB-OP2:SMPL', '1') +sleep(0.3) +caput('X07MB-OP2:SMPL', '1') +sleep(0.3) diff --git a/script/Users/Camelia/Test_XAS.py b/script/Users/Camelia/Test_XAS.py new file mode 100644 index 0000000..81e893a --- /dev/null +++ b/script/Users/Camelia/Test_XAS.py @@ -0,0 +1,333 @@ +import traceback +import imp +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string +import sys +import json + +# TO DO: Energy scan has onlz 1 positioner +# need to generalize definition of scans to several paraller positiner, +# to be able to use Create_Channels, alteratively need a dedicate channel creation for each scan type +# tricky, code should stay simple +# options. +# Define channel generation for each chanenl separatelz +# generalze scand to 1d and 2d with seveal posittioner in each dimension. +# this will get complicated ..... + +import X_X07MB_Pscan as PS +import X_X07MB_lib as PL + +imp.reload(PS) # always reload module +imp.reload(PL) # always reload module + +NoRead=0 + +def before_pass(): + get_context().dataManager.provider.embeddedAtributes = False + # Called at begining pf scan + print('before_pass') + SC.PerformActions('Pre_Actions') + pars=get_exec_pars() + print('pars.output : ') + print(pars.output) + print('pars.scanPath: ') + print(pars.scanPath) + print('pars.name: (filename) ') + print(pars.name) + # missing + # NEED TO SET path for Moench here +#end before_pass + + +def before_read(): + # Cannot call routine in class in rscan call, need to go via local routine + #print('before_read') + # SC.DetectorActions() excecutes all standard action as defied in GUI + SC.PerformActions('Detector_Actions') + #print('.... done before_read ' ) + + # alternativly use caput here explicitly... + # if needed +#end before read + +def after_read(rec,scan): + print('ENTER after_read .................' ) + # Called after reading + # calculate default dead time corrections and writ to file + SC.after_read_dtc(rec,scan) + print('.... done after_read ' ) + return +#end after_read init + +def after_pass(): + # Called after scan + print('after_pass') + + SC.PerformActions('Post_Actions') + print('................ done after_pass') +#end after pass + + +def before_region(index,scan): + print (index) + +# make some reset +try: + del SC +except: + SC=0 +#endexept +# originbal tag for data saving +# '{data}/{year}/{month}/{day}/{year}_{month}{day}_{time}_{name}' +# ........... FIrst read the scan +# + +# ==================================================== +# +# SCRIPT STARTS HERE +# +# ==================================================== +if NoRead==0: + try: + SD = 0 + SD = PS.get_channels('SPECTRA') # READ SCAN DEFINITION FROM GUI USING OLD CODE + print('returned from PS.get_channels()') + SC=0 + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) # create instance of library + + print('... done SC.Create_All_Sensors()') + SD.update({'All_Sensors':[]}) + except: + traceback.print_tb(sys.exc_info()[2]) + raise + # endexcept +# endif + +# example add new sensor, similarly add pre and postactions to existing code + +New_Sensors=[] +New_Sensors.append({'channel_name': 'X07MB-ES-MA1:ScanY.RBV' + , 'Subset_1': False + , 'Det_type': 'ScalarDetector' + , 'alias': 'MYSCANY_RBV' + , 'data_type': 'double'}) + +# examples add post action light on + +SD['Post_Actions'].append({'channel_name': 'X07MB-ES1-PP2:VO5' + , 'data_type': 'String' + , 'alias': 'Light_ON' + , 'operation': 'put' + , 'delay' : 0.1 + , 'value' : 5 }) + +# END OF USER INPUT + +# .... add new sensors to list +try: + try: + del AllSensors + except: + AllSensors=0 + #endecsept + All_Sensors = SC.Create_Sensor_List() # Create instance for all sensors + SC.Add_New_Sensors(New_Sensors) # Add user sensors +except: + traceback.print_tb(sys.exc_info()[2]) + raise +# endexcept + +# STRUCTUALR INCONSITENCY NEED TO CREATE List of sensors first +# without making Channel command.... ! +# +# TEST SAVE SCAN DEFINITION...Needs to be before definition +# SD is full GUI definiton of the scan try to save and reread this definiton + +SD.update({'New_Sensors' : New_Sensors}) +f=open('scandef.dat','w') +# Method to save abnd restore full scan definition... +with open('BaseScanDefinition.json', 'w') as fp: + json.dump(SD, fp,ensure_ascii=True) +#endwith +with open('BaseScanDefinition.json', 'r') as dd: + SD_reread=json.load(dd) +# .. this works, reread is unicode not string, but code seems still to work if all entries are in unicode + + +# step I: CREATE ALL SENSORS AND STORE IN A LIST +print('++++++++++++++++++++++++++') +AllSensors=0 +try: + # Code for beamline save...... + SavePhoenix=PL.SavePhoenix(Channel,caput,caputq,caget,cawait) # Channel,caput,caputq,caget,cawait) + # SavePhoenix.write_beamline_data().. Works., move to before pass... + + SC.noprint=0 # chose printing from SD on / off + + # Now creat all epics instances. print('... done SC.Create_All_Sensors()') + SD.update({'All_Sensors':All_Sensors}) + SC.Create_Channels('All_Sensors') + SC.Create_Channels('All_Positioner') + SC.Create_Channels('Detector_Actions') + SC.Create_Channels('Pre_Actions') + SC.Create_Channels('Post_Actions') + SC.Create_Channels('Energy_Scan') +except: + traceback.print_tb(sys.exc_info()[2]) + raise +# endexcept + +# ... create some abbreviations... +All_Sensors = SC.All_Sensors +All_Positioner = SD['All_Positioner'] +Pre_Actions = SD['Pre_Actions'] +Post_Actions = SD['Post_Actions'] +Detector_Actions = SD['Detector_Actions'] +Energy_Scan = SD['Energy_Scan'] + + +#............SOME OUTPUT +#print('----------- All_Positioner ---') +#print(' ') +#print(SD['All_Positioner']) +#print(' ------------ Pre_Action -------- ') +#print(' ') +#print(SD['Pre_Actions']) +#print(' ------------ Post_Action -------- ') +#print(' ') +#print(SD['Post_Actions']) +#print(' ') +#print(' ----------- Detector_Action--------- ') +#print(' ') +#print(SD['Detector_Actions']) +## ............. MISSING CREATE POSTACTIONS:::::: + +# STEP II read the energy position +print('') +print('..................................... positioner Energy ID? readback automatically saved? ') +print('initial energies e_i ',SD['e_i']) +print('final energies e_f ',SD['e_f']) +print('DELTA E e_delta ',SD['e_delta']) +print('DWELL TIME e_n_cycles',SD['e_n_cycles']) +print(SD['Energy_Scan']['Energy_Ranges']) + +#try: +# EnergyRanges,Cycles = SC.PositionerEnergyScan() +#except: +# traceback.print_tb(sys.exc_info()[2]) +# raise +# endexcept nowcall +#print(EnergyRanges,Cycles) + +# STEP II ... read the detector actions + +# Step IV perform the Preaction +#P=SC.DetectorActions() + +print(All_Sensors) +print('Energy_Ranges') +print(SD['Energy_Scan']['Energy_Ranges']) + +pars=get_exec_pars() +print('pars.output') +print(pars.output) +print('pars.scanPath') +print(pars.scanPath) +print(' ') +print('---------------') +print(' ') +print(' CALL SCAN NOW ') +print(' ') + +p=set_exec_pars(name=SD['filename']) +# This is one singe energy scan: + + +# save scan definition + +get_context().dataManager.provider.embeddedAtributes = False + +# .. now make individual scan for all positioners as defiens in GUI +# as we like want to have separete datasets for each scan \ +# +for i in range(len(All_Positioner[0]['value'])): # loop in number of points + # set all positioner + for j in range(len(All_Positioner)): # set positioner + t0=time.time() + ThisPositioner = All_Positioner[j]['Channel'] + ThisPosition = All_Positioner[j]['value'][i] + print('next,i,j',i,j) + print('name',All_Positioner[j]['channel_name']) + print('value',All_Positioner[j]['value'][i]) + print(time.time()-t0) + # .............. SET NEW POSITIONER + #ThisPositioner.write(ThisPosition) + ThisPositioner.put(ThisPosition) + #ThisPositioner.putq(ThisPosition) # simultaneous walk no waiting.. + print(time.time()-t0) + #endfor loop set positioner + # generate filename + p=set_exec_pars(name=SD['filename']+'_'+All_Positioner[0]['label'][i]) + pars=get_exec_pars() + print('filename this run : ') + print(pars.name) + + print('--------------- NEXT SCAN ----------------') + try: + #call rscan + print('cal rscan ') + #rscan(SD['Energy_Scan']['Channel'] + # , SC.get_list(All_Sensors,'Channel') + # , regions=SD['Energy_Scan']['Energy_Ranges'] + # , latency = 0.0, relative = False + # , before_pass = SC.PerformActions('Pre_Actions') # before_pass + # , before_read = before_read #SC.PerformActions('Detector_Actions') # before_read + # , after_read = SC.after_read_dtc #after_read + # , after_pass = after_pass + # , before_region = before_region + # , enabled_plots=['I0_KEITHLEY1','I1_KEITHLEY2','D1_ICR','D1_OCR']) + + #vscan(SD['Energy_Scan']['Channel'] + # , SC.get_list(All_Sensors,'Channel') + # , vector=SD['Energy_Scan']['Energy_Scan_Positions'] + # , latency = 0.0, relative = False + # , before_pass = SC.PerformActions('Pre_Actions') # before_pass + # , before_read = before_read #SC.PerformActions('Detector_Actions') # before_read + # , after_read = SC.after_read_dtc #after_read + # , after_pass = after_pass + # , before_region = before_region + # , enabled_plots=['I0_KEITHLEY1','I1_KEITHLEY2','D1_ICR','D1_OCR']) + + except: + traceback.print_tb(sys.exc_info()[2]) + raise + # END EXecpt + #endfor +#endfor +print('... scan finished ') +# + +#ret = lscan("ca://X07MB-OP-MO:E-SET", sensors, start=2450, end=2460, steps=10, enabled_plots=['X07MB-OP2-SAI_07:MEAN']) + + +#rscan("ca://X07MB-OP-MO:E-SET", sensors, [[2450.0, 2455.0, 1.0], [2456.0, 2460.0, 0.5]], latency = 0.0, relative = False) + + +#def BeforeReadout(position, scan): +# print "In position: " + str(pposition) + + +#def AfterReadout(record, scan): +# print "Aquired record: " + str(record) + +#lscan("ca://X07MB-OP-MO:E-SET", sensors, start=2450, end=2460, steps=10, latency=0.0, relative = False, before_read=BeforeReadout, after_read=AfterReadout) +#rscan("ca://X07MB-OP-MO:E-SET", sensors, [[2450.0, 2455.0, 1.0], [2456.0, 2460.0, 0.5]], latency = 0.0, relative = False) +#ascan(["ca://X07MB-OP-MO:E-SET", "X07MB-ES-MA1:ScanX.VAL"], sensors, start=[2450, 1.6], end=[2460, 1.8], steps=[2.0,0.05], latency=0.0, relative = False, zigzag = True) +## +# +# Vizualization............... +# diff --git a/script/Users/Thomas/BaseScanDefinition.json b/script/Users/Thomas/BaseScanDefinition.json new file mode 100644 index 0000000..c159c2e --- /dev/null +++ b/script/Users/Thomas/BaseScanDefinition.json @@ -0,0 +1 @@ +{"r_indices": ["ScanX", "ScanY", "TRZ1"], "detectors_to_plot": ["no_Plot", "PL_Vortex", "PL_KEITHLEY1", "PL_KEITHLEY2", "PL_KEITHLEY3"], "e_f": [2380.0, 2390.0, 2461.0, 2463.0], "e_i": [2369.0, 2380.0, 2460.0, 2462.0], "CH_User_detector": ["X07MB-PC-PSCAN:SM3-X-RBV", "X07MB-PC-PSCAN:SM3-Y-RBV", "X07MB-ES-MA1:ROT.RBV", "X07MB-ES1-SD1:cam1:NumFrames"], "r_channel_rbv": {"TRZ1": "X07MB-ES-MA1:TRZ1.RBV", "ScanX": "X07MB-ES-MA1:ScanX.RBV", "ScanY": "X07MB-ES-MA1:ScanY.RBV"}, "e_ex_active": [-1], "p_channel_rbv": ["X07MB-ES-MA1:ScanX.RBV", "X07MB-ES-MA1:ScanY.RBV", "X07MB-OP-SH2:size.RBV", "X07MB-OP-SV2:size.RBV", "X07MB-ES-MA1:TRX1.RBV", "X07MB-ES-MA1:TRZ1.RBV"], "r_channel": {"TRZ1": "X07MB-ES-MA1:TRZ1.VAL", "ScanX": "X07MB-ES-MA1:ScanX.VAL", "ScanY": "X07MB-ES-MA1:ScanY.VAL"}, "e_ex_ncy_f": [-1], "n_det_fluo": 4, "r_energies_active": [1, 1, 1, 1, 1, 1], "CH_MONO_TEMP": ["X07MB-OP-MOTHETA:TC1", "X07MB-OP-MOTRX:TC1", "X07MB-OP-MOC2:TC_Z", "X07MB-OP-MOC2:TC_Y", "X07MB-OP-MO:TC1", "X07MB-OP-MO:TC2", "X07MB-OP-MO:TC3", "X07MB-OP-MO:TC4", "X07MB-OP-MO:TC5", "X07MB-OP-MO:TC6", "X07MB-OP-MO:TC7", "X07MB-OP-MO:TC8", "X07MB-OP-MO:TC9", "X07MB-OP-MO:TC10", "X07MB-OP-MO:TC11", "X07MB-OP-MO:TC12", "X07MB-OP-MO:TC13", "X07MB-OP-MO:TC14", "X07MB-OP-MO:TC15", "X07MB-OP-MO:TC16"], "DAQ_XMAP": 1, "hardware_sdd": "XMAP", "filename": "TESTFILNAME", "detector_actions": [{"channel_name": "X07MB-XMAP:EraseStart", "Data_type": "String", "delay": "0.075", "value": "1", "operation": "putq"}, {"channel_name": "X07MB-OP2:SMPL", "Data_type": "String", "delay": "0.075", "value": "1", "operation": "put"}, {"channel_name": "X07MB-ES1-SD1:cam1:Acquire", "Data_type": "String", "delay": "0.5", "value": "1", "operation": "put"}, {"channel_name": "X07MB-OP2:SMPL-DONE", "Data_type": "Integer", "delay": "0.03", "value": "1", "operation": "wait"}, {"channel_name": "X07MB-ES1-SD1:cam1:Acquire", "Data_type": "Integer", "delay": "0.3", "value": "0", "operation": "wait"}, {"channel_name": "X07MB-XMAP:StopAll", "Data_type": "String", "delay": "0.05", "value": "1", "operation": "put"}], "ch_base_vortex_dxp": "X07MB-XMAP:dxp", "r_id": {"TRZ1": "TRZ1", "ScanX": "ScanX", "ScanY": "ScanY"}, "CH_XBPM3_POS": ["X07MB-OP-BPM3:POSX", "X07MB-OP-BPM3:POSY"], "n_roi": 18, "e_ex_t": [-1], "e_ex_k_i": [-1], "e_ex_k_f": [-1], "e_ex_icy": [-1], "r_num": [6], "CH_XBPM4_POS": ["X07MB-OP-BPM4:POSX", "X07MB-OP-BPM4:POSY"], "n_roi_for_xas": 8, "p_done_switch": [0, 0, 0, 0, 0, 0], "e_active": [1, 1, 1, 1], "r_done_switch": {"TRZ1": 0, "ScanX": 0, "ScanY": 0}, "d_list_fluo": [1, 2, 3, 4], "p_positioner_active": [1, 1, 1, 1, 1, 1], "EnergyScan": {"e_ex_t": [-1], "e_ex_k_i": [-1], "e_ex_k_f": [-1], "e_ex_E_edge": [4030.0], "e_ex_icy": [-1], "e_f": [2380.0, 2390.0, 2461.0, 2463.0], "e_i": [2369.0, 2380.0, 2460.0, 2462.0], "e_n_cycles": [600, 600, 2, 2], "channel_rbv": "X07MB-OP-MO:E-GET", "alias": "Energy", "e_ex_ncy": [-1], "n_exafs": 0, "e_ex_active": [-1], "channel_name": "X07MB-OP-MO:E-SET", "EnergyRanges": [[2369.0, 2380.0, 0.2], [2380.0, 2390.0, 1.0], [2460.0, 2461.0, 0.5], [2462.0, 2463.0, 0.1]], "e_ex_ncy_f": [-1], "EnergyCycles": [600, 600, 2, 2], "delay": 0, "e_ex_nst": [-1], "data_type": "double", "e_ex_e_i": [-1], "e_ex_d_i": [-1], "e_delta": [0.2, 1.0, 0.5, 0.1], "e_ex_e_f": [-1]}, "XMAP_save_only_xas_roi": 0, "ch_base_vortex_mca": "X07MB-XMAP:mca", "CH_BL_PRESS": ["X07MA-FE-CH2MP1:PRESSURE", "X07MB-OP-MI1MP1:PRESSURE", "X07MA-OP-CMMP:PRESSURE", "X07MA-OP-SCMP:PRESSURE", "X07MB-OP-IP1MP1:PRESSURE", "X07MB-OP-SL1MP1:PRESSURE", "X07MB-OP-FI1MP1:PRESSURE", "X07MB-OP-BM1MP1:PRESSURE", "X07MB-OP-IP2MP1:PRESSURE", "X07MB-OP-BM2MF1:PRESSURE", "X07MB-OP-MOMF1:PRESSURE"], "ID_XBPM3_POS": ["XBPM3_POSX", "XBPM3_POSY"], "p_done": ["X07MB-ES-MA1:ScanX.DMOV", null, null, null, null, null], "p_id": ["ScanX", "ScanY", "SL2_hor", "SL2_ver", "TRX1", "TRZ1"], "n_roi_for_xas_index": 8, "ID_MONO_ENC": ["ROLL1_V", "PITCH2_V", "ROLL2_V", "ROLL1_MUR", "PITCH2_MUR", "ROLL2_MUR", "ROLL1_DIFF", "PITCH2_DIFF", "ROLL2_DIFF", "ROLL1_VOLT", "PITCH2_VOLT", "ROLL2_VOLT", "T1_VAL", "T1_RBV", "T1_DIFF", "T1_REP", "T2_VAL", "T2_RBV", "T2_DIFF", "T2_REP", "THETA_VAL", "THETA_RBV", "THETA_DIFF", "THETA_REP"], "XMAP_name_convention": "ROI", "scan_type": "SPECTRA", "e_ex_E_edge": [4030.0], "detectors": ["no_Detector", "MOENCH", "Vortex", "KEITHLEY1", "KEITHLEY2", "KEITHLEY3"], "CH_ES1_PRESS": ["X07MB-ES1-MF1:PRESSURE", "X07MB-ES1-MC1:PRESSURE", "X07MB-OP-KBMF1:PRESSURE", "X07MB-OP-SL2MF1:PRESSURE"], "e_n_cycles": [600, 600, 2, 2], "p_label": ["ECal", "3", "celest", "FeS_sig"], "CH_XBPM4": ["X07MB-OP2-SAI_19:CUR-MEAN", "X07MB-OP2-SAI_20:CUR-MEAN", "X07MB-OP2-SAI_21:CUR-MEAN", "X07MB-OP2-SAI_22:CUR-MEAN"], "p_data": [[1.2999999999999998, 2.0, 3.0, 1.2999999999999998], [-3.825, -3.825, -3.825, -3.825], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [0.4719855990179035, 0.4719855990179035, 0.4719855990179035, 0.4719855990179035], [7.800514242742789, 7.800514242742789, 7.800514242742789, 7.800514242742789]], "CH_XBPM3": ["X07MB-OP2-SAI_14:CUR-MEAN", "X07MB-OP2-SAI_15:CUR-MEAN", "X07MB-OP2-SAI_16:CUR-MEAN", "X07MB-OP2-SAI_17:CUR-MEAN"], "r_active": [1], "XMAP_roi_numbers": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], "e_ex_ncy": [-1], "n_exafs": 0, "r_delta_y": [0.005], "r_delta_x": [0.005], "ID_MONO_TEMP": ["MONO_THETA_TC1", "MONO_TRX_TC1", "MONO_C2_TC_Z", "MONO_C2_TC_Y", "MONO_TC1", "MONO_TC2", "MONO_TC3", "MONO_TC4", "MONO_TC5", "MONO_TC6", "MONO_TC7", "MONO_TC8", "MONO_TC9", "MONO_TC10", "MONO_TC11", "MONO_TC12", "MONO_TC13", "MONO_TC14", "MONO_TC15", "MONO_TC16"], "ID_BL_TEMP": ["MI1TC1", "MI1TC3", "CMMITC1", "CMBTC1", "SCTC1", "FE_SH1TC1", "FE_SH1TC2", "FE_SH1TC3", "FE_SH1TC4", "FE_SV1TC1", "FE_SV1TC2", "FE_SV1TC3", "FE_SV1TC4", "SL1_SH1TC_X1", "SL1_SH1TC_X2", "SL1_SV1TC_Y1", "SL1_SV1TC_Y2"], "User_detector_fda_id": ["Sample_x", "Focus", "ROT", "N_FRAMES"], "e_channel": "X07MB-OP-MO:E-SET", "e_ex_nst": [-1], "CH_MONO_ENC": ["X07MB-OP-MO:C1-EC_ROZ", "X07MB-OP-MO:C2-EC_ROX", "X07MB-OP-MO:C2-EC_ROZ", "X07MB-OP-MO:C1-ROZ.DRBV", "X07MB-OP-MO:C2-ROX.DRBV", "X07MB-OP-MO:C2-ROZ.DRBV", "X07MB-OP-MO:C1-ROZ.DIFF", "X07MB-OP-MO:C2-ROX.DIFF", "X07MB-OP-MO:C2-ROZ.DIFF", "X07MB-OP-MO:C1-EC_ROZ.VAL", "X07MB-OP-MO:C2-EC_ROX.VAL", "X07MB-OP-MO:C2-EC_ROZ.VAL", "X07MB-OP-MO:C2-TRZ.VAL", "X07MB-OP-MO:C2-TRZ.RBV", "X07MB-OP-MO:C2-TRZ.DIFF", "X07MB-OP-MO:C2-TRZ.REP", "X07MB-OP-MO:C2-TRY.VAL", "X07MB-OP-MO:C2-TRY.RBV", "X07MB-OP-MO:C2-TRY.DIFF", "X07MB-OP-MO:C2-TRY.REP", "X07MB-OP-MO:THETA.VAL", "X07MB-OP-MO:THETA.RBV", "X07MB-OP-MO:THETA.DIFF", "X07MB-OP-MO:THETA.REP"], "CH_BL_TEMP": ["X07MB-OP-MI1:TC1", "X07MB-OP-MI1:TC3", "X07MA-OP-CMMI:TC1", "X07MA-OP-CMB:TC1", "X07MA-OP-SC:TC1", "X07MA-FE-SH1:TC1", "X07MA-FE-SH1:TC2", "X07MA-FE-SH1:TC3", "X07MA-FE-SH1:TC4", "X07MA-FE-SV1:TC1", "X07MA-FE-SV1:TC2", "X07MA-FE-SV1:TC3", "X07MA-FE-SV1:TC4", "X07MB-OP-SH1:TC_X1", "X07MB-OP-SH1:TC_X2", "X07MB-OP-SV1:TC_Y1", "X07MB-OP-SV1:TC_Y2"], "e_ex_d_i": [-1], "All_Positioner": [{"channel_name": "X07MB-ES-MA1:ScanX.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": "X07MB-ES-MA1:ScanX.DMOV", "delay": 0.0, "channel_rbv": "X07MB-ES-MA1:ScanX.RBV", "data_type": "double", "alias": "ScanX", "operation": "put", "value": [1.2999999999999998, 2.0, 3.0, 1.2999999999999998]}, {"channel_name": "X07MB-ES-MA1:ScanY.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": null, "delay": 0.0, "channel_rbv": "X07MB-ES-MA1:ScanY.RBV", "data_type": "double", "alias": "ScanY", "operation": "put", "value": [-3.825, -3.825, -3.825, -3.825]}, {"channel_name": "X07MB-OP-SH2:size.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": null, "delay": 0.0, "channel_rbv": "X07MB-OP-SH2:size.RBV", "data_type": "double", "alias": "SL2_hor", "operation": "put", "value": [1.0, 1.0, 1.0, 1.0]}, {"channel_name": "X07MB-OP-SV2:size.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": null, "delay": 0.0, "channel_rbv": "X07MB-OP-SV2:size.RBV", "data_type": "double", "alias": "SL2_ver", "operation": "put", "value": [1.0, 1.0, 1.0, 1.0]}, {"channel_name": "X07MB-ES-MA1:TRX1.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": null, "delay": 0.0, "channel_rbv": "X07MB-ES-MA1:TRX1.RBV", "data_type": "double", "alias": "TRX1", "operation": "put", "value": [0.4719855990179035, 0.4719855990179035, 0.4719855990179035, 0.4719855990179035]}, {"channel_name": "X07MB-ES-MA1:TRZ1.VAL", "done_switch": 0, "label": ["ECal", "3", "celest", "FeS_sig"], "done": null, "delay": 0.0, "channel_rbv": "X07MB-ES-MA1:TRZ1.RBV", "data_type": "double", "alias": "TRZ1", "operation": "put", "value": [7.800514242742789, 7.800514242742789, 7.800514242742789, 7.800514242742789]}], "ID_CAM1_POS": ["CentroidX_RBV", "CentroidY_RBV", "SigmaX_RBV", "SigmaY_RBV", "SigmaXY_RBV"], "ID_BL_PRESS": ["CH2MP1", "MI1MP", "CMMP", "SCMP", "IP1MP1", "SL1MP1", "FI1MP1", "BM1MP1", "IP2MP1", "BM2MF1", "MOMF1"], "CH_INITIAL": ["X07MB-OP-MO:C2-ROX.VAL", "X07MB-OP-MO:C2-ROZ"], "p_channel": ["X07MB-ES-MA1:ScanX.VAL", "X07MB-ES-MA1:ScanY.VAL", "X07MB-OP-SH2:size.VAL", "X07MB-OP-SV2:size.VAL", "X07MB-ES-MA1:TRX1.VAL", "X07MB-ES-MA1:TRZ1.VAL"], "e_channel_rbv": "X07MB-OP-MO:E-GET", "preactions": [{"channel_name": "X07MB-OP2:START-CSMPL", "delay": "0.05", "data_type": "String", "value": "0", "operation": "put"}, {"channel_name": "X07MB-XMAP:StopAll", "delay": "0.05", "data_type": "String", "value": "1", "operation": "put"}, {"channel_name": "X07MB-XMAP:CollectMode", "delay": "0.05", "data_type": "String", "value": "0", "operation": "put"}, {"channel_name": "X07MB-XMAP:Apply", "delay": "0.05", "data_type": "String", "value": "1", "operation": "put"}, {"channel_name": "X07MB-XMAP:PresetReal", "delay": "0.05", "data_type": "String", "value": "0", "operation": "put"}, {"channel_name": "X07MB-OP2:TOTAL-CYCLES", "delay": "0.05", "data_type": "String", "value": "2", "operation": "put"}, {"channel_name": "X07MB-OP2:SMPL", "delay": "0.7", "data_type": "String", "value": "1", "operation": "put"}, {"channel_name": "X07MB-ES1-PP2:VO5", "delay": "0.01", "data_type": "String", "value": "0", "operation": "put"}, {"channel_name": "X07MB-OP-WV1:WT_SET", "delay": "0.05", "data_type": "String", "value": "1", "operation": "put"}, {"channel_name": "X07MB-ES1-SD1:cam1:FileNumber", "delay": "0.5", "data_type": "String", "value": "100000", "operation": "put"}], "XMAP_save_spectra": 1, "r_ll_y": [-4.39], "r_ll_x": [1.925], "ID_ES1_PRESS": ["ES1MF1", "ES1MC1", "OPKBMF1", "OPSL2MF1"], "n_e": 4, "r_done": {"TRZ1": "X07MB-ES-RONTEC:TRX.DMOV", "ScanX": "X07MB-ES-MA1:ScanX.DMOV", "ScanY": "X07MB-ES-MA1:ScanY.DMOV"}, "n_p": 4, "Id_XMAP_roi_by_name": ["OKa", "FeL", "NaKa", "MgKa", "AlKa", "SiKa", "SrKa", "PKa", "SKa", "KKa", "CaKa", "CaKb", "TiKa", "VKa", "VKb", "MnKa", "FeKa", "El_72keV"], "beamline": "X07MB", "ID_XBPM4_POS": ["XBPM4_POSX", "XBPM4_POSY"], "r_energy_cycles": [5, 5, 5, 5, 5, 5], "CH_INITIAL_V": ["-10890", "-2350"], "number_of_executions": 1, "ID_XBPM4": ["XBPM4_SAI19_CUR_MEAN", "XBPM4_SAI20_CUR_MEAN", "XBPM4_SAI21_CUR_MEAN", "XBPM4_SAI22_CUR_MEAN"], "r_ur_x": [2.0], "ID_XBPM3": ["XBPM3_SAI14_CUR_MEAN", "XBPM3_SAI15_CUR_MEAN", "XBPM3_SAI16_CUR_MEAN", "XBPM3_SAI17_CUR_MEAN"], "e_ex_e_i": [-1], "ch_base_vortex": "X07MB-XMAP", "e_delta": [0.2, 1.0, 0.5, 0.1], "e_ex_e_f": [-1], "r_energies": [2450.0, 2471.2, 2473.0, 2481.0, 2488.0, 2498.0], "r_ur_y": [-4.35], "CH_CAM1_POS": ["X07MB-PS1:Stats1:CentroidX_RBV", "X07MB-PS1:Stats1:CentroidY_RBV", "X07MB-PS1:Stats1:SigmaX_RBV", "X07MB-PS1:Stats1:SigmaY_RBV", "X07MB-PS1:Stats1:SigmaXY_RBV"]} \ No newline at end of file diff --git a/script/Users/Thomas/CreatingLocalChannelDevices.py b/script/Users/Thomas/CreatingLocalChannelDevices.py new file mode 100644 index 0000000..be6000c --- /dev/null +++ b/script/Users/Thomas/CreatingLocalChannelDevices.py @@ -0,0 +1,9 @@ + +pos = Channel('X07MB-OP-MO:E-SET', alias="POS", type='s') +c1 = Channel('X07MB-OP2-SAI_07:MEAN', alias="TEST") +c2 = Channel('X07MB-OP-MO:E-GET', alias="TEST2") +sensors = [c1,c2] +ret = lscan(pos, sensors, start=2450, end=2460, steps=10) + + +for c in sensors: c.close() diff --git a/script/Users/Thomas/Mono_pitch.py b/script/Users/Thomas/Mono_pitch.py new file mode 100644 index 0000000..2ed383d --- /dev/null +++ b/script/Users/Thomas/Mono_pitch.py @@ -0,0 +1,139 @@ +#Script imported from: Mono_pitch.xml + +#Pre-actions +caput('X07MB-OP2:START-CSMPL', '0') +sleep(0.1) +caput('X07MB-XMAP:StopAll', '1') +sleep(0.1) +caput('X07MB-XMAP:PresetMode', '0') +sleep(0.1) +caput('X07MB-XMAP:PresetReal', '0') +sleep(0.1) +caput('X07MB-OP2:TOTAL-CYCLES', '1') +sleep(0.1) +print('dd') + +#TODO: Set the diplay names of positioners and detectors +scan = ManualScan(['Pitch'], ['bm3', 'bm4', 'Filter_RY', 'Harmonic', 'TC_Y', 'TC_Z', 'T_THETA', 'Id_OFF', 'Id_energy', 'E_Mono', 'Bragg_Id_theo', 'Theta_rbv', 'Theta_offset', 'Delta_E', 'Delta_theta', 'XX'] , [-10700.0], [-10750.0], [25]) +scan.start() + +#Creating channels: dimension 1 +#LinearPositioner Pitch +Pitch = Channel('X07MB-OP-MO:C2-ROX.VAL', type = 'd') +PitchReadback = Channel('X07MB-OP-MO:C2-ROX.RBV', type = 'd') +#ScalarDetector bm3 +bm3 = Channel('X07MB-OP2-SAI_03:MEAN', type = 'd') +#ScalarDetector bm4 +bm4 = Channel('X07MB-OP2-SAI_04:MEAN', type = 'd') +#ScalarDetector Filter_RY +Filter_RY = Channel('X07MB-OP-FI:ROY.VAL', type = 'd') +#ScalarDetector Harmonic +Harmonic = Channel('X07MA-ID:HARMONIC', type = 'd') +#ScalarDetector TC_Y +TC_Y = Channel('X07MB-OP-MOC2:TC_Y', type = 'd') +#ScalarDetector TC_Z +TC_Z = Channel('X07MB-OP-MOC2:TC_Z', type = 'd') +#ScalarDetector T_THETA +T_THETA = Channel('X07MB-OP-MOTHETA:TC1', type = 'd') +#ScalarDetector Id_OFF +Id_OFF = Channel('X07MA-ID:ENERGY-OFFS', type = 'd') +#ScalarDetector Id_energy +Id_energy = Channel('X07MA-ID:ENERGY', type = 'd') +#ScalarDetector E_Mono +E_Mono = Channel('X07MB-OP-MO:E-GET', type = 'd') +#ScalarDetector Bragg_Id_theo +Bragg_Id_theo = Channel('X07MB-OP-MO:BRAGG-CALC', type = 'd') +#ScalarDetector Theta_rbv +Theta_rbv = Channel('X07MB-OP-MO:THETA.RBV', type = 'd') +#ScalarDetector Theta_offset +Theta_offset = Channel('X07MB-OP-MO:THETA.OFF', type = 'd') + +#Dimension 1 +#Dimension Guard +cawait('ACOAU-ACCU:OP-MODE', 6, type = 'l') +#LinearPositioner Pitch +for setpoint1 in frange(-10700.0, -10750.0, -2.0, True): + if setpoint1 > -10700.0 or setpoint1 < -10750.0: + break + Pitch.put(setpoint1, timeout=None) # TODO: Set appropriate timeout + readback1 = PitchReadback.get() + if abs(readback1 - setpoint1) > 10.0 : # TODO: Check accuracy + print readback1, setpoint1 + raise Exception('Actor Pitch could not be set to the value ' + str(setpoint1)) + #Detector bm3 + #Detector X07MB-OP2-SAI_03:MEAN pre-actions + caput('X07MB-OP2:SMPL', '1') + sleep(0.1) + cawait('X07MB-OP2:SMPL-DONE', 1, type = 'l') + detector1 = bm3.get() + #Detector bm4 + detector2 = bm4.get() + #Detector Filter_RY + detector3 = Filter_RY.get() + #Detector Harmonic + detector4 = Harmonic.get() + #Detector TC_Y + detector5 = TC_Y.get() + #Detector TC_Z + detector6 = TC_Z.get() + #Detector T_THETA + detector7 = T_THETA.get() + #Detector Id_OFF + detector8 = Id_OFF.get() + #Detector Id_energy + detector9 = Id_energy.get() + #Detector E_Mono + detector10 = E_Mono.get() + #Detector Bragg_Id_theo + detector11 = Bragg_Id_theo.get() + #Detector Theta_rbv + detector12 = Theta_rbv.get() + #Detector Theta_offset + detector13 = Theta_offset.get() + #Manipulation Delta_E + #Variable Mappings + a = detector10 + b = detector9 + Delta_E = a-b + #Manipulation Delta_theta + #Variable Mappings + a = detector11 + b = detector12 + Delta_theta = a-b + #Manipulation XX + #Variable Mappings + a = detector11 + b = detector12 + XX = a*b + print(XX) + scan.append ([setpoint1], [readback1], [detector1, detector2, detector3, detector4, detector5, detector6, detector7, detector8, detector9, detector10, detector11, detector12, detector13, Delta_E, Delta_theta, E_Mono, XX]) + +#Closing channels +Pitch.close() +PitchReadback.close() +bm3.close() +bm4.close() +Filter_RY.close() +Harmonic.close() +TC_Y.close() +TC_Z.close() +T_THETA.close() +Id_OFF.close() +Id_energy.close() +E_Mono.close() +Bragg_Id_theo.close() +Theta_rbv.close() +Theta_offset.close() + +scan.end() + + +#Post-actions +caput('X07MB-OP2:START-CSMPL', '1') +sleep(0.1) +caput('X07MB-OP2:START-CSMPL', '1') +sleep(0.3) +caput('X07MB-OP2:SMPL', '1') +sleep(0.3) +caput('X07MB-OP2:SMPL', '1') +sleep(0.3) diff --git a/script/Users/Thomas/Pscan.py b/script/Users/Thomas/Pscan.py new file mode 100644 index 0000000..13af6d6 --- /dev/null +++ b/script/Users/Thomas/Pscan.py @@ -0,0 +1,3463 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek properly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + # endif + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + except: + try: + sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + # =============================== XTREME ============================== + f.write(' \n') + # f.write(' \n') + # f.write(' \n') + # f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + +# +++++++++++++ + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '.1'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py &','0')) + + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II chek whether MONO is initialzed + + + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,params): + + f.write(' \n') + f.write(' \n ') + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end fucntion_positiner_MOENCH + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + # ,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-OP-KEITH3:setGain' + # ,'Id' : 'KEITHLEY3_GAIN'}) + + #endif + + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + + ch_base_vortex=g['beamline']+'-XMAP:mca' + ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + print 'ddddddddddddddddd' + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # creat the ID' for the different channels + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + + ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ) + ch_ocr.append( g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ) + ch_eltm.append( g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ) + ch_ertm.append( g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ) + ch_dtim.append( g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + # endfor + # endif + + + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... +# o.k. tro here + + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. + # On long term, we can minimize the number of chanles to be read + + + + #import os + ##os.system ("ls -altr") + #try: + # from CaChannel import * + # from epicsMotor import * + # from epicsPV import * + # import time + # import string + + #except: + # try: + # sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + # sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + # from CaChannel import * + # from epicsPV import * + # except: + # os.system ("xkbbell") + # os.system ("xmessage -nearmouse -timeout 30 \ + # -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + # sys.exit(1) + # # endtry + + # endtry + + + + beamline='X07MB' + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') + + # .... remove all blanks from filenam + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) + # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) + # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) + # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) + # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): + # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') + # note that this assumes that the + # same roi name is choosen for all four spectra. + # XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') + # note that this assumes that the + # same roi name is choosen for all four spectra. + # XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('! NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): + # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + box='!choose at least one ENERGY range with constant energy' + box2=box+'spacing for taking SPECTRA (Menue XAS SCANS)' + #error stop as no energy is defined for energy scan + + error_stop(box2) + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least + # on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION + # for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum + # at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5') + ] + + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, + # we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_2={'channel' : 'X07MB-XMAP:StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # set to mca spectac mode (later add option for OTF mapping) + + preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + + preaction_2b={'channel' : 'X07MB-XMAP:Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + # ,preaction_5 # 4.10 take light out tmp + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + + detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + + detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all + # chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t +# , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! +# , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + , 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + , 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + diff --git a/script/Users/Thomas/PseudoScanDevices.py b/script/Users/Thomas/PseudoScanDevices.py new file mode 100644 index 0000000..d46c07c --- /dev/null +++ b/script/Users/Thomas/PseudoScanDevices.py @@ -0,0 +1,19 @@ +################################################################################################### +# Demonstrate use of Vector Scan: one or multiple positioners set with a list or generator. +################################################################################################### + + +class PseudoPositioner(Writable): + def write(self,pos): + print "Step = " + str(pos) + #caput() + #cawait() +positioner=PseudoPositioner() + + +class Clock(Readable): + def read(self): + return time.clock() +clock=Clock() + +lscan(positioner,[clock], start=2450, end=2460, steps=10, latency=0.0, relative = False, before_read=BeforeReadout, after_read=AfterReadout) diff --git a/script/Users/Thomas/ScanPlotOptions.py b/script/Users/Thomas/ScanPlotOptions.py new file mode 100644 index 0000000..2210867 --- /dev/null +++ b/script/Users/Thomas/ScanPlotOptions.py @@ -0,0 +1,9 @@ + +set_exec_pars(format="h5", name="") + +lscan("ca://X07MB-OP-MO:E-SET", sensors, start=2450, end=2460, steps=10) + + +sensors=['ca://X07MB-OP2-SAI_07:MEAN', 'ca://X07MB-OP-MO:E-GET'] +ret = lscan("ca://X07MB-OP-MO:E-SET", sensors, start=2450, end=2460, steps=10, enabled_plots=['X07MB-OP2-SAI_07:MEAN']) + diff --git a/script/Users/Thomas/ScanRecordCallbacks.py b/script/Users/Thomas/ScanRecordCallbacks.py new file mode 100644 index 0000000..4edb956 --- /dev/null +++ b/script/Users/Thomas/ScanRecordCallbacks.py @@ -0,0 +1,12 @@ + + + + +def BeforeReadout(position, scan): + print "In position: " + str(position) + str(sensors) + + +def AfterReadout(record, scan): + print "Aquired record: " + str(record) + +lscan("ca://X07MB-OP-MO:E-SET", sensors, start=2450, end=2460, steps=10, latency=0.0, relative = False, before_read=BeforeReadout, after_read=AfterReadout) diff --git a/script/Users/Thomas/Test.py b/script/Users/Thomas/Test.py new file mode 100644 index 0000000..8396253 --- /dev/null +++ b/script/Users/Thomas/Test.py @@ -0,0 +1,10 @@ +d={'a':1, + 'b':2} + +print(d) +d.update({'c':5}) +print(d) +print(type(d)) + + + \ No newline at end of file diff --git a/script/Users/Thomas/Test_thomas.py b/script/Users/Thomas/Test_thomas.py new file mode 100644 index 0000000..8ca7c91 --- /dev/null +++ b/script/Users/Thomas/Test_thomas.py @@ -0,0 +1,26 @@ +class test: + d=5 + d1='d' +#endclass + +def tt(a): + print('2') +#enddef + +tt(9) +print(test.d) +print(test.d1) + +box={ 'filename' : 'd' + , 'beamline' : 'dd'} + +print(box) +f=[1,2,2] +plot(f,title='f') +f1=get_plot_snapshots() +print(f1) +import os +import numpy + + + diff --git a/script/Users/Thomas/X_X07MB_Pscan.py b/script/Users/Thomas/X_X07MB_Pscan.py new file mode 100644 index 0000000..6598f3b --- /dev/null +++ b/script/Users/Thomas/X_X07MB_Pscan.py @@ -0,0 +1,3642 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + except: + try: + sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + # ask for SITORO 2nd to make itr the dominat choice + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + if (hardware_sdd != 'SITORO') and get_epicsPV('X07MB-PC-PSCAN:SITORO') !=XMAP : + hardware_sdd = False + #endif + + ch_base_vortex = beamline+'-'+ + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5') + ] + + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/X_X07MB_Pscan.py.old b/script/Users/Thomas/X_X07MB_Pscan.py.old new file mode 100644 index 0000000..1fb708c --- /dev/null +++ b/script/Users/Thomas/X_X07MB_Pscan.py.old @@ -0,0 +1,3434 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + except: + try: + sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + # =============================== XTREME ============================== + f.write(' \n') + # f.write(' \n') + # f.write(' \n') + # f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '.1'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py &','0')) + + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II chek whether MONO is initialzed + + + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,params): + + f.write(' \n') + f.write(' \n ') + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end fucntion_positiner_MOENCH + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + # ,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-OP-KEITH3:setGain' + # ,'Id' : 'KEITHLEY3_GAIN'}) + + #endif + + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + + ch_base_vortex=g['beamline']+'-XMAP:mca' + ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + print 'ddddddddddddddddd' + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # creat the ID' for the different channels + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + + ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ) + ch_ocr.append( g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ) + ch_eltm.append( g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ) + ch_ertm.append( g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ) + ch_dtim.append( g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + # endfor + # endif + + + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') + + # .... remove all blanks from filenam + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5') + ] + + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_2={'channel' : 'X07MB-XMAP:StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # set to mca spectac mode (later add option for OTF mapping) + + preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + + preaction_2b={'channel' : 'X07MB-XMAP:Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + # ,preaction_5 # 4.10 take light out tmp + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + + detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + + detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t +# , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! +# , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + , 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + , 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/X_X07MB_XAS_points_P1_queue.py b/script/Users/Thomas/X_X07MB_XAS_points_P1_queue.py new file mode 100644 index 0000000..891785a --- /dev/null +++ b/script/Users/Thomas/X_X07MB_XAS_points_P1_queue.py @@ -0,0 +1,543 @@ +#! /usr/bin/env python + +# ---------------------------------------------------------------------------------------- + + +def write_xml_XAS_single_point(g,N_position,BASE_DIR): + + + # ================================================================================== + # + # THIS ROUTINE CREATES THE XML FILE FOR TAKING XAS SPECTRA ON VARIOUS DATA POINTS + # + # + # Author T. Huthwelker October 2011 --- + # + # ================================================================================= + + + filename=str(g['filename']) + '_' + str(g['p_label'][N_position]) + + number_of_executions= str(g['number_of_executions']) + + filename_xml=BASE_DIR+"points_q_" +str(N_position)+'_'+ str(g['p_label'][N_position]) + ".xml" + filename_xml=BASE_DIR+"points_q_" +str(N_position)+ ".xml" + print filename + print filename_xml + + f = open(filename_xml, "w") + + # ............. write header and open configuration ...................... + + f.write(''+'\n') + + + f.write(''+'\n') + + + # option to take the number o repeats on panel as number of excecutions for each individual run + #num_ex=get_epicsPV('X07MB-PC-PSCAN:FdaNexec') + #f.write(''+'\n') + + + + + f.write(''+'\n') + + + # define default Variable + + Write_Variable_Definitions(f,g) + + # -------------------------- general preactions.......... + + f.write(' \n ') + + + write_preactions(f,g) + + + #___________________________________________ ______________ dimension 1 Energy + + f.write(' \n') # -..... open dimension 1 + + + # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + # endif + # endfor + + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + write_EXAFS_region(f,g) + + + f.write(' \n') # -..... close positoner + + + + # ____________________________________________________ DETECTORS............................. + + + + + # ......actions for detectors for each measurement + + + write_detector_actions(f,g) + + + # ... write guard, must be in first loop after detector actions... + + #write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + # ,'Value' : 6 }) + + + + # ...................create all entries for the detectors...... + [n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex] =write_all_detectors(f,g) + + + # .. other detectors... + + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-ES1:userCalc3.VAL' + # ,'Id' : 'T_heater_C '}) + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-ES1-PP3:PT1' + # ,'Id' : 'T_heater_V'}) + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-ES1-PP3:PT2' + # ,'Id' : 'T_sample_V'}) + + #write_detector(f,{'Det_type' : 'ScalarDetector' + # ,'Data_type' : 'Double' + # ,'Channel' : 'X07MB-ES1-PP2:VO1' + # ,'Id' : 'U_heater_SET'}) + + + # use guard, stop DAQ if there is no light + + + # ____________________________________________________ dimension 2 position Manipulator + + # write positioner for default chanels onlz if thez are defined... + print g['p_positioner_active'] + print g['p_channel'] + print g['p_id'] + print g['p_id'][0] + print ' ' + print 'g[p_data]' + print g['p_data'] + print ' ' + print g['p_data'][0] + + f.write(' \n') # -..... close dimension 1 + if sum(g['p_positioner_active']) > 0: + f.write(' \n ') # -..... open dimension 2 + print g['p_channel'] + print g['p_done_switch'] + + for i in range(len(g['p_id'])): + write_array_positioner(f,{'Channel' : g['p_channel'][i] + , 'Channel_rbv' : g['p_channel_rbv'][i] + , 'Id' : g['p_id'][i] + , 'Positions' : [g['p_data'][i][N_position]] + , 'Channel_done': g['p_done'][i] + , 'Use_done_value': g['p_done_switch'][i] + } + ) + + #endfor + + + # ... before closing dimensions, set a guard on the beam current + + # 31.7.2012 temp commented out........ + + + + + f.write(' \n') # -..... close dimension 2 + #endif + + # ....................postaction after detectors + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + write_default_postactions(f,g) + + + # ============================================================================================== + # ..........write all manipulations.... possible move away from hre into a standard routine + # ============================================================================================== + + # first walk through all detectors.... + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_UD + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + + + + f.write(' \n ') # -..... close scan # END OF SCAN + + # finally add the visualization ................. + + + # plot ICR and OCR for all VORTEX DETECTORS.... + # case I vortex 4-element detector + + if ('Vortex' in g['detectors']): + + #if n_det_vortex == 4 : + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D1_ICR D2_ICR D3_ICR D4_ICR D1_TrueICR D2_TrueICR D3_TrueICR D4_TrueICR' + , 'Title' : 'ICR ' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D1_OCR D2_OCR D3_OCR D4_OCR' + , 'Title' : 'OCR ' }) + + #write_visualization(f,{ 'Type': 'LinePlot' + # , 'X' : 'Energy' + # , 'DATA' : 'I0_KEITHLEY1' + # , 'Title' : 'I0 (KEITHLEY 1)' }) + + #write_visualization(f,{ 'Type': 'LinePlot' + # , 'X' : 'Energy' + # , 'DATA' : 'I1_KEITHLEY 2' + # , 'Title' : 'I1 (KEITHLEY 2)' }) + + + # now plot the roi for XAS + + print 'id_roi_vortex[0]' + print id_roi_vortex[0] + print "g[n_roi_for_xas]" + print g['n_roi_for_xas'] + print g['n_roi_for_xas_index'] + print id_roi_vortex[0][g['n_roi_for_xas_index']] + + + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']]+' '+ id_roi_vortex_dxp[0][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']] }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[1][g['n_roi_for_xas_index']]+' '+ id_roi_vortex_dxp[1][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[1][g['n_roi_for_xas_index']] }) + + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[2][g['n_roi_for_xas_index']]+' '+ id_roi_vortex_dxp[2][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[2][g['n_roi_for_xas_index']] }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[3][g['n_roi_for_xas_index']]+' '+ id_roi_vortex_dxp[3][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[3][g['n_roi_for_xas_index']] }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[1][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[1][g['n_roi_for_xas_index']]+'_corr' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[2][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[2][g['n_roi_for_xas_index']]+'_corr' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[3][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[3][g['n_roi_for_xas_index']]+'_corr' }) + + # now also vizualize roi over user detectors if user detectors are defined.. + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[3][g['n_roi_for_xas_index']]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Title' : id_roi_vortex[3][g['n_roi_for_xas_index']]+'_corr_over_'+g['User_detector_fda_id'][i_ud]} + ) + + + + # endif + + + # case II Roentex via XMAP + + if ('ROENTEC_XMAP' in g['detectors']): + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D1_ICR D1_TrueICR' + , 'Title' : 'ICR ' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D1_OCR ' + , 'Title' : 'OCR ' }) + + + # now plot the roi for XAS + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']]+' '+ id_roi_vortex_dxp[0][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']] }) + + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' }) + + + # endif + + + + + if ('KETEK_XMAP' in g['detectors']): + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D2_ICR D2_TrueICR' + , 'Title' : 'ICR ' }) + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : 'D2_OCR ' + , 'Title' : 'OCR ' }) + + + + # now plot the roi for XAS + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']] +' '+ id_roi_vortex_dxp[0][g['n_roi_for_xas_index']] + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']] }) + + + write_visualization(f,{ 'Type': 'LinePlot' + , 'X' : 'Energy' + , 'DATA' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' + , 'Title' : id_roi_vortex[0][g['n_roi_for_xas_index']]+'_corr' }) + + + # endif + + # finally add optional plots to data set + + special_visualization(f,g,{'Id_X': 'Energy', 'Id_Y':'undefined', 'Type':'LinePlot' }) + + + + + f.write(''+'\n') # close configuration # END OF CONFIGURATION + +# END ROUTINE + + + +from X_X07MB_Pscan import * +import commands +import os +import subprocess +import time + + + +# from subprocess import call +# HERE THE MaiN PRG STARTS..... + +#detectors=[' ',' ',' '] +#n_e=5 +#e_active = create_int_zeros(n_e) +#e_i = create_real_zeros(n_e) +#e_f = create_real_zeros(n_e) +#e_delta = create_real_zeros(n_e) + + +#n_p = 10 +#p_active = create_int_zeros(n_p) +#p_scanx = create_real_zeros(n_p) +##p_scany = create_real_zeros(n_p) +#p_theta = create_real_zeros(n_p) +#p_trx = create_real_zeros(n_p) +#p_trz = create_real_zeros(n_p) + +g=get_channels('SPECTRA_QUEUE') + + +beamline='X07MB' + +# .... check if PHOENIX is ONLINE, if offline, diconnect undulator - mono coupling.... + +#dddd + + +if g['scan_type'] == 'SPECTRA_QUEUE': + print 'WRITE XML FILE' + + + #print g['p_positioner_active'] + + #print len(g['p_id']) + i=0 + #print g['p_id'] + #print g['p_channel'] + # define base dir for tmp storage + #BASE_DIR='/sls/X07MB/data/settings/GUI_TMP/' + # writte directly into correct directory.. + BASE_DIR='/sls/X07MB/data/x07mbop/operation/fda/scans/users/0_Scripted/' + for N_position in range(g['n_p']): + print ' write xml file for point' +str(N_position) + write_xml_XAS_single_point(g,N_position,BASE_DIR) + print '... done' + #endfor + + print 'DONE WINDOW CLOSED in 3 sec ' + time.sleep(3) + # now copy file to correct place... + commands.getstatusoutput('ls /bin/ls') + diff --git a/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.24072020_1701.py b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.24072020_1701.py new file mode 100644 index 0000000..56d1ff6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.24072020_1701.py @@ -0,0 +1,3736 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.py new file mode 100644 index 0000000..ba7fb9d --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_Pscan.py @@ -0,0 +1,3830 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.075' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.075' } # fda 0.75 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_lib.py new file mode 100644 index 0000000..945f327 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102321/X_X07MB_lib.py @@ -0,0 +1,2249 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars=get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + print(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g +# ,'channel_name' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'channel_name' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecute a list fo preactions + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used for positioner, sensors and the + various actions (pre, post, detector, etc) + + Routine assumes an input in the form + SD[key]={['channel_name:'X07MB2', ...],['channel_name:'X07MB2', ..., ] ...} + and will add channel instance to each entry + + SD[key]={['channel_name:'X07MB2' + # , ..., + # Channel([Ch'X07MB2', ... alias=ThisID] + # ,['channel_name:'X07MB2', ..., ] ...} + + # where: + # C = self.SD[key][channel_name] + # ThisID = self.SD[key][alias] + # if alias is nor defined: + # ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + # C = self.SD[key][i][channel_name] + # ThisID = self.SD[key][i][alias] + # if alias is nor defined: + # ThisID = self.SD[key][i][channel_name] + + + input: + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + try: + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined actions + """ + self.pm(' PscanLib.DetectorActions') + N_PREACTION = len(self.SD[key]) + self.pm('..Execut action SD[key] with key') + self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + #self.pm(self.SD[key][i]) + + + if self.SD[key][i]['operation'] == 'put': + + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + + self.caputq(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait') + self.cawait(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.pm(self.time.time()-t0) + # endif + # endfor + print('total time', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + Routine defined positioner for energy scan as defined in GUI. + + """ + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Settling_time' : '0.1' # , 'Id' : 'FileCountMoench' # , 'V_ini' : g['e_i'][i] # , 'V_final' : g['e_f'][i] # , 'V_delta' : g['e_delta'][i] # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Use_done_value' : -1 # } # ) #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + + print('def after_read_dtc(rec,scan) ') + + + t0 = self.time.time() + pars = self.get_exec_pars() + print(pars.getName()) + #print(SD['AllSensors'][1]) + #print('Rec.index',rec.index) + #print(rec[1]) + #print('len',len(rec.values())) + #print('getexecgroup',get_exec_pars().group) + + # THIS IS ROUTINE FOR ENERGY SCAN ONLY + # Make deadt time correction for all channesl with + + # self.All:Sensors[i]['DTC']=True, whic are called + # self.All:Sensors[i]['alias'] Get List of these name in separate routine or + # in CreateSensors? + alias_for_dtc=[] + alias_for_subset=[] + # loop could slow down, move to Create_Sensor_list) + print('t1',self.time.time()-t0) + for i in range(len(self.All_Sensors)): + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + if self.All_Sensors[i]['Subset_1']: + alias_for_subset.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + print('after sorting names',self.time.time()-t0) + print('alias for deadtime correction') + print(alias_for_dtc) + print('Alias for writing to file') + print(alias_for_subset) + + return + + + + if rec.index == 0: + # STEP1 crEATE HEADEROF OUTPUT FILE + # FOR ENERGY SCA, OUT PUT SHOULD BE in this order + # + # columns need to be numbered + # + # ENERGY_c1 Energy_Set_c2 + # Keithley_readouts (4X) + # DTIM all det + # cps_all_det..all roi + # cps_all_roi_DTC + # trueice all det + # ICR, all det + # OCR all det + # det1_roi_cps,.., + # ... seek for sensor number.. + # create a list of indices wich are the oder of detector to save + # I_list=(1,4,6,3,7,8) + # loop through output + # sensor_to_write=sensor(i_list) + # if sensor['DTC?]==TRue: + # do calc and add to output + # endif + create_dataset("/DTCA","d") + d='#a b \n 3.455 4.5789' + append_dataset("/FDA", d ) #A calculated value + print('TABLE CREATED') + #endif + if rec.index > 0: + e=[3.286,3,rec.index] + print(e) + #e=' 2.343 4.5566666' + #append_ dataset(get_calc_group()+"MeanValues", mean(rec.values()[1:2]),e) #A calculated value + append_dataset(get_calc_group()+"MeanValues", e) #A calculated value + append_dataset("/FDA" , e) #A calculated value + print('DATA appended') + #endif + print(rec[0]) + + #end + + def get_calc_group(self): + return get_exec_pars().group + "calc/" + + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.py new file mode 100644 index 0000000..ba7fb9d --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_Pscan.py @@ -0,0 +1,3830 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.075' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.075' } # fda 0.75 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_lib.py new file mode 100644 index 0000000..336846b --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200728_102347/X_X07MB_lib.py @@ -0,0 +1,2249 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars=get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + print(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g +# ,'channel_name' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'channel_name' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecute a list fo preactions + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used for positioner, sensors and the + various actions (pre, post, detector, etc) + + Routine assumes an input in the form + SD[key]={['channel_name:'X07MB2', ...],['channel_name:'X07MB2', ..., ] ...} + and will add channel instance to each entry + + SD[key]={['channel_name:'X07MB2' + # , ..., + # Channel([Ch'X07MB2', ... alias=ThisID] + # ,['channel_name:'X07MB2', ..., ] ...} + + # where: + # C = self.SD[key][channel_name] + # ThisID = self.SD[key][alias] + # if alias is nor defined: + # ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + # C = self.SD[key][i][channel_name] + # ThisID = self.SD[key][i][alias] + # if alias is nor defined: + # ThisID = self.SD[key][i][channel_name] + + + input: + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + try: + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined actions + """ + self.pm(' PscanLib.DetectorActions') + N_PREACTION = len(self.SD[key]) + self.pm('..Execut action SD[key] with key') + self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + #self.pm(self.SD[key][i]) + + + if self.SD[key][i]['operation'] == 'put': + + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + + self.caputq(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait') + self.cawait(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + self.pm(self.time.time()-t0) + # endif + # endfor + print('total time', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + Routine defined positioner for energy scan as defined in GUI. + + """ + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Settling_time' : '0.1' # , 'Id' : 'FileCountMoench' # , 'V_ini' : g['e_i'][i] # , 'V_final' : g['e_f'][i] # , 'V_delta' : g['e_delta'][i] # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Use_done_value' : -1 # } # ) #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + + print('def after_read_dtc(rec,scan) ') + + + t0 = self.time.time() + pars = self.get_exec_pars() + print(pars.getName()) + #print(SD['AllSensors'][1]) + #print('Rec.index',rec.index) + #print(rec[1]) + #print('len',len(rec)) + #print('getexecgroup',get_exec_pars().group) + + # THIS IS ROUTINE FOR ENERGY SCAN ONLY + # Make deadt time correction for all channesl with + + # self.All:Sensors[i]['DTC']=True, whic are called + # self.All:Sensors[i]['alias'] Get List of these name in separate routine or + # in CreateSensors? + alias_for_dtc=[] + alias_for_subset=[] + # loop could slow down, move to Create_Sensor_list) + print('t1',self.time.time()-t0) + for i in range(len(self.All_Sensors)): + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + if self.All_Sensors[i]['Subset_1']: + alias_for_subset.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + print('after sorting names',self.time.time()-t0) + print('alias for deadtime correction') + print(alias_for_dtc) + print('Alias for writing to file') + print(alias_for_subset) + + return + + + + if rec.index == 0: + # STEP1 crEATE HEADEROF OUTPUT FILE + # FOR ENERGY SCA, OUT PUT SHOULD BE in this order + # + # columns need to be numbered + # + # ENERGY_c1 Energy_Set_c2 + # Keithley_readouts (4X) + # DTIM all det + # cps_all_det..all roi + # cps_all_roi_DTC + # trueice all det + # ICR, all det + # OCR all det + # det1_roi_cps,.., + # ... seek for sensor number.. + # create a list of indices wich are the oder of detector to save + # I_list=(1,4,6,3,7,8) + # loop through output + # sensor_to_write=sensor(i_list) + # if sensor['DTC?]==TRue: + # do calc and add to output + # endif + create_dataset("/DTCA","d") + d='#a b \n 3.455 4.5789' + append_dataset("/FDA", d ) #A calculated value + print('TABLE CREATED') + #endif + if rec.index > 0: + e=[3.286,3,rec.index] + print(e) + #e=' 2.343 4.5566666' + #append_ dataset(get_calc_group()+"MeanValues", mean(rec.values()[1:2]),e) #A calculated value + append_dataset(get_calc_group()+"MeanValues", e) #A calculated value + append_dataset("/FDA" , e) #A calculated value + print('DATA appended') + #endif + print(rec[0]) + + #end + + def get_calc_group(self): + return get_exec_pars().group + "calc/" + + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.py new file mode 100644 index 0000000..79a54c8 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_Pscan.py @@ -0,0 +1,3837 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + hardware_sdd='NoSDD' + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + + # ask for SITORO 2nd to make itr the dominat choice + if get_epicsPV(beamline+'-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + + if hardware_sdd != 'NoSDD': + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + else: + ch_base_vortex = 'NoSDD' + ch_base_vortex_mca = 'NoSDD' + ch_base_vortex_dxp = 'NoSDD' + # endelse + print( ch_base_vortex) + print( ch_base_vortex_mca) + print( ch_base_vortex_dxp) + print(hardware_sdd) + + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dummy WHY NOT use [] ???????? + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if (1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM'))) and (hardware_sdd !='NoSDD'): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')) and (hardware_sdd !='NoSDD'): + detectors.append('ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')) and (hardware_sdd !='NoSDD'): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')) and (hardware_sdd !='NoSDD') and 'Vortex' in detectors: + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')) and (hardware_sdd !='NoSDD') and 'ROENTEC_XMAP' in detectors: + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')) and (hardware_sdd !='NoSDD') and 'KETEK_XMAP' in detectors: + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : 0 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : 1.0 + ,'operation' : 'put' + ,'data_type' : 'Double' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.030' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.075' } # fda 0.075 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.00' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_lib.py new file mode 100644 index 0000000..f3f4f86 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_153145/X_X07MB_lib.py @@ -0,0 +1,2565 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + """ + PscanLib contains routines specific for PHOENIX beanmline + + Default initialization + + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Where + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + reads the scan definitio from PHEONIX GUI + + It creates default lists + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + + of format: + {'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': org.python.proxies.__main__$Channel$12@5098c7fe + , 'delay': '0.05' + , 'UsedAlias': 'X07MB-OP2:START-CSMPL' + , 'data_type': 's' + , 'value': '0' + , 'operation': 'put'} + (For action lists) + + For sensors: + + Channel instances are created and added by SC.Create_All_Sensors + + {'channel_name': 'X07MB-OP-MO:E-SET' + , 'Channel': org.python.proxies.__main__$Channel$12@1b37aa1a + , 'Subset_1': True + , 'number': 0 + , 'DTC': False + , 'UsedAlias': 'Energy_set' + , 'data_type': 'ScalarDetector' + , 'alias': 'Energy_set' + , 'operation': 'put'} +are default list as derived from the PHOENIX gui + using + + + + These lists can be easily used in general pshell scans + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions')) + + + """ + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars = get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + self.create_table =create_table + self.append_table =append_table + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + + # Parameter for subset 1 (file for Athena including dead time correction for SDD) + self.names_subset_1 =[] # Names of all sensors and elements to br written to file + # will be created in after_read_dtc in first call + self.types_subset_1 =[] + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + print(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + or ('ICR' in ThisSensor['alias']) + or ('OCR' in ThisSensor['alias']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + + + + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel_rbv'] ############## general g + ,'Id' : 'Energy_set_rbv'}) + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecutes the default list os preactions + TO BE RETIRED FROM CODE + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used fog positioner, sensors and the + various actions (pre, post, detector, etc) + + Expected input + SD[key]=[c1,c2,...,cn] + or + SD[key]=c1 + + with + c={'channel_name' : Strong epics channel + ,'value' : String or number depending on data_type + ,'data_type' : TYPE can be String,Double + ,alias : ALIASSTRING'} + Type = 'String','s','Double','d',Integer','i','Boolean','b','l' + Routine cleans up type definition + 'String' -->'s', + 'double' -->'d' + 'Integer'--> 'i' + 'Boolean' --> 'b' + + Internale adressing + where: + C = self.SD[key][channel_name] + ThisID = self.SD[key][alias] + if alias is nor defined: + ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + C = self.SD[key][i][channel_name] + ThisID = self.SD[key][i][alias] + if alias is nor defined: + ThisID = self.SD[key][i][channel_name] + + + input: + + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + + # clean up typoe defintion + + + + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + # CLean up channel types + print(self.SD[key][i]['data_type']) + if self.SD[key][i]['data_type'].upper() == 'STRING': + self.SD[key][i]['data_type']='s' + #endif + if self.SD[key][i]['data_type'].upper() == 'DOUBLE': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'FLOAT': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'Integer': + self.SD[key][i]['data_type']='i' + #endif + if self.SD[key][i]['data_type'].upper() == 'Boolean': + self.SD[key][i]['data_type']='b' + #endif + print('after type clan up ', self.SD[key][i]['data_type']) + try: + + + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) # ,type=self.SD[key][i]['data_type']) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + + # CLean up channel types + print(self.SD[key]['data_type']) + if self.SD[key]['data_type'].upper() == 'STRING': + self.SD[key]['data_type']='s' + #endif + if self.SD[key]['data_type'].upper() == 'DOUBLE': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'FLOAT': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'Integer': + self.SD[key]['data_type']='i' + #endif + if self.SD[key]['data_type'].upper() == 'Boolean': + self.SD[key]['data_type']='b' + #endif + print('after type clean up', self.SD[key]['data_type']) + + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined channel actions + as defined in list of format + + + [{'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': Channel('X07MB-OP2:START-CSMPL') + , 'delay' + , 'data_type': 's' (STILL WORKING ON THIS, CN WE GET RID OF THIS???? ) + , 'value': '0' + , 'operation': 'put' (or 'putq', 'wait'} + , {},{}....] + + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + are default list as derived from the PHOENIX gui + using + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + + + The definition + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Defines teh geberal scaning + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions') + + can be used. + + + """ + print(' -------------------- PscanLib.DetectorActions '+key) + N_PREACTION = len(self.SD[key]) + #self.pm('..Execut action SD[key] with key') + #self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + self.pm(self.SD[key][i]) + self.pm(self.SD[key][i]['value']) + + if self.SD[key][i]['operation'] == 'put': + #self.pm('... put',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + #self.SD[key][i]['Channel'].put(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + self.pm('... putq',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.caputq(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value']) + self.SD[key][i]['Channel'].putq(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.cawait(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value'],timeout=100) + print('(caget) Value before .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + + print('(.read(Value before .wait_for_value',self.SD[key][i]['Channel'].get(),'wait for', self.SD[key][i]['value']) + + self.pm('time',(self.time.time()-t0)) + try: + self.SD[key][i]['Channel'].wait_for_value(self.SD[key][i]['value']) + except: + # take care of case waitin fails, for example if + # the call to cawait happens to early + print('There is a problem with cawait / .wait_for_channel') + print('wait 10 seconds an then check for value and continue') + self.time.sleep(1) + waiting = True + i_tmp = 0 + while(waiting): + print('use caget ',self.caget(self.SD[key][i]['Channel'])) + print('uses .read',self.SD[key][i]['Channel'].get()) + if self.SD[key][i]['Channel'].read() == self.SD[key][i]['value']: + waiting=False + #endif + i_tmp = i_tmp+1 + if i_tmp == 3: + + waiting=False + #endif + print(' wait 1 second') + time.sleep(1) + #endwhile + print('Value after .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + self.pm('time',self.time.time()-t0) + self.time.sleep(2) + # endif + # endfor + print('........... . total time ACTIONS', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + Routine defined positioner for energy scan as defined in GUI. + + """ + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Settling_time' : '0.1' # , 'Id' : 'FileCountMoench' # , 'V_ini' : g['e_i'][i] # , 'V_final' : g['e_f'][i] # , 'V_delta' : g['e_delta'][i] # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' # , 'Use_done_value' : -1 # } # ) #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + # for calculation ofdeadtime + t0=self.time.time() + print('------------------------------------------------- def after_read_dtc(rec,scan) ') + + self.pm('rec0',rec[0]) + self.pm('rec energy set ',rec['Energy_set']) + self.pm(self.All_Sensors[0]['alias']) + self.pm('rec energy by alias ',rec[self.All_Sensors[0]['alias']]) + + # create header + + + pars = self.get_exec_pars() + self.pm(pars.name) + self.pm(pars.path) + self.pm(self.extract_filename()) + + # generate lists for varioue calulations + + alias_for_dtc = [] # sensor names + alias_for_roi_cps = [] # created names + alias_for_Subset_1 = [] + alias_for_icr = [] + alias_for_ocr = [] + alias_for_ertm = [] + + + t0 = self.time.time() + for i in range(len(self.All_Sensors)): + + # chanels which need dead time correction + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + + # channels which need to to be printed into extracted file as well + if self.All_Sensors[i]['Subset_1']: + alias_for_Subset_1.append(self.All_Sensors[i]['alias']) + #endif + + # Generate list for deadttime correction + # names for TrueICR calulation + if 'ICR' in self.All_Sensors[i]['alias'].upper(): + alias_for_icr.append(self.All_Sensors[i]['alias']) + #endif + + if 'OCR' in self.All_Sensors[i]['alias'].upper(): + alias_for_ocr.append(self.All_Sensors[i]['alias']) + #endif + + if 'ERTM' in self.All_Sensors[i]['alias'].upper(): + alias_for_ertm.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + + self.pm('after sorting names',self.time.time()-t0) + self.pm('alias for deadtime correction') + self.pm(alias_for_dtc) + self.pm('Alias for writing to file (Subset_1)') + self.pm(alias_for_Subset_1) + self.pm('Alias for ICR') + self.pm(alias_for_icr) + self.pm('Alias for OCR') + self.pm(alias_for_ocr) + self.pm('Alias for ERTM') + self.pm(alias_for_ertm) + + self.pm('time to create lists..',self.time.time()-t0) + + + # calculate icr/OCR*ertm for all SDD detectors in list + # + + icr_div_ocr_div_ertm=[] + for i in range(len(alias_for_icr)): + self.pm('DETECOR Nr ',i) + self.pm(rec[alias_for_icr[i]]) + self.pm(rec[alias_for_ocr[i]]) + self.pm(rec[alias_for_ertm[i]]) + try: + icr_div_ocr_div_ertm.append(rec[alias_for_icr[i]]/rec[alias_for_ocr[i]]/rec[alias_for_ertm[i]]) + except: + if rec[alias_for_ocr[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + if rec[alias_for_ertm[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + icr_div_ocr_div_ertm.append(-1.0) + #endelse + #endelse + #endexcept + # Missing call to trueICR + # + #endfor + self.pm(icr_div_ocr_div_ertm) + + # now walk through all detectors to be saved into file + # create header names and + + + #table = [ [1,2,3], + # [2,3,4], + # [3,4,5,] ] + + + # First create the list + path_extracted = "extracted/"+self.extract_filename() + + # walk through all subset for saving as listed in list alias_for_SubSet_1 + i_full=-1 + values =[] + for i in range(len(alias_for_Subset_1)): + if rec.index == 0: # first run only to create header for data set + if i==0: + self.names_subset_1 = [] + self.types_subset_1 = [] + + #endif + self.names_subset_1.append(alias_for_Subset_1[i]) + self.types_subset_1.append('d') + # make_dtc.append(False) + #endif + values.append(rec[alias_for_Subset_1[i]]) + i_full=i_full+1 + self.pm(i) + if alias_for_Subset_1[i] in alias_for_dtc: + # now we know this sensor needs dead time correction + self.pm('add dtc') + self.pm(i,i_full) + if rec.index == 0: # first runonly to create header for data set + self.names_subset_1.append(alias_for_Subset_1[i]+'_cps') + self.types_subset_1.append('d') + #endif + # now add data for dead time correction distinguish 4 cases + # for four detectors + self.pm(self.names_subset_1[i]) + self.pm(alias_for_Subset_1[i]) + if 'D1_' == self.names_subset_1[i][0:3]: + #self.pm('D_1') + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[0] ) + #self.pm('D_1 after ') + #endif + + if 'D2_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[1] ) + #endif + + if 'D3_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[2] ) + #endif + + if 'D4_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[3] ) + #endif + + i_full=i_full+1 + self.pm('.. after ifs... ') + # endif + #self.pm(i,alias_for_Subset_1[i],names[i_full],types[i_full]) + # endfor + + for i in range(len(self.names_subset_1)): + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + + # catch case for gain o KEithleygain, which give string + # of shape '1^3'as result + # + if ((type(values[i]) == unicode) or type(values[i]) == str) and ('_GAIN' in self.names_subset_1[i]) : + values[i] = float(values[i][3:4]) + self.types_subset_1[i] = "d" + #endif + + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + # endif + #endfor + if rec.index == 0: # first run only to create header for data set + self.create_table(path_extracted,self.names_subset_1,self.types_subset_1) + #endif + + + self.append_table(path_extracted,values) + + print('__________________________ time for dtc routine',self.time.time()-t0) + + return + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.py new file mode 100644 index 0000000..25d0a4c --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_Pscan.py @@ -0,0 +1,3901 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles): + """ + create input for energy scans for pshell + rscan and + vector scan + + """ + + # case I inout for rscan, this is only for + + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + # case II create input for vector scan, by creating explicitly every data point and the integration time + # this will be used to the EXAFS scans + + Energy_Scan_Positions=[] + for i in range(len(e_i)): # walk through the differen regions + This_Energy = e_i[i] + i_reg=0 + while (This_Energy < e_f[i]): + + This_Energy = e_i[i]+ float(e_delta[i])*i_reg + This_Cycle = e_n_cycles[i] + Energy_Scan_Positions.append([This_Energy,This_Cycle]) + i_reg=i_reg+1 + print(i_reg,This_Energy,This_Cycle) + #endwhile + #endfor + + + return Energy_Ranges,Energy_Cycles,Energy_Scan_Positions + + + + +def get_channels(scan_type): + + """ + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + """ + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + hardware_sdd='NoSDD' + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + + # ask for SITORO 2nd to make itr the dominat choice + if get_epicsPV(beamline+'-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + + if hardware_sdd != 'NoSDD': + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + else: + ch_base_vortex = 'NoSDD' + ch_base_vortex_mca = 'NoSDD' + ch_base_vortex_dxp = 'NoSDD' + # endelse + print( ch_base_vortex) + print( ch_base_vortex_mca) + print( ch_base_vortex_dxp) + print(hardware_sdd) + + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dummy WHY NOT use [] ???????? + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if (1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM'))) and (hardware_sdd !='NoSDD'): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')) and (hardware_sdd !='NoSDD'): + detectors.append('ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')) and (hardware_sdd !='NoSDD'): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')) and (hardware_sdd !='NoSDD') and 'Vortex' in detectors: + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')) and (hardware_sdd !='NoSDD') and 'ROENTEC_XMAP' in detectors: + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')) and (hardware_sdd !='NoSDD') and 'KETEK_XMAP' in detectors: + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : 0 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : 1.0 + ,'operation' : 'put' + ,'data_type' : 'Double' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.030' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.075' } # fda 0.075 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.00' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list +# Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges,Energy_Cycles,Energy_Scan_Positions = Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles) + + #Energy_Ranges=[] + #Energy_Cycles=[] + + #for i in range(len(e_i)): + # Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + # Energy_Cycles.append(e_n_cycles[i]) + #endfor + + + + + + + + + + + + + + + + + + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'Energy_Scan_Positions' : Energy_Scan_Positions + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_lib.py new file mode 100644 index 0000000..616b376 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200731_165246/X_X07MB_lib.py @@ -0,0 +1,2619 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + """ + PscanLib contains routines specific for PHOENIX beanmline + + Default initialization + + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Where + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + reads the scan definitio from PHEONIX GUI + + It creates default lists + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + + of format: + {'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': org.python.proxies.__main__$Channel$12@5098c7fe + , 'delay': '0.05' + , 'UsedAlias': 'X07MB-OP2:START-CSMPL' + , 'data_type': 's' + , 'value': '0' + , 'operation': 'put'} + (For action lists) + + For sensors: + + Channel instances are created and added by SC.Create_All_Sensors + + {'channel_name': 'X07MB-OP-MO:E-SET' + , 'Channel': org.python.proxies.__main__$Channel$12@1b37aa1a + , 'Subset_1': True + , 'number': 0 + , 'DTC': False + , 'UsedAlias': 'Energy_set' + , 'data_type': 'ScalarDetector' + , 'alias': 'Energy_set' + , 'operation': 'put'} +are default list as derived from the PHOENIX gui + using + + + + These lists can be easily used in general pshell scans + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions')) + + + """ + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars = get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + self.create_table =create_table + self.append_table =append_table + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + self.timeout = 10 # currently timtout set to 10 sec. Need to adapt to real dwell time, for Moench we will have lnger times + + # Parameter for subset 1 (file for Athena including dead time correction for SDD) + self.names_subset_1 =[] # Names of all sensors and elements to br written to file + # will be created in after_read_dtc in first call + self.types_subset_1 =[] + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + """ + routine allows to add a sensor to default list from guot + syntax: + Add_New_Sensor({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + TO DO: + + + MISSING DOES NOT ADD KEYS FOR SUBSET< DTC ETYC + TO BE MERGES WITH add_new_det_to_list() + + """ + + self.pm(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + Routine adds default keys based on sensor names for subset_a for + separate file saving in Athenae format and for dead time correction + + + Syntax + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + or ('ICR' in ThisSensor['alias']) + or ('OCR' in ThisSensor['alias']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + + + + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel_rbv'] ############## general g + ,'Id' : 'Energy_set_rbv'}) + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecutes the default list os preactions + TO BE RETIRED FROM CODE + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used fog positioner, sensors and the + various actions (pre, post, detector, etc) + + Expected input + SD[key]=[c1,c2,...,cn] + or + SD[key]=c1 + + with + c={'channel_name' : Strong epics channel + ,'value' : String or number depending on data_type + ,'data_type' : TYPE can be String,Double + ,alias : ALIASSTRING'} + Type = 'String','s','Double','d',Integer','i','Boolean','b','l' + Routine cleans up type definition + 'String' -->'s', + 'double' -->'d' + 'Integer'--> 'i' + 'Boolean' --> 'b' + + Internale adressing + where: + C = self.SD[key][channel_name] + ThisID = self.SD[key][alias] + if alias is nor defined: + ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + C = self.SD[key][i][channel_name] + ThisID = self.SD[key][i][alias] + if alias is nor defined: + ThisID = self.SD[key][i][channel_name] + + + input: + + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + + # clean up typoe defintion + + + + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + # CLean up channel types + print(self.SD[key][i]['data_type']) + if self.SD[key][i]['data_type'].upper() == 'STRING': + self.SD[key][i]['data_type']='s' + #endif + if self.SD[key][i]['data_type'].upper() == 'DOUBLE': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'FLOAT': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'Integer': + self.SD[key][i]['data_type']='i' + #endif + if self.SD[key][i]['data_type'].upper() == 'Boolean': + self.SD[key][i]['data_type']='b' + #endif + print('after type clan up ', self.SD[key][i]['data_type']) + try: + + + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) # ,type=self.SD[key][i]['data_type']) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + + # CLean up channel types + print(self.SD[key]['data_type']) + if self.SD[key]['data_type'].upper() == 'STRING': + self.SD[key]['data_type']='s' + #endif + if self.SD[key]['data_type'].upper() == 'DOUBLE': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'FLOAT': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'Integer': + self.SD[key]['data_type']='i' + #endif + if self.SD[key]['data_type'].upper() == 'Boolean': + self.SD[key]['data_type']='b' + #endif + print('after type clean up', self.SD[key]['data_type']) + + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined channel actions + as defined in list of format + + + [{'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': Channel('X07MB-OP2:START-CSMPL') + , 'delay' + , 'data_type': 's' (STILL WORKING ON THIS, CN WE GET RID OF THIS???? ) + , 'value': '0' + , 'operation': 'put' (or 'putq', 'wait'} + , {},{}....] + + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + are default list as derived from the PHOENIX gui + using + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + + + The definition + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Defines teh geberal scaning + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions') + + can be used. + + + """ + print(' -------------------- PscanLib.DetectorActions '+key) + N_PREACTION = len(self.SD[key]) + #self.pm('..Execut action SD[key] with key') + #self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + self.pm(self.SD[key][i]) + self.pm(self.SD[key][i]['value']) + + if self.SD[key][i]['operation'] == 'put': + #self.pm('... put',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + #self.SD[key][i]['Channel'].put(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + self.pm('... putq',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.caputq(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value']) + self.SD[key][i]['Channel'].putq(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.cawait(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value'],timeout=100) + print('(caget) Value before .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + + # print('(.read(Value before .wait_for_value',self.SD[key][i]['Channel'].get(),'wait for', self.SD[key][i]['value']) + + self.pm('time',(self.time.time()-t0)) + try: + #self.SD[key][i]['Channel'].wait_for_value(self.SD[key][i]['value'],timeout=self.timeout) + self.cawait(self.SD[key][i]['channel_name'], self.SD[key][i]['value'],timeout=self.timeout) + except: + # take care of case waitin fails, for example if + # the call to cawait happens to early + print('There is a problem with cawait / .wait_for_channel') + print('wait 10 seconds an then check for value and continue') + self.time.sleep(1) + waiting = True + i_tmp = 0 + while(waiting): + print('use caget ',self.caget(self.SD[key][i]['channel_name'])) + #print('uses .read',self.SD[key][i]['Channel'].get()) + if self.SD[key][i]['Channel'].read() == self.SD[key][i]['value']: + waiting=False + #endif + i_tmp = i_tmp+1 + if i_tmp == 3: + + waiting=False + #endif + print(' wait 1 second') + self.time.sleep(1) + #endwhile + print('Value after .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + self.pm('time',self.time.time()-t0) + self.time.sleep(2) + # endif + # endfor + print('........... . total time ACTIONS', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + + Routine defined positioner for energy scan as defined in GUI. + + + """ + print(' def PositionerEnergyScan(self)') + stop + + + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Settling_time' : '0.1' + # , 'Id' : 'FileCountMoench' + # , 'V_ini' : g['e_i'][i] + # , 'V_final' : g['e_f'][i] + # , 'V_delta' : g['e_delta'][i] + + # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Use_done_value' : -1 + # } + # ) + #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + # for calculation ofdeadtime + t0=self.time.time() + print('------------------------------------------------- def after_read_dtc(rec,scan) ') + + self.pm('rec0',rec[0]) + self.pm('rec energy set ',rec['Energy_set']) + self.pm(self.All_Sensors[0]['alias']) + self.pm('rec energy by alias ',rec[self.All_Sensors[0]['alias']]) + + # create header + + + pars = self.get_exec_pars() + self.pm(pars.name) + self.pm(pars.path) + self.pm(self.extract_filename()) + + # generate lists for varioue calulations + + alias_for_dtc = [] # sensor names + alias_for_roi_cps = [] # created names + alias_for_Subset_1 = [] + alias_for_icr = [] + alias_for_ocr = [] + alias_for_ertm = [] + + + t0 = self.time.time() + for i in range(len(self.All_Sensors)): + + # chanels which need dead time correction + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + + # channels which need to to be printed into extracted file as well + if self.All_Sensors[i]['Subset_1']: + alias_for_Subset_1.append(self.All_Sensors[i]['alias']) + #endif + + # Generate list for deadttime correction + # names for TrueICR calulation + if 'ICR' in self.All_Sensors[i]['alias'].upper(): + alias_for_icr.append(self.All_Sensors[i]['alias']) + #endif + + if 'OCR' in self.All_Sensors[i]['alias'].upper(): + alias_for_ocr.append(self.All_Sensors[i]['alias']) + #endif + + if 'ERTM' in self.All_Sensors[i]['alias'].upper(): + alias_for_ertm.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + + self.pm('after sorting names',self.time.time()-t0) + self.pm('alias for deadtime correction') + self.pm(alias_for_dtc) + self.pm('Alias for writing to file (Subset_1)') + self.pm(alias_for_Subset_1) + self.pm('Alias for ICR') + self.pm(alias_for_icr) + self.pm('Alias for OCR') + self.pm(alias_for_ocr) + self.pm('Alias for ERTM') + self.pm(alias_for_ertm) + + self.pm('time to create lists..',self.time.time()-t0) + + + # calculate icr/OCR*ertm for all SDD detectors in list + # + + icr_div_ocr_div_ertm=[] + for i in range(len(alias_for_icr)): + self.pm('DETECOR Nr ',i) + self.pm(rec[alias_for_icr[i]]) + self.pm(rec[alias_for_ocr[i]]) + self.pm(rec[alias_for_ertm[i]]) + try: + icr_div_ocr_div_ertm.append(rec[alias_for_icr[i]]/rec[alias_for_ocr[i]]/rec[alias_for_ertm[i]]) + except: + if rec[alias_for_ocr[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + if rec[alias_for_ertm[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + icr_div_ocr_div_ertm.append(-1.0) + #endelse + #endelse + #endexcept + # Missing call to trueICR + # + #endfor + self.pm(icr_div_ocr_div_ertm) + + # now walk through all detectors to be saved into file + # create header names and + + + #table = [ [1,2,3], + # [2,3,4], + # [3,4,5,] ] + + + # First create the list + path_extracted = "extracted/"+self.extract_filename() + + # walk through all subset for saving as listed in list alias_for_SubSet_1 + i_full=-1 + values =[] + for i in range(len(alias_for_Subset_1)): + if rec.index == 0: # first run only to create header for data set + if i==0: + self.names_subset_1 = [] + self.types_subset_1 = [] + + #endif + self.names_subset_1.append(alias_for_Subset_1[i]) + self.types_subset_1.append('d') + # make_dtc.append(False) + #endif + values.append(rec[alias_for_Subset_1[i]]) + i_full=i_full+1 + self.pm(i) + if alias_for_Subset_1[i] in alias_for_dtc: + # now we know this sensor needs dead time correction + self.pm('add dtc') + self.pm(i,i_full) + if rec.index == 0: # first runonly to create header for data set + self.names_subset_1.append(alias_for_Subset_1[i]+'_cps') + self.types_subset_1.append('d') + #endif + # now add data for dead time correction distinguish 4 cases + # for four detectors + self.pm(self.names_subset_1[i]) + self.pm(alias_for_Subset_1[i]) + if 'D1_' == self.names_subset_1[i][0:3]: + #self.pm('D_1') + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[0] ) + #self.pm('D_1 after ') + #endif + + if 'D2_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[1] ) + #endif + + if 'D3_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[2] ) + #endif + + if 'D4_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[3] ) + #endif + + i_full=i_full+1 + self.pm('.. after ifs... ') + # endif + #self.pm(i,alias_for_Subset_1[i],names[i_full],types[i_full]) + # endfor + + for i in range(len(self.names_subset_1)): + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + + # catch case for gain o KEithleygain, which give string + # of shape '1^3'as result + # + if ((type(values[i]) == unicode) or type(values[i]) == str) and ('_GAIN' in self.names_subset_1[i]) : + values[i] = float(values[i][3:4]) + self.types_subset_1[i] = "d" + #endif + + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + # endif + #endfor + if rec.index == 0: # first run only to create header for data set + self.create_table(path_extracted,self.names_subset_1,self.types_subset_1) + #endif + + + self.append_table(path_extracted,values) + + print('__________________________ time for dtc routine',self.time.time()-t0) + + return + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.py new file mode 100644 index 0000000..25d0a4c --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_Pscan.py @@ -0,0 +1,3901 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles): + """ + create input for energy scans for pshell + rscan and + vector scan + + """ + + # case I inout for rscan, this is only for + + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + # case II create input for vector scan, by creating explicitly every data point and the integration time + # this will be used to the EXAFS scans + + Energy_Scan_Positions=[] + for i in range(len(e_i)): # walk through the differen regions + This_Energy = e_i[i] + i_reg=0 + while (This_Energy < e_f[i]): + + This_Energy = e_i[i]+ float(e_delta[i])*i_reg + This_Cycle = e_n_cycles[i] + Energy_Scan_Positions.append([This_Energy,This_Cycle]) + i_reg=i_reg+1 + print(i_reg,This_Energy,This_Cycle) + #endwhile + #endfor + + + return Energy_Ranges,Energy_Cycles,Energy_Scan_Positions + + + + +def get_channels(scan_type): + + """ + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + """ + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + hardware_sdd='NoSDD' + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + + # ask for SITORO 2nd to make itr the dominat choice + if get_epicsPV(beamline+'-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + + if hardware_sdd != 'NoSDD': + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + else: + ch_base_vortex = 'NoSDD' + ch_base_vortex_mca = 'NoSDD' + ch_base_vortex_dxp = 'NoSDD' + # endelse + print( ch_base_vortex) + print( ch_base_vortex_mca) + print( ch_base_vortex_dxp) + print(hardware_sdd) + + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dummy WHY NOT use [] ???????? + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if (1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM'))) and (hardware_sdd !='NoSDD'): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')) and (hardware_sdd !='NoSDD'): + detectors.append('ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')) and (hardware_sdd !='NoSDD'): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')) and (hardware_sdd !='NoSDD') and 'Vortex' in detectors: + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')) and (hardware_sdd !='NoSDD') and 'ROENTEC_XMAP' in detectors: + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')) and (hardware_sdd !='NoSDD') and 'KETEK_XMAP' in detectors: + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : 0 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : 1.0 + ,'operation' : 'put' + ,'data_type' : 'Double' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.030' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.075' } # fda 0.075 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.00' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list +# Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges,Energy_Cycles,Energy_Scan_Positions = Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles) + + #Energy_Ranges=[] + #Energy_Cycles=[] + + #for i in range(len(e_i)): + # Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + # Energy_Cycles.append(e_n_cycles[i]) + #endfor + + + + + + + + + + + + + + + + + + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'Energy_Scan_Positions' : Energy_Scan_Positions + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_lib.py new file mode 100644 index 0000000..616b376 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200802_181409/X_X07MB_lib.py @@ -0,0 +1,2619 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + """ + PscanLib contains routines specific for PHOENIX beanmline + + Default initialization + + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Where + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + reads the scan definitio from PHEONIX GUI + + It creates default lists + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + + of format: + {'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': org.python.proxies.__main__$Channel$12@5098c7fe + , 'delay': '0.05' + , 'UsedAlias': 'X07MB-OP2:START-CSMPL' + , 'data_type': 's' + , 'value': '0' + , 'operation': 'put'} + (For action lists) + + For sensors: + + Channel instances are created and added by SC.Create_All_Sensors + + {'channel_name': 'X07MB-OP-MO:E-SET' + , 'Channel': org.python.proxies.__main__$Channel$12@1b37aa1a + , 'Subset_1': True + , 'number': 0 + , 'DTC': False + , 'UsedAlias': 'Energy_set' + , 'data_type': 'ScalarDetector' + , 'alias': 'Energy_set' + , 'operation': 'put'} +are default list as derived from the PHOENIX gui + using + + + + These lists can be easily used in general pshell scans + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions')) + + + """ + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars = get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + self.create_table =create_table + self.append_table =append_table + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + self.timeout = 10 # currently timtout set to 10 sec. Need to adapt to real dwell time, for Moench we will have lnger times + + # Parameter for subset 1 (file for Athena including dead time correction for SDD) + self.names_subset_1 =[] # Names of all sensors and elements to br written to file + # will be created in after_read_dtc in first call + self.types_subset_1 =[] + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + """ + routine allows to add a sensor to default list from guot + syntax: + Add_New_Sensor({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + TO DO: + + + MISSING DOES NOT ADD KEYS FOR SUBSET< DTC ETYC + TO BE MERGES WITH add_new_det_to_list() + + """ + + self.pm(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + Routine adds default keys based on sensor names for subset_a for + separate file saving in Athenae format and for dead time correction + + + Syntax + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + or ('ICR' in ThisSensor['alias']) + or ('OCR' in ThisSensor['alias']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + + + + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel_rbv'] ############## general g + ,'Id' : 'Energy_set_rbv'}) + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecutes the default list os preactions + TO BE RETIRED FROM CODE + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used fog positioner, sensors and the + various actions (pre, post, detector, etc) + + Expected input + SD[key]=[c1,c2,...,cn] + or + SD[key]=c1 + + with + c={'channel_name' : Strong epics channel + ,'value' : String or number depending on data_type + ,'data_type' : TYPE can be String,Double + ,alias : ALIASSTRING'} + Type = 'String','s','Double','d',Integer','i','Boolean','b','l' + Routine cleans up type definition + 'String' -->'s', + 'double' -->'d' + 'Integer'--> 'i' + 'Boolean' --> 'b' + + Internale adressing + where: + C = self.SD[key][channel_name] + ThisID = self.SD[key][alias] + if alias is nor defined: + ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + C = self.SD[key][i][channel_name] + ThisID = self.SD[key][i][alias] + if alias is nor defined: + ThisID = self.SD[key][i][channel_name] + + + input: + + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + + # clean up typoe defintion + + + + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + # CLean up channel types + print(self.SD[key][i]['data_type']) + if self.SD[key][i]['data_type'].upper() == 'STRING': + self.SD[key][i]['data_type']='s' + #endif + if self.SD[key][i]['data_type'].upper() == 'DOUBLE': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'FLOAT': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'Integer': + self.SD[key][i]['data_type']='i' + #endif + if self.SD[key][i]['data_type'].upper() == 'Boolean': + self.SD[key][i]['data_type']='b' + #endif + print('after type clan up ', self.SD[key][i]['data_type']) + try: + + + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) # ,type=self.SD[key][i]['data_type']) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + + # CLean up channel types + print(self.SD[key]['data_type']) + if self.SD[key]['data_type'].upper() == 'STRING': + self.SD[key]['data_type']='s' + #endif + if self.SD[key]['data_type'].upper() == 'DOUBLE': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'FLOAT': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'Integer': + self.SD[key]['data_type']='i' + #endif + if self.SD[key]['data_type'].upper() == 'Boolean': + self.SD[key]['data_type']='b' + #endif + print('after type clean up', self.SD[key]['data_type']) + + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined channel actions + as defined in list of format + + + [{'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': Channel('X07MB-OP2:START-CSMPL') + , 'delay' + , 'data_type': 's' (STILL WORKING ON THIS, CN WE GET RID OF THIS???? ) + , 'value': '0' + , 'operation': 'put' (or 'putq', 'wait'} + , {},{}....] + + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + are default list as derived from the PHOENIX gui + using + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + + + The definition + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Defines teh geberal scaning + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions') + + can be used. + + + """ + print(' -------------------- PscanLib.DetectorActions '+key) + N_PREACTION = len(self.SD[key]) + #self.pm('..Execut action SD[key] with key') + #self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + self.pm(self.SD[key][i]) + self.pm(self.SD[key][i]['value']) + + if self.SD[key][i]['operation'] == 'put': + #self.pm('... put',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + #self.SD[key][i]['Channel'].put(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + self.pm('... putq',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.caputq(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value']) + self.SD[key][i]['Channel'].putq(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.cawait(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value'],timeout=100) + print('(caget) Value before .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + + # print('(.read(Value before .wait_for_value',self.SD[key][i]['Channel'].get(),'wait for', self.SD[key][i]['value']) + + self.pm('time',(self.time.time()-t0)) + try: + #self.SD[key][i]['Channel'].wait_for_value(self.SD[key][i]['value'],timeout=self.timeout) + self.cawait(self.SD[key][i]['channel_name'], self.SD[key][i]['value'],timeout=self.timeout) + except: + # take care of case waitin fails, for example if + # the call to cawait happens to early + print('There is a problem with cawait / .wait_for_channel') + print('wait 10 seconds an then check for value and continue') + self.time.sleep(1) + waiting = True + i_tmp = 0 + while(waiting): + print('use caget ',self.caget(self.SD[key][i]['channel_name'])) + #print('uses .read',self.SD[key][i]['Channel'].get()) + if self.SD[key][i]['Channel'].read() == self.SD[key][i]['value']: + waiting=False + #endif + i_tmp = i_tmp+1 + if i_tmp == 3: + + waiting=False + #endif + print(' wait 1 second') + self.time.sleep(1) + #endwhile + print('Value after .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + self.pm('time',self.time.time()-t0) + self.time.sleep(2) + # endif + # endfor + print('........... . total time ACTIONS', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + + Routine defined positioner for energy scan as defined in GUI. + + + """ + print(' def PositionerEnergyScan(self)') + stop + + + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Settling_time' : '0.1' + # , 'Id' : 'FileCountMoench' + # , 'V_ini' : g['e_i'][i] + # , 'V_final' : g['e_f'][i] + # , 'V_delta' : g['e_delta'][i] + + # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Use_done_value' : -1 + # } + # ) + #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + # for calculation ofdeadtime + t0=self.time.time() + print('------------------------------------------------- def after_read_dtc(rec,scan) ') + + self.pm('rec0',rec[0]) + self.pm('rec energy set ',rec['Energy_set']) + self.pm(self.All_Sensors[0]['alias']) + self.pm('rec energy by alias ',rec[self.All_Sensors[0]['alias']]) + + # create header + + + pars = self.get_exec_pars() + self.pm(pars.name) + self.pm(pars.path) + self.pm(self.extract_filename()) + + # generate lists for varioue calulations + + alias_for_dtc = [] # sensor names + alias_for_roi_cps = [] # created names + alias_for_Subset_1 = [] + alias_for_icr = [] + alias_for_ocr = [] + alias_for_ertm = [] + + + t0 = self.time.time() + for i in range(len(self.All_Sensors)): + + # chanels which need dead time correction + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + + # channels which need to to be printed into extracted file as well + if self.All_Sensors[i]['Subset_1']: + alias_for_Subset_1.append(self.All_Sensors[i]['alias']) + #endif + + # Generate list for deadttime correction + # names for TrueICR calulation + if 'ICR' in self.All_Sensors[i]['alias'].upper(): + alias_for_icr.append(self.All_Sensors[i]['alias']) + #endif + + if 'OCR' in self.All_Sensors[i]['alias'].upper(): + alias_for_ocr.append(self.All_Sensors[i]['alias']) + #endif + + if 'ERTM' in self.All_Sensors[i]['alias'].upper(): + alias_for_ertm.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + + self.pm('after sorting names',self.time.time()-t0) + self.pm('alias for deadtime correction') + self.pm(alias_for_dtc) + self.pm('Alias for writing to file (Subset_1)') + self.pm(alias_for_Subset_1) + self.pm('Alias for ICR') + self.pm(alias_for_icr) + self.pm('Alias for OCR') + self.pm(alias_for_ocr) + self.pm('Alias for ERTM') + self.pm(alias_for_ertm) + + self.pm('time to create lists..',self.time.time()-t0) + + + # calculate icr/OCR*ertm for all SDD detectors in list + # + + icr_div_ocr_div_ertm=[] + for i in range(len(alias_for_icr)): + self.pm('DETECOR Nr ',i) + self.pm(rec[alias_for_icr[i]]) + self.pm(rec[alias_for_ocr[i]]) + self.pm(rec[alias_for_ertm[i]]) + try: + icr_div_ocr_div_ertm.append(rec[alias_for_icr[i]]/rec[alias_for_ocr[i]]/rec[alias_for_ertm[i]]) + except: + if rec[alias_for_ocr[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + if rec[alias_for_ertm[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + icr_div_ocr_div_ertm.append(-1.0) + #endelse + #endelse + #endexcept + # Missing call to trueICR + # + #endfor + self.pm(icr_div_ocr_div_ertm) + + # now walk through all detectors to be saved into file + # create header names and + + + #table = [ [1,2,3], + # [2,3,4], + # [3,4,5,] ] + + + # First create the list + path_extracted = "extracted/"+self.extract_filename() + + # walk through all subset for saving as listed in list alias_for_SubSet_1 + i_full=-1 + values =[] + for i in range(len(alias_for_Subset_1)): + if rec.index == 0: # first run only to create header for data set + if i==0: + self.names_subset_1 = [] + self.types_subset_1 = [] + + #endif + self.names_subset_1.append(alias_for_Subset_1[i]) + self.types_subset_1.append('d') + # make_dtc.append(False) + #endif + values.append(rec[alias_for_Subset_1[i]]) + i_full=i_full+1 + self.pm(i) + if alias_for_Subset_1[i] in alias_for_dtc: + # now we know this sensor needs dead time correction + self.pm('add dtc') + self.pm(i,i_full) + if rec.index == 0: # first runonly to create header for data set + self.names_subset_1.append(alias_for_Subset_1[i]+'_cps') + self.types_subset_1.append('d') + #endif + # now add data for dead time correction distinguish 4 cases + # for four detectors + self.pm(self.names_subset_1[i]) + self.pm(alias_for_Subset_1[i]) + if 'D1_' == self.names_subset_1[i][0:3]: + #self.pm('D_1') + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[0] ) + #self.pm('D_1 after ') + #endif + + if 'D2_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[1] ) + #endif + + if 'D3_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[2] ) + #endif + + if 'D4_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[3] ) + #endif + + i_full=i_full+1 + self.pm('.. after ifs... ') + # endif + #self.pm(i,alias_for_Subset_1[i],names[i_full],types[i_full]) + # endfor + + for i in range(len(self.names_subset_1)): + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + + # catch case for gain o KEithleygain, which give string + # of shape '1^3'as result + # + if ((type(values[i]) == unicode) or type(values[i]) == str) and ('_GAIN' in self.names_subset_1[i]) : + values[i] = float(values[i][3:4]) + self.types_subset_1[i] = "d" + #endif + + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + # endif + #endfor + if rec.index == 0: # first run only to create header for data set + self.create_table(path_extracted,self.names_subset_1,self.types_subset_1) + #endif + + + self.append_table(path_extracted,values) + + print('__________________________ time for dtc routine',self.time.time()-t0) + + return + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + #print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'Data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.075' } + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'Data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'Data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'Data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list + Energies=[] + + # First generate regions, as uses for pshell scan definitions + EnergyRanges=[] + EnergyCycles=[] + + for i in range(len(e_i)): + EnergyRanges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + EnergyCycles.append(e_n_cycles[i]) + #endfor + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'EnergyRanges' : EnergyRanges + ,'EnergyCycles' : EnergyCycles + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner=\ + {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Confguration=[\ + { 'scan_type' : scan_type}] + + + + box={ 'filename' : filename + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'EnergyScan' : EnergyScan + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.backup.py b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.backup.py new file mode 100644 index 0000000..04d5bd6 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.backup.py @@ -0,0 +1,3664 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + print ch_rbv + print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + print(channel) + b=epicsPV(channel).getw() + print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel type + + +def post_action_channel_action(channel,value,operation,type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'Channel' : 'ACOAU-ACCU:OP-MODE' + ,'Value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + + + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'Data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def get_channels(scan_type): + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + #endif + print( get_epicsPV('X07MB-PC-PSCAN:XMAP')) + + # ask for SITORO 2nd to make itr the dominat choice + #print get_epicsPV('X07MB-PC-PSCAN:SITORO') + #print type(get_epicsPV('X07MB-PC-PSCAN:SITORO')) + #sdfgjha + + if get_epicsPV('X07MB-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dumma + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM')): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')): + detectors.append('ROENTEC_XMAP') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')): + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')): + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')): + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REABGE CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + + + + + + + # Now read also the parameters for the region with non equi distant energy spacing + + + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + print 'next found ' + print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + print CH_User_detector + print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + p_done.append(p_done_full[i]) + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print p_data + #print p_done + #print p_done_switch + + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + print r_energies + print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel' : 'X07MB-OP2:START-CSMPL','value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : '2' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel' : 'X07MB-OP2:SMPL' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.7'} + + + preaction_5={'channel' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'Channel' : 'X07MB-XMAP:EraseStart' + # ,'Value' : '1' + # ,'Operation' : 'putq' + # ,'Data_type' : 'String' + # ,'Delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'Channel' : ch_base_vortex+':EraseStart' + ,'Value' : '1' + ,'Operation' : 'putq' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_2 = { 'Channel' : 'X07MB-OP2:SMPL' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.075' } + + detector_action_3 = { 'Channel' : 'X07MB-OP2:SMPL-DONE' + ,'Value' : '1' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.03' } + # old until 15.1.2020 + #detector_action_4 = { 'Channel' : 'X07MB-XMAP:StopAll' + # ,'Value' : '1' + # ,'Operation' : 'put' + # ,'Data_type' : 'String' + # ,'Delay' : '0.05' } + + detector_action_4 = { 'Channel' : ch_base_vortex+':StopAll' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.05' } + + + detector_action_moench_aquire = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '1' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.5' } + + detector_action_moench_wait = { 'Channel' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'Value' : '0' + ,'Operation' : 'wait' + ,'Data_type' : 'Integer' + ,'Delay' : '0.3' } + + detector_action_MO_ID_Off={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : ' ' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + detector_action_MO_ID_on={'Channel' : 'X07MB-OP-MO:E-SET.OUT' + ,'Value' : 'X07MA-ID:ENERGY NPP NMS' + ,'Operation' : 'put' + ,'Data_type' : 'String' + ,'Delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + #print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + #print 'next found ' + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + box={ 'filename' : filename + , 'beamline' : beamline + , 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'preactions' : preactions + , 'detector_actions' : detector_actions + , 'scan_type' : scan_type + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : 'X07MB-OP-MO:E-GET' + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + + print box + print detectors + print('preactions') + print preactions + + + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.py b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.py new file mode 100644 index 0000000..25d0a4c --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_Pscan.py @@ -0,0 +1,3901 @@ +#!/usr/bin/env python +# +# Main library for PHOENIX DAQ gui +# +# written by Thomas Huthwelker 2011- +# +# ........... other helping rouintes +# Changes +# +# 2.12.2014 Add Ketek as a additional Fluorescence detector option (This is a detctor which uses only channel 2) (T.Huthwelker) +# +# 16.3.2015 Get some bugs out of software (T.Huthwelker) +# +# 16.3.2015 implenet Ketek propoerly now also for imaging (T.Huthwelker) +# +# 10.10.2015 +# d_list_fluo =[-1] changed 10.10. Need to give initial definition for d_list_fluo, +# as it will remain undefined of no Fluo detector is used. +# Define channel -1 as number for no fluo detector ' +# +# 1.11.2015 +# add INstall changes from 10.10.2015 +# extend predefeind detector group for Mono encoders by adding values for T1, T2, Theta and +# monitoring the differences values and encoder positions (field val,rbv,diff, rep), and voltages from LVDT +# decrease delay for all preactions to 50 ms ste delays in detector DAQ to 75 ms (100 before) to be tested. +# +# 28.8.2017 put call to writing of header into backgournd preocess tro speed up measurements + + +# ........... other helping rouintes + +import math +import time + +import os +from CaChannel import * +from epicsMotor import * +from epicsPV import * +import time +import string + + +class DefineScan: + # This class restored scann definition + # as full class + + + + def __init__(self,SD): + """ + input is old list from routinf get_channels + Aim is to make scan definition in a more structured way + + ABANDONED AS REFORMATING REQUIRES TOO MUCH CHANGES IN EXISTING CODE + KEEP LIST APPROACH + + """ + + self.filename=SD['filename'] + self.description = 'Description' + #self.description.filename=self.filename + self.All_Positioner=SD['All_Positioner'] + self.EnergyScan=SD['EnergyScan'] + self.preactions=SD['preactions'] + self.detector_actions=SD['detector_actions'] + + + + # Create an enty with list of mai keys + #endef +#endclass + +def create_rbv_val(ch): + ll=len(ch) + print ll + print ch[ll-4:ll] + extension=ch[ll-4:ll] + if extension == ".RBV": + ch_rbv = ch + ch_val = ch[0:ll-4]+".VAL" + #print 'Channel has extension .rbv' + if extension == ".VAL": + ch_rbv = ch[0:ll-4]+".RBV" + ch_val = ch + #print 'Channel has extension .VAL' + + if (extension <> ".VAL") and (extension <> ".RBV"): + ch_rbv = ch + ch_val = ch + #print 'Channel has no extension, used chanel as it is for .VAl and .RBV ' + + #print ch_rbv + #print ch_val + + return [ch_rbv,ch_val] + + +def get_epicsPV(channel): + +# try: +# from CaChannel import * +# from epicsMotor import * +# from epicsPV import * +# import time +# import string +# except: +# try: +# sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) +# sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) +# from CaChannel import * +# from epicsPV import * +# except: +# os.system ("xkbbell") +# os.system ("xmessage -nearmouse -timeout 30 \ +# -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") +# sys.exit(1) +# # endtry + + # endtry + + n_tries=0 + tt=0 + b=-1 + while tt==0: + #print(channel) + b=epicsPV(channel).getw() + #print(b) + try: + #print ' try reading channel' ,channel,'Tr Nr ',tt + b=epicsPV(channel).getw() + tt=1 + except: + print ' \n ' + print 'trouble reading epics PV..',channel,' try again ' + print ' \n ' + n_tries=n_tries+1 + tt=0 + time.sleep(.25) + if n_tries==20: + tt=1 + print 'give up after 20 trying reading channel ' + #sys.exit("*** Program STOP ***") + #endif + #endtry + #endwhile + # DIRTY TICK MAKE ALLS RETURN TO TYPE STRING + #b=str(b) + #print('channel',channel,' type',type(b)) + if type(b) == unicode: + b=str(b) + # endif + return b + +def error_stop(info_line): + import time + print ' --------------------------------------------- ' + print ' ' + print ' EMERGENCY STOP ' + print ' ' + print info_line + print ' ' + print ' ' + print ' ' + print ' ' + print ' ' + print ' script stops in 30 sec ' + print ' ' + print ' ' + print ' Window can be closed or closes automatically' + print ' --------------------------------------------- ' + time.sleep(30) + stop + + +# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + +def remove_blanks_from_str(xx): + box='' + for i in range(len(xx)): + if xx[i:i+1] <> ' ': + box=box+xx[i:i+1] + #endif + # endfor + return box + +# =======================================++++++++++++++++++++++++++++++++++++++ + +def create_str_list(n): + d=range(n) + for i in range(len(d)): + d[i]=' ' + return d + +# ================================== + + +def create_int_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=d[i]-d[i] + return d + +# .............................................. + +def create_real_zeros(n): + d=range(n) + for i in range(len(d)): + d[i]=(d[i]-d[i])*0.0 + return d + +# ............................ + +def array_to_string(array_in): + print array_in + positions_str=' ' + for x in array_in: + positions_str=positions_str+' ' + str(x) + return positions_str + +# ............................ + +def write_guard(f,params): + + print params + if get_epicsPV('X07MB-PC-PSCAN:GUARD') == 1: + f.write(' \n ') # -..... close dimension 1 + f.write(' \n') + + # =============================== XTREME ============================== + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + f.write(' \n ') # -..... close dimension 1 + #endif + + #end write_guard + + + +# .......................... .VISUALIZATIONS ... + +def write_visualization(f,params): + + if params['Type'] <> "MatrixPlot": + f.write(' \n ') + # endif + + if params['Type'] == "MatrixPlot": + print 'CREATE MATRIX PLOT' + print params['DATA'] + print params['DATA'].count(' ') + if params['DATA'].count(' ') == 0: + f.write(' \n ') + # endif + # endif + + + + + +# ............................................. Special visualizations (1-D) + +def special_visualization(f,g,params): + + + # Type may be 'LinePlot' or MatrixPlot + + + # routine plots predefined and active detector sets as function of coordinate X (Must be FDA Id) + + + if (('PL_KEITHLEY1' in g['detectors_to_plot']) and ('KEITHLEY1' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I0_KEITHLEY1' + , 'Title' : 'KEITHLEY1 (I0)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY2' in g['detectors_to_plot']) and ('KEITHLEY2' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'I1_KEITHLEY2' + , 'Title' : 'KEITHLEY2 (I1)'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_KEITHLEY3' in g['detectors_to_plot']) and ('KEITHLEY3' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY4_TEY' + , 'Title' : 'KEITHLEY4_TEY'+'=f('+params['Id_X']+')'}) + + #endif + + if ('MOENCH' in g['detectors']): + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'KEITHLEY3' + , 'Title' : 'KEITHLEY3'+'=f('+params['Id_X']+')'}) + + + + # ............................ BL PRESSURES ........................ + print g['detectors_to_plot'] + print g['detectors'] + + + + print 'type', params['Type'] + + + if (('PL_CAM1_POS' in g['detectors_to_plot']) and ('CAM1_POS' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'CentroidX_RBV CentroidY_RBV' + , 'Title' : 'Centroid X, Centroid Y '+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'SigmaX_RBV SigmaY_RBV' + , 'Title' : 'Sigma X Sigma Y '+'=f('+params['Id_X']+')'}) + #endif + + + #'PLot user detector' + + + if (('PL_USER_DET' in g['detectors_to_plot']) and ('USER_DET' in g['detectors'])): + y_string='' + for i in range(len(g['User_detector_fda_id'])): + y_string=y_string+' '+g['User_detector_fda_id'][i] + # endfor + + print + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'USER DETECTORS '+y_string}) + + # endif + + + + + + + if (('PL_BL_PRESS' in g['detectors_to_plot']) and ('BL_PRESS' in g['detectors'])): + print g['ID_BL_PRESS'] + print len(g['ID_BL_PRESS']) + y_string=' ' + for i in range(len(g['ID_BL_PRESS'])): + y_string=y_string+' '+g['ID_BL_PRESS'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline pressures'+'=f('+params['Id_X']+')'}) + #endif + + if (('PL_BL_TEMP' in g['detectors_to_plot']) and ('BL_TEMP' in g['detectors'])): + print g['ID_BL_TEMP'] + print len(g['ID_BL_TEMP']) + y_string=' ' + for i in range(len(g['ID_BL_TEMP'])): + y_string=y_string+' '+g['ID_BL_TEMP'][i] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beamline temperatures'+'=f('+params['Id_X']+')'}) + #endif + + + # ................. MONO TEMPERATURES ............... + + if (('PL_MONO_TEMP' in g['detectors_to_plot']) and ('MONO_TEMP' in g['detectors'])): + + # plot first 4 important temperatures + y_string=' ' + for i in range(4): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp (Theta,T1,T2,TRZ)'+'=f('+params['Id_X']+')'}) + + # plot all other Temperature sensors + y_string=' ' + + + for i in range(6,len(g['ID_MONO_TEMP'])): + y_string=y_string+' '+g['ID_MONO_TEMP'][i] + # endfor + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Mono Temp '+'=f('+params['Id_X']+')'}) + + #endif + + # .......... encoders... + + if (('PL_MONO_ENC' in g['detectors_to_plot']) and ('MONO_ENC' in g['detectors'])): + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_V ROLL2_V PITCH2_V' + , 'Title' : 'MONO LVDT [V]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_MUR ROLL2_MUR PITCH2_MUR' + , 'Title' : 'MONO ROLL and PITCH [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_VOLT ROLL2_VOLT PITCH2_VOLT' + , 'Title' : 'ROLL1 VOLT ROLL2_VOLT PITCH_VOLT [V]'+'=f('+params['Id_X']+')'}) + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'ROLL1_DIFF ROLL2_DIFF PITCH2_DIFF' + , 'Title' : 'ROLL1 DIFF ROLL2_DIFF PITCH_DIFF [MUR]'+'=f('+params['Id_X']+')'}) + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : 'T1_DIFF T2_DIFF THETA_DIFF' + , 'Title' : 'T1_DIFF T2_DIFF THETA_DIFF '+'=f('+params['Id_X']+')'}) + + + + #endif + + + + if (('PL_ES1_PRESS' in g['detectors_to_plot']) and ('ES1_PRESS' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_ES1_PRESS'])): + y_string=y_string+' '+g['ID_ES1_PRESS'][i] + # endfor + print 'ystring' + print y_string + + print 'pt',params['Type'] + print 'idy',params['Id_X'] + print 'py',params['Id_Y'] + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + + #endif + + if (('PL_XBPM4' in g['detectors_to_plot']) and ('XBPM4' in g['detectors'])): + + # first plot current on 4 pads + y_string=' ' + for i in range(len(g['ID_XBPM4'])): + y_string=y_string+' '+g['ID_XBPM4'][i] + # endfor + print 'ystring' + print y_string + + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM4 '+'=f('+params['Id_X']+')'}) + + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM4_POS'])): + y_string=y_string+' '+g['ID_XBPM4_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM4 '+'=f('+params['Id_X']+')'}) + + #endif + + + + if (('PL_XBPM3' in g['detectors_to_plot']) and ('XBPM3' in g['detectors'])): + y_string=' ' + for i in range(len(g['ID_XBPM3'])): + y_string=y_string+' '+g['ID_XBPM3'][i] + # endfor + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'XBPM3 '+'=f('+params['Id_X']+')'}) + # plot position on XBPM + + y_string=' ' + for i in range(len(g['ID_XBPM3_POS'])): + y_string=y_string+' '+g['ID_XBPM3_POS'][i] + # endfor + + print 'ystring' + print y_string + + write_visualization(f,{ 'Type': params['Type'] + , 'X' : params['Id_X'] + , 'Y' : params['Id_Y'] + , 'DATA' : y_string + , 'Title' : 'Beam position on XBPM3 '+'=f('+params['Id_X']+')'}) + + + + #endif + + +# ............................................. END Special visualizations (1-D) + + +# ................... write postactions channel data_type + + +def post_action_channel_action(channel,value,operation,data_type,delay): + post_action_channel_action=' \n ' + return post_action_channel_action + +def post_action_shell_action(command,exitvalue): + post_action_channel_action=' \n ' + return post_action_channel_action + + +# ______________ routine to creat strings for action and preaction + + +def write_shell_action(f,command): + f.write(' ') + # end routine + +# _______________________________________________________________-- + +def write_action_channel_action(f,params): + + f.write(''+'\n') + # end routine + +# _______________________________________________________________-- + +def write_preaction_channel_action(f,params): + + preaction_channel_action = ''+'\n' + f.write(preaction_channel_action) + + +# =========================================================== + + +def Write_Variable_Definitions(f,g): + # Write the default vaiables, to be defined in general + f.write('') + f.write('') + f.write('') + +# end Write_Variable_Definitions + +# =========================================================== + + + +def write_preactions(f,g): + print g['preactions'] + print len(g['preactions']) + + + + # write write currentt data file name into EPICS channel + # this is done by use of a shell script + + + # TMP CHANGES TO CODE 10.11.2018 + + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}") # old version obosolete 14.4.2014 : 10.11.2018 disabled.. + # first write the header file (save_phoenix) (tmp disable 10.11.2018) + write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &") + + # write header file + + # write_shell_action(f,"/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py -F ${FILENAME}") + + # ............ Now write default preactions which arm the data aquisition + + + for i in range(len(g['preactions'])): + write_preaction_channel_action(f,g['preactions'][i]) + # endfor + if 'MOENCH' in g['detectors']: + print(' finally create dir to make sure moench files are write to correct dir') + #write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py &") + write_shell_action(f,"/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_Moench.py ") + #endif + # ............ second write the user defined preactions... + + if g['CH_INITIAL'][0] <> 'NO_INITIAL_VALUES': + for i in range(len(g['CH_INITIAL'])): + user_preaction={'channel_name' : g['CH_INITIAL'][i],'value' : str(g['CH_INITIAL_V'][i]) + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '3'} + print user_preaction + write_preaction_channel_action(f,user_preaction) + # endfor + # endif + +# .................... write default post actions.... + +def write_default_postactions(f,g): + f.write(post_action_shell_action('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_write_filename_to_file.sh ${FILENAME} &','0')) + # post action for MONCH reset + if 'MOENCH' in g['detectors']: + f.write(post_action_shell_action('/sls/X07MB/data/x07mbop/Data1/Commissioning/Develop/Develop_Moench/X_X07MB_reset_Moench.py ;','0')) + #endif + + + + f.write(post_action_channel_action('X07MB-OP2:START-CSMPL','1','put','String','0.1')) + # finally close shutter PHOENIX I + f.write(post_action_channel_action('X07MB-OP-WV1:WT_SET','0','put','String','0.1')) + #f.write(post_action_channel_action('X07MB-ES1:userCalc4.INPL','0','put','String','2')) + + + if 'MOENCH' in g['detectors']: + print('missing...') + #endif + + + #endif +# ========================================================== + +def write_detector_actions(f,g): + print g['detector_actions'] + print len(g['detector_actions']) + + + if 'MOENCH' in g['detectors']: + command="/sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_Moench/X_X07MB_Moench_Rise_FN.py ;" + f.write(' ') + +# + #endif + + for i in range(len(g['detector_actions'])): + write_action_channel_action(f,g['detector_actions'][i]) + # endfor + + write_guard(f,{'channel_name' : 'ACOAU-ACCU:OP-MODE' + ,'value' : 6 }) + + # For PHOENIX II check whether MONO is initialzed (See wrote guard routine! it is there noew) + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + #f.write(' \n') + + + +# ______________ routine to write positioner + + + + +# ........................... + +def write_start_positioner(f,params): + + # routine opens positioner (needed to write region positioner with several regions..) + # later add possibility to have different regions here.. + + # f.write(' \n') + + if params['Ch_done'] <> 'None': + f.write(' \n') + + else: + f.write(' \n') + + + +# ______________ routine to write individual regions for region positioner.. + + +def write_region(f,g,params): + + f.write(' \n') + # this preaction sets the numbe rof cycles for the current setup + # it does not take into account that the numbe rof frames in monch detector should be adjusted + # accordingly to the number of cycles. + # there are to options to solve. Allow in general for several preactions, which are defined. + # complex, as an additional dimension needs to be added + # + # in the general setup, or define an exception here to derive the Moench frame number as functio of the + # cycles . (easier) + + if not ('MOENCH' in g['detectors']): + f.write(' \n ') + #endif + cycles = params['Ch_preaction_value'] + frames_per_sec = 200. # de prAXI RATE$ + seconds = 0.2*cycles + frames = seconds * frames_per_sec + cycles_min = min(150,cycles) + if 'MOENCH' in g['detectors']: + # first preaction for cycles + + f.write(' \n ') + # first preaction for frames of Moench + + f.write(' \n ') + + + + #endif + + f.write('' + str(params['V_ini']) + ' \n ' ) + f.write(''+str(params['V_final'])+'') + f.write(''+str(params['V_delta'])+' \n') + + + #if 'MOENCH' in g['detectors']: + # write_function_enhance_moench_filenumber(f) + ##endif + + print params.keys() + print 'Not_close_region' in params.keys() + + if 'Not_close_region' in params.keys(): + print 'do not write region close ' + else: + print 'close region (Default)' + f.write(' \n') + + + # endif + +# .......................................................... + +def write_EXAFS_region(f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + for i in range(g['n_exafs']): + print i + + + # first write region (for now stet # cycles to, + # set cycles to initial value of e_ex_ncy + + write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + ,'V_final' : g['e_ex_k_f'][i] + ,'V_delta' : g['e_ex_d_i'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_ex_ncy'][i] + ,'Not_close_region' : 0}) # close region later as we need to add a function here... + + #endfor + + # Now write the function for EXAFS + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end write_EXAFS_region + + + + + + + +# .......................................................... + + + +def write_array_positioner(f,params): + print params + + # case 1 use readback value for positioner (this is the default) + + + if params['Use_done_value'] == 0: + f.write('\n') + # endif + # case 2 use done value for positioner (e.g. for soft motors) + + + # case II use done value must be 1 if positioner is finished. Use settling time of 0.05 sec. This is the time likely needed to change the done field to 'moving' state. + + if params['Use_done_value'] == 1: + f.write('\n') + + # endif + + + + f.write('' + array_to_string(params['Positions']) + ' \n') + + # write preactions... + + if params.has_key('Ch_preaction'): + + f.write(' \n ') + + #endif + + + f.write(' \n') + +#, 'Channel_done': g['p_done'][i] +#, 'Use_done_value': g['p_done_switch'][i] + +def write_linear_positioner(f,params): + + # ... routine write linear positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + + if params['Use_done_value'] == 1: + + f.write('' ) + # endif + + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + f.write(' \n') + + + +def write_function_positioner_MOENCH(f,params): + + # ... routine write fcuntion positioner. + # + # f----- file object for writing... + # + # keys in list params for input are: + # + # 'Channel' + # 'Channel_rbv' + # 'Settling_time' + # 'Id' + # 'V_ini' + # 'V_final' + # 'V_delta' + # + # + # ================================================= + + + if params['Use_done_value'] == 0: + + f.write('' ) + # endif + + if params['Use_done_value'] == 1: + f.write('' ) + # endif + + f.write('' + str(params['V_ini']) + ' \n') + f.write('' + str(params['V_final']) + ' \n') + f.write('' + str(params['V_delta']) + ' \n') + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + +# end function_positiner_MOENCH + + + +def write_function_enhance_moench_filenumber(f): + + f.write(' \n') + f.write('') + f.write('') + f.write(' \n') + f.write(' \n') + +# end function_write_function_enhance_moench_filenumber() + + +def write_all_detectors(f,g): + + print g['detectors'] + + # .............. First store set values of standard positioner: + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + # in case CCD's are used write the number of the image + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['e_channel'] ############## general g + ,'Channel' : 'X07MB-OP-MO:E-SET' ############## PHOENIX ########### + #,'Channel' : 'X07MA-PHS-E:GO.A' ############## XTREME ########### + ,'Id' : 'Energy_set'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print i + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print ' write Detector Keithley 1' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + + #endif + + + if 'KEITHLEY2' in g['detectors']: + print ' write Detector Keithley 2' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print ' write Detector Keithley 3' + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + #endif + + + if 'XBPM3' in g['detectors']: + print ' write Detector XBPM3 ' + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print ' write Detector XBPM 4' + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + + # ........... vortex 4-element + if 'Vortex' in g['detectors']: + n_det = 4 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print n_roi_vortex + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=write_vortex(f,g,n_det) + #endif + print id_roi_vortex + print n_det + + + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + + for i in range(len(g['ID_BL_PRESS'])): + print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + # endif + + + if 'BL_TEMP' in g['detectors']: + + for i in range(len(g['ID_BL_TEMP'])): + print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + + for i in range(len(g['ID_MONO_TEMP'])): + print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + # endif + + if 'MONO_ENC' in g['detectors']: + + for i in range(len(g['ID_MONO_ENC'])): + print i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + # endif + + + + + # write detector group microscope position + + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print i + print i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i] + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + # endif + + + + return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + +#............................... end ........ + +def write_detector(f,params): + print params + + if params['Det_type'] =='ScalarDetector': + f.write(' \n ') + # endif + if params['Det_type'] =='ArrayDetector': + f.write(' \n ') + + + if params['Det_type'] =='String': + f.write(' \n ') + + + # end routine + + + +# ============================================================= + +def write_vortex(f,g,n_det): + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + print '......... use all rois as detectors...' + print g['XMAP_save_only_xas_roi'] + print g['Id_XMAP_roi_by_name'] + print g['XMAP_roi_numbers'] + print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + print 'j',j + print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + endif + #endelse + + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp' # endfor + ) + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + print 'channel_roi_vortex',channel_roi_vortex + print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print 'channel_roi_vortex_dxp',channel_roi_vortex_dxp + print 'id_roi_vortex_dxp',id_roi_vortex_dxp + #endif + print 'det_nr',det_nr + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + print 'next j',j + print g['XMAP_roi_numbers'] + + print range(len(g['XMAP_roi_numbers'])) + print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + # endif + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + print id_icr + print ch_icr + print 'kkkkkkkkkkkkk' + print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_icr[i] + ,'Id' : id_icr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + write_detector(f,{'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'Channel' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + print ' write detector to save Flourescence spectra' + for i in d_list: + print i + # until 17.1.2020 + #write_detector(f,{'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'Channel' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + write_detector(f,{'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'Channel' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + +# end routine write_vortex + + +# ================================================================== +# +# +# MANIPULATIONS.. +# +# +# +# =================================================================== + + +def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_dead_time_roi(f,params): + + # .... call of routine: + # + # write_manip_dead_time_peamp(f,{'Id_roi':'Det1ROI1' + # , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + f.write(' \n ') + + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +def write_manip_fyxas(f,params): + + f.write('') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + +# -------------------------------------- + +def write_manip_divide_channels(f,params): + + print params + f.write('') + + f.write(' \n') + f.write(' \n') + f.write(' \n ') + f.write(' \n ') + + +# ---------------------------------------------------------------------------------------- + +def write_manip_sum_vortex(f,params): + + # + # + # routine calculates the summ of all four vortex detctors + # .... call of routine: + # + # write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + # , 'Id_icr' : id_icr_vortex[j] + # , 'Id_ocr' : id_ocr_vortex[j] + # , 'Id_elapsedLT': id_eltm_vortex[j] + # , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + + + print 'routine write_manip_sum_vortex' + print params + + + f.write(' \n ') + + # define the mapping of all variables... + string_for_params='' + n_det=0 + for ID_ROI in params['Id_roi']: + f.write(' \n') + string_for_params=string_for_params+ID_ROI+' , ' + n_det=n_det+1 + #endfor + + ##for Id_elapsedLT in params['Id_elapsedLT']: + ## print Id_elapsedLT + ## f.write(' \n') + ## string_for_params=string_for_params+Id_elapsedLT+' , ' + # endfor + + # remove coma at end of string_for_params + string_for_params=string_for_params[0:len(string_for_params)-3] + + + + f.write(' \n') + f.write('\n') + f.write(' \n ') + + +# =================================================================== + + +def read_list(detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + f = open('list.txt', "r") + box=' ' + box = f.readline() + #print 'box',box + # .............................. read 2 detectors.......... + detectors[0]=f.readline() + detectors[1]=f.readline() + + detectors[0] =detectors[0][0:len(detectors[0])-2] + detectors[1] =detectors[1][0:len(detectors[1])-2] + #print 'detectors',detectors + + # .............................. read energy arrays .......... + + box = f.readline() + #print box + + # r_box=create_real_zeros(5) + for i in range(5): + box = f.readline() + r_box=box.split() + #print 'r_box',r_box + + e_active[i]=r_box[0] + e_i[i]=r_box[1] + e_f[i]=r_box[2] + e_delta[i]=r_box[3] + #print e_active + #print e_i + #print e_f + #print e_delta + +# ...................................................................... + +def Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles): + """ + create input for energy scans for pshell + rscan and + vector scan + + """ + + # case I inout for rscan, this is only for + + Energy_Ranges=[] + Energy_Cycles=[] + + for i in range(len(e_i)): + Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + Energy_Cycles.append(e_n_cycles[i]) + #endfor + + # case II create input for vector scan, by creating explicitly every data point and the integration time + # this will be used to the EXAFS scans + + Energy_Scan_Positions=[] + for i in range(len(e_i)): # walk through the differen regions + This_Energy = e_i[i] + i_reg=0 + while (This_Energy < e_f[i]): + + This_Energy = e_i[i]+ float(e_delta[i])*i_reg + This_Cycle = e_n_cycles[i] + Energy_Scan_Positions.append([This_Energy,This_Cycle]) + i_reg=i_reg+1 + print(i_reg,This_Energy,This_Cycle) + #endwhile + #endfor + + + return Energy_Ranges,Energy_Cycles,Energy_Scan_Positions + + + + +def get_channels(scan_type): + + """ + + # + # This routine reads the epics chanels and stores the inout data into the correct + # variables in the python script epics chanels to be defined later. + # detectors, e_active,e_i,E_f,Delta_e, p_active,Scanx, Scany, Theta, Trx, TRZ ): + # + # Author T.Huthwelker October 2011 + # + # + # INPUT scan_type defines the type of scan. + # needs to be defined in the scan + # currently we have + # + # 'IMAGE' (for imaging) X_X07MB_regions.py + # + # 'SPECTRA' spectra, all data sets into one single data file (file X_X07MB_XAS_points.py) + # + # 'SPETRA_QUEUE' spectra, but each spectrum into a singl data file + # + # currently only used to check for consistencies of data input. On long term, we can minimize the number of chanles to be read + + """ + + import os + #os.system ("ls -altr") + try: + from CaChannel import * + from epicsMotor import * + from epicsPV import * + import time + import string + + except: + try: + #sys.path.insert(0, os.path.expandvars("$SLSBASE/sls/lib/python22/CaChannel")) + #sys.path.insert(0, os.path.expandvars("/exchange/share/mXAS/pyth/mod")) + + from CaChannel import * + from epicsPV import * + except: + os.system ("xkbbell") + os.system ("xmessage -nearmouse -timeout 30 \ + -buttons \"\" \"epicsPV or CaChannel module cannot be found\"") + sys.exit(1) + # endtry + + # endtry + + + + beamline='X07MB' + + #global switch missing XMAP or FALCON + # added 15.1.2020 + + hardware_sdd='NoSDD' + + if get_epicsPV('X07MB-PC-PSCAN:XMAP') == 1: + hardware_sdd = 'XMAP' + + # ask for SITORO 2nd to make itr the dominat choice + if get_epicsPV(beamline+'-PC-PSCAN:SITORO') == 1: + hardware_sdd = 'SITORO' + #endif + + if hardware_sdd != 'NoSDD': + ch_base_vortex = beamline+'-'+hardware_sdd + ch_base_vortex_mca = beamline+'-'+hardware_sdd+':mca' + ch_base_vortex_dxp = beamline+'-'+hardware_sdd+':dxp' + else: + ch_base_vortex = 'NoSDD' + ch_base_vortex_mca = 'NoSDD' + ch_base_vortex_dxp = 'NoSDD' + # endelse + print( ch_base_vortex) + print( ch_base_vortex_mca) + print( ch_base_vortex_dxp) + print(hardware_sdd) + + + + + filename = get_epicsPV(beamline+'-PC-PSCAN:FdaFname') # NOTE 15.7.2020 + # this is fda BASENAME + # It may differ from the full filename + # which is saved in /sls/X07MA/Data1/x07mbop/Commissioning/Develop/Develop_gui/t.tmp' + # because EPICS variable FdaFname allows maximum of 18 characters. + # This is critical for operation with Moench detector, as filenames are + # exchanged via EPICS channels. + + # .... remove all blanks from filename + + filename=filename.replace(' ', '') + + + # ......... define general Channels.... + + + # ........ define scan type + + + + #scan_type=['XAS_several_points'] # options are + # 'XAS_several_points' : several XAS spectra + # at different points + # 'E_Image' : image for a given (or several energies) + + + n_roi_for_xas = int(get_epicsPV(beamline+'-PC-PSCAN:FdaXasRoi')) # this is the roi we are choosing + # for taking the XAS spectrum (starts at 0) + + XMAP_save_only_xas_roi = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSRoi')) # if 1 we store ony roi choosen for XAS, + # other wise store all rois defined. + + XMAP_save_spectra = int(get_epicsPV(beamline+'-PC-PSCAN:FdaSSpec')) # flag whether we store fluo spectra or not. + + # ........... number of scans + number_of_executions = int(get_epicsPV(beamline+'-PC-PSCAN:FdaNexec')) # number of repetitions in scan + + # ............ read detectors.... + + # create a list of detetectors used in experiment + + detectors=['no_Detector'] # define list of detectors by creating dummy WHY NOT use [] ???????? + + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_ES1_SD1')): + detectors.append('MOENCH') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS1_CAM1')): + detectors.append('PS1_CAM1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:USE_PS2_CAM1')): + detectors.append('PS1_CAM2') + #endif + + if (1==int(get_epicsPV(beamline+'-PC-PSCAN:VORT_XM'))) and (hardware_sdd !='NoSDD'): + detectors.append('Vortex') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ROENT_XM')) and (hardware_sdd !='NoSDD'): + detectors.append('ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KETEK_XM')) and (hardware_sdd !='NoSDD'): # Add KETK as option. This detector uses only Channel 2 of 4 XMAP Channels + detectors.append('KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH1')): + detectors.append('KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH2')): + detectors.append('KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:KEITH3')): + detectors.append('KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_PRESS')): + detectors.append('BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:BL_TEMP')): + detectors.append('BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:ES1_PRESS')): + detectors.append('ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_ENC')): + detectors.append('MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:MO_TEMP')): + detectors.append('MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM4')): + detectors.append('XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:XBPM3')): + detectors.append('XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:CAM1_POS')): + detectors.append('CAM1_POS') + #endif + + + #print get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET') + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + #print 'gggggggg' + detectors.append('USER_DET') + #endif + + #print detectors + + if len(detectors) == 1: + error_stop('!!!!!!!!!!! no detector choosen') + # endif + + + # create a list of plots to be choosen + + detectors_to_plot=['no_Plot'] # define list of detectors by creating dumma + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_VORT_XM')) and (hardware_sdd !='NoSDD') and 'Vortex' in detectors: + detectors_to_plot.append('PL_Vortex') + #endif + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ROENT_XM')) and (hardware_sdd !='NoSDD') and 'ROENTEC_XMAP' in detectors: + detectors_to_plot.append('PL_ROENTEC_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KETEK_XM')) and (hardware_sdd !='NoSDD') and 'KETEK_XMAP' in detectors: + detectors_to_plot.append('PL_KETEK_XMAP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH1')): + detectors_to_plot.append('PL_KEITHLEY1') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH2')): + detectors_to_plot.append('PL_KEITHLEY2') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_KEITH3')): + detectors_to_plot.append('PL_KEITHLEY3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_PRESS')): + detectors_to_plot.append('PL_BL_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_BL_TEMP')): + detectors_to_plot.append('PL_BL_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_ES1_PRESS')): + detectors_to_plot.append('PL_ES1_PRESS') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_ENC')): + detectors_to_plot.append('PL_MONO_ENC') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_MO_TEMP')): + detectors_to_plot.append('PL_MONO_TEMP') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM3')): + detectors_to_plot.append('PL_XBPM3') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_XBPM4')): + detectors_to_plot.append('PL_XBPM4') + #endif + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_CAM1_POS')): + detectors_to_plot.append('PL_CAM1_POS') + + + if 1==int(get_epicsPV(beamline+'-PC-PSCAN:PL_USER_DET')): + detectors_to_plot.append('PL_USER_DET') + + + # GET NAMING CONVENTION FOR FDA + # if channel X07MB-PC-PSCAN:FdaNConv = 1 get names from XMAP rois + # other wise use standard definition det_i_roi_j + + + if get_epicsPV(beamline+'-PC-PSCAN:FdaNConv') == 1: + XMAP_name_convention= 'ROI' # if ROI is choosen, the column name in data file is the + else: + XMAP_name_convention= ' ' + # endelse + + #... if XMAP is used determine the number of ROIS chosen: + + + if ('Vortex' in detectors) and ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('Vortex' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + if ('ROENTEC_XMAP' in detectors) and ('KETEK_XMAP' in detectors): + error_stop('!!!!!!!!!!! ERROR CANNOT USE BOTH VORTEX AND ROENTEC WITH XMAP ') + # endif + + + n_roi=-1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + n_det_fluo = -1 # set to -1 as not yet defined, will be reset if XMAP is used, otherwise -1 means error + Id_XMAP_roi_by_name=-1 + d_list_fluo =[-1] # changed 10.10. Need to give initial definition for d_list_fluo, + # as it will remain undefined of no Fluo detector is used. + # Define channel 0 as number for unused channel' + XMAP_roi_numbers =-1 + + + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors): + + if ('Vortex' in detectors): + n_det_fluo = 4 # do script for 4 detectors (VORTEX) + d_list_fluo =[1,2,3,4] + # endif + if ('ROENTEC_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (ROENTEC ) + d_list_fluo =[1] # roentek by default in XMAP Channel # 1 + # endif + + + if ('KETEK_XMAP' in detectors): + n_det_fluo = 1 # do script for 1 detector (Ketek ) + d_list_fluo =[2] # Ketek by default in XMAP channel # 2 + # endif + + + + + print 'analyse XMAP ' + + # case 1 roentec and vortex, use ROI's as defined for detector 1 + + if ('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors): + + print 'vortex assuming that rois defined for detector 1 are equal for all detectors...' + + + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca1.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + this_name=get_epicsPV(ch_base_vortex_mca+'1.R'+str(i1)+'NM') # note that this assumes that the + #print 'THISNAME ',this_name + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + # case 2 Ketek, which is by defalut defined on channel 2 + + #print(detectors) + + if ('KETEK_XMAP' in detectors): + + print 'KETEC assuming that channel 2 is used in XMAP ' + + n_roi=0 + + for i1 in range(31): + # old until 15.1.2020 + #this_name=get_epicsPV(beamline+'-XMAP:mca2.R'+str(i1)+'NM') # note that this assumes that the + # NEW 15.1.2020 + #print(ch_base_vortex_mca+'2.R'+str(i1)+'NM') + this_name=get_epicsPV(ch_base_vortex_mca+'2.R'+str(i1)+'NM') # note that this assumes that the + + # same roi name is choosen for all four spectra. XMAP allow different labels for each roi and each detector. + # ..... remove blanks from string + box='' + for i2 in range(len(this_name.split())): + box=box+this_name.split()[i2] + # endfor + + if box <> '': + n_roi=n_roi+1 + if n_roi ==1: + Id_XMAP_roi_by_name=[box] + XMAP_roi_numbers=[i1] + else: + Id_XMAP_roi_by_name.append(box) + XMAP_roi_numbers.append(i1) + # endelse + + # endif + + # endfor + + # endif + + + + + print n_roi + if n_roi == 0 : + error_stop('!!!!! INCONSISTENT INPUT: NO ROI DEFINED IN XMAP (GOTO Phoenix user panel --> CHOOSE SDD/FLUO and ADD ROI ') + #endif + if n_roi_for_xas > n_roi: + print 'stop inconsistent input ' + print ' value for n_roi_for_xas is larger that maximum value of defines roi' + print Id_XMAP_roi_by_name + print ' Use name convention: ',XMAP_name_convention + #endif + #endif + print Id_XMAP_roi_by_name + + + # finally define variable which contains the roi used fro XAs in the list of rois we use + + n_roi_for_xas_index=n_roi_for_xas + # now, for case use onlz XAS roi, create the subset from ID_XMAP + # default is to store all ROI to data files. Now treat case where we need a data subset + n_roi_for_xas_index=n_roi_for_xas + #print Id_XMAP_roi_by_name + + + if XMAP_save_only_xas_roi == 1: + + # create list for headers for subset + Id_XMAP_roi_by_name=[Id_XMAP_roi_by_name[n_roi_for_xas]] + # create list with indices for roi chosen. by this prepare solution to make a list of rois to store + XMAP_roi_numbers=[n_roi_for_xas] + # set n_roi to 1 as we now consider only one region of interest + n_roi_for_xas_index=0 + n_roi=1 + + + + # ............... now store the 21 possible regions for the energy scans + # once chanels are defined create array with chanle names and go through loop + + n_e = 21 # start with maximun, reset number later + ch_e_base=beamline+'-PC-PSCAN:E-' + + # faster code reads only active channels..... + + i_0=0 + + if ('SPECTRA' == scan_type) or ('SPECTRA_QUEUE' == scan_type) or ('STACK' == scan_type): # read parameter only if a spectrum is to be taken + for i in range(n_e): + #print 'read energy points'+str(i) + this_active = get_epicsPV(ch_e_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + e_active = [this_active] # must be one or zero + e_i = [get_epicsPV(ch_e_base+'I'+str(i))] + e_f = [get_epicsPV(ch_e_base+'F'+str(i))] + e_delta = [get_epicsPV(ch_e_base+'D'+str(i))] + e_n_cycles = [int(get_epicsPV(ch_e_base+'NCY'+str(i)))] + i_0=i_0+1 + else: + if ( this_active== 1): + e_active.append(this_active) # must be one or zero + e_i.append(get_epicsPV(ch_e_base+'I'+str(i))) + e_f.append(get_epicsPV(ch_e_base+'F'+str(i))) + e_delta.append(get_epicsPV(ch_e_base+'D'+str(i))) + e_n_cycles.append(int(get_epicsPV(ch_e_base+'NCY'+str(i)))) + i_0=i_0+1 + # endif + + # endelse + if i_0 == 0 : + error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY range with constant energy spacing for taking SPECTRA (Menue XAS SCANS)') + #error stop as no energy is defined for energy scan + + # endif + + else: # case data set is not a spectrum assign dummy values + e_active = ['undefined'] + e_i = ['undefined'] + e_f = ['undefined'] + e_delta = ['undefined'] + e_n_cycles = ['undefined'] + i_0 = 0 + # endelse + #print e_f,e_i,i_0 + + + # now READ POSITIONER FOR exafs DATA.. + + n_e = i_0 # reset n_e to number of real data points + + ch_ex_base=beamline+'-PC-PSCAN:EX-' + e_ex_E_edge = [get_epicsPV(ch_ex_base+'E-EDGE')] + + # do not check whether i_0 is zero, program assumes that at least on range with constant range is chosen. + + n_exafs=2 # currently allow for 2 region + i_0 = 0 + e_ex_active=[-1] # set to -1. If there is no active region for EXAFS scans, e_ex_active = -1 + + + #print n_exafs + + for i in range(n_exafs): + this_active = get_epicsPV(ch_ex_base+'ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + e_ex_active = [this_active] # must be one or zero + e_ex_e_i = [get_epicsPV(ch_ex_base+'E-I'+str(i)) ] + e_ex_e_f = [get_epicsPV(ch_ex_base+'E-F'+str(i)) ] + e_ex_k_i = [get_epicsPV(ch_ex_base+'K-I'+str(i)) ] + e_ex_k_f = [get_epicsPV(ch_ex_base+'K-F'+str(i)) ] + e_ex_d_i = [get_epicsPV(ch_ex_base+'D'+str(i)) ] + e_ex_ncy = [get_epicsPV(ch_ex_base+'NCY'+str(i)) ] + e_ex_ncy_f = [get_epicsPV(ch_ex_base+'NCY-F'+str(i)) ] + e_ex_icy = [get_epicsPV(ch_ex_base+'ICY'+str(i)) ] + e_ex_nst = [get_epicsPV(ch_ex_base+'NST'+str(i)) ] + e_ex_t = [get_epicsPV(ch_ex_base+'T'+str(i)) ] + i_0=i_0+1 + else: + if ( this_active== 1): + e_ex_active.append(this_active) # must be one or zero + e_ex_e_i.append(get_epicsPV(ch_ex_base+'E-I'+str(i)) ) + e_ex_e_f.append(get_epicsPV(ch_ex_base+'E-F'+str(i)) ) + e_ex_k_i.append(get_epicsPV(ch_ex_base+'K-I'+str(i)) ) + e_ex_k_f.append(get_epicsPV(ch_ex_base+'K-F'+str(i)) ) + e_ex_d_i.append(get_epicsPV(ch_ex_base+'D'+str(i)) ) + e_ex_ncy.append(get_epicsPV(ch_ex_base+'NCY'+str(i)) ) + e_ex_ncy_f.append(get_epicsPV(ch_ex_base+'NCY-F'+str(i))) + e_ex_icy.append(get_epicsPV(ch_ex_base+'ICY'+str(i))) + e_ex_nst.append(get_epicsPV(ch_ex_base+'NST'+str(i))) + e_ex_t.append(get_epicsPV(ch_ex_base+'T'+str(i))) + i_0=i_0+1 + # endif + # endelse + # endfor + + n_exafs = i_0 # determine the number of EXAFS ranegs choosen. + + + if i_0 == 0 : + print 'NO EXAFS REAGION CHOOSEN ' + e_ex_e_i = [-1] + e_ex_e_f = [-1] + e_ex_k_i = [-1] + e_ex_k_f = [-1] + e_ex_d_i = [-1] + e_ex_ncy = [-1] + e_ex_ncy_f = [-1] + e_ex_icy = [-1] + e_ex_nst = [-1] + e_ex_t = [-1] + + # endif + + #print e_ex_e_i + #print e_ex_e_f + #print e_ex_k_i + #print e_ex_k_f + #print e_ex_d_i + #print e_ex_ncy + #print e_ex_ncy_f + #print e_ex_nst + #print e_ex_t + # Now read also the parameters for the region with non equi distant energy spacing + #print n_e + #print e_active + #print e_i + #print e_f + #print e_delta + + + # ............ now store the various data point for the energy scans.... + + # ............ put these names into a configuration file ???? + + ch_p_base=beamline+'-PC-PSCAN:P-' + + + + # first read all positions for standard detectors for regions + # to do read only active columns ... + + + n_p = 21 # set first to max number of datapoints, reset later + + # faster code read only active chanels ........(but still all positioner, even if undefined..) + + i_0_tmp=0 + p_label='undefined_label' + for i in range(n_p): + #print ' read positions for point scans '+str(i)+str(n_p) + this_active = int(get_epicsPV(ch_p_base+'ACT'+str(i))) # read channel with active / inactive... + #print i, this_active + if (i_0_tmp ==0 ) and ( this_active== 1) : + p_label = [get_epicsPV(ch_p_base+'LABEL'+str(i))] + p_active = [this_active] + p_0 = [get_epicsPV(ch_p_base+'P0D'+str(i))] + p_1 = [get_epicsPV(ch_p_base+'P1D'+str(i))] + p_2 = [get_epicsPV(ch_p_base+'P2D'+str(i))] + p_3 = [get_epicsPV(ch_p_base+'P3D'+str(i))] + p_4 = [get_epicsPV(ch_p_base+'P4D'+str(i))] + p_5 = [get_epicsPV(ch_p_base+'P5D'+str(i))] + #print 'First found' + i_0_tmp=i_0_tmp+1 + else: + if ( this_active== 1): + #print 'next found ' + #print i + p_label.append(get_epicsPV(ch_p_base+'LABEL'+str(i))) + p_active.append(this_active) + p_0.append(get_epicsPV(ch_p_base+'P0D'+str(i))) + p_1.append(get_epicsPV(ch_p_base+'P1D'+str(i))) + p_2.append(get_epicsPV(ch_p_base+'P2D'+str(i))) + p_3.append(get_epicsPV(ch_p_base+'P3D'+str(i))) + p_4.append(get_epicsPV(ch_p_base+'P4D'+str(i))) + p_5.append(get_epicsPV(ch_p_base+'P5D'+str(i))) + i_0_tmp=i_0_tmp+1 + #endif + #endif + if i_0_tmp == 0 : + print 'error stop removed' + #error_stop('!!!!! INCONSISTENT INPUT: choose at least one POSITION for SPECTRA (MENUE XAS SCANS)') + # create mark in positioner variables that no position has been chosen + p_0='no pos' + p_1='no pos' + p_2='no pos' + p_3='no pos' + p_4='no pos' + p_5='no pos' + # set count of data points to 1, this is the case where we take a spectrum at all current positioners without moving the positioner + i_0_tmp = 1 + # endif + + + #print p_label + + n_p = i_0_tmp # reset n_p to real number of data points + #print n_p + + + # put all data into one full list + p_data_full=[[p_0],[p_1],[p_2],[p_3],[p_4],[p_5]] + + #print i_0_tmp + + + # ........... done reading all positions for standard positioner ... + + # .... get epics chanels of defau;lt positioner (set value) + #print ' read actuators' + + + # CHANNEL NEEDED .rbv is as default in channel.remove .rbv and create .val for p_channel_full here + + # case 1 extension of + + ch0 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN0') + ch1 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN1') + ch2 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN2') + ch3 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN3') + ch4 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN4') + ch5 = get_epicsPV(beamline+'-PC-PSCAN:POS-CHN5') + + [ch0_rbv,ch0_val] = create_rbv_val(ch0) + [ch1_rbv,ch1_val] = create_rbv_val(ch1) + [ch2_rbv,ch2_val] = create_rbv_val(ch2) + [ch3_rbv,ch3_val] = create_rbv_val(ch3) + [ch4_rbv,ch4_val] = create_rbv_val(ch4) + [ch5_rbv,ch5_val] = create_rbv_val(ch5) + + + p_channel_full = [ch0_val,ch1_val,ch2_val,ch3_val,ch4_val,ch5_val] + + #print ' read actuator rbv ' + + # .... get epics chanels of default positioner (rbv value) + p_channel_rbv_full = [ch0_rbv,ch1_rbv,ch2_rbv,ch3_rbv,ch4_rbv,ch5_rbv] + #print p_channel_full + #print p_channel_rbv_full + + + # names for identifier for 6 default positioner in point scans..) + + #print ' read actuator FDA ID ' + + p_id_full = [str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID0')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID1')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID2')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID3')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID4')), + str(get_epicsPV(beamline+'-PC-PSCAN:POS-FDAID5')) + ] + #print(p_id_full) + # read done channels for positioner + + p_done_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-RBC0'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC1'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC2'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC3'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC4'), + get_epicsPV(beamline+'-PC-PSCAN:POS-RBC5') + ] + + + #print p_done_full + + # read on / off for done mode done channels for positioner + + p_done_switch_full = [get_epicsPV(beamline+'-PC-PSCAN:POS-DN0-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN1-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN2-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN3-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN4-ACT'), + get_epicsPV(beamline+'-PC-PSCAN:POS-DN5-ACT') + ] + + #print p_done_switch_full + + # ................................... read additional predefined user detectors + + + + i_tmp=0 + CH_User_detector = ['noUserDetector'] + User_detector_fda_id = ['noUserDetector'] + for i in range(10): + User_detector_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)) + User_detector_fda_id_box = get_epicsPV(beamline+'-PC-PSCAN:UDET'+str(i)+'-FDAID') + if (remove_blanks_from_str(User_detector_box) <> '') : + if i_tmp == 0 : + CH_User_detector = [remove_blanks_from_str(User_detector_box)] + if User_detector_box <> '': + User_detector_fda_id = [remove_blanks_from_str(User_detector_fda_id_box)] + else: + User_detector_fda_id = ['User_det_'+str(i)] + #endelse + i_tmp = i_tmp + 1 + else: + CH_User_detector.append(remove_blanks_from_str(User_detector_box)) + User_detector_fda_id.append(remove_blanks_from_str(User_detector_fda_id_box)) + # endelse + # endif + # endfor + + #print CH_User_detector + #print User_detector_fda_id + + + # get the active detectors now... + + p_positioner_active=[0,0,0,0,0,0] # variable which of the default positioner is active + + p_positioner_active[0] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT0')) # Default scanx + p_positioner_active[1] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT1')) # Default scany + p_positioner_active[2] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT2')) # Default ROT + p_positioner_active[3] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT3')) # Default TRX + p_positioner_active[4] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT4')) # Default TRZ + p_positioner_active[5] = int(get_epicsPV(beamline+'-PC-PSCAN:POS-ACT5')) # Default DETECTOR + + #print p_positioner_active + # stop + # create array with Id values and EPICS channels for fda... + + p_data_full=[p_0,p_1,p_2,p_3,p_4,p_5] + + if sum(p_positioner_active) == 0 : + + # case I no positioner defined + p_channel=[' '] + p_channel_rbv=[' '] + p_id =[' '] + p_data =[' '] + p_done =[' '] + p_done_switch =[' '] + else: + + # case II no positioner are defined + i_0_tmp=0 + for i in range(len(p_positioner_active)): + #print i_0_tmp + #print i + if (i_0_tmp == 0) and (p_positioner_active[i] == 1 ): + p_channel=[p_channel_full[i]] + p_channel_rbv= [p_channel_rbv_full[i]] + p_id = [p_id_full[i]] + p_data = [p_data_full[i]] + p_done = [p_done_full[i]] + p_done_switch =[p_done_switch_full[i]] + i_0_tmp =i_0_tmp+1 + else: + if (p_positioner_active[i] == 1 ): + p_channel.append(p_channel_full[i]) + p_channel_rbv.append(p_channel_rbv_full[i]) + p_id.append(p_id_full[i]) + p_data.append(p_data_full[i]) + if p_done_switch_full[i] == 1: + p_done.append(p_done_full[i]) + else: + p_done.append(None) + #endelse + p_done_switch.append(p_done_switch_full[i]) + i_0_tmp =i_0_tmp+1 + #endif + #endelse + #endfor + #endelse + #print 'i_0_tmp' + #print i_0_tmp + #print 'p_data' + #print(' ') + #print p_channel + #print(' ') + #print p_id + #print(' ') + #print p_channel_rbv + #print(' ') + #print p_data + #print p_done + #print p_done_switch + + + # now after we have stored all positions (including the non-active data sets...) into the matrices + # we create an array containing the complete data set...(Positioner ID and positions data) + # + + #print 'p_positioner_active' + #print p_positioner_active + #print 'p0' + #print p_0 + #print 'p_id' + #print p_id + + # .................... done creation of full array for all positions... + + + # now connect the data to one variable with dictionary + + # ----------------------------------------------------------------- + # + # ............set up data for image regions ....... + # + # ------------------------------------------------------------------ + + + # ........... first the energies (currently as a few fixed energy values, we can think about stacks as well later + + ch_r_base=beamline+'-PC-PSCAN:R' + + r_n_e = 20 # start with max number of data points + + i_0=0 + + for i in range(r_n_e): + #print 'read energies for regions'+str(i) + #print ch_r_base+'-EACT'+str(i) + this_active = get_epicsPV(ch_r_base+'-EACT'+str(i)) + #print 'this_active' + #xprint this_active + if (i_0 ==0 ) and ( this_active== 1) : + r_energies_active = [this_active] + time.sleep(0.05) + r_energies = [(get_epicsPV(ch_r_base+'-E'+str(i)))] + time.sleep(0.05) + r_energy_cycles = [int(get_epicsPV(ch_r_base+'-E-NCY'+str(i)))] + i_0 = i_0 + 1 + #print 'first found ' + else: + if (this_active == 1): + #print 'next found ' + r_energies_active.append(1) + time.sleep(0.05) + r_energies.append( (get_epicsPV(ch_r_base+ '-E' +str(i)))) + time.sleep(0.05) + r_energy_cycles.append( int(get_epicsPV(ch_r_base+ '-E-NCY' +str(i)))) + i_0 = i_0 + 1 + #print 'energies',r_energies + + #endif + #endelse + # endfor + + # ___________ stop, if there are no energies chosen..... + + if i_0 == 0 : + + # error_stop('!!!!! INCONSISTENT INPUT: choose at least one ENERGY for taking images') + # in case there no energy is chosen, work with current status of the beamline + r_energies = 'undefined' + r_energy_cycles = 'undefined' + r_energies_active = 'undefined' + #endif + r_n_e=i_0 # reset r_n_e + + #print r_energies + #print r_energy_cycles + + # ....................................... finally the image coordinates + + n_r = 21 # maximum 10 images at current + + # allow for scanx, scany and detector for now. Default for taking 2-D images + # this is by default in actuator 0,1, and 5. (ScanX, ScanY and Detector) + # the following code is historically grown and extremly unnice + # detector movement prepared, but not implemented yet in IOC + # TO DO REMOVE DETECTOR AS THIS IS USELESS:.. + + r_indices=[p_id_full[0] + ,p_id_full[1] + ,p_id_full[5] + ] + + r_channel = { p_id_full[0] : p_channel_full[0] + ,p_id_full[1] : p_channel_full[1] + ,p_id_full[5] :p_channel_full[5] + } + + r_channel_rbv = { p_id_full[0] : p_channel_rbv_full[0] + ,p_id_full[1] : p_channel_rbv_full[1] + ,p_id_full[5] : p_channel_rbv_full[5]} + + + r_id = { p_id_full[0] : p_id_full[0] + ,p_id_full[1] : p_id_full[1] + ,p_id_full[5] : p_id_full[5]} + + r_done = {p_id_full[0] : p_done_full[0] + ,p_id_full[1] : p_done_full[1] + ,p_id_full[5] : p_done_full[5] + } + + r_done_switch = {p_id_full[0] : p_done_switch_full[0] + ,p_id_full[1] : p_done_switch_full[1] + ,p_id_full[5] : p_done_switch_full[5] + } + + #print r_channel + + + # faster code , reads only active chanels + + i_0 = 0 + for i in range(n_r): + #print 'read region'+str(i) + this_active = get_epicsPV(ch_r_base+'-ACT'+str(i)) + if (i_0 ==0 ) and ( this_active== 1) : + #print ' first region active' + r_active = [this_active] + time.sleep(0.05) + r_ll_x = [get_epicsPV(ch_r_base+'-XLL'+str(i))] + time.sleep(0.05) + r_ll_y = [get_epicsPV(ch_r_base+'-YLL'+str(i))] + time.sleep(0.05) + r_ur_x = [get_epicsPV(ch_r_base+'-XUR'+str(i))] + time.sleep(0.05) + r_ur_y = [get_epicsPV(ch_r_base+'-YUR'+str(i))] + time.sleep(0.05) + r_delta_x = [get_epicsPV(ch_r_base+'-DX'+str(i))] + time.sleep(0.05) + r_delta_y = [get_epicsPV(ch_r_base+'-DY'+str(i))] + r_num = [i+1] # runing number for region to generate the numbering of filename + i_0=i_0+1 + + else: + if ( this_active== 1): + #print 'next found ' + r_active.append( this_active) + r_ll_x.append( get_epicsPV(ch_r_base+'-XLL'+str(i))) + time.sleep(0.05) + r_ll_y.append( get_epicsPV(ch_r_base+'-YLL'+str(i))) + time.sleep(0.05) + r_ur_x.append( get_epicsPV(ch_r_base+'-XUR'+str(i))) + time.sleep(0.05) + r_ur_y.append( get_epicsPV(ch_r_base+'-YUR'+str(i))) + time.sleep(0.05) + r_delta_x.append( get_epicsPV(ch_r_base+'-DX'+str(i))) + time.sleep(0.05) + r_delta_y.append( get_epicsPV(ch_r_base+'-DY'+str(i))) + r_num.append(i+1) + # endif + #endelse + + if (i_0 == 0 ): + error_stop('!!!!! INCONSISTENT INPUT: choose at least one REGION for taking images') + # endif + n_r=i_0 # reset number of data points + # ..... configure general preactions (configure at end, + # ..... as preaction in later version wil be derived from general input. + + # This is the case if KEthley and Vortex are used add distinction for case w/o keithley + + # ... preactions for DAQ with XMAP ................ + + # First check whether we need XMAP Actions: + + if (('Vortex' in detectors) or ('ROENTEC_XMAP' in detectors) or ('KETEK_XMAP' in detectors) ): + DAQ_XMAP = 1 + else: + DAQ_XMAP = 0 + # endif_else + + preaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : 0 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.05'} + # until 15.1.2020 + #preaction_2={'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + preaction_2={'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + # set to mca spectac mode (later add option for OTF mapping) + # until 15.1.2020 + #preaction_2a={'channel_name' : 'X07MB-XMAP:CollectMode' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2a={'channel_name' : ch_base_vortex+':CollectMode' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + # force application of collection mode setting. + # until 15.1.2020 + #preaction_2b={'channel_name' : 'X07MB-XMAP:Apply' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + # new 15.1.2020 + + preaction_2b={'channel_name' : ch_base_vortex+':Apply' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + # SITORO doe not know apply, hence for now do preaction 2a twice + #print(hardware_sdd) + if hardware_sdd == 'SITORO': + preaction_2b=preaction_2a + #endif + # until 15.1.2020 + #preaction_3={'channel_name' : 'X07MB-XMAP:PresetReal' + # ,'value' : '0' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05'} + + #new 15.1.2020 + preaction_3={'channel_name' : ch_base_vortex+':PresetReal' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + preaction_4={'channel_name' : 'X07MB-OP2:TOTAL-CYCLES' + ,'value' : 1.0 + ,'operation' : 'put' + ,'data_type' : 'Double' + ,'delay' : '0.05'} + + # 7.5.2018 press once start sampling to allow system to reset delay = 0.7 sec to maske sure + # that there is sufficient time to count up once for 2 cycles. This is a backup + # to ensure that the trigger EPIC setup does not hand when the system starts + + preaction_4a={'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.7'} + + + preaction_5={'channel_name' : 'X07MB-ES1-PP2:VO5' + ,'value' : '0' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.01'} + + + # preaction: open local shutter automatically + + preaction_6={'channel_name' : 'X07MB-OP-WV1:WT_SET' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + preaction_Moench_1={'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber' + ,'value' : '100000' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + #Moench 2 and 3 DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + + preaction_Moench_2={'channel_name' : 'X07MB-ES1-SD1:cam1:FilePath' + ,'value' : '/tmp' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5'} + + + preaction_Moench_3={'channel_name' : 'X07MB-ES1-SD1:cam1:FileName' + ,'value' : 'moench_' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05'} + + + + preaction_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + + preaction_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.2'} + + + # general case ... + + if DAQ_XMAP == 1: + + # IDCOUPLING + preactions=[preaction_1 + ,preaction_2 + ,preaction_2a + ,preaction_2b + ,preaction_3 + ,preaction_4 + ,preaction_4a + ,preaction_5 # + # ,preaction_MO_ID_Off + # ,preaction_MO_ID_on + ] + + # endif DAQ_XMAP = 1 + + + + # case no XMAP in data aquisition + + if DAQ_XMAP == 0: + preactions=[preaction_1,preaction_4,preaction_4a] + # endif DAQ_XMAP = 0 + + + + # add shutter auto opening if chosen + + if get_epicsPV('X07MB-PC-PSCAN:MBWV1_OPEN') == 1: + preactions.append(preaction_6) + # endif + + # NOw add ccd detectort id needed + # Case 1 Moenche deetctor + if 'MOENCH' in detectors: + print(' no Moench preaction for now...') + preactions.append(preaction_Moench_1) + #preactions.append(preaction_Moench_2) THESE DO NOT WORK WOTH FDA FDA CANNOT WRITE A STRING + #preactions.append(preaction_Moench_3) + #endif + + + # ... preactions for DAQ without XMAP ................ + + + # Define actions to be taken for each measurement + + # until 15.1.2020 + #detector_action_1 = { 'channel_name' : 'X07MB-XMAP:EraseStart' + # ,'value' : '1' + # ,'operation' : 'putq' + # ,'data_type' : 'String' + # ,'delay' : '0.075' } + # NEW 15.1.2020 + detector_action_1 = { 'channel_name' : ch_base_vortex+':EraseStart' + ,'value' : '1' + ,'operation' : 'putq' + ,'data_type' : 'String' + ,'delay' : '0.030' } # fda we sues 0.75 + + detector_action_2 = { 'channel_name' : 'X07MB-OP2:SMPL' + ,'value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.075' } # fda 0.075 + + detector_action_3 = { 'channel_name' : 'X07MB-OP2:SMPL-DONE' + ,'value' : '1' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.00' } + # old until 15.1.2020 + #detector_action_4 = { 'channel_name' : 'X07MB-XMAP:StopAll' + # ,'value' : '1' + # ,'operation' : 'put' + # ,'data_type' : 'String' + # ,'delay' : '0.05' } + + detector_action_4 = { 'channel_name' : ch_base_vortex+':StopAll' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.05' } + + + detector_action_moench_aquire = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.5' } + + detector_action_moench_wait = { 'channel_name' : 'X07MB-ES1-SD1:cam1:Acquire' + ,'value' : '0' + ,'operation' : 'wait' + ,'data_type' : 'Integer' + ,'delay' : '0.3' } + + detector_action_MO_ID_Off={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : ' ' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + detector_action_MO_ID_on={'channel_name' : 'X07MB-OP-MO:E-SET.OUT' + ,'value' : 'X07MA-ID:ENERGY NPP NMS' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + + + # now walk through different cases + + if DAQ_XMAP == 1: + + # IDCOUPLING + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_3 + ,detector_action_4 +# ,detector_action_MO_ID_Off +# ,detector_action_MO_ID_on + ] + #print detector_actions + + # endif DAQ_XMAP = 1 + if DAQ_XMAP == 0: + detector_actions=[detector_action_2 + ,detector_action_3] + + #print detectors + + if (DAQ_XMAP == 1) and ('MOENCH' in detectors): + + detector_actions=[detector_action_1 + ,detector_action_2 + ,detector_action_moench_aquire + ,detector_action_3 + ,detector_action_moench_wait + ,detector_action_4] + + + # ================================================================= + # + # DEFINE DEFAULT POSTACTIONS + # + # ================================================================ + + + + postaction_1={'channel_name' : 'X07MB-OP2:START-CSMPL','value' : '1' + ,'operation' : 'put' + ,'data_type' : 'String' + ,'delay' : '0.1'} + + postaction_2={'channel_name' : 'X07MB-OP2:SMPL','value' : 1 + ,'operation' : 'put' + ,'data_type' : 'Integer' + ,'delay' : '0.1'} + + postactions=[postaction_1 + ,postaction_2] + + + # establish predefined detector groups.... + + # group 1 beamline pressures... + + CH_BL_PRESS = ['X07MA-FE-CH2MP1:PRESSURE' + ,'X07MB-OP-MI1MP1:PRESSURE' + ,'X07MA-OP-CMMP:PRESSURE' + ,'X07MA-OP-SCMP:PRESSURE' + ,'X07MB-OP-IP1MP1:PRESSURE' + ,'X07MB-OP-SL1MP1:PRESSURE' + ,'X07MB-OP-FI1MP1:PRESSURE' + ,'X07MB-OP-BM1MP1:PRESSURE' + ,'X07MB-OP-IP2MP1:PRESSURE' + ,'X07MB-OP-BM2MF1:PRESSURE' + ,'X07MB-OP-MOMF1:PRESSURE' ] + + ID_BL_PRESS = ['CH2MP1' + ,'MI1MP' + ,'CMMP' + ,'SCMP' + ,'IP1MP1' + ,'SL1MP1' + ,'FI1MP1' + ,'BM1MP1' + ,'IP2MP1' + ,'BM2MF1' + ,'MOMF1'] + + # group BL temperatures temperatures... + + CH_BL_TEMP=['X07MB-OP-MI1:TC1' + ,'X07MB-OP-MI1:TC3' + ,'X07MA-OP-CMMI:TC1' + ,'X07MA-OP-CMB:TC1' + ,'X07MA-OP-SC:TC1' + ,'X07MA-FE-SH1:TC1' + ,'X07MA-FE-SH1:TC2' + ,'X07MA-FE-SH1:TC3' + ,'X07MA-FE-SH1:TC4' + ,'X07MA-FE-SV1:TC1' + ,'X07MA-FE-SV1:TC2' + ,'X07MA-FE-SV1:TC3' + ,'X07MA-FE-SV1:TC4' + ,'X07MB-OP-SH1:TC_X1' + ,'X07MB-OP-SH1:TC_X2' + ,'X07MB-OP-SV1:TC_Y1' + ,'X07MB-OP-SV1:TC_Y2' + ] + + ID_BL_TEMP=['MI1TC1' + ,'MI1TC3' + ,'CMMITC1' + ,'CMBTC1' + ,'SCTC1' + ,'FE_SH1TC1' + ,'FE_SH1TC2' + ,'FE_SH1TC3' + ,'FE_SH1TC4' + ,'FE_SV1TC1' + ,'FE_SV1TC2' + ,'FE_SV1TC3' + ,'FE_SV1TC4' + ,'SL1_SH1TC_X1' + ,'SL1_SH1TC_X2' + ,'SL1_SV1TC_Y1' + ,'SL1_SV1TC_Y2' + ] + + + # DETECTOR GROUP .......... Mono temperatures + + CH_MONO_TEMP=['X07MB-OP-MOTHETA:TC1' + ,'X07MB-OP-MOTRX:TC1' + ,'X07MB-OP-MOC2:TC_Z' + ,'X07MB-OP-MOC2:TC_Y'] + + ID_MONO_TEMP=['MONO_THETA_TC1' + ,'MONO_TRX_TC1' + ,'MONO_C2_TC_Z' + ,'MONO_C2_TC_Y'] + + for i in range(16): + CH_MONO_TEMP.append('X07MB-OP-MO:TC'+str(i+1)) + ID_MONO_TEMP.append('MONO_TC'+str(i+1)) + #endfor + + + + # ............DETECTOR GROUP MONO ENCODERS ... + + + CH_MONO_ENC = [ 'X07MB-OP-MO:C1-EC_ROZ' , 'X07MB-OP-MO:C2-EC_ROX' , 'X07MB-OP-MO:C2-EC_ROZ' + ,'X07MB-OP-MO:C1-ROZ.DRBV','X07MB-OP-MO:C2-ROX.DRBV','X07MB-OP-MO:C2-ROZ.DRBV' + ,'X07MB-OP-MO:C1-ROZ.DIFF','X07MB-OP-MO:C2-ROX.DIFF','X07MB-OP-MO:C2-ROZ.DIFF' + ,'X07MB-OP-MO:C1-EC_ROZ.VAL','X07MB-OP-MO:C2-EC_ROX.VAL','X07MB-OP-MO:C2-EC_ROZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.VAL' + ,'X07MB-OP-MO:C2-TRZ.RBV' + ,'X07MB-OP-MO:C2-TRZ.DIFF' + ,'X07MB-OP-MO:C2-TRZ.REP' + ,'X07MB-OP-MO:C2-TRY.VAL' + ,'X07MB-OP-MO:C2-TRY.RBV' + ,'X07MB-OP-MO:C2-TRY.DIFF' + ,'X07MB-OP-MO:C2-TRY.REP' + ,'X07MB-OP-MO:THETA.VAL' + ,'X07MB-OP-MO:THETA.RBV' + ,'X07MB-OP-MO:THETA.DIFF' + ,'X07MB-OP-MO:THETA.REP'] + + + + ID_MONO_ENC = [ 'ROLL1_V' , 'PITCH2_V' , 'ROLL2_V' + ,'ROLL1_MUR' , 'PITCH2_MUR' , 'ROLL2_MUR' + ,'ROLL1_DIFF','PITCH2_DIFF','ROLL2_DIFF' + ,'ROLL1_VOLT','PITCH2_VOLT','ROLL2_VOLT' + ,'T1_VAL' + ,'T1_RBV' + ,'T1_DIFF' + ,'T1_REP' + ,'T2_VAL' + ,'T2_RBV' + ,'T2_DIFF' + ,'T2_REP' + ,'THETA_VAL' + ,'THETA_RBV' + ,'THETA_DIFF' + ,'THETA_REP'] + + + + + + + + # .................... Detector group Pressures endstation ............................. + + + CH_ES1_PRESS=['X07MB-ES1-MF1:PRESSURE' + ,'X07MB-ES1-MC1:PRESSURE' + ,'X07MB-OP-KBMF1:PRESSURE' + ,'X07MB-OP-SL2MF1:PRESSURE' + ] + + + ID_ES1_PRESS=['ES1MF1' + ,'ES1MC1' + ,'OPKBMF1' + ,'OPSL2MF1' + ] + + # .................... Detector group XBPM and microscope missing ............................. + + # ........................................... XBPM 3 + + CH_XBPM4=['X07MB-OP2-SAI_19:CUR-MEAN' + ,'X07MB-OP2-SAI_20:CUR-MEAN' + ,'X07MB-OP2-SAI_21:CUR-MEAN' + ,'X07MB-OP2-SAI_22:CUR-MEAN'] + + + + ID_XBPM4=['XBPM4_SAI19_CUR_MEAN' + ,'XBPM4_SAI20_CUR_MEAN' + ,'XBPM4_SAI21_CUR_MEAN' + ,'XBPM4_SAI22_CUR_MEAN'] + + + CH_XBPM4_POS=['X07MB-OP-BPM4:POSX' + ,'X07MB-OP-BPM4:POSY'] + + ID_XBPM4_POS=['XBPM4_POSX' + ,'XBPM4_POSY'] + + + # ........................................... XBPM 4 + + CH_XBPM3=['X07MB-OP2-SAI_14:CUR-MEAN' + ,'X07MB-OP2-SAI_15:CUR-MEAN' + ,'X07MB-OP2-SAI_16:CUR-MEAN' + ,'X07MB-OP2-SAI_17:CUR-MEAN'] + + ID_XBPM3=['XBPM3_SAI14_CUR_MEAN' + ,'XBPM3_SAI15_CUR_MEAN' + ,'XBPM3_SAI16_CUR_MEAN' + ,'XBPM3_SAI17_CUR_MEAN'] + + + CH_XBPM3_POS=['X07MB-OP-BPM3:POSX' + ,'X07MB-OP-BPM3:POSY'] + + ID_XBPM3_POS=['XBPM3_POSX' + ,'XBPM3_POSY'] + + + + # ........................................... XBPM 3 + + CH_CAM1_POS=['X07MB-PS1:Stats1:CentroidX_RBV' + ,'X07MB-PS1:Stats1:CentroidY_RBV' + ,'X07MB-PS1:Stats1:SigmaX_RBV' + ,'X07MB-PS1:Stats1:SigmaY_RBV' + ,'X07MB-PS1:Stats1:SigmaXY_RBV' + ] + + + ID_CAM1_POS=['CentroidX_RBV' + ,'CentroidY_RBV' + ,'SigmaX_RBV' + ,'SigmaY_RBV' + ,'SigmaXY_RBV' + ] + + + + # read channel and initial values for + + ch_ini_base=beamline+'-PC-PSCAN:' + N_initial=6 # for now limit to 5 initial channels + i_0 = 0 + for i in range(N_initial): + + print 'read initial value ' + str(i) + print ch_ini_base+'ChInit'+str(i)+'-ACT' + this_active = get_epicsPV(ch_ini_base+'ChInit'+str(i)+'-ACT') + time.sleep(0.05) + #print this_active + if (i_0 ==0 ) and ( this_active== 1) : + print ' first region active............. ' + CH_INITIAL = [get_epicsPV(ch_ini_base+'ChInit'+str(i))] + time.sleep(0.05) + CH_INITIAL_V = [get_epicsPV(ch_ini_base+'VChInit'+str(i))] + time.sleep(0.05) + i_0=i_0+1 + else: + if ( this_active== 1): + print 'next found ',i + time.sleep(0.05) + CH_INITIAL.append(get_epicsPV(ch_ini_base+'ChInit'+str(i))) + time.sleep(0.05) + CH_INITIAL_V.append(get_epicsPV(ch_ini_base+'VChInit'+str(i))) + # endif + # endelse + # endfor + print('END LOOP READ CHINIT') + if (i_0 == 0 ): + CH_INITIAL = ['NO_INITIAL_VALUES'] + CH_INITIAL_V = [0] + #print CH_INITIAL + #print CH_INITIAL_V + + # ________________ finally do consistency checks on the input data + + # CASE 1 emergengy stop if number of choosen roi is larger that the number of available rois + + + if ((n_roi_for_xas >= n_roi) and (n_roi <> -1) and (n_roi_for_xas <> -1)) and (XMAP_save_only_xas_roi <> 1 ) : # if values are negative, XMAP is not used.. + error_stop('!!!!! INCONSISTENT INPUT: Number of Roi for XAS larger than choosen roi !!!') + # endif + # CASE 2 emergengy stop if there are no active regions + + + # finally collect all read data into one structure, which completely defines the scan. + # This structure is returned as result of thie routine. + # All all readouts of this structure are adressed by the structure names, and never by indices, + # the structure can be extendened in a very general way + # on the longterm one could envision that the python routine just monitors all chanels, and + # creates a regular update... this would avoid the -time consuming- rereading of all chanels for every creation + # of the measurements scripts. + + + # now combine all data for the energies into standard positiner list +# Energies=[] + + # First generate regions, as uses for pshell scan definitions + Energy_Ranges,Energy_Cycles,Energy_Scan_Positions = Energy_Scan_Create(e_i,e_f,e_delta,e_n_cycles) + + #Energy_Ranges=[] + #Energy_Cycles=[] + + #for i in range(len(e_i)): + # Energy_Ranges.append([e_i[i] , e_f[i] , float(e_delta[i])]) + # Energy_Cycles.append(e_n_cycles[i]) + #endfor + + + + + + + + + + + + + + + + + + + e_channel = 'X07MB-OP-MO:E-SET' # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + e_channel_rbv = 'X07MB-OP-MO:E-GET' + #e_channel = 'X07MA-PHS-E:GO.A' # XTREME + #e_channel_rbv = 'X07MA-PGM:CERBK' + #e_channel = 'X07MB-OP:userCalc1.L' # test write energy in calc record + #e_channel_rbv = 'X07MB-OP:userCalc1.L' + + EnergyScan={'channel_name' : e_channel + ,'channel_rbv' : e_channel_rbv + ,'Energy_Ranges' : Energy_Ranges + ,'Energy_Cycles' : Energy_Cycles + ,'Energy_Scan_Positions' : Energy_Scan_Positions + ,'delay' : 0 + ,'data_type' : 'double' + ,'alias' : 'Energy' + ,'e_i' : e_i + ,'e_f' : e_f + ,'e_delta' : e_delta + ,'e_n_cycles' : e_n_cycles + ,'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + } + + # add on on 23.7.2020 we create a new list with teh + # same principal shape as teh one for preactions, and detector actions + # There is a lsit of entries for each positioner. + # This method will make the storaing of positioners, and any channel action uniform + + All_Positioner=[] + for i_tmp in range(len(p_channel)): + This_Positioner= {'channel_name' : p_channel[i_tmp] + ,'channel_rbv' : p_channel_rbv_full[i_tmp] + ,'alias' : p_id[i_tmp] + ,'label' : p_label + ,'done' : p_done[i_tmp] + ,'done_switch' : p_done_switch[i_tmp] + ,'operation' :'put' + ,'data_type' : 'double' + ,'delay' : 0.0 + ,'value' : p_data[i_tmp]} + #print(This_Positioner) + All_Positioner.append(This_Positioner) + #endfor + #print('-------- All_Positioner -----') + #print(All_Positioner) + Configuration={ 'scan_type' : scan_type + , 'DAQ_XMAP' : DAQ_XMAP + ,'beamline' : beamline } # below here only detail information, likely remove }] + + DetectorGroups={'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS } + + SDD={ 'hardware_sdd' : hardware_sdd + , 'ch_base_vortex' : ch_base_vortex + , 'ch_base_vortex_dxp' : ch_base_vortex_dxp + , 'ch_base_vortex_mca' : ch_base_vortex_mca + , 'n_roi_for_xas' : n_roi_for_xas + , 'n_roi_for_xas_index' : n_roi_for_xas_index + , 'n_roi' : n_roi + , 'n_det_fluo' : n_det_fluo + , 'd_list_fluo' : d_list_fluo + , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name + , 'XMAP_roi_numbers' : XMAP_roi_numbers + , 'XMAP_name_convention' : XMAP_name_convention + , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi + , 'XMAP_save_spectra' : XMAP_save_spectra} + + + box={ 'filename' : filename + , 'Configuration' : Configuration + , 'SDD' : SDD + , 'All_Positioner' : All_Positioner # NEEDED FOR PSCAN SCAN DEFINITION + , 'Detector_Groups' : DetectorGroups + , 'Pre_Actions' : preactions + , 'Post_Actions' : postactions + , 'Detector_Actions' : detector_actions + , 'Energy_Scan' : EnergyScan + , 'beamline' : beamline # below here only detail information, likely remove + , 'scan_type' : scan_type + , 'detectors' : detectors + , 'detectors_to_plot' : detectors_to_plot +# , 'hardware_sdd' : hardware_sdd +# , 'ch_base_vortex' : ch_base_vortex +# , 'ch_base_vortex_dxp' : ch_base_vortex_dxp +# , 'ch_base_vortex_mca' : ch_base_vortex_mca +# , 'n_roi_for_xas' : n_roi_for_xas +# , 'n_roi_for_xas_index' : n_roi_for_xas_index +# , 'n_roi' : n_roi +# , 'n_det_fluo' : n_det_fluo +# , 'd_list_fluo' : d_list_fluo +# , 'Id_XMAP_roi_by_name' : Id_XMAP_roi_by_name +# , 'XMAP_roi_numbers' : XMAP_roi_numbers +# , 'XMAP_name_convention' : XMAP_name_convention +# , 'XMAP_save_only_xas_roi' : XMAP_save_only_xas_roi +# , 'XMAP_save_spectra' : XMAP_save_spectra + , 'number_of_executions' : number_of_executions + , 'n_e' : n_e + , 'e_active' : e_active + , 'e_i' : e_i + , 'e_f' : e_f + , 'e_delta' : e_delta + , 'e_n_cycles' : e_n_cycles + , 'n_exafs' : n_exafs + , 'e_ex_E_edge' : e_ex_E_edge + , 'e_ex_active' : e_ex_active + , 'e_ex_e_i' : e_ex_e_i + , 'e_ex_e_f' : e_ex_e_f + , 'e_ex_k_i' : e_ex_k_i + , 'e_ex_k_f' : e_ex_k_f + , 'e_ex_d_i' : e_ex_d_i + , 'e_ex_ncy' : e_ex_ncy + , 'e_ex_ncy_f' : e_ex_ncy_f + , 'e_ex_icy' : e_ex_icy + , 'e_ex_nst' : e_ex_nst + , 'e_ex_t' : e_ex_t + , 'e_channel' : e_channel # PHOENIX I NEED A CHECK that we canonly run the right mono in the script! + , 'e_channel_rbv' : e_channel_rbv + #, 'e_channel' : 'X07MA-PHS-E:GO.A' # XTREME + #, 'e_channel_rbv' : 'X07MA-PGM:CERBK' + #, 'e_channel' : 'X07MB-OP:userCalc1.L' # test write energy in calc record + #, 'e_channel_rbv' : 'X07MB-OP:userCalc1.L' + , 'n_p' : n_p + , 'p_channel' : p_channel + , 'p_channel_rbv' : p_channel_rbv + , 'p_id' : p_id + , 'p_positioner_active': p_positioner_active + , 'p_label' : p_label + , 'p_data' : p_data + , 'p_done' : p_done + , 'p_done_switch' : p_done_switch + , 'r_energy_cycles' : r_energy_cycles + , 'r_energies' : r_energies + , 'r_energies_active' : r_energies_active + , 'r_channel' : r_channel + , 'r_channel_rbv' : r_channel_rbv + , 'r_indices' : r_indices + , 'r_id' : r_id + , 'r_active' : r_active + , 'r_ll_x' : r_ll_x + , 'r_ll_y' : r_ll_y + , 'r_ur_x' : r_ur_x + , 'r_ur_y' : r_ur_y + , 'r_delta_x' : r_delta_x + , 'r_delta_y' : r_delta_y + , 'r_num' : r_num + , 'r_done' : r_done + , 'r_done_switch' : r_done_switch + , 'CH_CAM1_POS' : CH_CAM1_POS + , 'ID_CAM1_POS' : ID_CAM1_POS + , 'CH_BL_PRESS' : CH_BL_PRESS + , 'ID_BL_PRESS' : ID_BL_PRESS + , 'CH_BL_TEMP' : CH_BL_TEMP + , 'ID_BL_TEMP' : ID_BL_TEMP + , 'CH_MONO_TEMP' : CH_MONO_TEMP + , 'ID_MONO_TEMP' : ID_MONO_TEMP + , 'CH_MONO_ENC' : CH_MONO_ENC + , 'ID_MONO_ENC' : ID_MONO_ENC + , 'CH_ES1_PRESS' : CH_ES1_PRESS + , 'ID_ES1_PRESS' : ID_ES1_PRESS + , 'CH_XBPM3' : CH_XBPM3 + , 'ID_XBPM3' : ID_XBPM3 + , 'CH_XBPM3_POS' : CH_XBPM3_POS + , 'ID_XBPM3_POS' : ID_XBPM3_POS + , 'CH_XBPM4' : CH_XBPM4 + , 'ID_XBPM4' : ID_XBPM4 + , 'CH_XBPM4_POS' : CH_XBPM4_POS + , 'ID_XBPM4_POS' : ID_XBPM4_POS + , 'DAQ_XMAP' : DAQ_XMAP + , 'CH_INITIAL' : CH_INITIAL + , 'CH_INITIAL_V' : CH_INITIAL_V + , 'CH_User_detector' : CH_User_detector + , 'User_detector_fda_id' : User_detector_fda_id + } + + #ScanDef=DefineScan(box) + #print('ScanDef content ') + #print(dir(ScanDef)) + + + + #print box + #print detectors + #print('preactions') + #print preactions + + print('.... done get_channels..') + return box + + + diff --git a/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_lib.py b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_lib.py new file mode 100644 index 0000000..616b376 --- /dev/null +++ b/script/Users/Thomas/backup/backup_20200811_125738/X_X07MB_lib.py @@ -0,0 +1,2619 @@ + +# ========================================================= +# +# CLASS Pscan_lib +# +# =========================================================== + +class PscanLib(): + + """ + PscanLib contains routines specific for PHOENIX beanmline + + Default initialization + + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Where + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + reads the scan definitio from PHEONIX GUI + + It creates default lists + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + + of format: + {'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': org.python.proxies.__main__$Channel$12@5098c7fe + , 'delay': '0.05' + , 'UsedAlias': 'X07MB-OP2:START-CSMPL' + , 'data_type': 's' + , 'value': '0' + , 'operation': 'put'} + (For action lists) + + For sensors: + + Channel instances are created and added by SC.Create_All_Sensors + + {'channel_name': 'X07MB-OP-MO:E-SET' + , 'Channel': org.python.proxies.__main__$Channel$12@1b37aa1a + , 'Subset_1': True + , 'number': 0 + , 'DTC': False + , 'UsedAlias': 'Energy_set' + , 'data_type': 'ScalarDetector' + , 'alias': 'Energy_set' + , 'operation': 'put'} +are default list as derived from the PHOENIX gui + using + + + + These lists can be easily used in general pshell scans + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions')) + + + """ + + def __init__(self,SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table): + import time + self.SD=SD # scandefitions (variable g in old code) + self.Channel=Channel # Channel as defined in PSCAN + self.get_exec_pars = get_exec_pars + self.caput = caput + self.caputq = caputq + self.caget = caget + self.cawait = cawait + self.create_table =create_table + self.append_table =append_table + + self.All_Sensors=[] # this is the list of all detectors + self.noprint=0 + self.time=time + self.timeout = 10 # currently timtout set to 10 sec. Need to adapt to real dwell time, for Moench we will have lnger times + + # Parameter for subset 1 (file for Athena including dead time correction for SDD) + self.names_subset_1 =[] # Names of all sensors and elements to br written to file + # will be created in after_read_dtc in first call + self.types_subset_1 =[] + + # runtime variable + self.detector_number = 0 # Number of sensor in list is needed to + # find detector back in 'after_read' routine + # end init + + + # ====================================================== + # + # ROUTINES TO CREATE SENSORS / DETECTORS + # + # ===================================================== + + def Add_New_Sensors(self,SensorList): + """ + routine allows to add a sensor to default list from guot + syntax: + Add_New_Sensor({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + TO DO: + + + MISSING DOES NOT ADD KEYS FOR SUBSET< DTC ETYC + TO BE MERGES WITH add_new_det_to_list() + + """ + + self.pm(SensorList) + for i in range(len(SensorList)): + self.add_det_to_list({'Det_type' : SensorList[i]['Det_type'] + ,'data_type' : SensorList[i]['data_type'] + ,'channel_name' : SensorList[i]['channel_name'] + ,'Id' : SensorList[i]['alias']}) + #endfor + + def add_det_to_list(self,params): + + """ + This routine creates the device of a single sensor, adds + it to the existing list and also create a running number + which is needed to identify the sensor when makin calculations + with the sensor in the call to after_read + + Routine adds default keys based on sensor names for subset_a for + separate file saving in Athenae format and for dead time correction + + + Syntax + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + + """ + self.pm('enter add_det_to_list') + self.pm(params) + + #dev = Channel('X07MB-OP2-SAI_07:MEAN', alias=channel_name) + try: + + ThisSensor={'channel_name' : params['channel_name'] + ,'operation' : 'put' + ,'data_type' : params['Det_type'] + ,'alias' : params['Id'] +# ,'delay' : '0.05' # likely useless parameter + ,'number' : self.detector_number} + self.detector_number=self.detector_number+1 + except: + self.pm('Cannot create ThisSensor') + stop + self.pm('ThisSensor in add_det_to_list') + try: + self.pm( ThisSensor) # THIS PRINT COMMAND DOES NOT WORK + except: + self.pm('Cannor excecute self.pm(ThisSensor) in add_det_to_list') + try: + self.All_Sensors.append(ThisSensor) + except: + self.pm('cannot excecute self.Al_Sensors.append(ThisSensor) in add_det_to_list ') + self.pm(ThisSensor) + stop + # + # + # Finally add some flags for certain actions + # + # + + # This detector needs to be deadtime corrected + # + print('------------------------') + print(ThisSensor) + if ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']): + ThisSensor.update({'DTC':True}) + else: + ThisSensor.update({'DTC':False}) + #endelse + + # This detector should be in limited output + + if (('ENERGY' in ThisSensor['alias'].upper() ) \ + or('KEITHLEY' in ThisSensor['alias'].upper() ) + or ('mca1.R' in ThisSensor['channel_name'])\ + or ('mca2.R' in ThisSensor['channel_name'])\ + or ('mca3.R' in ThisSensor['channel_name'])\ + or ('mca4.R' in ThisSensor['channel_name']) + or ('ICR' in ThisSensor['alias']) + or ('OCR' in ThisSensor['alias']) + ): + ThisSensor.update({'Subset_1':True}) + else: + ThisSensor.update({'Subset_1':False}) + #endelse + + + + + + self.pm('Leave add_det_to_list') + return + # end routine + + + + def Create_Sensor_List(self): + """ + # This routine creates all standard sensors, + # and in particular analyzes teh ROI names + # for the XMAP detectors + # + # it is moreless a copy of teh old routine + write_detectors, which wrote the detectot definition for the fda xml files. + The routine call self add_det_to_list, whic + adds any new detecto to the list + # bad code + # g was name of list in old code fo fda + # here we use write_detecto to create a list which is compatible with th + # format of the general positioner lists... + """ + self.pm('PscanLib.Create_Sensor_List') + + # Here we equate old variable g and SD (Scan definition) + self.All_Sensors=[] # reset List All_Sensors + self.detector_number=0 + g=self.SD + f=0 # NOT NEEDED ANYMORE TIHS WAS OLD FILE UNIT + + #self.List_Devices_Sensors=[[],[],[],[]] + #self.List_Devices_Sensors=[] + #self.pm('----------') + print( g['detectors']) + print( g['p_channel']) + print( g['p_id']) + + # First store the energy (Changed to previous code) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel'] ############## general g + ,'Id' : 'Energy_set'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['e_channel_rbv'] ############## general g + ,'Id' : 'Energy_set_rbv'}) + + # .............. First store set values of standard positioner: + + + for i in range(len(g['p_channel'])): + if g['p_id'][i] <> ' ': # change 3.5.2012: do not write positioniner, + # if there is not positioner + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['p_channel'][i] + ,'Id' : g['p_id'][i] +'_set'}) + #endif + # endfor + # the write a few other standard detectors as well: + + + # write Keithleys............ + + if 'KEITHLEY1' in g['detectors']: + print (' write Detector Keithley 1' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_07:MEAN' + ,'Id' : 'I0_KEITHLEY1'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH1:setGain' + ,'Id' : 'KEITHLEY1_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY2' in g['detectors']: + print (' write Detector Keithley 2' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_08:MEAN' + ,'Id' : 'I1_KEITHLEY2'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH2:setGain' + ,'Id' : 'KEITHLEY2_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + if 'KEITHLEY3' in g['detectors']: + print(' write Detector Keithley 3' ) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_06:MEAN' + ,'Id' : 'KEITHLEY3'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH3:setGain' + ,'Id' : 'KEITHLEY3_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_01:MEAN' + ,'Id' : 'KEITHLEY4_TEY'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'DBF_ENUM' + ,'channel_name' : 'X07MB-OP-KEITH4:setGain' + ,'Id' : 'KEITHLEY4_GAIN'}) + # NOTE: Channel read out is of format srting '10^4' in extracted data file + # we convert to float(4) + #endif + + + # ........... vortex 4-element + + + # write fluo detectors................... + + # first set some default values for the case of no FLUO detector + + n_det_vortex = 0 + n_roi_vortex = -1 + channel_roi_vortex = -1 + id_roi_vortex = '-1' + id_trueicr_vortex = '-1' + id_icr_vortex = '-1' + id_ocr_vortex = '-1' + id_eltm_vortex = -1 + id_ertm_vortex = -1 + + + + if 'Vortex' in g['detectors']: + n_det = 4 + + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + + else: + # The next line makes sure that the variables will be defined in any case . + # The will be overwriten with reasonable numbers, in case either KETEK or ROENTEK are chosen + [n_det,n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_true_icr_vortex,id_ocr,id_eltm,id_ertm]=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + #endif + print( n_roi_vortex) + + # ........... Roentex via XMAP 1-element + if 'ROENTEC_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + # ........... KETEK via XMAP 1-element + if 'KETEK_XMAP' in g['detectors']: + n_det=1 + [n_det_vortex,n_roi_vortex,channel_roi_vortex + ,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex + ,id_eltm_vortex,id_ertm_vortex]=self.write_vortex(f,self.SD['SDD'],n_det) + #endif + print (id_roi_vortex) + print (n_det) + + + + + + if 'MOENCH' in g['detectors']: + # special case for using Moench detector plot also the file number of general file + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:cam1:FileNumber_RBV' + ,'Id' : 'MOENCH_FN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-ES1-SD1:TIFF1:FileNumber_RBV' + ,'Id' : 'MOENCH_TIFF_FN'}) + + #endif + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-MO:BEAM-OFS' + ,'Id' : 'Mono_offset'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'ARIDI-PCT:CURRENT' + ,'Id' : 'I_SLS'}) + + + + + + # write user defined detectors + + + if g['CH_User_detector'] <> ['noUserDetector']: + for i in range(len(g['CH_User_detector'])): + print( i) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_User_detector'][i] + ,'Id' : g['User_detector_fda_id'][i]}) + #endfor + #endif + + + + + + + + + if 'XBPM3' in g['detectors']: + print(' write Detector XBPM3 ') + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM3_GAIN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_14:CUR-MEAN' + ,'Id' : 'XBPM3_SAI14_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_15:CUR-MEAN' + ,'Id' : 'XBPM3_SAI15_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_16:CUR-MEAN' + ,'Id' : 'XBPM3_SAI16_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_17:CUR-MEAN' + ,'Id' : 'XBPM3_SAI17_CUR_MEAN'}) + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSX' + ,'Id' : 'XBPM3_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM3:POSY' + ,'Id' : 'XBPM3_POSY'}) + + + + + #endif + + + if 'XBPM4' in g['detectors']: + print(' write Detector XBPM 4') + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2:LCAD3-GAIN' + ,'Id' : 'XBPM4_GAIN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_19:CUR-MEAN' + ,'Id' : 'XBPM4_SAI19_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_20:CUR-MEAN' + ,'Id' : 'XBPM4_SAI20_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_21:CUR-MEAN' + ,'Id' : 'XBPM4_SAI21_CUR_MEAN'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP2-SAI_22:CUR-MEAN' + ,'Id' : 'XBPM4_SAI22_CUR_MEAN'}) + + + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSX' + ,'Id' : 'XBPM4_POSX'}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : 'X07MB-OP-BPM4:POSY' + ,'Id' : 'XBPM4_POSY'}) + + + #endif + + + self.pm('g[detectors]',g['detectors']) + + # beamline pressures + + if 'BL_PRESS' in g['detectors']: + self.pm('Write BL_PRESS') + for i in range(len(g['ID_BL_PRESS'])): + #print i,g['CH_BL_PRESS'][i],g['ID_BL_PRESS'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_PRESS'][i] + ,'Id' : g['ID_BL_PRESS'][i]}) + #ENDFOR + # endif + + + if 'BL_TEMP' in g['detectors']: + self.pm('Create BL_TEMP') + for i in range(len(g['ID_BL_TEMP'])): + #print i,g['CH_BL_TEMP'][i],g['ID_BL_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_BL_TEMP'][i] + ,'Id' : g['ID_BL_TEMP'][i]}) + #ENDFOR + # endif + + + + + if 'MONO_TEMP' in g['detectors']: + self.pm('create MONO_TEMP') + for i in range(len(g['ID_MONO_TEMP'])): + #print i,g['CH_MONO_TEMP'][i],g['ID_MONO_TEMP'][i] + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_TEMP'][i] + ,'Id' : g['ID_MONO_TEMP'][i]}) + #ENDFOR + # endif + + if 'MONO_ENC' in g['detectors']: + for i in range(len(g['ID_MONO_ENC'])): + print (i,g['CH_MONO_ENC'][i],g['ID_MONO_ENC'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_MONO_ENC'][i] + ,'Id' : g['ID_MONO_ENC'][i]}) + #ENDFOr + # endif + + + if 'ES1_PRESS' in g['detectors']: + + for i in range(len(g['ID_ES1_PRESS'])): + print( i,g['CH_ES1_PRESS'][i],g['ID_ES1_PRESS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_ES1_PRESS'][i] + ,'Id' : g['ID_ES1_PRESS'][i]}) + #ENDFOR + # endif + + # write detector group microscope position + + if 'CAM1_POS' in g['detectors']: + + for i in range(len(g['ID_CAM1_POS'])): + print( i) + print( i,g['CH_CAM1_POS'][i],g['ID_CAM1_POS'][i]) + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : g['CH_CAM1_POS'][i] + ,'Id' : g['ID_CAM1_POS'][i]}) + #ENDFOR + # endif + + Sensor_List=self.All_Sensors + + print(n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex) + + return Sensor_List + + # return n_det_vortex,n_roi_vortex,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr_vortex,id_trueicr_vortex,id_ocr_vortex,id_eltm_vortex,id_ertm_vortex + + + def write_vortex(self,f,g,n_det): + + self.pm('PscanLib.write_vortex') + + + # this routine write all detectors for the VORTEX detector + # Author T.Huthwelker, October 2011 + # revision for use in pshell July 2020 + # ------------------------------------------------ + # input + # f file object (xml file) + # g readout from user gui as defined in routine get_channels + # g is a structures variable (i.e. variable with directory) + # from g we need these entries + # g['n_roi_for_xas'] : Roi number, which is used in XAS measurements + + # ------------------------------------------------ + + + # -------- configuration parameter for thie routine, might be added as input parameter later. + + n_roi = g['n_roi'] # get number of rois as determined from XMAP software..... + + # the number of rois from the actual entries in the XMAP software + # UNTIL 15.1.2019: + # ch_base_vortex=g['beamline']+'-XMAP:mca' + # ch_base_vortex_dxp=g['beamline']+'-XMAP:dxp' + # NEW: + ch_base_vortex=g['ch_base_vortex'] + ch_base_vortex_dxp=g['ch_base_vortex_dxp'] + ch_base_vortex_mca=g['ch_base_vortex_mca'] + + #..variable channel_roi contains epics channels fo all rois available + + + # now create 2-D list to store all rois for all detectors and + # as the corresponding id as used in XML script. Here we nake sure that we define only the ID values for the rois used later + # This will alow in later use of these variable, just to work through the list id_roi_this_detector. + # for the case XMAP_save_only_xas_roi, we reduce the list to one single value in list id_roi_this_detector. + # UNfortunatly, we need to reset the variable n_roi to 1, as we use only one single roi here... + # It is a quite bad looking code... + + + + # g['Id_XMAP_roi_by_name'] stores roi names ast list + # g[XMAP_roi_numbers'] stores number of rois in Id list as as list + + # new list based code... + + #print '......... use all rois as detectors...' + #print g['XMAP_save_only_xas_roi'] + #print g['Id_XMAP_roi_by_name'] + #print g['XMAP_roi_numbers'] + #print g['n_roi'] + + + + d_list =g['d_list_fluo'] # get the list, which contains the numbers of the choosen detectors + n_det_from_list = len(d_list) # only local variable. In principle g['n_det_fluo'] should contain the same number... + + #for i in range(n_det): # =============== CHANGE + # 16.4.2015 start adding roi readout from SCA variable + + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + #print ch_base_vortex + + for i in d_list: + det_nr=det_nr+1 + # inner loop: walk through all regions of interest.... + for j in range(len(g['XMAP_roi_numbers'])): + #print 'j',j + #print 'list',g['XMAP_roi_numbers'] + + if j == 0: + # create 1st element of list + rois_this_detector = [ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp = [ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts'] + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp'] + #endif + else: + id_roi_this_detector=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )] + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp=['D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp'] + #endif + #endelse + else: + + # for list for det i + + rois_this_detector.append(ch_base_vortex_mca+str(i)+'.R'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + rois_this_detector_dxp.append(ch_base_vortex_dxp+str(i)+':SCA'+str( g['XMAP_roi_numbers'][j] )+'Counts' ) + #endif + if g['XMAP_name_convention'].lower() == 'roi': + id_roi_this_detector.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j]) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_'+g['Id_XMAP_roi_by_name'][j] +'_dxp') + #endif + else: + id_roi_this_detector.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] )) + if g['hardware_sdd']=='XMAP': + id_roi_this_detector_dxp.append('D'+str(i)+'_ROI_'+str( g['XMAP_roi_numbers'][j] ) +'_dxp') + #endif + # endelse + + # endelse + + # endfor + + # now add rois to fill 2-D list + if det_nr == 0: + channel_roi_vortex = [rois_this_detector] + id_roi_vortex = [id_roi_this_detector] + + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp = [rois_this_detector_dxp] + id_roi_vortex_dxp = [id_roi_this_detector_dxp] + #endif + else: + channel_roi_vortex.append(rois_this_detector) + id_roi_vortex.append(id_roi_this_detector) + if g['hardware_sdd']=='XMAP': + channel_roi_vortex_dxp.append(rois_this_detector_dxp) + id_roi_vortex_dxp.append(id_roi_this_detector_dxp) + #endif + # endelse + # endfor + + # now we have created a list with all chhoses detectors from the list det_nr + + + + #print 'channel_roi_vortex',channel_roi_vortex + #print ' id_roi_vortex' ,id_roi_vortex + if g['hardware_sdd']=='XMAP': + print( 'channel_roi_vortex_dxp',channel_roi_vortex_dxp) + print( 'id_roi_vortex_dxp',id_roi_vortex_dxp) + #endif + print ('det_nr',det_nr) + + + # now write all detectors to file... + # + + #for i in range(n_det): # =============== CHANGE + + # Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + for i in range(n_det_from_list): + + for j in range(len(g['XMAP_roi_numbers'])): + #print 'next j',j + #print g['XMAP_roi_numbers'] + + #print range(len(g['XMAP_roi_numbers'])) + #print i,j,'000000000000000000000000000000000' + + # write MCA channel detector + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex[i][j] + ,'Id' : id_roi_vortex[i][j]}) + # write sca channel roi detector + if g['hardware_sdd']=='XMAP': + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : channel_roi_vortex_dxp[i][j] + ,'Id' : id_roi_vortex_dxp[i][j]}) + #endif + + # endfor + # endfor + + + + print channel_roi_vortex + print id_roi_vortex + + # Finally write all detector parameters relevant to standard user. + # create FDA Id for ICR, OCR, ELTIM and ERTIM + + # 19.5.2012 add dead time to default detectors. + + # give names with DD to technical parameters to ease data extraction ... + + + # next loop loops needs to adress the physical number of the detectors in the index again there fore loop + # loop thorugh the entries of the full list. + + #for i in range(n_det): # =============== CHANGE + det_nr=-1 # counts detectors used, if zero start ne list, if higher, add elemenst to list + + + for i in d_list: + det_nr=det_nr+1 + + #print i + if det_nr == 0: + # create the ID' for the different channels + # distinction bwteen 'D' and 'DD' is to ease the splitting of the data + # files into subsets of simpler data files + + id_trueicr = [ 'D'+str(i)+'_TrueICR' ] + id_icr = [ 'D'+str(i)+'_ICR' ] + id_ocr = [ 'D'+str(i)+'_OCR' ] + id_eltm = [ 'DD'+str(i)+'_ELTM' ] + id_ertm = [ 'DD'+str(i)+'_ERTM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + id_dtim = [ 'DD'+str(i)+'_DTIM' ] + + # create a list with the channels for the id's + # OLD: until 15.1.2019 + + #ch_icr = [ g['beamline']+'-XMAP:dxp'+str(i)+':InputCountRate' ] + #ch_ocr = [ g['beamline']+'-XMAP:dxp'+str(i)+':OutputCountRate' ] + #ch_eltm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ELTM' ] + #ch_ertm = [ g['beamline']+'-XMAP:mca'+str(i)+'.ERTM' ] + #ch_dtim = [ g['beamline']+'-XMAP:mca'+str(i)+'.DTIM' ] + + ch_icr = [ g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ] + ch_ocr = [ g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ] + ch_eltm = [ g['ch_base_vortex_mca']+str(i)+'.ELTM' ] + ch_ertm = [ g['ch_base_vortex_mca']+str(i)+'.ERTM' ] + ch_dtim = [ g['ch_base_vortex_mca']+str(i)+'.DTIM' ] + + else: + # ADD ID's + id_trueicr.append('D'+str(i)+'_TrueICR') + id_icr.append('D'+str(i)+'_ICR') + id_ocr.append('D'+str(i)+'_OCR') + id_eltm.append('DD'+str(i)+'_ELTM') + id_ertm.append('DD'+str(i)+'_ERTM') + id_dtim.append('DD'+str(i)+'_DTIM') + + # ADD Channels + ch_icr.append( g['ch_base_vortex_dxp']+str(i)+':InputCountRate' ) + ch_ocr.append( g['ch_base_vortex_dxp']+str(i)+':OutputCountRate' ) + ch_eltm.append( g['ch_base_vortex_mca']+str(i)+'.ELTM' ) + ch_ertm.append( g['ch_base_vortex_mca']+str(i)+'.ERTM' ) + ch_dtim.append( g['ch_base_vortex_mca']+str(i)+'.DTIM' ) + + # endelse + + # endfor + + #print id_icr + #print ch_icr + #print 'kkkkkkkkkkkkk' + #print id_ocr + + + + + # + #Now loop goes through the list which is generated above and contains only the channels/detectors choosen + # Therefore here we count only in range n_det_from_list, the index i is here lits number of the generated lists. + + + for i in range(n_det_from_list): + self.pm(i,f) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_icr[i] + ,'Id' : id_icr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ocr[i] + ,'Id' : id_ocr[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_eltm[i] + ,'Id' : id_eltm[i]}) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_ertm[i] + ,'Id' : id_ertm[i] }) + + self.add_det_to_list({'Det_type' : 'ScalarDetector' + ,'data_type' : 'Double' + ,'channel_name' : ch_dtim[i] + ,'Id' : id_dtim[i] }) + + #endfor + #print n_det,n_roi,channel_roi_vortex,id_roi_vortex,id_icr,id_ocr,id_eltm,id_ertm + + + + #.......... finally generate detectors for the full spectra.......... + + print g['XMAP_save_spectra'] + + if g['XMAP_save_spectra'] == 1: + #print ' write detector to save Flourescence spectra' + for i in d_list: + #print i + # until 17.1.2020 + #self.add_det_to_list({'Det_type' : 'ArrayDetector' + # ,'arraySize' : '2048' + # ,'channel_name' : g['beamline']+'-XMAP:mca'+str(i)+'.VAL' + # ,'Id' : 'Spec_'+str(i)}) + + self.add_det_to_list({'Det_type' : 'ArrayDetector' + ,'arraySize' : '2048' + ,'channel_name' : g['ch_base_vortex_mca']+str(i)+'.VAL' + ,'Id' : 'Spec_'+str(i)}) + + # endfor + # endif + + if g['hardware_sdd']=='SITORO': + channel_roi_vortex_dxp=-1 + id_roi_vortex_dxp=-1 + #endif + self.pm('... done PscanLib.write_vortex') + return n_det,n_roi,channel_roi_vortex,id_roi_vortex,channel_roi_vortex_dxp,id_roi_vortex_dxp,id_icr,id_trueicr,id_ocr,id_eltm,id_ertm + + + # ================================================ + # + # ROUTINES TO TREAT AL ACTIONS + # + # ================================================= + + def Preactions(self): + """ + Excecutes the default list os preactions + TO BE RETIRED FROM CODE + """ + print(' TO BE RETIRED / REMOVED ??? ') + + STOP + self.pm('PscanLib.Preactions') + + N_PREACTION = len(self.SD['Preactionss']) + self.pm('...............................ACTION TO BE EXCECUTED [Preactionss]') + self.pm('NEED ALSO SHELL ACTIONS ') + self.pm('likely obsolete:') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_file_to_EPICS.sh ${FILENAME}') + self.pm(' still needed : ') + self.pm('/sls/X07MB/data/settings/Scripts/GUI_X07MB/X_X07MB_fda_write_header.py &') + for i in range(N_PREACTION): + self.pm('i') + self.pm(self.SD['Preactionss'][i]) + # .. excute practions... + # QUESTION:\ + # + # HOW TO MAKE CHANNEL WRITE + # use epics PV of pshell special ? + # WHAT WOULD BE MORE COMPATIBLE TO PHYTHON? + # endfor + self.pm('..... done PscanLib.Preactions') + return + + def Create_Channels(self,key='detector_actions'): + + """ + Create_Channels(key): + + Method creates Chanel objects + which are added into the list + + Method is to be used fog positioner, sensors and the + various actions (pre, post, detector, etc) + + Expected input + SD[key]=[c1,c2,...,cn] + or + SD[key]=c1 + + with + c={'channel_name' : Strong epics channel + ,'value' : String or number depending on data_type + ,'data_type' : TYPE can be String,Double + ,alias : ALIASSTRING'} + Type = 'String','s','Double','d',Integer','i','Boolean','b','l' + Routine cleans up type definition + 'String' -->'s', + 'double' -->'d' + 'Integer'--> 'i' + 'Boolean' --> 'b' + + Internale adressing + where: + C = self.SD[key][channel_name] + ThisID = self.SD[key][alias] + if alias is nor defined: + ThisID = self.SD[key][channel_name] + + if SD[key] contains several elements: + + C = self.SD[key][i][channel_name] + ThisID = self.SD[key][i][alias] + if alias is nor defined: + ThisID = self.SD[key][i][channel_name] + + + input: + + key : String ='detector_action,'Preactions + + """ + self.pm('PscanLib.Create_Channels') + N_ACTION = len(self.SD[key]) + self.pm('....Channel for ',key) + + # clean up typoe defintion + + + + try: + for i in range(N_ACTION): + self.pm('create channel for action ',i) + self.pm(' ',self.SD[key][i]['channel_name']) + try: + ThisID=self.SD[key][i]['alias'] + except: + ThisID=self.SD[key][i]['channel_name'] + #endexcept + # CLean up channel types + print(self.SD[key][i]['data_type']) + if self.SD[key][i]['data_type'].upper() == 'STRING': + self.SD[key][i]['data_type']='s' + #endif + if self.SD[key][i]['data_type'].upper() == 'DOUBLE': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'FLOAT': + self.SD[key][i]['data_type']='d' + #endif + if self.SD[key][i]['data_type'].upper() == 'Integer': + self.SD[key][i]['data_type']='i' + #endif + if self.SD[key][i]['data_type'].upper() == 'Boolean': + self.SD[key][i]['data_type']='b' + #endif + print('after type clan up ', self.SD[key][i]['data_type']) + try: + + + ThisDevice = self.Channel(self.SD[key][i]['channel_name'], alias=ThisID) # ,type=self.SD[key][i]['data_type']) + self.SD[key][i].update({'Channel':ThisDevice}) + self.SD[key][i].update({'UsedAlias':ThisID}) + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key][i]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + # Clean up types if possible + self.pm('key',key) + self.pm(' i' , i) + + + self.pm(self.SD[key][i]['data_type'].upper(), 'Integer'.upper()) + + try: + if self.SD[key][i]['data_type'].upper() == 'Integer'.upper(): + self.SD[key][i]['value']=int(self.SD[key][i]['value']) + #endif + if self.SD[key][i]['data_type'].upper() == 'Float'.upper(): + self.SD[key][i]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + + # endfor + except: + + # assume that there is only 1 entry + + #self.pm('create channel for action in 1 element list ') + #self.pm(' ',self.SD[key]['channel_name']) + #self.pm(self.SD[key]) + try: + ThisID=self.SD[key]['alias'] + print(self.SD[key]['alias']) + except: + ThisID=self.SD[key]['channel_name'] + print(self.SD[key]['channel_name']) + #endexcept + print(ThisID) + print(self.SD[key]['channel_name']) + + + # CLean up channel types + print(self.SD[key]['data_type']) + if self.SD[key]['data_type'].upper() == 'STRING': + self.SD[key]['data_type']='s' + #endif + if self.SD[key]['data_type'].upper() == 'DOUBLE': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'FLOAT': + self.SD[key]['data_type']='d' + #endif + if self.SD[key]['data_type'].upper() == 'Integer': + self.SD[key]['data_type']='i' + #endif + if self.SD[key]['data_type'].upper() == 'Boolean': + self.SD[key]['data_type']='b' + #endif + print('after type clean up', self.SD[key]['data_type']) + + + try: + ThisDevice = self.Channel(self.SD[key]['channel_name'], alias=ThisID) + self.SD[key].update({'Channel':ThisDevice}) + self.SD[key].update({'UsedAlias':ThisID}) + + except: + print(' ================================ ') + print(' ') + print('CANNOT CREATE THIS CHANNEL ') + print('i',i,'key',key) + print(self.SD[key]['channel_name']) + print(' possibly does not exist ') + print(' EMERGGENCY STOP ') + print(' ================================ ') + print(' ') + stop + #endexcept + + # Clean up types if possible + try: + if self.SD[key]['data_type'].upper() == 'Integer'.upper(): + self.SD[key]['value']=int(self.SD['value']) + #endif + if self.SD[key]['data_type'].upper() == 'Float'.upper(): + self.SD[key]['value']=float(self.SD[key]['value']) + #endif + except: + a_tmp=0 + #endexcept + self.pm(self.SD) + # endexcept + + self.pm('... done PscanLib.Create_Channels') + return + #d={'a':1, + # 'b':2} + #self.pm(d) + #d.update({'c':5}) + + + def PerformActions(self,key): + """ + Performs a list of predefined channel actions + as defined in list of format + + + [{'channel_name': 'X07MB-OP2:START-CSMPL' + , 'Channel': Channel('X07MB-OP2:START-CSMPL') + , 'delay' + , 'data_type': 's' (STILL WORKING ON THIS, CN WE GET RID OF THIS???? ) + , 'value': '0' + , 'operation': 'put' (or 'putq', 'wait'} + , {},{}....] + + The default lists (SD stands for ScanDefinition) + SD['Pre_Actions'] + SD['Post_Actions'] + SD['Detector_Actions'] + are default list as derived from the PHOENIX gui + using + SD = PS.get_channels('SPECTRA') # 'SPECTRA for energy scans 'IMAGE' for images (not yet implemented' + + + The definition + SC=PL.PscanLib(SD,Channel,caput,caputq,caget,cawait,get_exec_pars,create_table,append_table) + + Defines teh geberal scaning + + rscan(SD['Energy_Scan']['Channel'] + , SC.get_list(All_Sensors,'Channel') + , regions=SD['Energy_Scan']['Energy_Ranges'] + , latency = 0.0, relative = False + , before_pass = SC.PerformActions('Pre_Actions') + , after_pass = SC.PerformActions('Post_Actions') + , after_read = SC.PerformActions('Detecto_actions') + + can be used. + + + """ + print(' -------------------- PscanLib.DetectorActions '+key) + N_PREACTION = len(self.SD[key]) + #self.pm('..Execut action SD[key] with key') + #self.pm(key) + t0=self.time.time() + + for i in range(N_PREACTION): + self.pm('in PerformActions for key',key,' ',i,self.SD[key][i]['channel_name']) + self.pm(self.SD[key][i]) + self.pm(self.SD[key][i]['value']) + + if self.SD[key][i]['operation'] == 'put': + #self.pm('... put',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + self.caput(self.SD[key][i]['channel_name'] + ,self.SD[key][i]['value']) + #self.SD[key][i]['Channel'].put(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'putq': + self.pm('... putq',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.caputq(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value']) + self.SD[key][i]['Channel'].putq(self.SD[key][i]['value']) + self.time.sleep(float(self.SD[key][i]['delay'])) + self.pm(self.time.time()-t0) + # endif + + if self.SD[key][i]['operation'] == 'wait': + self.pm('... wait',self.SD[key][i]['channel_name'],self.SD[key][i]['value']) + #self.cawait(self.SD[key][i]['channel_name'] + # ,self.SD[key][i]['value'],timeout=100) + print('(caget) Value before .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + + # print('(.read(Value before .wait_for_value',self.SD[key][i]['Channel'].get(),'wait for', self.SD[key][i]['value']) + + self.pm('time',(self.time.time()-t0)) + try: + #self.SD[key][i]['Channel'].wait_for_value(self.SD[key][i]['value'],timeout=self.timeout) + self.cawait(self.SD[key][i]['channel_name'], self.SD[key][i]['value'],timeout=self.timeout) + except: + # take care of case waitin fails, for example if + # the call to cawait happens to early + print('There is a problem with cawait / .wait_for_channel') + print('wait 10 seconds an then check for value and continue') + self.time.sleep(1) + waiting = True + i_tmp = 0 + while(waiting): + print('use caget ',self.caget(self.SD[key][i]['channel_name'])) + #print('uses .read',self.SD[key][i]['Channel'].get()) + if self.SD[key][i]['Channel'].read() == self.SD[key][i]['value']: + waiting=False + #endif + i_tmp = i_tmp+1 + if i_tmp == 3: + + waiting=False + #endif + print(' wait 1 second') + self.time.sleep(1) + #endwhile + print('Value after .wait_for_value',self.caget(self.SD[key][i]['channel_name'],type='i'),'wait for', self.SD[key][i]['value']) + self.pm('time',self.time.time()-t0) + self.time.sleep(2) + # endif + # endfor + print('........... . total time ACTIONS', self.time.time()-t0) + self.pm('... done PscanLib.DetectorActions') + + return + # end routine + + # ==================================================== + # + # + # ROUTINES FOR DEFINITION OD ENERGY SCANS + # + # ================================================= + + def PositionerEnergyScan(self): + """ + + Routine defined positioner for energy scan as defined in GUI. + + + """ + print(' def PositionerEnergyScan(self)') + stop + + + self.pm('PositionerEnergyScan') + # ......... open positioner + n_ranges=len(self.SD['e_i']) + Ranges = [] + Cycles = [] + for i in range(n_ranges): + Ranges.append([self.SD['e_i'][i] , self.SD['e_f'][i] , float(self.SD['e_delta'][i])]) + Cycles.append(self.SD['e_delta'][i]) + return Ranges,Cycles + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + + + # endif + # endfor # ......... open positioner + + + write_start_positioner(f,{'Type' : 'RegionPositioner' + ,'Ch_set' : g['e_channel'] + ,'Ch_done' : 'None' + ,'Ch_readback' : g['e_channel_rbv'] + ,'Settling_time' : '0.2' + ,'Id' : 'Energy'}) + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #print g['e_i'] + #print g['e_f'] + #print g['e_active'] + #print g['n_e'] + + for i in range(g['n_e']): + if g['e_active'][i] == 1: + print i + print g['e_active'][i] + print g['e_i'][i] + write_region(f,g,{'V_ini' : g['e_i'][i] + ,'V_final' : g['e_f'][i] + ,'V_delta' : g['e_delta'][i] + ,'Ch_preaction' : ch_preaction + ,'Ch_preaction_value' : g['e_n_cycles'][i]}) + + # endif + # endfor + for i in range(g['n_e']): + if g['e_active'][i] == 1: + if 'MOENCH' in g['detectors']: + self.pm('TEST LOOP') + #write_function_positioner_MOENCH(f,{ 'channel_name': 'X07MB-ES1-SD1:cam1:FileNumber' + + # ,'Channel_rbv' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Settling_time' : '0.1' + # , 'Id' : 'FileCountMoench' + # , 'V_ini' : g['e_i'][i] + # , 'V_final' : g['e_f'][i] + # , 'V_delta' : g['e_delta'][i] + + # , 'Channel_done' : 'X07MB-ES1-SD1:cam1:FileNumber' + # , 'Use_done_value' : -1 + # } + # ) + #endif + #endif + #endfor + # NOw add one positioner for EXAFS with a non-linear gris spacing Currently only one range + + print 'kkkkkkkkkk' + return + + print g['e_ex_e_i'] + + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + self.write_EXAFS_region(f,g) + self.pm('... done PositionerEnergyScan') + return + + def write_EXAFS_region(): + self.pm('Missing') + # end write_EXAFS_region + + + # ==================================================================== + # + # ROUTINES WHICH TREAT DEAD TIME CORRECTIONS FOR XMAP + # + # ================================================================== + + + def after_read_dtc(self,rec,scan): + + # TO BE CALLED IN after_read + # Called after reading + # for calculation ofdeadtime + t0=self.time.time() + print('------------------------------------------------- def after_read_dtc(rec,scan) ') + + self.pm('rec0',rec[0]) + self.pm('rec energy set ',rec['Energy_set']) + self.pm(self.All_Sensors[0]['alias']) + self.pm('rec energy by alias ',rec[self.All_Sensors[0]['alias']]) + + # create header + + + pars = self.get_exec_pars() + self.pm(pars.name) + self.pm(pars.path) + self.pm(self.extract_filename()) + + # generate lists for varioue calulations + + alias_for_dtc = [] # sensor names + alias_for_roi_cps = [] # created names + alias_for_Subset_1 = [] + alias_for_icr = [] + alias_for_ocr = [] + alias_for_ertm = [] + + + t0 = self.time.time() + for i in range(len(self.All_Sensors)): + + # chanels which need dead time correction + if self.All_Sensors[i]['DTC']: + alias_for_dtc.append(self.All_Sensors[i]['alias']) + #endif + + # channels which need to to be printed into extracted file as well + if self.All_Sensors[i]['Subset_1']: + alias_for_Subset_1.append(self.All_Sensors[i]['alias']) + #endif + + # Generate list for deadttime correction + # names for TrueICR calulation + if 'ICR' in self.All_Sensors[i]['alias'].upper(): + alias_for_icr.append(self.All_Sensors[i]['alias']) + #endif + + if 'OCR' in self.All_Sensors[i]['alias'].upper(): + alias_for_ocr.append(self.All_Sensors[i]['alias']) + #endif + + if 'ERTM' in self.All_Sensors[i]['alias'].upper(): + alias_for_ertm.append(self.All_Sensors[i]['alias']) + #endif + #endfor + + + self.pm('after sorting names',self.time.time()-t0) + self.pm('alias for deadtime correction') + self.pm(alias_for_dtc) + self.pm('Alias for writing to file (Subset_1)') + self.pm(alias_for_Subset_1) + self.pm('Alias for ICR') + self.pm(alias_for_icr) + self.pm('Alias for OCR') + self.pm(alias_for_ocr) + self.pm('Alias for ERTM') + self.pm(alias_for_ertm) + + self.pm('time to create lists..',self.time.time()-t0) + + + # calculate icr/OCR*ertm for all SDD detectors in list + # + + icr_div_ocr_div_ertm=[] + for i in range(len(alias_for_icr)): + self.pm('DETECOR Nr ',i) + self.pm(rec[alias_for_icr[i]]) + self.pm(rec[alias_for_ocr[i]]) + self.pm(rec[alias_for_ertm[i]]) + try: + icr_div_ocr_div_ertm.append(rec[alias_for_icr[i]]/rec[alias_for_ocr[i]]/rec[alias_for_ertm[i]]) + except: + if rec[alias_for_ocr[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + if rec[alias_for_ertm[i]] ==0 : + icr_div_ocr_div_ertm.append(0.0) + else: + icr_div_ocr_div_ertm.append(-1.0) + #endelse + #endelse + #endexcept + # Missing call to trueICR + # + #endfor + self.pm(icr_div_ocr_div_ertm) + + # now walk through all detectors to be saved into file + # create header names and + + + #table = [ [1,2,3], + # [2,3,4], + # [3,4,5,] ] + + + # First create the list + path_extracted = "extracted/"+self.extract_filename() + + # walk through all subset for saving as listed in list alias_for_SubSet_1 + i_full=-1 + values =[] + for i in range(len(alias_for_Subset_1)): + if rec.index == 0: # first run only to create header for data set + if i==0: + self.names_subset_1 = [] + self.types_subset_1 = [] + + #endif + self.names_subset_1.append(alias_for_Subset_1[i]) + self.types_subset_1.append('d') + # make_dtc.append(False) + #endif + values.append(rec[alias_for_Subset_1[i]]) + i_full=i_full+1 + self.pm(i) + if alias_for_Subset_1[i] in alias_for_dtc: + # now we know this sensor needs dead time correction + self.pm('add dtc') + self.pm(i,i_full) + if rec.index == 0: # first runonly to create header for data set + self.names_subset_1.append(alias_for_Subset_1[i]+'_cps') + self.types_subset_1.append('d') + #endif + # now add data for dead time correction distinguish 4 cases + # for four detectors + self.pm(self.names_subset_1[i]) + self.pm(alias_for_Subset_1[i]) + if 'D1_' == self.names_subset_1[i][0:3]: + #self.pm('D_1') + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[0] ) + #self.pm('D_1 after ') + #endif + + if 'D2_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[1] ) + #endif + + if 'D3_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[2] ) + #endif + + if 'D4_' == self.names_subset_1[i][0:3]: + values.append(- rec[alias_for_Subset_1[i]] * icr_div_ocr_div_ertm[3] ) + #endif + + i_full=i_full+1 + self.pm('.. after ifs... ') + # endif + #self.pm(i,alias_for_Subset_1[i],names[i_full],types[i_full]) + # endfor + + for i in range(len(self.names_subset_1)): + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + + # catch case for gain o KEithleygain, which give string + # of shape '1^3'as result + # + if ((type(values[i]) == unicode) or type(values[i]) == str) and ('_GAIN' in self.names_subset_1[i]) : + values[i] = float(values[i][3:4]) + self.types_subset_1[i] = "d" + #endif + + self.pm(self.names_subset_1[i],self.types_subset_1[i],values[i],type(values[i])) + # endif + #endfor + if rec.index == 0: # first run only to create header for data set + self.create_table(path_extracted,self.names_subset_1,self.types_subset_1) + #endif + + + self.append_table(path_extracted,values) + + print('__________________________ time for dtc routine',self.time.time()-t0) + + return + + + + def write_manip_calc_TrueICR(f,params): + + # .... call of routine: + # + # write_manip_calc_TrueICR(f,{ , 'Id_icr':'Det1_icr' + # , 'Id_ocr':'DET1_ocr' + # , 'id_elapsedLT:'Elap_real'' + # , 'Id_out':'Det_corr'}) + # f File object for xml output + # 'id_roi' ------ ID (in FDA) for ROI, which is processed (input manipulation) + # 'id_icr' ------ ID for ICR :'Det1_icr' (input manipulation) + # 'id_ocr' ------ ID for OCR (input manipulation) + # 'id_elapsedTR' ------ ID elapsed real time for detector which is processed(input manipulation) + # + # 'id_out ------ ID of results (ouput manipulation) + + + #f.write(' \n ') + + + for i in range(len(g['detectors'])): # outer loop: walk through all defined detector + # types. Only if type Vortex is defined, we write the + # manipulations needed for dead time correction of Vortex + # + if (g['detectors'][i] == 'Vortex') or (g['detectors'][i] == 'ROENTEC_XMAP') or (g['detectors'][i] == 'KETEK_XMAP'): + + # ......o.k. Vortex s defined, now make dead time corrections for + # all rois from Vortex detector. + + #print n_det_vortex,n_roi_vortex + print n_roi_vortex + print range(n_roi_vortex) + + # manipulation to calulate the true ICR + for j in range(n_det_vortex): + write_manip_calc_TrueICR(f,{'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_trueicr_vortex[j]}) + # endfor + + # note at later stage use result from calculated true ice as input for subsequent manipulations. + for k in range(n_roi_vortex): + for j in range(n_det_vortex): + + # create array with Id for all detectors for roi # k + if j ==0: + id_roi_for_det_sum=[id_roi_vortex[0][k]+'_corr'] + else: + id_roi_for_det_sum.append(id_roi_vortex[j][k]+'_corr') + # endelse + + print ' next in loop writin manipulator..' + print n_det_vortex,n_roi_vortex + print i,j,k + print id_roi_vortex[j][k] + print id_icr_vortex + + # ... MISSING HERE OPTION TO SET ESTIMATE FOR DEAD TIME CORRECTION FOR DIFFERENT PEAKING TIMES ............. + + write_manip_dead_time_roi(f,{'Id_roi' : id_roi_vortex[j][k] + , 'Id_icr' : id_icr_vortex[j] + , 'Id_ocr' : id_ocr_vortex[j] + , 'Id_elapsedTime': id_ertm_vortex[j] + , 'Id_out' : id_roi_vortex[j][k]+'_corr'}) + + # write manipulations for division of roi by all user detector (only of user det = on is choosen..) + # need to add new flagg... + + print g['User_detector_fda_id'] + + print g['detectors_to_plot'] + if 'PL_USER_DET' in g['detectors_to_plot']: + for i_ud in range(len(g['User_detector_fda_id'])): + print i_ud + write_manip_divide_channels(f,{'Id_out': id_roi_vortex[j][k]+'_corr_over_'+g['User_detector_fda_id'][i_ud] + , 'Id_1': id_roi_vortex[j][k]+'_corr' + , 'Id_2': g['User_detector_fda_id'][i_ud]}) + # endfor i_U + + # endif + + # now manipulations for all detector for this rois + # now calculate ths sum of deadtime corrected + # detector data + # this_id_roi = id_roi_vortex[0][k][len(id_roi_vortex[0][k])-3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + this_id_roi = id_roi_vortex[0][k][3:len(id_roi_vortex[0][k])] # remove D1_ from ID name + #print 'idroi ' ,id_roi_vortex + #print 'aaa',id_roi_vortex[0][k],'bbb' + #print 'len',len(id_roi_vortex[0][k]) + #print 'this_id_roi ',this_id_roi + + + write_manip_sum_vortex(f,{'Id_roi' : id_roi_for_det_sum + , 'Id_out' : this_id_roi+'_sum_cps'}) + + + + # endfor + # endif + # endfor + + + # ================================================== + # + # + # Functions positioner + # + # ================================================= + + def TrueIcr_from_ICR(self,ICR,OCR,ElapsedTime): + #old... + #b=ICR + #c=OCR + #D= ELAPSEDTIME + + DeadTime = 1.182e-7 # Deadtime of SDD detector .. + + if (OCR) == 0: + box = -1.0 + return box + #endif + if (ICR) == 0: + box = -2.0 + return box + #endif + Test = 1.e8 + TestICR = ICR + n = 0 + while ((Test >= DeadTime) and (n < 30)): + try: + TrueICR = ICR * math.exp(TestICR * DeadTime) + except: + TrueICR = -10. + Test = (TrueICR - TestICR) / TestICR + TestICR = TrueICR + n = n + 1 + #endexcept + if (OCR) != 0.: + box = TrueICR + #endif + if (OCR*ElapsedTime) == 0: + box=-3.0 + #endif + return box + # end TrueIcr_from_ICR + + + + def EXFAS_SCAN(self,f,g): + + # this routine just adds the region definitione needed to define a constant k spacing scan + # NOT FINISHED + + print 'in write_EXAFS' + print g['n_exafs'] + print g['e_ex_e_i'] + print g['e_ex_e_f'] # Eini + print g['e_ex_k_i'] # k ini + print g['e_ex_k_f'] # k final + print g['e_ex_d_i'] # Delta_E (at begin) + print g['e_ex_ncy'] + print g['e_ex_ncy_f'] + print g['e_ex_nst'] + print g['e_ex_t'] + + print 'sart loop' + + ch_preaction='X07MB-OP2:TOTAL-CYCLES' + + #for i in range(g['n_exafs']): + # print i# + + + # # first write region (for now stet # cycles to, + # # set cycles to initial value of e_ex_ncy + + # write_region(f,g,{'V_ini' : g['e_ex_k_i'][i] + # ,'V_final' : g['e_ex_k_f'][i] + # ,'V_delta' : g['e_ex_d_i'][i] + # ,'Ch_preaction' : ch_preaction + # ,'Ch_preaction_value' : g['e_ex_ncy'][i] + # ,'Not_close_region' : 0}) # close region later as we need to add a function here... + # + ##endfor + + # Now write the function for EXAFS + + #f.write('') + #f.write('') + #f.write('