Sequencer: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 9: Line 9:


= Introduction =
= Introduction =
A Sequencer for starting and stopping runs was implemented in June 2011. Since then development has continued, with more commands being added, and the option of using a Midas Script Language (MSL) for commands, in addition to the XML language.
A Sequencer for starting and stopping runs is part of the MIDAS distribution. It uses a simple Midas Script Language (MSL) for commands.


The sequencer runs inside [[mhttpd]]. The first time  the  {{Button|name=Sequencer}} button on the [[Status Page]] is pressed, the ODB [[/Sequencer ODB tree|Sequencer Tree]] is created. If the Sequencer button is not present on the [[Status Page]], it may have been  [[Status Page#page-switch-buttons|suppressed]].
The sequencer runs as a separate process and must be started before running a sequence via the command '''sequencer'''. The first time  the  {{Button|name=Sequencer}} button on the [[Status Page]] is pressed, the ODB [[/Sequencer ODB tree|Sequencer Tree]] is created. If the Sequencer button is not present on the [[Status Page]], it may have been  [[Status Page#page-switch-buttons|suppressed]].


The sequencer runs scripts in XML or MSL (Midas Script Language) format, which reside on the server (where {{Utility|name=mhttpd}} is running). The sequencer state is completely stored in the ODB, meaning that even if  {{Utility|name=mhttpd}} is stopped and restarted, the active sequence operation continues exactly where it has been stopped.
The sequencer runs scripts in MSL (Midas Script Language) format, which reside on the server (where {{Utility|name=mhttpd}} is running). The sequencer state is completely stored in the ODB, meaning that even if  {{Utility|name=mhttpd}} or the sequencer is stopped and restarted, the active sequence operation continues exactly where it has been stopped.


Refer to the [[/Sequencer ODB tree]] for more details on its organization.  
Refer to the [[/Sequencer ODB tree]] for more details on its organization.  
Line 26: Line 26:


{| class="wikitable" style="text-align: left; color: black; tr:nth-child(even) {background-color: #F0F0F0};"  
{| class="wikitable" style="text-align: left; color: black; tr:nth-child(even) {background-color: #F0F0F0};"  
!style="width: 20%;background-color:#C0C0C0;"|XML format
!style="width: 20%;background-color:#C0C0C0;"|MSL format
!style="width: 20%;background-color:#C0C0C0;"|MSL format
!style="width: 60%;background-color:#C0C0C0;"|Description
!style="width: 60%;background-color:#C0C0C0;"|Description
Line 34: Line 33:
||Include another XML file ''name''.xml
||Include another XML file ''name''.xml
|-
|-
||<Call name="''name''"> a,b,c...</Call>
||CALL ''name'', ''a'', ''b'', ''c'', ...
||CALL ''name'', ''a'', ''b'', ''c'', ...
||Call a subroutine. Optional parameters ''a'',''b'',''c''... are passed to the subroutine, where they can be referenced via $1, $2, $3, etc. The subroutine can either reside in the current file, or in a library file which is included.
||Call a subroutine. Optional parameters ''a'',''b'',''c''... are passed to the subroutine, where they can be referenced via $1, $2, $3, etc. The subroutine can either reside in the current file, or in a library file which is included.
|-
|-
||<Cat name="''name''"> ''a'',''b'',''c''... </Set>
||CAT ''name'', ''a'', ''b'', ''c'', ...
||CAT ''name'', ''a'', ''b'', ''c'', ...
||Concatenates the strings ''a'',''b'',''c'',... into a single variable name . Can be referenced with $''name''. If a string must contain a comma, it can be enclosed in quotes such as in '''CAT title $run, ",", $n events'''
||Concatenates the strings ''a'',''b'',''c'',... into a single variable name . Can be referenced with $''name''. If a string must contain a comma, it can be enclosed in quotes such as in '''CAT title $run, ",", $n events'''
|-
|-
||<Comment> ''comment'' </Comment>
||COMMENT ''comment''
||COMMENT ''comment''
||A comment for this XML file, for information only. This comment is shown when one clicks on the XML file in the browser inside the web page and can be used to show some information about an XML file. This can be helpful if one has many XML files and the file name only is not enough to supply enough information.
||A comment for this XML file, for information only. This comment is shown when one clicks on the XML file in the browser inside the web page and can be used to show some information about an XML file. This can be helpful if one has many XML files and the file name only is not enough to supply enough information.
|-
|-
||<Goto line="''n''" / >
||GOTO ''n''
||GOTO ''n''
||Jump to line ''n'' in script
||Jump to line ''n'' in script
|-
|-
||<If condition="''con''" > <br>
... <br>
<else /> <br>
... <br>
</if>
||IF ''con''  <br>
||IF ''con''  <br>
... <br>
... <br>
Line 62: Line 52:
||Statements between <if> and </if> are only executed if condition con is true, otherwise the statements between the optional <else /> and </if> are executed. The condition can use variables via $name and/or constants together with operators "<", "<=", ">", ">=", "==", "!=", "&" (bitwise AND). Up to four nested IF statements are possible.
||Statements between <if> and </if> are only executed if condition con is true, otherwise the statements between the optional <else /> and </if> are executed. The condition can use variables via $name and/or constants together with operators "<", "<=", ">", ">=", "==", "!=", "&" (bitwise AND). Up to four nested IF statements are possible.
|-  
|-  
||<Library name="''name''" >...</Library>
||LIBRARY ''name''
||LIBRARY ''name''
||Indicates that the current file is a library (which can be included by other files). A library usually consists of a set of subroutines.
||Indicates that the current file is a library (which can be included by other files). A library usually consists of a set of subroutines.


|-
|-
||<Loop n="''n''" [var="''name''"]> ... </Loop>
||LOOP [''name'' ,] ''n'' ... ENDLOOP
||LOOP [''name'' ,] ''n'' ... ENDLOOP
||To execute a loop ''n'' times. For infinite loops, "infinite" can be specified as ''n''. Optionally, the loop variable running from 1..''n'' can be accessed inside the loop via $''name''.
||To execute a loop ''n'' times. For infinite loops, "infinite" can be specified as ''n''. Optionally, the loop variable running from 1..''n'' can be accessed inside the loop via $''name''.


|-
|-
||<Loop var="''name''" values="''a'',''b'',''c'',..."> ... </Loop>
||LOOP ''name'',  ''a'', ''b'', ''c'', ... ... ENDLOOP
||LOOP ''name'',  ''a'', ''b'', ''c'', ... ... ENDLOOP
||Loop though a list of values. The loop is executed once for each value, which is stored into the variable ''name'' so it can be accessed inside the loop via $''name''.
||Loop though a list of values. The loop is executed once for each value, which is stored into the variable ''name'' so it can be accessed inside the loop via $''name''.


|-
|-
||<Message [wait="1"]> ''message'' </Message>
||MESSAGE ''message'' [,1]
||MESSAGE ''message'' [,1]
||Opens a message box in the browser containing the text message. If wait="1", then the sequencer waits until the box is closed by the user before continuing.
||Opens a message box in the browser containing the text message. If wait="1", then the sequencer waits until the box is closed by the user before continuing.
|-
|-
||<ODBGet path="''path''" > ''name'' </ODBGet>
||ODBGET ''path'', ''name''
||ODBGET ''path'', ''name''
||To get a value from a variable ''name''. The variable can then be referenced with $''name''.
||To get a value from a variable ''name''. The variable can then be referenced with $''name''.
|-
|-
||<ODBInc path="''path''" > delta </ODBInc>
||ODBINC ''path'' [, ''delta'']
||ODBINC ''path'' [, ''delta'']
||To increment a value in the ODB. ''delta'' can be positive or negative. If no "delta" is given, 1 is used.
||To increment a value in the ODB. ''delta'' can be positive or negative. If no "delta" is given, 1 is used.
|-
|-
||<ODBSet [notify="0|1"] path="''path''" > ''value'' </ODBSet>
||ODBSET ''path'', ''value'' [, 0|1]
||ODBSET ''path'', ''value'' [, 0|1]
||To set a value in the ODB. The notify flag specifies if possible hot-links to this ODB value are notified. This can be useful if a front-end program has many parameters, which must be set for a specific run. The front-end usually has a hot-link to its parameters, so on each modification a callback function in the front-end is called which usually modifies some hardware. If there are many ODBSet statements for all parameters, the callback would be executed on each ODBSet, so the hardware would be reconfigured many times slowing down the startup of a run. In order to prevent this, notify="0" can be specified for all ODBSet statements except the last one which contains notify="1", so the callback function is called only once at the end.
||To set a value in the ODB. The notify flag specifies if possible hot-links to this ODB value are notified. This can be useful if a front-end program has many parameters, which must be set for a specific run. The front-end usually has a hot-link to its parameters, so on each modification a callback function in the front-end is called which usually modifies some hardware. If there are many ODBSet statements for all parameters, the callback would be executed on each ODBSet, so the hardware would be reconfigured many times slowing down the startup of a run. In order to prevent this, notify="0" can be specified for all ODBSet statements except the last one which contains notify="1", so the callback function is called only once at the end.
|-
|-
||<ODBSubdir path="''path''" >...</ODBSubdir>
||ODBSUBDIR ''path'' ...ENDODBSUBDIR
||ODBSUBDIR ''path'' ...ENDODBSUBDIR
||If one wants to se several ODB values in the same directory, the ODBSet commands can be rather long if thepath is long. Using this command, the subdir can be specified for all commands between the opening and ending tags. So instead of writing <br>
||If one wants to se several ODB values in the same directory, the ODBSet commands can be rather long if thepath is long. Using this command, the subdir can be specified for all commands between the opening and ending tags. So instead of writing <br>
Line 108: Line 90:
</ODBSubdir><br>  
</ODBSubdir><br>  
|-
|-
||<Param name="''name''" [comment="''comment''"][options="''a'',''b'',''c'',..."] [type="bool"] />
||PARAM ''name'', ''comment'', [''a'',''b'',''c'' | bool]
||PARAM ''name'', ''comment'', [''a'',''b'',''c'' | bool]
||When starting a script, a start page is shown where one can enter additional parameters for the script. Parameters can be defined either centrally for all scripts in the ODB under /Experiment/Edit on sequence. This subdirectory in the ODB can contain links to ODB values, which are queried at the start page. In addition, each script can define additional parameters appended to this list. They will be stored under /Sequencer/Variables and can be referenced inside the script via $name, where name can be any variable name specified in the parameter statement. The optional "comment" is shown on the start page below the parameter name. If only certain options are possible for the parameter, they can be defined via the options list. The web page will then contain a drop-down list showing the options. In case of type="bool", a checkbox will be shown.
||When starting a script, a start page is shown where one can enter additional parameters for the script. Parameters can be defined either centrally for all scripts in the ODB under /Experiment/Edit on sequence. This subdirectory in the ODB can contain links to ODB values, which are queried at the start page. In addition, each script can define additional parameters appended to this list. They will be stored under /Sequencer/Variables and can be referenced inside the script via $name, where name can be any variable name specified in the parameter statement. The optional "comment" is shown on the start page below the parameter name. If only certain options are possible for the parameter, they can be defined via the options list. The web page will then contain a drop-down list showing the options. In case of type="bool", a checkbox will be shown.
|-
|-
||<RunDescription> ''description'' </RunDescription>
||RUNDESCRIPTION ''description''
||RUNDESCRIPTION ''description''
||a run description which is stored under /Experiment/Run Parameters/Run Description .
||a run description which is stored under /Experiment/Run Parameters/Run Description .
|-
|-
||<Script [params="''a'',''b'',''c'',..."]> ''script'' </Script>
||SCRIPT ''script'' [, a, b, c, ...]
||SCRIPT ''script'' [, a, b, c, ...]
||To call a script on the server side. Optionally, pass parameters to the script.
||To call a script on the server side. Optionally, pass parameters to the script.
|-
|-
||<Set name="''name''"> ''value'' </Set>
||SET ''name'', ''value''
||SET ''name'', ''value''
||Sets the variable ''name'' to "value". The variable can then be referenced later in the script by putting a "$" in front of the name like $"name".
||Sets the variable ''name'' to "value". The variable can then be referenced later in the script by putting a "$" in front of the name like $"name".
|-
|-
||<Subroutine name="''name''">...</Subroutine>
||SUBROUTINE ''name'' ... ENDSUBROUTINE
||SUBROUTINE ''name'' ... ENDSUBROUTINE
||Declares a subroutine which can be called via CALL.
||Declares a subroutine which can be called via CALL.
|-
|-
||<Transition>Start | Stop</Transition>
||TRANSITION start | stop | pause | resume
||TRANSITION start | stop | pause | resume
||To start, stop, pause or resume a run
||To start, stop, pause or resume a run
|-
|-
||<Wait for="events | ODBvalue | seconds" [path="''ODB path''"] [op=">=/>/<=/</==/!="]> ''value'' </Wait>
||<Wait for="events | ODBvalue | seconds" [path="''ODB path''"] [op=">=/>/<=/</==/!="]> ''value'' </Wait>
||WAIT events | ODBvalue | seconds, [''ODB path''], [''op''], [''value'']
||Wait until a number of events is acquired (testing /Equipment/Trigger/Statistics/Events sent), or until a value in the ODB exceeds value, or wait for ''value'' seconds. If the operand ''op'' is given, the ODB value is compared with value using this operand. So one could wait until an ODB value is equal to value or becomes smaller than value. Here is an example of such a statement which waits until some high voltage is below 100 V.  
||Wait until a number of events is acquired (testing /Equipment/Trigger/Statistics/Events sent), or until a value in the ODB exceeds value, or wait for ''value'' seconds. If the operand ''op'' is given, the ODB value is compared with value using this operand. So one could wait until an ODB value is equal to value or becomes smaller than value. Here is an example of such a statement which waits until some high voltage is below 100 V.  
WAIT ODBvalue, /Equipment/HV/Variables/Measured[3], <, 100
WAIT ODBvalue, /Equipment/HV/Variables/Measured[3], <, 100
Line 151: Line 126:
     TRANSITION STOP
     TRANSITION STOP
ENDLOOP
ENDLOOP
</pre>
= XML Example =
The following XML script does exactly the same.
<pre>
<?xml version="1.0" encoding="ISO-8859-1"?>
<RunSequence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="">
 
  <Comment>This is a XML test file</Comment>
  <RunDescription>Test run</RunDescription>
  <Param name="runs" />
  <Loop n="$runs">
    <Transition>START</Transition>
    <Wait for="events">3000</Wait>
    <Transition>STOP</Transition>
  </Loop>
</RunSequence>
</pre>
</pre>


[[Category:Sequencer]]
[[Category:Sequencer]]

Revision as of 08:56, 8 January 2018


Links

Introduction

A Sequencer for starting and stopping runs is part of the MIDAS distribution. It uses a simple Midas Script Language (MSL) for commands.

The sequencer runs as a separate process and must be started before running a sequence via the command sequencer. The first time the Sequencer button on the Status Page is pressed, the ODB Sequencer Tree is created. If the Sequencer button is not present on the Status Page, it may have been suppressed.

The sequencer runs scripts in MSL (Midas Script Language) format, which reside on the server (where mhttpd is running). The sequencer state is completely stored in the ODB, meaning that even if mhttpd or the sequencer is stopped and restarted, the active sequence operation continues exactly where it has been stopped.

Refer to the /Sequencer ODB tree for more details on its organization.

For instructions on getting started with the sequencer, see Sequencer Page


Sequencer Commands

The following commands are implemented in the MIDAS Sequencer. The left syntax is for the XML file, the right for the MSL (Midas Script Language).

Variable names are indicated in italic, options are enclosed in [brackets].

MSL format Description
< !DOCTYPE RunSequence[< !ENTITY name SYSTEM "name.xml" >]> &name; INCLUDE name Include another XML file name.xml
CALL name, a, b, c, ... Call a subroutine. Optional parameters a,b,c... are passed to the subroutine, where they can be referenced via $1, $2, $3, etc. The subroutine can either reside in the current file, or in a library file which is included.
CAT name, a, b, c, ... Concatenates the strings a,b,c,... into a single variable name . Can be referenced with $name. If a string must contain a comma, it can be enclosed in quotes such as in CAT title $run, ",", $n events
COMMENT comment A comment for this XML file, for information only. This comment is shown when one clicks on the XML file in the browser inside the web page and can be used to show some information about an XML file. This can be helpful if one has many XML files and the file name only is not enough to supply enough information.
GOTO n Jump to line n in script
IF con

...
ELSE
...
ENDIF

Statements between <if> and </if> are only executed if condition con is true, otherwise the statements between the optional <else /> and </if> are executed. The condition can use variables via $name and/or constants together with operators "<", "<=", ">", ">=", "==", "!=", "&" (bitwise AND). Up to four nested IF statements are possible.
LIBRARY name Indicates that the current file is a library (which can be included by other files). A library usually consists of a set of subroutines.
LOOP [name ,] n ... ENDLOOP To execute a loop n times. For infinite loops, "infinite" can be specified as n. Optionally, the loop variable running from 1..n can be accessed inside the loop via $name.
LOOP name, a, b, c, ... ... ENDLOOP Loop though a list of values. The loop is executed once for each value, which is stored into the variable name so it can be accessed inside the loop via $name.
MESSAGE message [,1] Opens a message box in the browser containing the text message. If wait="1", then the sequencer waits until the box is closed by the user before continuing.
ODBGET path, name To get a value from a variable name. The variable can then be referenced with $name.
ODBINC path [, delta] To increment a value in the ODB. delta can be positive or negative. If no "delta" is given, 1 is used.
ODBSET path, value [, 0|1] To set a value in the ODB. The notify flag specifies if possible hot-links to this ODB value are notified. This can be useful if a front-end program has many parameters, which must be set for a specific run. The front-end usually has a hot-link to its parameters, so on each modification a callback function in the front-end is called which usually modifies some hardware. If there are many ODBSet statements for all parameters, the callback would be executed on each ODBSet, so the hardware would be reconfigured many times slowing down the startup of a run. In order to prevent this, notify="0" can be specified for all ODBSet statements except the last one which contains notify="1", so the callback function is called only once at the end.
ODBSUBDIR path ...ENDODBSUBDIR If one wants to se several ODB values in the same directory, the ODBSet commands can be rather long if thepath is long. Using this command, the subdir can be specified for all commands between the opening and ending tags. So instead of writing

<ODBSet path="/Very/long/path/into/the/odb/value1">1</ODBSet>
<ODBSet path="/Very/long/path/into/the/odb/value2">1</ODBSet>
<ODBSet path="/Very/long/path/into/the/odb/value3">1</ODBSet>
<ODBSet path="/Very/long/path/into/the/odb/value4">1</ODBSet>
one can write
<ODBSubdir path="/Very/long/path/into/the/odb">
<ODBSet path="value1">1</ODBSet>
<ODBSet path="value2">1</ODBSet>
<ODBSet path="value3">1</ODBSet>
<ODBSet path="value4">1</ODBSet>
</ODBSubdir>

PARAM name, comment, [a,b,c | bool] When starting a script, a start page is shown where one can enter additional parameters for the script. Parameters can be defined either centrally for all scripts in the ODB under /Experiment/Edit on sequence. This subdirectory in the ODB can contain links to ODB values, which are queried at the start page. In addition, each script can define additional parameters appended to this list. They will be stored under /Sequencer/Variables and can be referenced inside the script via $name, where name can be any variable name specified in the parameter statement. The optional "comment" is shown on the start page below the parameter name. If only certain options are possible for the parameter, they can be defined via the options list. The web page will then contain a drop-down list showing the options. In case of type="bool", a checkbox will be shown.
RUNDESCRIPTION description a run description which is stored under /Experiment/Run Parameters/Run Description .
SCRIPT script [, a, b, c, ...] To call a script on the server side. Optionally, pass parameters to the script.
SET name, value Sets the variable name to "value". The variable can then be referenced later in the script by putting a "$" in front of the name like $"name".
SUBROUTINE name ... ENDSUBROUTINE Declares a subroutine which can be called via CALL.
TRANSITION start | stop | pause | resume To start, stop, pause or resume a run
<Wait for="events | ODBvalue | seconds" [path="ODB path"] [op=">=/>/<=/</==/!="]> value </Wait> Wait until a number of events is acquired (testing /Equipment/Trigger/Statistics/Events sent), or until a value in the ODB exceeds value, or wait for value seconds. If the operand op is given, the ODB value is compared with value using this operand. So one could wait until an ODB value is equal to value or becomes smaller than value. Here is an example of such a statement which waits until some high voltage is below 100 V.

WAIT ODBvalue, /Equipment/HV/Variables/Measured[3], <, 100

MSL Example

The following example is a simple script, which writes a run description to the ODB, asks for a number of runs, then executes the runs, each running for 60 seconds.

COMMENT "This is a MSL test file"
RUNDESCRIPTION "Test run"
PARAM runs

LOOP $runs
     TRANSITION START
     WAIT Seconds 60
     TRANSITION STOP
ENDLOOP