<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://daq00.triumf.ca/MidasWiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marco.francesconi</id>
	<title>MidasWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://daq00.triumf.ca/MidasWiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marco.francesconi"/>
	<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php/Special:Contributions/Marco.francesconi"/>
	<updated>2026-05-08T06:26:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Sequencer&amp;diff=3077</id>
		<title>Sequencer</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Sequencer&amp;diff=3077"/>
		<updated>2021-06-30T10:47:27Z</updated>

		<summary type="html">&lt;p&gt;Marco.francesconi: added ODBLoad sequencer command&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
&lt;br /&gt;
= Links =&lt;br /&gt;
&amp;lt;div style=&amp;quot;column-count:3;-moz-column-count:3;-webkit-column-count:3&amp;quot;&amp;gt;&lt;br /&gt;
* [[/Sequencer ODB tree]]&lt;br /&gt;
* [[Sequencer Page]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
A Sequencer for starting and stopping runs is part of the MIDAS distribution. It uses a simple Midas Script Language (MSL) for commands.&lt;br /&gt;
&lt;br /&gt;
The sequencer runs as a separate process and must be started before running a sequence via the command &#039;&#039;&#039;msequencer&#039;&#039;&#039;. 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]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Refer to the [[/Sequencer ODB tree]] for more details on its organization. &lt;br /&gt;
&lt;br /&gt;
For instructions on &#039;&#039;&#039;getting started with the sequencer&#039;&#039;&#039;, see [[Sequencer Page]]&lt;br /&gt;
&lt;br /&gt;
= Sequencer Commands =&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
Variable names are indicated in italic, options are enclosed in [brackets].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left; color: black; tr:nth-child(even) {background-color: #F0F0F0};&amp;quot; &lt;br /&gt;
!style=&amp;quot;width: 20%;background-color:#C0C0C0;&amp;quot;|MSL format&lt;br /&gt;
!style=&amp;quot;width: 60%;background-color:#C0C0C0;&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
||INCLUDE &#039;&#039;name&#039;&#039;&lt;br /&gt;
||Include another XML file &#039;&#039;name&#039;&#039;.xml&lt;br /&gt;
|-&lt;br /&gt;
||CALL &#039;&#039;name&#039;&#039;, &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ...&lt;br /&gt;
||Call a subroutine. Optional parameters &#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039;... 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.&lt;br /&gt;
|-&lt;br /&gt;
||CAT &#039;&#039;name&#039;&#039;, &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ...&lt;br /&gt;
||Concatenates the strings &#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039;,... into a single variable name . Can be referenced with $&#039;&#039;name&#039;&#039;. If a string must contain a comma, it can be enclosed in quotes such as in &#039;&#039;&#039;CAT title $run, &amp;quot;,&amp;quot;, $n events&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
||COMMENT &#039;&#039;comment&#039;&#039;&lt;br /&gt;
||A comment for this XML file, for information only. This comment is shown in the title bar next to the file name if one runs a script. This can be helpful if one has many XML files and the file name only is not enough to supply enough information.&lt;br /&gt;
|-&lt;br /&gt;
||GOTO &#039;&#039;n&#039;&#039;&lt;br /&gt;
||Jump to line &#039;&#039;n&#039;&#039; in script&lt;br /&gt;
|-&lt;br /&gt;
||IF &#039;&#039;con&#039;&#039;  &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
ELSE &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
ENDIF&lt;br /&gt;
||Statements between &amp;quot;IF&amp;quot; and &amp;quot;ENDIF&amp;quot; are only executed if condition &amp;quot;con&amp;quot; is true, otherwise the statements between the optional &amp;quot;ELSE&amp;quot; and &amp;quot;ENDIF&amp;quot; are executed. The condition can use variables via $name and/or constants together with operators &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;lt;=&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;&amp;gt;=&amp;quot;, &amp;quot;==&amp;quot;, &amp;quot;!=&amp;quot;, &amp;quot;&amp;amp;&amp;quot; (bitwise AND). Up to four nested IF statements are possible.&lt;br /&gt;
|- &lt;br /&gt;
||LIBRARY &#039;&#039;name&#039;&#039;&lt;br /&gt;
||Indicates that the current file is a library (which can be included by other files). A library usually consists of a set of subroutines.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||LOOP [&#039;&#039;name&#039;&#039; ,] &#039;&#039;n&#039;&#039; ... ENDLOOP&lt;br /&gt;
||To execute a loop &#039;&#039;n&#039;&#039; times. For infinite loops, &amp;quot;infinite&amp;quot; can be specified as &#039;&#039;n&#039;&#039;. Optionally, the loop variable running from 0...&#039;&#039;(n-1)&#039;&#039; can be accessed inside the loop via $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||LOOP &#039;&#039;name&#039;&#039;,  &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ... ... ENDLOOP&lt;br /&gt;
||Loop though a list of values. The loop is executed once for each value, which is stored into the variable &#039;&#039;name&#039;&#039; so it can be accessed inside the loop via $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||MESSAGE &#039;&#039;message&#039;&#039; [,1]&lt;br /&gt;
||Opens a message box in the browser containing the text message. If wait=&amp;quot;1&amp;quot;, then the sequencer waits until the box is closed by the user before continuing.&lt;br /&gt;
|-&lt;br /&gt;
||ODBGET &#039;&#039;path&#039;&#039;, &#039;&#039;name&#039;&#039;&lt;br /&gt;
||To get a value from a variable &#039;&#039;name&#039;&#039;. The variable can then be referenced with $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
||ODBINC &#039;&#039;path&#039;&#039; [, &#039;&#039;delta&#039;&#039;]&lt;br /&gt;
||To increment a value in the ODB. &#039;&#039;delta&#039;&#039; can be positive or negative. If no &amp;quot;delta&amp;quot; is given, 1 is used.&lt;br /&gt;
|-&lt;br /&gt;
||ODBSET &#039;&#039;path&#039;&#039;, &#039;&#039;value&#039;&#039; [, 0|1]&lt;br /&gt;
||To set a value in the ODB.&amp;lt;br&amp;gt;&lt;br /&gt;
The path value can match multiple keys using the &#039;?&#039; and &#039;*&#039; wildcard (one or any number of characters respectively). This is useful to set the same sub-path on multiple folders:&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder0/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder1/value&amp;quot;, &amp;quot;1&amp;quot; &lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder2/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
can be shortened as:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder*/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
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=&amp;quot;0&amp;quot; can be specified for all ODBSet statements except the last one which contains notify=&amp;quot;1&amp;quot;, so the callback function is called only once at the end. &lt;br /&gt;
|-&lt;br /&gt;
||ODBLOAD &#039;&#039;file&#039;&#039; [, &#039;&#039;path&#039;&#039;]&lt;br /&gt;
||Load an external file into the ODB.&amp;lt;br&amp;gt;&lt;br /&gt;
JSON, XML and ODB file format are supported with the value inferred by the content of the file.&lt;br /&gt;
The optional path marks the position where to load the given file into the ODB, if no position is given the file is loaded from ODB root.&amp;lt;br&amp;gt;&lt;br /&gt;
For the input file few options are supported: if the filename starts with &amp;quot;/&amp;quot; is is assumed as an absolute path, if it starts with a &amp;quot;$&amp;quot; the path starts from the Sequncer root folder stored in the ODB by /Sequencer/Path. In all other cases it is intended as a relative path to the local MSL file.&lt;br /&gt;
|-&lt;br /&gt;
||ODBSUBDIR &#039;&#039;path&#039;&#039; ...ENDODBSUBDIR&lt;br /&gt;
||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 &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value1&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value2&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value3&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value4&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
one can write &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ODBSubdir path=&amp;quot;/Very/long/path/into/the/odb&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value1&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value2&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value3&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value4&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;/ODBSubdir&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
||PARAM &#039;&#039;name&#039;&#039;, &#039;&#039;comment&#039;&#039;, [&#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039; | bool]&lt;br /&gt;
||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 &amp;quot;comment&amp;quot; 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=&amp;quot;bool&amp;quot;, a checkbox will be shown.&lt;br /&gt;
|-&lt;br /&gt;
||RUNDESCRIPTION &#039;&#039;description&#039;&#039;&lt;br /&gt;
||a run description which is stored under /Experiment/Run Parameters/Run Description .&lt;br /&gt;
|-&lt;br /&gt;
||SCRIPT &#039;&#039;script&#039;&#039; [, a, b, c, ...]&lt;br /&gt;
||To call a script on the server side. Optionally, pass parameters to the script.&lt;br /&gt;
|-&lt;br /&gt;
||SET &#039;&#039;name&#039;&#039;, &#039;&#039;value&#039;&#039;&lt;br /&gt;
||Sets the variable &#039;&#039;name&#039;&#039; to &amp;quot;value&amp;quot;. The variable can then be referenced later in the script by putting a &amp;quot;$&amp;quot; in front of the name like $&amp;quot;name&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
||SUBROUTINE &#039;&#039;name&#039;&#039; ... ENDSUBROUTINE&lt;br /&gt;
||Declares a subroutine which can be called via CALL.&lt;br /&gt;
|-&lt;br /&gt;
||TRANSITION start | stop | pause | resume&lt;br /&gt;
||To start, stop, pause or resume a run&lt;br /&gt;
|-&lt;br /&gt;
||WAIT events | ODBvalue | seconds, [&#039;&#039;ODB path&#039;&#039;], [&#039;&#039;op&#039;&#039;], [&#039;&#039;value&#039;&#039;]&lt;br /&gt;
||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 &#039;&#039;value&#039;&#039; seconds. If the operand &#039;&#039;op&#039;&#039; 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. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WAIT ODBvalue, /Equipment/HV/Variables/Measured[3], &amp;lt;, 100&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= MSL Example =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
COMMENT &amp;quot;This is a MSL test file&amp;quot;&lt;br /&gt;
RUNDESCRIPTION &amp;quot;Test run&amp;quot;&lt;br /&gt;
PARAM runs&lt;br /&gt;
&lt;br /&gt;
LOOP $runs&lt;br /&gt;
     TRANSITION START&lt;br /&gt;
     WAIT Seconds 60&lt;br /&gt;
     TRANSITION STOP&lt;br /&gt;
ENDLOOP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Sequencer]]&lt;/div&gt;</summary>
		<author><name>Marco.francesconi</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=ODB_Access_and_Use&amp;diff=2935</id>
		<title>ODB Access and Use</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=ODB_Access_and_Use&amp;diff=2935"/>
		<updated>2020-04-06T10:25:12Z</updated>

		<summary type="html">&lt;p&gt;Marco.francesconi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
= Links =&lt;br /&gt;
&amp;lt;div style=&amp;quot;column-count:3;-moz-column-count:3;-webkit-column-count:3&amp;quot;&amp;gt;&lt;br /&gt;
* [[odbedit]]&lt;br /&gt;
* [[Odbedit command list]]&lt;br /&gt;
* [[mhttpd]] ODB page&lt;br /&gt;
* [[Online Database|ODB structure]]&lt;br /&gt;
* &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
= Purpose =&lt;br /&gt;
This page gives details on how users may access and use the ODB. &lt;br /&gt;
 &lt;br /&gt;
= Introduction =&lt;br /&gt;
The MIDAS Online Data Base (ODB) is the main communication platform between MIDAS applications. It contains all the information needed to run an experiment. A description of [[Online Database#The ODB Structure|the ODB Structure]] and a list of all the ODB trees used by the system can be found in [[Online Database]].&lt;br /&gt;
&lt;br /&gt;
= ODB Keys =&lt;br /&gt;
&lt;br /&gt;
The ODB is hierarchically structured, similar to a file system, with directories and sub-directories (or trees and subtrees). The data are stored in key/data pairs, similar to the Windows NT registry. ODB keys can be dynamically created and deleted. The data associated with a key can be of different types such as: byte, words, double words, float, strings, etc. or arrays of any of those.&lt;br /&gt;
&lt;br /&gt;
A key can also be a directory or a symbolic link. ODB Key names are &#039;&#039;&#039;case-independent&#039;&#039;&#039;, and &#039;&#039;&#039;may contain spaces&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
As of Jan 2017, ODB key names are now checked to ensure they are UTF-8 compliant.  This check will show up in (at least) two ways:&lt;br /&gt;
&lt;br /&gt;
# Attempts to create a new ODB variable if the ODB key is not UTF-8 compliant.  &lt;br /&gt;
#  When a program first connects to the ODB, it runs a check to ensure that the ODB is valid.  This will now include a check that all key names are UTF-8 compliant. Any non-UTF8 compliant key names will be replaced by a string of the pointer to the key.  &lt;br /&gt;
&lt;br /&gt;
This behaviour (checking UTF-8 compatibility and automatically fixing ODB names) can be disabled by setting an environment variable&lt;br /&gt;
&lt;br /&gt;
MIDAS_INVALID_STRING_IS_OK&lt;br /&gt;
&lt;br /&gt;
It doesn&#039;t matter what the environment variable is set to; it just needs to be set.  Note also that this variable is only checked once, when a program starts.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Accessing the ODB =&lt;br /&gt;
&lt;br /&gt;
The MIDAS ODB can be accessed &#039;&#039;&#039;interactively&#039;&#039;&#039; in two ways:&lt;br /&gt;
*  [[odbedit|odbedit application]] command line.&lt;br /&gt;
*  Midas server [[mhttpd]] ODB page&lt;br /&gt;
&lt;br /&gt;
For non-interactive access,&lt;br /&gt;
* The MIDAS library provides a complete &#039;&#039;&#039;set of functions&#039;&#039;&#039; (in C/C++) to manage and operate on ODB keys (see [http://ladd00.triumf.ca/~daqweb/doc/midas-devel/doc/html/group__odbfunctionc.html odb functions]). &lt;br /&gt;
Examples of many of these routines in use can be found in [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
* Scripts can easily access the odb using the [[odbedit]] &#039;&#039;-c&#039;&#039; argument. Examples of this can be found in [[#Accessing the ODB from a script|Script Access]]&lt;br /&gt;
&lt;br /&gt;
* A set of Javascript functions are provided to allow the web server [[Custom Page|Custom Pages]] to access the ODB.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Creating the ODB =&lt;br /&gt;
&lt;br /&gt;
After installation of MIDAS, before any other applications are started, the ODB must be created by the user (see [[odbedit #Creating the ODB|creating the ODB ]]).  Running [[odbedit]] to create the ODB also causes the trees [[/Runinfo ODB tree|/Runinfo]], [[/Experiment ODB tree|/Experiment]], [[/System ODB tree|/System]] to be created and filled with default values. Other system applications will automatically create their own initial ODB structure&lt;br /&gt;
filled with default values (for example, the [[mlogger|data logger]] creates the  [[/Logger ODB tree]]. The user may then modify these configurations to fit  his/her requirements  (see [[#Customizing|customizing]]). A list of the trees in the ODB  used by the system can be found [[Online Database|here]]. &lt;br /&gt;
&lt;br /&gt;
== Shared-memory files ==&lt;br /&gt;
[[odbedit #Creating the ODB|Creating the ODB ]]also creates&lt;br /&gt;
all the shared-memory files needed for the experiment (see list below). By default, these files will be created in the area indicated in the [[exptab]] file for your experiment. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.ALARM.SHM  .ELOG.SHM  .HISTORY.SHM  .MSG.SHM  .ODB.SHM  .SYSMSG.SHM  .SYSTEM.SHM&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Customizing the ODB =&lt;br /&gt;
The user customizes the ODB for their experiment by modifying the values of &amp;quot;system&amp;quot; parameters (e.g. [[Keys in the ODB /Logger tree]], or adding extra keys under existing trees as needed, e.g. &amp;quot;Edit on Start&amp;quot; parameters under the [[/Experiment ODB tree]].  The user may creates &amp;quot;optional&amp;quot; trees e.g. ([[/Script ODB tree]], [[/Custom ODB tree]]) populating them with keys as required.&lt;br /&gt;
The user is also free to create his/her own tree structure under root (/) for his/her own purposes. &lt;br /&gt;
&lt;br /&gt;
== Creating ODB keys ==&lt;br /&gt;
&lt;br /&gt;
The easiest way to create, set (and delete if necessary) [[#ODB Keys|ODB keys]] is to use the [[ODB Page]] of the web server [[mhttpd]]. This also includes creating &#039;&#039;&#039;subdirectories&#039;&#039;&#039; and &#039;&#039;&#039;symbolic links&#039;&#039;&#039;. See [[ODB Page#Create an ODB key]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Alternatively, [[odbedit]] can be used as demonstrated in the following example. [[Odbedit]] is more powerful, also allowing the user to for example re-order, copy or rename  the keys (see [[odbedit command list]]).&lt;br /&gt;
&lt;br /&gt;
Once a directory is created, keys can be created of the types supported by MIDAS (see [[Midas Data Types]]), e.g. INT DWORD BOOL FLOAT DOUBLE STRING.  Arrays of all these types can also be created. Values are then assigned to the keys using the {{Odbedit cmd|cmd=set}}.&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
This example shows how to create an ODB tree (&amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Custom&amp;lt;/span&amp;gt;) using [[odbedit]]. Creating the same tree using the [[ODB Page]] is easy (see [[ODB Page#Create an ODB key]] for more information).&lt;br /&gt;
 &lt;br /&gt;
The [[odbedit]] commands are shown in red. Comments are shown in green and preceded by a &amp;quot;#&amp;quot;.&lt;br /&gt;
 $ odbedit   &lt;br /&gt;
 [local:midas:S]/&amp;gt;pwd    &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# show current directory (tree) &amp;lt;/span&amp;gt;&lt;br /&gt;
 /&lt;br /&gt;
 [local:midas:S]/&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;mkdir custom/images&amp;lt;/span&amp;gt;    &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# make directory &amp;quot;custom&amp;quot; and subdirectory &amp;quot;images&amp;quot;&amp;lt;/span&amp;gt;&lt;br /&gt;
 [local:midas:S]/&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;ls&amp;lt;/span&amp;gt;  &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# list all keys&amp;lt;/span&amp;gt;&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Experiment&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&lt;br /&gt;
 Custom&lt;br /&gt;
 [local:midas:S]/&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;cd custom &amp;lt;/span&amp;gt;  &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# change directory to &amp;quot;/custom&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
 [local:midas:S]/custom&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;ls&amp;lt;/span&amp;gt;&lt;br /&gt;
 images&lt;br /&gt;
 [local:midas:S]/custom&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;create string &amp;quot;custom page&amp;amp;&amp;quot;&amp;lt;/span&amp;gt;  &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# Create a key of type STRING. Note use of quotes as key name contains a space &amp;lt;/span&amp;gt;&lt;br /&gt;
 String length [32]: 128&lt;br /&gt;
 [local:midas:S]/custom&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;set &amp;quot;custom page&amp;amp;&amp;quot; /home/midas/custom/custom.html&amp;lt;/span&amp;gt;  &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# Set key to a value. &lt;br /&gt;
 #             Could type instead &amp;quot;set cus&amp;quot; followed by tab to demonstrate tab-completion &amp;lt;/span&amp;gt;&lt;br /&gt;
 [local:midas:S]/custom&amp;gt;&amp;lt;span style=&amp;quot;color:red; font-style:normal&amp;quot;&amp;gt;ls -r&amp;lt;/span&amp;gt;  &amp;lt;span style=&amp;quot;color:green; font-style:normal&amp;quot;&amp;gt;# list recursively &amp;lt;/span&amp;gt;&lt;br /&gt;
 custom&lt;br /&gt;
    images&lt;br /&gt;
    custom page&amp;amp;           /home/midas/custom/custom.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Creating arrays ==&lt;br /&gt;
Creating arrays in the ODB is simple using the [[ODB Page]] (see [[ODB Page#Create an ODB key]] for more information).&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates the use of [[odbedit]] to create an array, set its elements to various value, and expand it. An array can be truncated using the [[odbedit]] &#039;&#039;trunc&#039;&#039; command.&lt;br /&gt;
 [local:pol:S]/test&amp;gt;create int fred[5]&lt;br /&gt;
 [local:pol:S]/test&amp;gt;set fred[*] 5&lt;br /&gt;
 [local:pol:S]/test&amp;gt;set fred[1..3] 6&lt;br /&gt;
 [local:pol:S]/test&amp;gt;set fred[8] 9&lt;br /&gt;
 [local:pol:S]/test&amp;gt;ls&lt;br /&gt;
 fred&lt;br /&gt;
                                5&lt;br /&gt;
                                6&lt;br /&gt;
                                6&lt;br /&gt;
                                6&lt;br /&gt;
                                5&lt;br /&gt;
                                0&lt;br /&gt;
                                0&lt;br /&gt;
                                0&lt;br /&gt;
                                9&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reordering ODB keys ==&lt;br /&gt;
Sometimes it may be desired to reorder the ODB keys once created. This must be done using [[odbedit]]. &lt;br /&gt;
&lt;br /&gt;
The  {{Odbedit cmd|cmd=move}} is used for this purpose as in the following example:&lt;br /&gt;
&lt;br /&gt;
The key &amp;quot;custom&amp;quot; can be moved to the top (or bottom) of the list, e.g.&lt;br /&gt;
 &lt;br /&gt;
 [local:midas:S]/&amp;gt;ls&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Experiment&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&lt;br /&gt;
 Custom&lt;br /&gt;
&lt;br /&gt;
The key &amp;quot;Custom&amp;quot; can be moved to the top&lt;br /&gt;
&lt;br /&gt;
 [local:midas:S]/&amp;gt;move custom top&lt;br /&gt;
 [local:midas:S]/&amp;gt;ls&lt;br /&gt;
 Custom&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Experiment&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&lt;br /&gt;
&lt;br /&gt;
or to any position, e.g.&lt;br /&gt;
&lt;br /&gt;
 [local:midas:Stopped]/&amp;gt;move custom 1&lt;br /&gt;
 [local:midas:Stopped]/&amp;gt;ls&lt;br /&gt;
 System&lt;br /&gt;
 Custom&lt;br /&gt;
 Programs&lt;br /&gt;
 Experiment&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&lt;br /&gt;
&lt;br /&gt;
== Create a subdirectory in the ODB ==&lt;br /&gt;
Creating a subdirectory is very easy to do using the [[ODB Page]]. See [[ODB Page#Create an ODB key|Create an ODB key]].&lt;br /&gt;
&lt;br /&gt;
Using [[odbedit]], select the desired directory using {{Odbedit cmd|cmd=cd}} then make the directory with {{Odbedit cmd|cmd=mkdir}} e.g.&lt;br /&gt;
&lt;br /&gt;
 [local:test:S]cd /Experiment&lt;br /&gt;
 [local:test:S]mkdir &amp;quot;edit on start&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Setting multiple keys at once ==&lt;br /&gt;
There are occasions where multiple keys of different subfolder need to be modified; an Equipment may have multiple boards each one with its own configuration.&lt;br /&gt;
For this reason the set command can expand paths to match multiple keys with a single command. An example using the standard ODB:&lt;br /&gt;
&lt;br /&gt;
 [local:test:S]set /Alarms/Alarms/*/Active n&lt;br /&gt;
&lt;br /&gt;
will deactivate all alarms.&lt;br /&gt;
&lt;br /&gt;
== Create a symbolic link in the ODB ==&lt;br /&gt;
Creating a symbolic link is easy to do using the [[ODB Page]]. See [[ODB Page#Create an ODB key|Create an ODB key]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Creating the same symbolic link with [[odbedit]]&lt;br /&gt;
 [local:test:S]cd /Experiment/edit on start&lt;br /&gt;
 [local:test:S]Edit on Start&amp;gt; ln &amp;quot;/logger/write data&amp;quot; &amp;quot;write data&amp;quot;&lt;br /&gt;
 [local:test:S]Edit on Start&amp;gt; ls&lt;br /&gt;
 write data -&amp;gt; /logger/write data&lt;br /&gt;
                                y&lt;br /&gt;
&lt;br /&gt;
= Save and reload the ODB =&lt;br /&gt;
The ODB can be saved at its current position in several formats (ascii, xml as a c structure) using the [[odbedit]] &#039;&#039;save&#039;&#039; command, and reloaded from a saved file with the [[odbedit]] &#039;&#039;load&#039;&#039; command.&lt;br /&gt;
; NOTE&lt;br /&gt;
: JSON format has been added (January 2016). See [[#JSON]].&lt;br /&gt;
&lt;br /&gt;
e.g. to save the ODB into a file in the local directory in ASCII format :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:exp:Stopped]/&amp;gt;save my_exp.odb &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and to load the ODB from a previously saved file in the local directory :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:npet:Stopped]/&amp;gt;load saved.odb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Since the ODB may become [[#Corrupted ODB|corrupted]],  a copy is saved automatically at the beginning of each run. Since this file is overwritten each time, users often also save a copy (that will not be overwritten) at the end of each run (see [[Keys in the ODB /Logger tree#ODB Dump|ODB Dump]]) along with the data for that run. (The ODB contents can also be sent to the logging channel and saved with the run data - see [[Keys in the ODB /Logger/Channels tree #ODB Dump|ODB Dump in /Logger/Channels subtree]]).&lt;br /&gt;
&lt;br /&gt;
Users can then return their ODB to the state it was in for any particular run.&lt;br /&gt;
&lt;br /&gt;
The entire database need not be loaded. Saved ASCII files can be made of just a part of the database, and these can be reloaded into the database. Since the full path is given in the saved file, the file can be loaded from any position in the database.&lt;br /&gt;
&lt;br /&gt;
The saved ASCII file may of course be edited prior to loading, if keynames or values need to be changed. If the keys in the load file do not exist, they will be created. If they do exist, the values from the file will be loaded.&lt;br /&gt;
&lt;br /&gt;
= &#039;&#039;&#039;experim.h&#039;&#039;&#039; include file =&lt;br /&gt;
&lt;br /&gt;
The [[odbedit]] &#039;&#039;&#039;make&#039;&#039;&#039; command creates &amp;quot;&#039;&#039;experim.h&#039;&#039;&amp;quot;, a file containing a C structure and ascii representation of part of the ODB. The file is created in the current directory. &lt;br /&gt;
e.g.&lt;br /&gt;
 [local:midas:S]/&amp;gt;make&lt;br /&gt;
 Analyzer &amp;quot;Analyzer&amp;quot; not found in ODB, skipping analyzer parameters.&lt;br /&gt;
 &amp;quot;experim.h&amp;quot; has been written to /home/midas/online&lt;br /&gt;
&lt;br /&gt;
The file &#039;&#039;experim.h&#039;&#039; contains C structures for the ODB trees &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Experiment, /Analyzer/Parameters&amp;lt;/span&amp;gt;, and &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Equipment/&amp;lt;equipment-name&amp;gt;/Settings&amp;lt;/span&amp;gt; if these trees are present.   All C structures are accompanied by a string representation which can be used in the &#039;&#039;db_create_record&#039;&#039; function to setup an ODB structure which matches the required C structure, ensuring that the required keys are present in the ODB (see&lt;br /&gt;
[[Frontend user code#Function begin_of_run|Frontend]] or [[Event Notification (Hot-Link)#How to set up a Hot-Link|setting up a hot link]]). &lt;br /&gt;
&lt;br /&gt;
If the name of the analyzer is not the default (i.e. &amp;quot;Analyzer&amp;quot;), then in order to include the analyzer section, the ODB key &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/&amp;lt;Analyzer-name&amp;gt;/Parameters&amp;lt;/span&amp;gt; has to be present, where &amp;lt;Analyzer-name&amp;gt; is the name of the analyzer. &lt;br /&gt;
&lt;br /&gt;
The command used is then &amp;quot;make &amp;lt;Analyzer-name&amp;gt; &amp;quot;.&lt;br /&gt;
&lt;br /&gt;
An example &#039;&#039;experim.h&#039;&#039; can be found at&lt;br /&gt;
[http://ladd00.triumf.ca/~daqweb/doc/midas/examples/Triumf/c/experim.h].&lt;br /&gt;
&lt;br /&gt;
= JSON =&lt;br /&gt;
New commands have been added (January 2016) which correspond to JSON encoding of ODB data see [[mjsonrpc#JSON encoding of ODB data]]. &lt;br /&gt;
The command  {{Odbedit cmd|cmd=json}} encodes all ODB data and metadata. ODB can be fully reloaded or restored from ODB JSON save files.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ odbedit&lt;br /&gt;
[local:js:S]&amp;gt;cd /Equipment/rpcexample/variables&lt;br /&gt;
[local:js:S]Variables&amp;gt;ls&lt;br /&gt;
SLOW&lt;br /&gt;
                                1273&lt;br /&gt;
                                1376610644&lt;br /&gt;
                                74.31448279461522&lt;br /&gt;
[local:js:S]Variables&amp;gt;json&lt;br /&gt;
status: 1, json: {&lt;br /&gt;
  &amp;quot;SLOW/key&amp;quot; : { &amp;quot;type&amp;quot; : 10, &amp;quot;num_values&amp;quot; : 3, &amp;quot;access_mode&amp;quot; : 7, &amp;quot;last_written&amp;quot; : 1448506616 },&lt;br /&gt;
  &amp;quot;SLOW&amp;quot; : [ 1273, 1376610644, 7.4314482794615216e+01 ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The {{Odbedit cmd|cmd=jsls}}  encodes a single ODB directory and returns the full information printed by the {{Odbedit cmd|cmd=ls -l}}.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:js:S]Variables&amp;gt;jsls&lt;br /&gt;
jsls &amp;quot;/Equipment/RpcExample/Variables&amp;quot;, status: 1, json: {&lt;br /&gt;
  &amp;quot;SLOW/key&amp;quot; : { &amp;quot;type&amp;quot; : 10, &amp;quot;num_values&amp;quot; : 3, &amp;quot;access_mode&amp;quot; : 7, &amp;quot;last_written&amp;quot; : 1448506616 },&lt;br /&gt;
  &amp;quot;SLOW&amp;quot; : [ 1273, 1376610644, 7.4314482794615216e+01 ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The {{Odbedit cmd|cmd=jsvalues}}  list the data in a format for exporting ODB data to web pages: links are followed to their final values and ODB key names are converted to lower case for use with case-sensitive languages such as Javascript.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:js:S]Variables&amp;gt;jsvalues&lt;br /&gt;
status: 1, json: {&lt;br /&gt;
  &amp;quot;slow/name&amp;quot; : &amp;quot;SLOW&amp;quot;,&lt;br /&gt;
  &amp;quot;slow/last_written&amp;quot; : 1448506616,&lt;br /&gt;
  &amp;quot;slow&amp;quot; : [ 1273, 1376610644, 7.4314482794615216e+01 ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= Corrupted ODB =&lt;br /&gt;
If the ODB becomes corrupted, [[odbedit]] may no longer work, and other clients will also fail to open the database. In this case, the old ODB should be deleted and a new one created. The contents of the ODB can be reloaded from a [[#Save and reload the ODB|saved ODB file]].&lt;br /&gt;
Follow the instructions in [[Recovery from Corrupted ODB]].&lt;br /&gt;
&lt;br /&gt;
= Accessing the ODB from a script =&lt;br /&gt;
The external command feature of [[odbedit]] (see [[Odbedit#Using an external command]]) allows for sophisticated scripts to be created that can manipulate the ODB.&lt;br /&gt;
Such scripts can for example&lt;br /&gt;
&lt;br /&gt;
*    check ODB parameters prior to beginning of run&lt;br /&gt;
*    send run parameters to the electronic logbook&lt;br /&gt;
*    set some ODB parameters when a script button on the [[mhttpd]] main status page is pressed&lt;br /&gt;
*    load a particular saved odb file when a button on a custom page is pressed (e.g. load a &amp;quot;tune&amp;quot;) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Examples of shell scripts that may send [[odbedit]] commands :&lt;br /&gt;
&lt;br /&gt;
*    script run at end-of-run or begin-of-run  (see [[#Example end-of-run script|below]])&lt;br /&gt;
*    script run when a [[/Script ODB tree#Script-button|script-button]] or [[Custom Page Features#CustomScript Buttons|Customscript button]] is pressed&lt;br /&gt;
&lt;br /&gt;
Script writers may find it useful to [#Message Page and message log|send messages to the MIDAS message log]] to indicate progress or error.&lt;br /&gt;
&lt;br /&gt;
== Example end-of-run script ==&lt;br /&gt;
The following is part of a script run at end-of-run, where it reads some parameters from the odb and saves them in a temporary file to be sent to the elog.&lt;br /&gt;
&lt;br /&gt;
To make the script run at end of run, the name of the script is entered in the ODB key {{Odbpath|path=/Programs/Execute on stop run}} (see [[/Programs ODB tree#Execute on stop run]]). Similarly, a script may be made to run at the beginning of run by entering its name in the ODB key  {{Odbpath|path=/Programs/Execute on start run}} (see [[/Programs ODB tree#Execute on start run]]). &lt;br /&gt;
&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # This script is started at the end of each run. It takes some parameters&lt;br /&gt;
 # from the odb and creates an entry in the elog &lt;br /&gt;
 .....&lt;br /&gt;
 # Start collecting information from ODB first&lt;br /&gt;
 set Run_number = `odb -e $MIDAS_EXPT_NAME -c &#039;ls &amp;quot;/Runinfo/Run number&amp;quot;&#039;`&lt;br /&gt;
 set number = `echo $Run_number | awk &#039;{print $3}&#039;`&lt;br /&gt;
 set sample = `odb -e $MIDAS_EXPT_NAME -c &#039;ls &amp;quot;/Experiment/Edit on Start/sample&amp;quot;&#039;`&lt;br /&gt;
 set Sample = `echo $sample | awk &#039;{print $2}&#039;`&lt;br /&gt;
 .....&lt;br /&gt;
 # Now create the temporary file to be sent to the elog&lt;br /&gt;
 echo &amp;quot;Run # $number&amp;quot; &amp;gt;&amp;gt; $fin&lt;br /&gt;
 odb -e $MIDAS_EXPT_NAME -c &#039;ls &amp;quot;/Runinfo/Start time&amp;quot;&#039; &amp;gt;&amp;gt; $fin&lt;br /&gt;
 odb -e $MIDAS_EXPT_NAME -c &#039;ls &amp;quot;/Runinfo/Stop time&amp;quot;&#039; &amp;gt;&amp;gt; $fin&lt;br /&gt;
 echo &amp;quot;$Sample at T = $T K, H = $H T and RF = $RF mW&amp;quot;&amp;gt;&amp;gt; $fin&lt;br /&gt;
 .....&lt;br /&gt;
&lt;br /&gt;
= Chat command =&lt;br /&gt;
The  {{Odbedit cmd|cmd=chat}} can be used to communicate between users, each running  {{Utility|name=odbedit}} clients. The chat messages are also (sing Aug 2016) sent to the  {{Utility|name=mhttpd}} [[Chat Page]]. The  {{Odbedit cmd|cmd=msg}} can be also be used interactively to generate chat messages. If chat messages do not appear in the [[Chat Page]] see [[#Troubleshooting]].&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:js:S]/&amp;gt;chat&lt;br /&gt;
Your name&amp;gt; george&lt;br /&gt;
Exit chat mode with empty line.&lt;br /&gt;
&amp;gt; Are you there?&lt;br /&gt;
[george,USER] Are you there?&lt;br /&gt;
19:33:59 [fred,USER] Hallo George&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Msg command - send a message  =&lt;br /&gt;
The parameters of the {{Odbedit cmd|cmd=msg}} have been changed (August 2016). The  {{Odbedit cmd|cmd=msg}} now works differently &#039;&#039;&#039;interactively&#039;&#039;&#039; than from the [[odbedit#Using an external command|command line]]. A hidden parameter &amp;quot;facility&amp;quot; has been added, which is either set to &amp;quot;chat&amp;quot; or &amp;quot;midas&amp;quot;.&lt;br /&gt;
== To web server Chat page ==&lt;br /&gt;
&#039;&#039;&#039;Interactively&#039;&#039;&#039;, the  {{Odbedit cmd|cmd=msg}} works like the [[#Chat command]], sending a chat message which appears on the web server [[Chat Page]] and on any other  {{Utility|name=odbedit}} session for that experiment. The chat message does NOT appear in the MIDAS [[Message System#midas.log|message log]] or [[Message Page]]. In this case, the &amp;quot;facility&amp;quot; is hard-coded as &amp;quot;chat&amp;quot; and there are two parameters, &amp;quot;user&amp;quot; and &amp;quot;message&amp;quot;, e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:js:S]/&amp;gt;msg fred &amp;quot;hi, are you there?&amp;quot;&lt;br /&gt;
[fred,USER] hi, are you there?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== To web server Message Page and message log ==&lt;br /&gt;
To send a message to the webserver [[Message Page]] and the  [[Message System#midas.log|message logfile]] ( {{File|name=midas.log}}) use the [[odbedit#Using an external command|command line]] with the  {{Odbedit cmd|cmd=msg}}. In this case, the &amp;quot;facility&amp;quot; is hard-coded as &amp;quot;midas&amp;quot;, and there are three parameters, two of which are optional:&lt;br /&gt;
; type  (optional)&lt;br /&gt;
: Default is 8 (MT_USER). If supplied, it must be set to one of the &#039;&#039;&#039;numerical&#039;&#039;&#039; values 1 (MT_ERROR), 2 (MT_INFO), 4 (MT_DEBUG) or 8 (MT_USER),  as defined in [http://ladd00.triumf.ca/~daqweb/doc/midas-devel/html/ midas.h].&lt;br /&gt;
; name  (optional)&lt;br /&gt;
: Ignored unless the type is MT_ERROR. Default is &amp;quot;script&amp;quot;.&lt;br /&gt;
; message&lt;br /&gt;
: the message to be sent, enclosed in quotes if it includes spaces&lt;br /&gt;
&lt;br /&gt;
See Table 1 below for examples.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Table 1 : examples of  {{Odbedit cmd|cmd=msg}}&lt;br /&gt;
|-&lt;br /&gt;
! odbedit -c &#039;msg  command&#039; !!colspan=&#039;2&#039;| Type !! Name !! Resulting Message !! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| &#039;msg 2 &amp;quot;testing 123&amp;quot; &#039; &lt;br /&gt;
|  2&lt;br /&gt;
|  &#039;&#039;&#039;MT_INFO&#039;&#039;&#039; &lt;br /&gt;
| &lt;br /&gt;
|  [ODBEdit,&#039;&#039;&#039;INFO&#039;&#039;&#039;] testing 123&lt;br /&gt;
|  Message type supplied. Program name set to &amp;quot;ODBEdit&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
| &#039;msg &amp;quot;testing 123&amp;quot; &#039;&lt;br /&gt;
| 8&lt;br /&gt;
|  &#039;&#039;&#039;MT_USER&#039;&#039;&#039;&lt;br /&gt;
| &lt;br /&gt;
|   [script,&#039;&#039;&#039;USER&#039;&#039;&#039;] testing 123&lt;br /&gt;
| Message type omitted, defaults to MT_USER &amp;lt;br&amp;gt;which sets program name to &amp;quot;script&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|  &#039;msg 1 my_name &amp;quot;error message&amp;quot; &#039;&lt;br /&gt;
| 1&lt;br /&gt;
| &#039;&#039;&#039;MT_ERROR&#039;&#039;&#039;&lt;br /&gt;
| my_name&lt;br /&gt;
|[ODBEdit,&#039;&#039;&#039;ERROR&#039;&#039;&#039;] [odbedit.cxx:2490:my_name,ERROR] error message&lt;br /&gt;
| Name parameter is supplied. Error message appears with a red background.&lt;br /&gt;
|-&lt;br /&gt;
| &#039;msg 1 &amp;quot;error message&amp;quot; &#039;  &lt;br /&gt;
| 1&lt;br /&gt;
| &#039;&#039;&#039;MT_ERROR &#039;&#039;&#039;&lt;br /&gt;
| &lt;br /&gt;
| [ODBEdit,&#039;&#039;&#039;ERROR&#039;&#039;&#039;] [odbedit.cxx:2490:script,ERROR] error message&lt;br /&gt;
| Name parameter omitted,  default name is &amp;quot;script&amp;quot;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
If the message does not appear on the [[Chat Page]] (interactive) or [[Message Page]] (command line),  check that the ODB key  [[Keys in the ODB /Logger tree#Data dir|/Logger/Data dir]] is set to a &#039;&#039;&#039;full directory path&#039;&#039;&#039;, such as &#039;&#039;/home/user/online/js&#039;&#039;, not a relative path such as the current directory &amp;quot;./&amp;quot;. If set to a full directory path, all clients will use the &#039;&#039;&#039;same&#039;&#039;&#039;  {{File|name=midas.log}} file, regardless of which directory they were started from. With a relative path,  {{Utility|name=mhttpd}} and  {{Utility|name=odbedit}} must be started in the same directory&lt;br /&gt;
for messages/chat to appear in the appropriate [[mhttpd]] page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:ODB]]&lt;/div&gt;</summary>
		<author><name>Marco.francesconi</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Sequencer&amp;diff=2934</id>
		<title>Sequencer</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Sequencer&amp;diff=2934"/>
		<updated>2020-04-06T10:04:54Z</updated>

		<summary type="html">&lt;p&gt;Marco.francesconi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
&lt;br /&gt;
= Links =&lt;br /&gt;
&amp;lt;div style=&amp;quot;column-count:3;-moz-column-count:3;-webkit-column-count:3&amp;quot;&amp;gt;&lt;br /&gt;
* [[/Sequencer ODB tree]]&lt;br /&gt;
* [[Sequencer Page]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
A Sequencer for starting and stopping runs is part of the MIDAS distribution. It uses a simple Midas Script Language (MSL) for commands.&lt;br /&gt;
&lt;br /&gt;
The sequencer runs as a separate process and must be started before running a sequence via the command &#039;&#039;&#039;msequencer&#039;&#039;&#039;. 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]].&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
Refer to the [[/Sequencer ODB tree]] for more details on its organization. &lt;br /&gt;
&lt;br /&gt;
For instructions on &#039;&#039;&#039;getting started with the sequencer&#039;&#039;&#039;, see [[Sequencer Page]]&lt;br /&gt;
&lt;br /&gt;
= Sequencer Commands =&lt;br /&gt;
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).&lt;br /&gt;
&lt;br /&gt;
Variable names are indicated in italic, options are enclosed in [brackets].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align: left; color: black; tr:nth-child(even) {background-color: #F0F0F0};&amp;quot; &lt;br /&gt;
!style=&amp;quot;width: 20%;background-color:#C0C0C0;&amp;quot;|MSL format&lt;br /&gt;
!style=&amp;quot;width: 60%;background-color:#C0C0C0;&amp;quot;|Description&lt;br /&gt;
|-&lt;br /&gt;
||INCLUDE &#039;&#039;name&#039;&#039;&lt;br /&gt;
||Include another XML file &#039;&#039;name&#039;&#039;.xml&lt;br /&gt;
|-&lt;br /&gt;
||CALL &#039;&#039;name&#039;&#039;, &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ...&lt;br /&gt;
||Call a subroutine. Optional parameters &#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039;... 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.&lt;br /&gt;
|-&lt;br /&gt;
||CAT &#039;&#039;name&#039;&#039;, &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ...&lt;br /&gt;
||Concatenates the strings &#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039;,... into a single variable name . Can be referenced with $&#039;&#039;name&#039;&#039;. If a string must contain a comma, it can be enclosed in quotes such as in &#039;&#039;&#039;CAT title $run, &amp;quot;,&amp;quot;, $n events&#039;&#039;&#039;&lt;br /&gt;
|-&lt;br /&gt;
||COMMENT &#039;&#039;comment&#039;&#039;&lt;br /&gt;
||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.&lt;br /&gt;
|-&lt;br /&gt;
||GOTO &#039;&#039;n&#039;&#039;&lt;br /&gt;
||Jump to line &#039;&#039;n&#039;&#039; in script&lt;br /&gt;
|-&lt;br /&gt;
||IF &#039;&#039;con&#039;&#039;  &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
ELSE &amp;lt;br&amp;gt;&lt;br /&gt;
... &amp;lt;br&amp;gt;&lt;br /&gt;
ENDIF&lt;br /&gt;
||Statements between &amp;lt;if&amp;gt; and &amp;lt;/if&amp;gt; are only executed if condition con is true, otherwise the statements between the optional &amp;lt;else /&amp;gt; and &amp;lt;/if&amp;gt; are executed. The condition can use variables via $name and/or constants together with operators &amp;quot;&amp;lt;&amp;quot;, &amp;quot;&amp;lt;=&amp;quot;, &amp;quot;&amp;gt;&amp;quot;, &amp;quot;&amp;gt;=&amp;quot;, &amp;quot;==&amp;quot;, &amp;quot;!=&amp;quot;, &amp;quot;&amp;amp;&amp;quot; (bitwise AND). Up to four nested IF statements are possible.&lt;br /&gt;
|- &lt;br /&gt;
||LIBRARY &#039;&#039;name&#039;&#039;&lt;br /&gt;
||Indicates that the current file is a library (which can be included by other files). A library usually consists of a set of subroutines.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||LOOP [&#039;&#039;name&#039;&#039; ,] &#039;&#039;n&#039;&#039; ... ENDLOOP&lt;br /&gt;
||To execute a loop &#039;&#039;n&#039;&#039; times. For infinite loops, &amp;quot;infinite&amp;quot; can be specified as &#039;&#039;n&#039;&#039;. Optionally, the loop variable running from 1..&#039;&#039;n&#039;&#039; can be accessed inside the loop via $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||LOOP &#039;&#039;name&#039;&#039;,  &#039;&#039;a&#039;&#039;, &#039;&#039;b&#039;&#039;, &#039;&#039;c&#039;&#039;, ... ... ENDLOOP&lt;br /&gt;
||Loop though a list of values. The loop is executed once for each value, which is stored into the variable &#039;&#039;name&#039;&#039; so it can be accessed inside the loop via $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
||MESSAGE &#039;&#039;message&#039;&#039; [,1]&lt;br /&gt;
||Opens a message box in the browser containing the text message. If wait=&amp;quot;1&amp;quot;, then the sequencer waits until the box is closed by the user before continuing.&lt;br /&gt;
|-&lt;br /&gt;
||ODBGET &#039;&#039;path&#039;&#039;, &#039;&#039;name&#039;&#039;&lt;br /&gt;
||To get a value from a variable &#039;&#039;name&#039;&#039;. The variable can then be referenced with $&#039;&#039;name&#039;&#039;.&lt;br /&gt;
|-&lt;br /&gt;
||ODBINC &#039;&#039;path&#039;&#039; [, &#039;&#039;delta&#039;&#039;]&lt;br /&gt;
||To increment a value in the ODB. &#039;&#039;delta&#039;&#039; can be positive or negative. If no &amp;quot;delta&amp;quot; is given, 1 is used.&lt;br /&gt;
|-&lt;br /&gt;
||ODBSET &#039;&#039;path&#039;&#039;, &#039;&#039;value&#039;&#039; [, 0|1]&lt;br /&gt;
||To set a value in the ODB.&amp;lt;br&amp;gt;&lt;br /&gt;
The path value can match multiple keys using the &#039;?&#039; and &#039;*&#039; wildcard (one or any number of characters respectively). This is useful to set the same sub-path on multiple folders:&amp;lt;br&amp;gt; &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder0/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder1/value&amp;quot;, &amp;quot;1&amp;quot; &lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder2/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
can be shortened as:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ODBSET &amp;quot;/Path/to/somewhere/folder*/value&amp;quot;, &amp;quot;1&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
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=&amp;quot;0&amp;quot; can be specified for all ODBSet statements except the last one which contains notify=&amp;quot;1&amp;quot;, so the callback function is called only once at the end. &lt;br /&gt;
|-&lt;br /&gt;
||ODBSUBDIR &#039;&#039;path&#039;&#039; ...ENDODBSUBDIR&lt;br /&gt;
||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 &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value1&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value2&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value3&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;/Very/long/path/into/the/odb/value4&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
one can write &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;ODBSubdir path=&amp;quot;/Very/long/path/into/the/odb&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value1&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value2&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt; &lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value3&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;ODBSet path=&amp;quot;value4&amp;quot;&amp;gt;1&amp;lt;/ODBSet&amp;gt;&lt;br /&gt;
&amp;lt;/ODBSubdir&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
||PARAM &#039;&#039;name&#039;&#039;, &#039;&#039;comment&#039;&#039;, [&#039;&#039;a&#039;&#039;,&#039;&#039;b&#039;&#039;,&#039;&#039;c&#039;&#039; | bool]&lt;br /&gt;
||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 &amp;quot;comment&amp;quot; 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=&amp;quot;bool&amp;quot;, a checkbox will be shown.&lt;br /&gt;
|-&lt;br /&gt;
||RUNDESCRIPTION &#039;&#039;description&#039;&#039;&lt;br /&gt;
||a run description which is stored under /Experiment/Run Parameters/Run Description .&lt;br /&gt;
|-&lt;br /&gt;
||SCRIPT &#039;&#039;script&#039;&#039; [, a, b, c, ...]&lt;br /&gt;
||To call a script on the server side. Optionally, pass parameters to the script.&lt;br /&gt;
|-&lt;br /&gt;
||SET &#039;&#039;name&#039;&#039;, &#039;&#039;value&#039;&#039;&lt;br /&gt;
||Sets the variable &#039;&#039;name&#039;&#039; to &amp;quot;value&amp;quot;. The variable can then be referenced later in the script by putting a &amp;quot;$&amp;quot; in front of the name like $&amp;quot;name&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
||SUBROUTINE &#039;&#039;name&#039;&#039; ... ENDSUBROUTINE&lt;br /&gt;
||Declares a subroutine which can be called via CALL.&lt;br /&gt;
|-&lt;br /&gt;
||TRANSITION start | stop | pause | resume&lt;br /&gt;
||To start, stop, pause or resume a run&lt;br /&gt;
|-&lt;br /&gt;
||WAIT events | ODBvalue | seconds, [&#039;&#039;ODB path&#039;&#039;], [&#039;&#039;op&#039;&#039;], [&#039;&#039;value&#039;&#039;]&lt;br /&gt;
||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 &#039;&#039;value&#039;&#039; seconds. If the operand &#039;&#039;op&#039;&#039; 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. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
WAIT ODBvalue, /Equipment/HV/Variables/Measured[3], &amp;lt;, 100&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= MSL Example =&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
COMMENT &amp;quot;This is a MSL test file&amp;quot;&lt;br /&gt;
RUNDESCRIPTION &amp;quot;Test run&amp;quot;&lt;br /&gt;
PARAM runs&lt;br /&gt;
&lt;br /&gt;
LOOP $runs&lt;br /&gt;
     TRANSITION START&lt;br /&gt;
     WAIT Seconds 60&lt;br /&gt;
     TRANSITION STOP&lt;br /&gt;
ENDLOOP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Sequencer]]&lt;/div&gt;</summary>
		<author><name>Marco.francesconi</name></author>
	</entry>
</feed>