<?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=Olchansk</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=Olchansk"/>
	<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php/Special:Contributions/Olchansk"/>
	<updated>2026-06-04T06:02:18Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.6</generator>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3355</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3355"/>
		<updated>2023-09-15T19:33:31Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Configuration file elogd.cfg */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Elog will run from it&#039;s build directory, an &amp;quot;install&amp;quot; step is not needed.&lt;br /&gt;
&lt;br /&gt;
We will use Elog in conjunction with MIDAS mhttpd and Apache httpd. mhttpd will run on TCP port 8080, elogd on port 8082, apache httpd will provide HTTPS encryption and password protection, see https://daq00.triumf.ca/DaqWiki/index.php/Ubuntu#Install_apache_httpd_proxy_for_midas_and_elog&lt;br /&gt;
&lt;br /&gt;
Make sure &amp;quot;ProxyPass /elog/&amp;quot; is uncommented in apache config file, restart apache after making this change.&lt;br /&gt;
&lt;br /&gt;
Try https://yourhostname/elog/, after entering correct password, error should be: &amp;quot;Service Unavailable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8082                           &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /home/exptuser/packages/elog&lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; this is the URL of the elogd https proxy&lt;br /&gt;
  url = https://myexpt.triumf.ca/elog/&lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd https proxy&lt;br /&gt;
  main tab url = https://myexpt.triumf.ca&lt;br /&gt;
  ; email server for sending email notifications, contact your campus network administrator for correct hostname&lt;br /&gt;
  smtp host = smtp.triumf.ca             &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Konstantin&#039;s most recently used config file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
port = 9085&lt;br /&gt;
URL = https://daq00.triumf.ca/elog-dl&lt;br /&gt;
SMTP host = smtp.triumf.ca&lt;br /&gt;
Logfile = elogd.log&lt;br /&gt;
Time format = %d %b %Y %H:%M&lt;br /&gt;
Default encoding = 1&lt;br /&gt;
Allowed encoding = 1&lt;br /&gt;
Password file = elogd-dl.passwd&lt;br /&gt;
Admin User = Olchansk&lt;br /&gt;
Menu commands = List, New, Edit, Delete, Reply, Duplicate, Find, Config, Help&lt;br /&gt;
Self register = 3&lt;br /&gt;
Message Width = 80&lt;br /&gt;
Preset Author = $long_name&lt;br /&gt;
Preset on reply Author = $long_name&lt;br /&gt;
Locked Attributes = Author&lt;br /&gt;
Max content length = 100000000&lt;br /&gt;
&lt;br /&gt;
[DarkLight]&lt;br /&gt;
Theme = default&lt;br /&gt;
Comment = DarkLight elog&lt;br /&gt;
Attributes = Author, Type, Category, Subject&lt;br /&gt;
Options Type = Routine, Problem Report, Problem Fixed&lt;br /&gt;
Options Category = General, Software, Hardware&lt;br /&gt;
Extendable Options = Category, Type&lt;br /&gt;
Required Attributes = Author, Type&lt;br /&gt;
Page Title = DL - $subject&lt;br /&gt;
Reverse sort = 1&lt;br /&gt;
Quick filter = Date, Type&lt;br /&gt;
Use Email Subject = [DL] $subject&lt;br /&gt;
Use email from = noreply@daq00.triumf.ca&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon&lt;br /&gt;
* -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* if elog is not running on same machine as midas (mhttpd, mlogger), change the odbedit command in the config file to have correct -e and -h arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$HOME/packages/elog/elogd -c dldaq.cfg -x&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3354</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3354"/>
		<updated>2023-09-15T18:19:42Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Start the Elog daemon */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Elog will run from it&#039;s build directory, an &amp;quot;install&amp;quot; step is not needed.&lt;br /&gt;
&lt;br /&gt;
We will use Elog in conjunction with MIDAS mhttpd and Apache httpd. mhttpd will run on TCP port 8080, elogd on port 8082, apache httpd will provide HTTPS encryption and password protection, see https://daq00.triumf.ca/DaqWiki/index.php/Ubuntu#Install_apache_httpd_proxy_for_midas_and_elog&lt;br /&gt;
&lt;br /&gt;
Make sure &amp;quot;ProxyPass /elog/&amp;quot; is uncommented in apache config file, restart apache after making this change.&lt;br /&gt;
&lt;br /&gt;
Try https://yourhostname/elog/, after entering correct password, error should be: &amp;quot;Service Unavailable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8082                           &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /home/exptuser/packages/elog&lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; this is the URL of the elogd https proxy&lt;br /&gt;
  url = https://myexpt.triumf.ca/elog/&lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd https proxy&lt;br /&gt;
  main tab url = https://myexpt.triumf.ca&lt;br /&gt;
  ; email server for sending email notifications, contact your campus network administrator for correct hostname&lt;br /&gt;
  smtp host = smtp.triumf.ca             &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1&lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon&lt;br /&gt;
* -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* if elog is not running on same machine as midas (mhttpd, mlogger), change the odbedit command in the config file to have correct -e and -h arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$HOME/packages/elog/elogd -c dldaq.cfg -x&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3353</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3353"/>
		<updated>2023-09-15T18:11:37Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Configuration file elogd.cfg */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Elog will run from it&#039;s build directory, an &amp;quot;install&amp;quot; step is not needed.&lt;br /&gt;
&lt;br /&gt;
We will use Elog in conjunction with MIDAS mhttpd and Apache httpd. mhttpd will run on TCP port 8080, elogd on port 8082, apache httpd will provide HTTPS encryption and password protection, see https://daq00.triumf.ca/DaqWiki/index.php/Ubuntu#Install_apache_httpd_proxy_for_midas_and_elog&lt;br /&gt;
&lt;br /&gt;
Make sure &amp;quot;ProxyPass /elog/&amp;quot; is uncommented in apache config file, restart apache after making this change.&lt;br /&gt;
&lt;br /&gt;
Try https://yourhostname/elog/, after entering correct password, error should be: &amp;quot;Service Unavailable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8082                           &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /home/exptuser/packages/elog&lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; this is the URL of the elogd https proxy&lt;br /&gt;
  url = https://myexpt.triumf.ca/elog/&lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd https proxy&lt;br /&gt;
  main tab url = https://myexpt.triumf.ca&lt;br /&gt;
  ; email server for sending email notifications, contact your campus network administrator for correct hostname&lt;br /&gt;
  smtp host = smtp.triumf.ca             &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1&lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3333</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3333"/>
		<updated>2023-09-13T21:18:41Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Installation considerations */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
Elog will run from it&#039;s build directory, an &amp;quot;install&amp;quot; step is not needed.&lt;br /&gt;
&lt;br /&gt;
We will use Elog in conjunction with MIDAS mhttpd and Apache httpd. mhttpd will run on TCP port 8080, elogd on port 8082, apache httpd will provide HTTPS encryption and password protection, see https://daq00.triumf.ca/DaqWiki/index.php/Ubuntu#Install_apache_httpd_proxy_for_midas_and_elog&lt;br /&gt;
&lt;br /&gt;
Make sure &amp;quot;ProxyPass /elog/&amp;quot; is uncommented in apache config file, restart apache after making this change.&lt;br /&gt;
&lt;br /&gt;
Try https://yourhostname/elog/, after entering correct password, error should be: &amp;quot;Service Unavailable&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8081                             &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /elog_installation_dir     &lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; URL under which elogd is accessible&lt;br /&gt;
  url = http://NodeB.triumf.ca:8081      &lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd which must run on a different port&lt;br /&gt;
  main tab url = http://NodeA:8080&lt;br /&gt;
  ; only needed for email notifications&lt;br /&gt;
  smtp host = your.smtp.host              &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1             &lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3332</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3332"/>
		<updated>2023-09-13T21:12:47Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Download Elog package */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation considerations ==&lt;br /&gt;
You need to take note of several considerations for its installation. Several locations are required for the different files that elog deals with.&lt;br /&gt;
* elog resource directory ( e.g. /elog_installation_dir where elog is installed)&lt;br /&gt;
* logbook directory (ex: /myexpt/logbook where the pwd and elog entries are stored).&lt;br /&gt;
* The pwd file uses encryption for the user password.&lt;br /&gt;
&lt;br /&gt;
* As this Elog installation is tailored towards an experiment, a restriction applies i.e. ensure that the mhttpd and elog applications shares at least the same file system. &lt;br /&gt;
** This means that either both applications runs on the same machine or a nsf mount provides file sharing.&lt;br /&gt;
** You need to know the node and ports for both applications. Like mhttpd, elogd also requires a port number for communication through the web (e.g. NodeA:mhttpd -p 8080, NodeB:elogd -p 8081).&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8081                             &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /elog_installation_dir     &lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; URL under which elogd is accessible&lt;br /&gt;
  url = http://NodeB.triumf.ca:8081      &lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd which must run on a different port&lt;br /&gt;
  main tab url = http://NodeA:8080&lt;br /&gt;
  ; only needed for email notifications&lt;br /&gt;
  smtp host = your.smtp.host              &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1             &lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3331</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3331"/>
		<updated>2023-09-13T21:09:26Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Build Elog package */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
cd elog&lt;br /&gt;
git pull ### update to latest version&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Download Elog package ==&lt;br /&gt;
&lt;br /&gt;
* Download the Elog package from the web site mentioned above.&lt;br /&gt;
** Windows, Linux, Mac version can be found there. Simple installation procedures are also described. Its installation can be done at the system level or at the user level. The Elog can service multiple Electronic logbooks in parallel and therefore an extra entry in its configuration file can provide specific experimental elog in a similar fashion as the internal one.&lt;br /&gt;
&lt;br /&gt;
== Installation considerations ==&lt;br /&gt;
You need to take note of several considerations for its installation. Several locations are required for the different files that elog deals with.&lt;br /&gt;
* elog resource directory ( e.g. /elog_installation_dir where elog is installed)&lt;br /&gt;
* logbook directory (ex: /myexpt/logbook where the pwd and elog entries are stored).&lt;br /&gt;
* The pwd file uses encryption for the user password.&lt;br /&gt;
&lt;br /&gt;
* As this Elog installation is tailored towards an experiment, a restriction applies i.e. ensure that the mhttpd and elog applications shares at least the same file system. &lt;br /&gt;
** This means that either both applications runs on the same machine or a nsf mount provides file sharing.&lt;br /&gt;
** You need to know the node and ports for both applications. Like mhttpd, elogd also requires a port number for communication through the web (e.g. NodeA:mhttpd -p 8080, NodeB:elogd -p 8081).&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8081                             &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /elog_installation_dir     &lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; URL under which elogd is accessible&lt;br /&gt;
  url = http://NodeB.triumf.ca:8081      &lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd which must run on a different port&lt;br /&gt;
  main tab url = http://NodeA:8080&lt;br /&gt;
  ; only needed for email notifications&lt;br /&gt;
  smtp host = your.smtp.host              &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1             &lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3330</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3330"/>
		<updated>2023-09-13T21:08:52Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Download Elog package */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Build Elog package ==&lt;br /&gt;
&lt;br /&gt;
On Linux and Mac, we recommend building elog from git sources:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mkdir -p $HOME/packages&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://bitbucket.org/ritt/elog --recursive&lt;br /&gt;
make -j&lt;br /&gt;
ls -l elogd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Download Elog package ==&lt;br /&gt;
&lt;br /&gt;
* Download the Elog package from the web site mentioned above.&lt;br /&gt;
** Windows, Linux, Mac version can be found there. Simple installation procedures are also described. Its installation can be done at the system level or at the user level. The Elog can service multiple Electronic logbooks in parallel and therefore an extra entry in its configuration file can provide specific experimental elog in a similar fashion as the internal one.&lt;br /&gt;
&lt;br /&gt;
== Installation considerations ==&lt;br /&gt;
You need to take note of several considerations for its installation. Several locations are required for the different files that elog deals with.&lt;br /&gt;
* elog resource directory ( e.g. /elog_installation_dir where elog is installed)&lt;br /&gt;
* logbook directory (ex: /myexpt/logbook where the pwd and elog entries are stored).&lt;br /&gt;
* The pwd file uses encryption for the user password.&lt;br /&gt;
&lt;br /&gt;
* As this Elog installation is tailored towards an experiment, a restriction applies i.e. ensure that the mhttpd and elog applications shares at least the same file system. &lt;br /&gt;
** This means that either both applications runs on the same machine or a nsf mount provides file sharing.&lt;br /&gt;
** You need to know the node and ports for both applications. Like mhttpd, elogd also requires a port number for communication through the web (e.g. NodeA:mhttpd -p 8080, NodeB:elogd -p 8081).&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8081                             &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /elog_installation_dir     &lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; URL under which elogd is accessible&lt;br /&gt;
  url = http://NodeB.triumf.ca:8081      &lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd which must run on a different port&lt;br /&gt;
  main tab url = http://NodeA:8080&lt;br /&gt;
  ; only needed for email notifications&lt;br /&gt;
  smtp host = your.smtp.host              &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1             &lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3329</id>
		<title>Electronic Logbook (ELOG)</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Electronic_Logbook_(ELOG)&amp;diff=3329"/>
		<updated>2023-09-13T21:05:01Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Introduction */&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;
* [[/Elog ODB tree]]&lt;br /&gt;
* [[mhttpd]]&lt;br /&gt;
* mhttpd [[Elog Page]]&lt;br /&gt;
* [https://midas.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ]&lt;br /&gt;
* [[Melog]] Utility&lt;br /&gt;
* [[Elog|Elog Utility]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Introduction =&lt;br /&gt;
The &#039;&#039;&#039;Electronic LogBook&#039;&#039;&#039; (ELOG) is a utility built-in the [[mhttpd|web server]]. It is available and operational once the web-server is running. A dedicated button &amp;quot;ELOG&amp;quot; will be present on the main &lt;br /&gt;
Midas status page for creating new entries. This mode is referred as the [[#Built-in Elog|Built-in Elog]].&lt;br /&gt;
&lt;br /&gt;
This tool can replace the experimental logbook for daily entries. The main advantage of the Elog over a paper logbook is the possiblity to access it remotely, and provide a general knowledge of the experiment.&lt;br /&gt;
&lt;br /&gt;
More recently, the independent [https://elog.psi.ch/elog/ &#039;&#039;&#039;Elog&#039;&#039;&#039; ] package can be linked to a Midas experiment. Its advantage over the built-in version is its flexibility. This package is used worldwide and improvements are constantly being made. A full-features documentation and standalone installation can be found at the Elog web site.&lt;br /&gt;
&lt;br /&gt;
== Built-in Elog ==&lt;br /&gt;
The ELOG page (accessed by clicking the Elog button if present on the main status page ) provides access to an electronic logbook.  the Elog is not limited strictly to experiments. Worldwide Elog implementations can be found on the internet. This internal implementation doesn&#039;t requires any setup to be operational. The Elog is customized through the ODB /Elog tree.&lt;br /&gt;
 &lt;br /&gt;
== External Elog ==&lt;br /&gt;
The external implementation requires a proper Elog installation which is fully described on the Elog web site. The External Elog implementation also requires a dedicated entry in the [[/Elog ODB tree]] as shown in the code below. It also requires the package Elog to be already installed, and properly configured. Once the ODB entry is present, the internal ELOG is disabled. &lt;br /&gt;
&lt;br /&gt;
The External Elog is customized through the configuration file elogd.cfg (see [[#Installation|Installation]] below).&lt;br /&gt;
&lt;br /&gt;
= Installation of External Elog =&lt;br /&gt;
Installation requires requires several steps described below.&lt;br /&gt;
&lt;br /&gt;
== Download Elog package ==&lt;br /&gt;
* Download the Elog package from the web site mentioned above.&lt;br /&gt;
** Windows, Linux, Mac version can be found there. Simple installation procedures are also described. Its installation can be done at the system level or at the user level. The Elog can service multiple Electronic logbooks in parallel and therefore an extra entry in its configuration file can provide specific experimental elog in a similar fashion as the internal one.&lt;br /&gt;
&lt;br /&gt;
== Installation considerations ==&lt;br /&gt;
You need to take note of several considerations for its installation. Several locations are required for the different files that elog deals with.&lt;br /&gt;
* elog resource directory ( e.g. /elog_installation_dir where elog is installed)&lt;br /&gt;
* logbook directory (ex: /myexpt/logbook where the pwd and elog entries are stored).&lt;br /&gt;
* The pwd file uses encryption for the user password.&lt;br /&gt;
&lt;br /&gt;
* As this Elog installation is tailored towards an experiment, a restriction applies i.e. ensure that the mhttpd and elog applications shares at least the same file system. &lt;br /&gt;
** This means that either both applications runs on the same machine or a nsf mount provides file sharing.&lt;br /&gt;
** You need to know the node and ports for both applications. Like mhttpd, elogd also requires a port number for communication through the web (e.g. NodeA:mhttpd -p 8080, NodeB:elogd -p 8081).&lt;br /&gt;
&lt;br /&gt;
== Configuration file elogd.cfg ==&lt;br /&gt;
* copy the default midas/src/elogd.cfg from the MIDAS distrbution to your operating directory.&lt;br /&gt;
* modify the elogd.cfg to reflect your configuration&lt;br /&gt;
  &lt;br /&gt;
  # This is a simple elogd configuration file to work with MIDAS&lt;br /&gt;
  # &lt;br /&gt;
  [global]&lt;br /&gt;
  ; port under which elogd should run&lt;br /&gt;
  port = 8081                             &lt;br /&gt;
  ; password file, created under &#039;logbook dir&#039;&lt;br /&gt;
  password file = elog.pwd                &lt;br /&gt;
  ; directory under which elog was installed (themes etc.)&lt;br /&gt;
  resource dir = /elog_installation_dir     &lt;br /&gt;
  ; directory where the password file will end up&lt;br /&gt;
  logbook dir = /myexpt/logbook     &lt;br /&gt;
  ; anyone can create it&#039;s own account&lt;br /&gt;
  self register = 1                       &lt;br /&gt;
  ; URL under which elogd is accessible&lt;br /&gt;
  url = http://NodeB.triumf.ca:8081      &lt;br /&gt;
  ; the &amp;quot;main&amp;quot; tab will bring you back to mhttpd&lt;br /&gt;
  main tab = Xenon                        &lt;br /&gt;
  ; this is the URL of mhttpd which must run on a different port&lt;br /&gt;
  main tab url = http://NodeA:8080&lt;br /&gt;
  ; only needed for email notifications&lt;br /&gt;
  smtp host = your.smtp.host              &lt;br /&gt;
  ; Define one logbook for online use. Severl logbooks can be defined here&lt;br /&gt;
  [MyOnline]&lt;br /&gt;
  ; directory where the logfiles will be written to&lt;br /&gt;
  Data dir = /myexpt/logbook            &lt;br /&gt;
  Comment = My MIDAS Experiment Electronic Logbook&lt;br /&gt;
  ; mimic old mhttpd behaviour&lt;br /&gt;
  Attributes = Run number, Author, Type, System, Subject     &lt;br /&gt;
  Options Type = Routine, Shift Summary, Minor Error, Severe Error, Fix, Question, Info, Modification, Alarm, Test, Other, &lt;br /&gt;
  Options System = General, DAQ, Detector, Electronics, Target, Beamline&lt;br /&gt;
  Extendable Options = Type, System&lt;br /&gt;
  ; This substitution will enter the current run number&lt;br /&gt;
  Preset Run number = $shell(odbedit -e myexpt -h NodeA -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)    &lt;br /&gt;
  Preset Author = $long_name&lt;br /&gt;
  Required Attributes = Type, Subject&lt;br /&gt;
  ; Run number and Author cannot be changed&lt;br /&gt;
  Locked Attributes = Run number, Author  &lt;br /&gt;
  Page Title = ELOG - $subject&lt;br /&gt;
  Reverse sort = 1&lt;br /&gt;
  Quick filter = Date, Type, Author&lt;br /&gt;
  ; Don&#039;t send any emails&lt;br /&gt;
  Suppress email to users = 1             &lt;br /&gt;
&lt;br /&gt;
== Start the Elog daemon ==&lt;br /&gt;
* start the elog daemon. -x is for the shell substitution of the command Preset Run number = $shell(...)&lt;br /&gt;
* The argument invokes the odbedit remotely if needed to retrieve the current run number. You will have to ensure the proper path to the odbedit and the proper -e, -h arguments for the experiment and host. &lt;br /&gt;
&lt;br /&gt;
You may want to verify this command from the console.&lt;br /&gt;
&lt;br /&gt;
  NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x&amp;lt;cr&amp;gt; starts the mhttpd at its correct port and possibly in the daemon form.&lt;br /&gt;
  NodeA:~&amp;gt;mhttpd -p 8080 -D &lt;br /&gt;
&lt;br /&gt;
== Activate External Elog ==&lt;br /&gt;
&lt;br /&gt;
At this point the Elog from the MIDAS web page is accessing the [[[#Built-in Elog|Built-in]]] (internal) Elog. To activate the external Elog you need to edit two ODB variables (which mhttpd automatically created):&lt;br /&gt;
&lt;br /&gt;
* the ODB string &amp;quot;/Elog/URL&amp;quot; needs to be set to the URL of the external ELOG.&lt;br /&gt;
* the ODB bool &amp;quot;/Elog/External Elog&amp;quot; needs to be set to &#039;y&#039;&lt;br /&gt;
&lt;br /&gt;
Note that after changing the ODB variable &#039;External Elog&#039; from &#039;n&#039; to &#039;y&#039; you will need to reload the elog page in order to get the external elog.&lt;br /&gt;
&lt;br /&gt;
Confirm proper operation of the external Elog by creating an entry. You will be prompted for a username and password. Click on New registration. Full control of these features are described in the Elog documentation.&lt;br /&gt;
Stop and restart the Elogd in the background.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt;/installation_elog_dir/elogd -c elogd.cfg -x -D&lt;br /&gt;
&lt;br /&gt;
= How to convert Built-in Elog files to External files =&lt;br /&gt;
In the event you had a previous entry under the internal elog, you can convert the internal to external using the elconv tool.&lt;br /&gt;
&lt;br /&gt;
   NodeB:~&amp;gt; cp internal/elog_logbook/*.log /myexpt/logbook/.&lt;br /&gt;
   NodeB:~&amp;gt; cd /myexpt/logbook&lt;br /&gt;
   NodeB:~&amp;gt; /installation_elog_dir/elconv&lt;br /&gt;
&lt;br /&gt;
= How to send entries to the Elog from a script =&lt;br /&gt;
Utilities exist to send elog entries automatically (e.g. from a script run at begin-of-run). Use [[Melog|melog]] to send an&lt;br /&gt;
entry to a Built-in elog, or [[Elog|elog]] to send an entry to an &#039;&#039;&#039;external&#039;&#039;&#039; elog.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
[[Category:ELOG]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Zaher&amp;diff=3320</id>
		<title>User talk:Zaher</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Zaher&amp;diff=3320"/>
		<updated>2023-08-17T22:24:24Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 15:24, 17 August 2023 (PDT)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=3179</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=3179"/>
		<updated>2023-02-17T23:04:25Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-develop/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket] Source code, bug tracking, etc&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum] Discussion, announcements, problem reports, requests for improvements&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
For news about bug fixes and new releases, go to the&lt;br /&gt;
[https://midas.triumf.ca/forum MIDAS forum] hosted by TRIUMF using&lt;br /&gt;
the [http://elog.psi.ch/elog ELOG] system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://elog.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=3000</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=3000"/>
		<updated>2020-07-30T16:56:35Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER,INDEX ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; flush privileges;&lt;br /&gt;
Query OK, 0 rows affected (0.001 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader -p ### should ask for reader password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for writer password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* test MIDAS connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mh2sql --mysql mysql_writer.txt&lt;br /&gt;
(there should be no errors printed)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* if desired, import midas history from .hst files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mh2sql --mysql mysql_writer.txt *.hst&lt;br /&gt;
Reading 130813.hst&lt;br /&gt;
[mh2sql,ERROR] [history_schema.cxx:1165:Mysql::Prepare,ERROR] mysql_query(SELECT event_name, table_name, itimestamp FROM _history_index WHERE table_name!=&#039;&#039;;) error 1146 (Table &#039;history._history_index&#039; doesn&#039;t exist)&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;rpcexample&amp;quot;, status 311&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;rpcexample_1596127680&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;_history_index&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;event_name&amp;quot; to SQL table &amp;quot;_history_index&amp;quot;, status 1&lt;br /&gt;
...&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;run_transitions&amp;quot;, status 311&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;state&amp;quot; to SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;run_number&amp;quot; to SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
Reading 130815.hst&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2999</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2999"/>
		<updated>2020-07-30T16:56:10Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER,INDEX ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; flush privileges;&lt;br /&gt;
Query OK, 0 rows affected (0.001 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader -p ### should ask for reader password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for writer password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* test MIDAS connection&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mh2sql --mysql mysql_writer.txt&lt;br /&gt;
(there should be no errors printed)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* if desired, import midas history from .hst files:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mh2sql --mysql mysql_writer.txt *.hst&lt;br /&gt;
Reading 130813.hst&lt;br /&gt;
[mh2sql,ERROR] [history_schema.cxx:1165:Mysql::Prepare,ERROR] mysql_query(SELECT event_name, table_name, itimestamp FROM _history_index WHERE table_name!=&#039;&#039;;) error 1146 (Table &#039;history._history_index&#039; doesn&#039;t exist)&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;rpcexample&amp;quot;, status 311&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;rpcexample_1596127680&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;_history_index&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;event_name&amp;quot; to SQL table &amp;quot;_history_index&amp;quot;, status 1&lt;br /&gt;
...&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;run_transitions&amp;quot;, status 311&lt;br /&gt;
[mh2sql,INFO] Adding SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;state&amp;quot; to SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
[mh2sql,INFO] Adding column &amp;quot;run_number&amp;quot; to SQL table &amp;quot;run_transitions_1596127681&amp;quot;, status 1&lt;br /&gt;
Reading 130815.hst&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/re&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2998</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2998"/>
		<updated>2020-07-30T16:47:53Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER,INDEX ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; flush privileges;&lt;br /&gt;
Query OK, 0 rows affected (0.001 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader -p ### should ask for reader password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for writer password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2997</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2997"/>
		<updated>2020-07-30T16:46:12Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER,INDEX ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader -p ### should ask for reader password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for writer password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2996</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2996"/>
		<updated>2020-07-30T16:43:10Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader -p ### should ask for reader password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for writer password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2995</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2995"/>
		<updated>2020-07-30T16:20:37Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use some other passwords instead of the example &amp;quot;reader_password&amp;quot; and &amp;quot;writer_password&amp;quot;&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_reader&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;reader_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader ### should connect without a password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2994</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2994"/>
		<updated>2020-07-30T16:16:29Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use your own password instead of &amp;quot;writer_password&amp;quot; in this example&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader ### should connect without a password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2993</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2993"/>
		<updated>2020-07-30T16:15:57Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use your own password instead of &amp;quot;writer_password&amp;quot; in this example&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader ### should connect without a password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=reader&lt;br /&gt;
password=reader_password ### change this!!!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* enable MYSQL history in mlogger:&lt;br /&gt;
** change ODB /Logger/History/MYSQL/Active to &amp;quot;y&amp;quot;, &amp;quot;mysql writer&amp;quot; and &amp;quot;mysql reader&amp;quot; to location of these files (leave the default values if these files are in the experiment directory).&lt;br /&gt;
* enable MYSQL history in mhttpd:&lt;br /&gt;
** change ODB /History/LoggerHistoryChannel to &amp;quot;MYSQL&amp;quot;&lt;br /&gt;
* restart mlogger, restart mhttpd&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2992</id>
		<title>Keys in the ODB /Logger/History subtree</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2992"/>
		<updated>2020-07-30T16:08:16Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MYSQL Reader */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
* [[/Logger ODB tree| /Logger tree]] &lt;br /&gt;
* [[/History ODB tree| /History tree]]&lt;br /&gt;
* [[History System]]&lt;br /&gt;
* [[Logging to a mySQL database]]&lt;br /&gt;
* [[Keys in the ODB /Logger/Channels subtree| /Logger/Channels subtree]] &lt;br /&gt;
* [[Keys in the ODB /Logger/SQL subtree| /Logger/SQL subtree]] &lt;br /&gt;
* [[mlogger |MIDAS logger (mlogger)]] &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt; subtree =&lt;br /&gt;
&lt;br /&gt;
The ODB &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt;  subtree is a subdirectory of the [[Keys in the ODB /Logger tree | ODB /Logger tree]], created&lt;br /&gt;
when the MIDAS logger utility [[mlogger]] is started for the first time. The keys will be filled with default values which users may change as required to customize their experiments. &lt;br /&gt;
&lt;br /&gt;
When [[mlogger]] is started for the first time, it now creates &#039;&#039;&#039;five&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt; /Logger/History/&amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt;&amp;lt;/span&amp;gt; ODB subtrees to control the five default history-logging-channels&#039;&#039;,  named for each of the default &lt;br /&gt;
[[History System#History drivers|History drivers]]. &lt;br /&gt;
&lt;br /&gt;
The keys present in each history-logging-channel are described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Example  =&lt;br /&gt;
The following example shows the &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History &amp;lt;/span&amp;gt;  ODB subtree after creation by [[mlogger]]  (obtained using the [[odbedit]] &#039;&#039;&#039;ls&#039;&#039;&#039; command).  &lt;br /&gt;
See below for information on individual keys. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:midas:S]/&amp;gt;ls -r /Logger/History&lt;br /&gt;
History&lt;br /&gt;
    MIDAS&lt;br /&gt;
        Type                    MIDAS&lt;br /&gt;
        Active                  y&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        PerVariableHistory      0&lt;br /&gt;
    ODBC&lt;br /&gt;
        Type                    ODBC&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Writer_ODBC_DSN         history_writer&lt;br /&gt;
        Reader_ODBC_DSN         history_reader&lt;br /&gt;
    SQLITE&lt;br /&gt;
        Type                    SQLITE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Sqlite dir&lt;br /&gt;
    MYSQL&lt;br /&gt;
        Type                    MYSQL&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        MYSQL Writer            mysql_writer.txt&lt;br /&gt;
        MYSQL Reader            mysql_reader.txt&lt;br /&gt;
    FILE&lt;br /&gt;
        Type                    FILE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        History dir&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;&amp;lt;history-logging-channel&amp;gt;&#039;&#039;&amp;lt;/span&amp;gt; subtrees =&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt; subtree in the [[#top|Logger/History subtree]]&lt;br /&gt;
is created  (by [[mlogger]]) to control one of the [[History System#History drivers|history drivers]] available, and named for that history driver.&lt;br /&gt;
&amp;lt;br&amp;gt;Presently the five following history-logging-channel subtrees are created :&lt;br /&gt;
* MIDAS&lt;br /&gt;
* ODBC&lt;br /&gt;
* SQLITE&lt;br /&gt;
* MYSQL&lt;br /&gt;
* FILE&lt;br /&gt;
(see [[#Example|Example]] above).&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel is [[#active|Active]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: In older MIDAS versions, the history-logging-channel subtrees were named 0,1,2... respectively&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Keys common to all history logging channel subtrees ==&lt;br /&gt;
The following three keys are common to all [[#&amp;lt;history-logging-channel&amp;gt; subtrees|history logging channel subtrees]] :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt;===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  [[History System#History drivers|History driver]] name&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key which specifies the type of &lt;br /&gt;
[[History System#History drivers|History driver]] for this channel.&lt;br /&gt;
&lt;br /&gt;
When the subtree is created, the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key is set to the respective History driver name, e.g. &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;MIDAS&amp;quot;&#039;&#039;&#039; &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;ODBC&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;ODBC&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
and so on (see [[#Example|Example]] above for all five logging channels).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; BOOL&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;n&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which enables or disables history logging in this channel.&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel will be set active, i.e. ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Active&amp;lt;/span&amp;gt; will be set to &amp;quot;y&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
;Note&lt;br /&gt;
: This key in the [[#MIDAS subtree|MIDAS subtree]]  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/WriteFileHistory|/Logger/WriteFileHistory]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which controls the debug level for this channel. If set to 0, debugging is disabled.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:This key in the [[#ODBC subtree|ODBC subtree]]   replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls   [[History System#History drivers|MIDAS-history]] logging.&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: By default, this logging channel will be set active.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;PerVariableHistory&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MIDAS subtree|MIDAS subtree]] (whose [[#Type|Type]] key set to &amp;quot;MIDAS&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The default value of 0 is intended to operate the MIDAS-history in &amp;quot;traditional&amp;quot; mode. In this mode:&lt;br /&gt;
* there is one history record for each equipment&lt;br /&gt;
* history record id is equal to the equipment id&lt;br /&gt;
* Subtrees &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Events&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; are not required and can be safely deleted&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/PerVariableHistory&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;ODBC&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|ODBC-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:[[#Debug|Debug]] key in this subtree  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the ODBC subtree:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Writer_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_writer&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the  [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for writing and is used by [[mlogger]].&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC DSN |/Logger/ODBC DSN]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Reader_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_reader&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for reading, and is used by [[mhttpd]] and [[mhist]] utilities.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/history/ODB_DSN&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;SQLITE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|SQLITE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the SQLITE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Sqlite dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#SQLITE subtree|SQLITE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;SQLITE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the location of SQLITE database files, and is of the form &amp;quot;/file/system/path&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|MYSQL-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the MYSQL subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Writer&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_writer.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history writer account. This file should look similar to the following: see [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Reader&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_reader.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose  [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history reader account. This file should look similar to the following: see [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;FILE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|FILE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the FILE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;History dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#FILE subtree|FILE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;FILE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the directory in which the FILE-history files are to be stored.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Logger Tree]] [[Category:History]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2991</id>
		<title>Keys in the ODB /Logger/History subtree</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2991"/>
		<updated>2020-07-30T16:07:50Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MYSQL Reader */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
* [[/Logger ODB tree| /Logger tree]] &lt;br /&gt;
* [[/History ODB tree| /History tree]]&lt;br /&gt;
* [[History System]]&lt;br /&gt;
* [[Logging to a mySQL database]]&lt;br /&gt;
* [[Keys in the ODB /Logger/Channels subtree| /Logger/Channels subtree]] &lt;br /&gt;
* [[Keys in the ODB /Logger/SQL subtree| /Logger/SQL subtree]] &lt;br /&gt;
* [[mlogger |MIDAS logger (mlogger)]] &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt; subtree =&lt;br /&gt;
&lt;br /&gt;
The ODB &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt;  subtree is a subdirectory of the [[Keys in the ODB /Logger tree | ODB /Logger tree]], created&lt;br /&gt;
when the MIDAS logger utility [[mlogger]] is started for the first time. The keys will be filled with default values which users may change as required to customize their experiments. &lt;br /&gt;
&lt;br /&gt;
When [[mlogger]] is started for the first time, it now creates &#039;&#039;&#039;five&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt; /Logger/History/&amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt;&amp;lt;/span&amp;gt; ODB subtrees to control the five default history-logging-channels&#039;&#039;,  named for each of the default &lt;br /&gt;
[[History System#History drivers|History drivers]]. &lt;br /&gt;
&lt;br /&gt;
The keys present in each history-logging-channel are described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Example  =&lt;br /&gt;
The following example shows the &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History &amp;lt;/span&amp;gt;  ODB subtree after creation by [[mlogger]]  (obtained using the [[odbedit]] &#039;&#039;&#039;ls&#039;&#039;&#039; command).  &lt;br /&gt;
See below for information on individual keys. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:midas:S]/&amp;gt;ls -r /Logger/History&lt;br /&gt;
History&lt;br /&gt;
    MIDAS&lt;br /&gt;
        Type                    MIDAS&lt;br /&gt;
        Active                  y&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        PerVariableHistory      0&lt;br /&gt;
    ODBC&lt;br /&gt;
        Type                    ODBC&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Writer_ODBC_DSN         history_writer&lt;br /&gt;
        Reader_ODBC_DSN         history_reader&lt;br /&gt;
    SQLITE&lt;br /&gt;
        Type                    SQLITE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Sqlite dir&lt;br /&gt;
    MYSQL&lt;br /&gt;
        Type                    MYSQL&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        MYSQL Writer            mysql_writer.txt&lt;br /&gt;
        MYSQL Reader            mysql_reader.txt&lt;br /&gt;
    FILE&lt;br /&gt;
        Type                    FILE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        History dir&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;&amp;lt;history-logging-channel&amp;gt;&#039;&#039;&amp;lt;/span&amp;gt; subtrees =&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt; subtree in the [[#top|Logger/History subtree]]&lt;br /&gt;
is created  (by [[mlogger]]) to control one of the [[History System#History drivers|history drivers]] available, and named for that history driver.&lt;br /&gt;
&amp;lt;br&amp;gt;Presently the five following history-logging-channel subtrees are created :&lt;br /&gt;
* MIDAS&lt;br /&gt;
* ODBC&lt;br /&gt;
* SQLITE&lt;br /&gt;
* MYSQL&lt;br /&gt;
* FILE&lt;br /&gt;
(see [[#Example|Example]] above).&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel is [[#active|Active]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: In older MIDAS versions, the history-logging-channel subtrees were named 0,1,2... respectively&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Keys common to all history logging channel subtrees ==&lt;br /&gt;
The following three keys are common to all [[#&amp;lt;history-logging-channel&amp;gt; subtrees|history logging channel subtrees]] :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt;===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  [[History System#History drivers|History driver]] name&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key which specifies the type of &lt;br /&gt;
[[History System#History drivers|History driver]] for this channel.&lt;br /&gt;
&lt;br /&gt;
When the subtree is created, the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key is set to the respective History driver name, e.g. &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;MIDAS&amp;quot;&#039;&#039;&#039; &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;ODBC&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;ODBC&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
and so on (see [[#Example|Example]] above for all five logging channels).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; BOOL&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;n&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which enables or disables history logging in this channel.&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel will be set active, i.e. ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Active&amp;lt;/span&amp;gt; will be set to &amp;quot;y&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
;Note&lt;br /&gt;
: This key in the [[#MIDAS subtree|MIDAS subtree]]  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/WriteFileHistory|/Logger/WriteFileHistory]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which controls the debug level for this channel. If set to 0, debugging is disabled.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:This key in the [[#ODBC subtree|ODBC subtree]]   replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls   [[History System#History drivers|MIDAS-history]] logging.&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: By default, this logging channel will be set active.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;PerVariableHistory&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MIDAS subtree|MIDAS subtree]] (whose [[#Type|Type]] key set to &amp;quot;MIDAS&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The default value of 0 is intended to operate the MIDAS-history in &amp;quot;traditional&amp;quot; mode. In this mode:&lt;br /&gt;
* there is one history record for each equipment&lt;br /&gt;
* history record id is equal to the equipment id&lt;br /&gt;
* Subtrees &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Events&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; are not required and can be safely deleted&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/PerVariableHistory&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;ODBC&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|ODBC-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:[[#Debug|Debug]] key in this subtree  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the ODBC subtree:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Writer_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_writer&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the  [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for writing and is used by [[mlogger]].&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC DSN |/Logger/ODBC DSN]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Reader_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_reader&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for reading, and is used by [[mhttpd]] and [[mhist]] utilities.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/history/ODB_DSN&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;SQLITE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|SQLITE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the SQLITE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Sqlite dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#SQLITE subtree|SQLITE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;SQLITE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the location of SQLITE database files, and is of the form &amp;quot;/file/system/path&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|MYSQL-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the MYSQL subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Writer&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_writer.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history writer account. This file should look similar to the following: see [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Reader&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_reader.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose  [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history reader account. This file should look similar to the following: [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;FILE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|FILE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the FILE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;History dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#FILE subtree|FILE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;FILE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the directory in which the FILE-history files are to be stored.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Logger Tree]] [[Category:History]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2990</id>
		<title>Keys in the ODB /Logger/History subtree</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2990"/>
		<updated>2020-07-30T16:07:25Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MYSQL Writer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
* [[/Logger ODB tree| /Logger tree]] &lt;br /&gt;
* [[/History ODB tree| /History tree]]&lt;br /&gt;
* [[History System]]&lt;br /&gt;
* [[Logging to a mySQL database]]&lt;br /&gt;
* [[Keys in the ODB /Logger/Channels subtree| /Logger/Channels subtree]] &lt;br /&gt;
* [[Keys in the ODB /Logger/SQL subtree| /Logger/SQL subtree]] &lt;br /&gt;
* [[mlogger |MIDAS logger (mlogger)]] &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt; subtree =&lt;br /&gt;
&lt;br /&gt;
The ODB &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt;  subtree is a subdirectory of the [[Keys in the ODB /Logger tree | ODB /Logger tree]], created&lt;br /&gt;
when the MIDAS logger utility [[mlogger]] is started for the first time. The keys will be filled with default values which users may change as required to customize their experiments. &lt;br /&gt;
&lt;br /&gt;
When [[mlogger]] is started for the first time, it now creates &#039;&#039;&#039;five&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt; /Logger/History/&amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt;&amp;lt;/span&amp;gt; ODB subtrees to control the five default history-logging-channels&#039;&#039;,  named for each of the default &lt;br /&gt;
[[History System#History drivers|History drivers]]. &lt;br /&gt;
&lt;br /&gt;
The keys present in each history-logging-channel are described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Example  =&lt;br /&gt;
The following example shows the &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History &amp;lt;/span&amp;gt;  ODB subtree after creation by [[mlogger]]  (obtained using the [[odbedit]] &#039;&#039;&#039;ls&#039;&#039;&#039; command).  &lt;br /&gt;
See below for information on individual keys. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:midas:S]/&amp;gt;ls -r /Logger/History&lt;br /&gt;
History&lt;br /&gt;
    MIDAS&lt;br /&gt;
        Type                    MIDAS&lt;br /&gt;
        Active                  y&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        PerVariableHistory      0&lt;br /&gt;
    ODBC&lt;br /&gt;
        Type                    ODBC&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Writer_ODBC_DSN         history_writer&lt;br /&gt;
        Reader_ODBC_DSN         history_reader&lt;br /&gt;
    SQLITE&lt;br /&gt;
        Type                    SQLITE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Sqlite dir&lt;br /&gt;
    MYSQL&lt;br /&gt;
        Type                    MYSQL&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        MYSQL Writer            mysql_writer.txt&lt;br /&gt;
        MYSQL Reader            mysql_reader.txt&lt;br /&gt;
    FILE&lt;br /&gt;
        Type                    FILE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        History dir&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;&amp;lt;history-logging-channel&amp;gt;&#039;&#039;&amp;lt;/span&amp;gt; subtrees =&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt; subtree in the [[#top|Logger/History subtree]]&lt;br /&gt;
is created  (by [[mlogger]]) to control one of the [[History System#History drivers|history drivers]] available, and named for that history driver.&lt;br /&gt;
&amp;lt;br&amp;gt;Presently the five following history-logging-channel subtrees are created :&lt;br /&gt;
* MIDAS&lt;br /&gt;
* ODBC&lt;br /&gt;
* SQLITE&lt;br /&gt;
* MYSQL&lt;br /&gt;
* FILE&lt;br /&gt;
(see [[#Example|Example]] above).&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel is [[#active|Active]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: In older MIDAS versions, the history-logging-channel subtrees were named 0,1,2... respectively&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Keys common to all history logging channel subtrees ==&lt;br /&gt;
The following three keys are common to all [[#&amp;lt;history-logging-channel&amp;gt; subtrees|history logging channel subtrees]] :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt;===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  [[History System#History drivers|History driver]] name&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key which specifies the type of &lt;br /&gt;
[[History System#History drivers|History driver]] for this channel.&lt;br /&gt;
&lt;br /&gt;
When the subtree is created, the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key is set to the respective History driver name, e.g. &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;MIDAS&amp;quot;&#039;&#039;&#039; &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;ODBC&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;ODBC&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
and so on (see [[#Example|Example]] above for all five logging channels).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; BOOL&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;n&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which enables or disables history logging in this channel.&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel will be set active, i.e. ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Active&amp;lt;/span&amp;gt; will be set to &amp;quot;y&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
;Note&lt;br /&gt;
: This key in the [[#MIDAS subtree|MIDAS subtree]]  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/WriteFileHistory|/Logger/WriteFileHistory]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which controls the debug level for this channel. If set to 0, debugging is disabled.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:This key in the [[#ODBC subtree|ODBC subtree]]   replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls   [[History System#History drivers|MIDAS-history]] logging.&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: By default, this logging channel will be set active.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;PerVariableHistory&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MIDAS subtree|MIDAS subtree]] (whose [[#Type|Type]] key set to &amp;quot;MIDAS&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The default value of 0 is intended to operate the MIDAS-history in &amp;quot;traditional&amp;quot; mode. In this mode:&lt;br /&gt;
* there is one history record for each equipment&lt;br /&gt;
* history record id is equal to the equipment id&lt;br /&gt;
* Subtrees &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Events&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; are not required and can be safely deleted&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/PerVariableHistory&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;ODBC&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|ODBC-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:[[#Debug|Debug]] key in this subtree  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the ODBC subtree:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Writer_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_writer&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the  [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for writing and is used by [[mlogger]].&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC DSN |/Logger/ODBC DSN]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Reader_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_reader&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for reading, and is used by [[mhttpd]] and [[mhist]] utilities.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/history/ODB_DSN&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;SQLITE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|SQLITE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the SQLITE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Sqlite dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#SQLITE subtree|SQLITE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;SQLITE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the location of SQLITE database files, and is of the form &amp;quot;/file/system/path&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|MYSQL-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the MYSQL subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Writer&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_writer.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history writer account. This file should look similar to the following: see [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Reader&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_reader.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose  [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history reader account. This file should look similar to the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server=localhost&lt;br /&gt;
port=3306&lt;br /&gt;
database=history&lt;br /&gt;
socket=/var/lib/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=[password of mysql user]&lt;br /&gt;
buffer=10000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;FILE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|FILE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the FILE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;History dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#FILE subtree|FILE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;FILE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the directory in which the FILE-history files are to be stored.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Logger Tree]] [[Category:History]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2989</id>
		<title>Keys in the ODB /Logger/History subtree</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Keys_in_the_ODB_/Logger/History_subtree&amp;diff=2989"/>
		<updated>2020-07-30T16:07:04Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MYSQL Writer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
* [[/Logger ODB tree| /Logger tree]] &lt;br /&gt;
* [[/History ODB tree| /History tree]]&lt;br /&gt;
* [[History System]]&lt;br /&gt;
* [[Logging to a mySQL database]]&lt;br /&gt;
* [[Keys in the ODB /Logger/Channels subtree| /Logger/Channels subtree]] &lt;br /&gt;
* [[Keys in the ODB /Logger/SQL subtree| /Logger/SQL subtree]] &lt;br /&gt;
* [[mlogger |MIDAS logger (mlogger)]] &lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=&amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt; subtree =&lt;br /&gt;
&lt;br /&gt;
The ODB &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;/Logger/History&#039;&#039;&amp;lt;/span&amp;gt;  subtree is a subdirectory of the [[Keys in the ODB /Logger tree | ODB /Logger tree]], created&lt;br /&gt;
when the MIDAS logger utility [[mlogger]] is started for the first time. The keys will be filled with default values which users may change as required to customize their experiments. &lt;br /&gt;
&lt;br /&gt;
When [[mlogger]] is started for the first time, it now creates &#039;&#039;&#039;five&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt; /Logger/History/&amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt;&amp;lt;/span&amp;gt; ODB subtrees to control the five default history-logging-channels&#039;&#039;,  named for each of the default &lt;br /&gt;
[[History System#History drivers|History drivers]]. &lt;br /&gt;
&lt;br /&gt;
The keys present in each history-logging-channel are described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Example  =&lt;br /&gt;
The following example shows the &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History &amp;lt;/span&amp;gt;  ODB subtree after creation by [[mlogger]]  (obtained using the [[odbedit]] &#039;&#039;&#039;ls&#039;&#039;&#039; command).  &lt;br /&gt;
See below for information on individual keys. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[local:midas:S]/&amp;gt;ls -r /Logger/History&lt;br /&gt;
History&lt;br /&gt;
    MIDAS&lt;br /&gt;
        Type                    MIDAS&lt;br /&gt;
        Active                  y&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        PerVariableHistory      0&lt;br /&gt;
    ODBC&lt;br /&gt;
        Type                    ODBC&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Writer_ODBC_DSN         history_writer&lt;br /&gt;
        Reader_ODBC_DSN         history_reader&lt;br /&gt;
    SQLITE&lt;br /&gt;
        Type                    SQLITE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        Sqlite dir&lt;br /&gt;
    MYSQL&lt;br /&gt;
        Type                    MYSQL&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        MYSQL Writer            mysql_writer.txt&lt;br /&gt;
        MYSQL Reader            mysql_reader.txt&lt;br /&gt;
    FILE&lt;br /&gt;
        Type                    FILE&lt;br /&gt;
        Active                  n&lt;br /&gt;
        Debug                   0&lt;br /&gt;
        History dir&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;&amp;lt;history-logging-channel&amp;gt;&#039;&#039;&amp;lt;/span&amp;gt; subtrees =&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;&#039;&#039;history-logging-channel&#039;&#039;&amp;gt; subtree in the [[#top|Logger/History subtree]]&lt;br /&gt;
is created  (by [[mlogger]]) to control one of the [[History System#History drivers|history drivers]] available, and named for that history driver.&lt;br /&gt;
&amp;lt;br&amp;gt;Presently the five following history-logging-channel subtrees are created :&lt;br /&gt;
* MIDAS&lt;br /&gt;
* ODBC&lt;br /&gt;
* SQLITE&lt;br /&gt;
* MYSQL&lt;br /&gt;
* FILE&lt;br /&gt;
(see [[#Example|Example]] above).&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel is [[#active|Active]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: In older MIDAS versions, the history-logging-channel subtrees were named 0,1,2... respectively&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Keys common to all history logging channel subtrees ==&lt;br /&gt;
The following three keys are common to all [[#&amp;lt;history-logging-channel&amp;gt; subtrees|history logging channel subtrees]] :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt;===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  [[History System#History drivers|History driver]] name&lt;br /&gt;
&amp;lt;/div&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key which specifies the type of &lt;br /&gt;
[[History System#History drivers|History driver]] for this channel.&lt;br /&gt;
&lt;br /&gt;
When the subtree is created, the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Type&#039;&#039;&amp;lt;/span&amp;gt; key is set to the respective History driver name, e.g. &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;MIDAS&amp;quot;&#039;&#039;&#039; &lt;br /&gt;
: ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;ODBC&#039;&#039;&#039;/Type&amp;lt;/span&amp;gt; will be set to &#039;&#039;&#039;&amp;quot;ODBC&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
 &lt;br /&gt;
and so on (see [[#Example|Example]] above for all five logging channels).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; BOOL&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;n&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Active&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which enables or disables history logging in this channel.&lt;br /&gt;
&lt;br /&gt;
By default, only the MIDAS-history logging channel will be set active, i.e. ODB key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/Logger/History/&#039;&#039;&#039;MIDAS&#039;&#039;&#039;/Active&amp;lt;/span&amp;gt; will be set to &amp;quot;y&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
;Note&lt;br /&gt;
: This key in the [[#MIDAS subtree|MIDAS subtree]]  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/WriteFileHistory|/Logger/WriteFileHistory]] &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
Each [[#&amp;lt;history-logging-channel&amp;gt; subtrees |history-logging-channel subtree]] contains a  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Debug&#039;&#039;&amp;lt;/span&amp;gt; key&lt;br /&gt;
which controls the debug level for this channel. If set to 0, debugging is disabled.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:This key in the [[#ODBC subtree|ODBC subtree]]   replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]] &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls   [[History System#History drivers|MIDAS-history]] logging.&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: By default, this logging channel will be set active.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MIDAS&#039;&#039;&amp;lt;/span&amp;gt; subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;PerVariableHistory&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; INT&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  0&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MIDAS subtree|MIDAS subtree]] (whose [[#Type|Type]] key set to &amp;quot;MIDAS&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
The default value of 0 is intended to operate the MIDAS-history in &amp;quot;traditional&amp;quot; mode. In this mode:&lt;br /&gt;
* there is one history record for each equipment&lt;br /&gt;
* history record id is equal to the equipment id&lt;br /&gt;
* Subtrees &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Events&amp;lt;/span&amp;gt; and &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; are not required and can be safely deleted&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/History/PerVariableHistory&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;ODBC&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|ODBC-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
:[[#Debug|Debug]] key in this subtree  replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC_Debug |/Logger/ODBC_Debug]]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the ODBC subtree:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Writer_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_writer&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the  [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for writing and is used by [[mlogger]].&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key [[Keys in the ODB /Logger tree #/Logger/ODBC DSN |/Logger/ODBC DSN]] &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Reader_ODBC_DSN&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;history_reader&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#ODBC subtree|ODBC]] subtree  (whose [[#Type|Type]] key is set to &amp;quot;ODBC&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the ODBC Data Source Name for reading, and is used by [[mhttpd]] and [[mhist]] utilities.&lt;br /&gt;
&lt;br /&gt;
;Note&lt;br /&gt;
: this key replaces obsolete key  &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;/history/ODB_DSN&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;SQLITE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|SQLITE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the SQLITE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;Sqlite dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#SQLITE subtree|SQLITE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;SQLITE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the location of SQLITE database files, and is of the form &amp;quot;/file/system/path&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|MYSQL-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the MYSQL subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Writer&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_writer.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history writer account. This file should look similar to the following: see [[History_System#Write_MYSQL-history_events]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server=localhost&lt;br /&gt;
port=3306&lt;br /&gt;
database=history&lt;br /&gt;
socket=/var/lib/mysql/mysql.sock&lt;br /&gt;
user=history_writer&lt;br /&gt;
password=[password of mysql user]&lt;br /&gt;
buffer=10000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;MYSQL Reader&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  mysql_reader.txt&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#MYSQL subtree|MYSQL subtree]]  (whose  [[#Type|Type]] key is set to &amp;quot;MYSQL&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the config file for the MYSQL database and the history reader account. This file should look similar to the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server=localhost&lt;br /&gt;
port=3306&lt;br /&gt;
database=history&lt;br /&gt;
socket=/var/lib/mysql/mysql.sock&lt;br /&gt;
user=history_reader&lt;br /&gt;
password=[password of mysql user]&lt;br /&gt;
buffer=10000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;FILE&#039;&#039;&amp;lt;/span&amp;gt; subtree ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This is the  [[#&amp;lt;history-logging-channel&amp;gt; subtrees| history-logging-channel subtree]]  that  controls  [[History System#History drivers|FILE-history]] logging.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For those Keys common to all history-logging-channels see&lt;br /&gt;
*[[#Type|Type]]&lt;br /&gt;
*[[#Active|Active]]&lt;br /&gt;
*[[#Debug|Debug]]&lt;br /&gt;
&lt;br /&gt;
The following section(s) describe keys unique to the FILE subtree :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;span style=&amp;quot;color: purple;&amp;quot;&amp;gt;&#039;&#039;History dir&#039;&#039;&amp;lt;/span&amp;gt; ===&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;
* &#039;&#039;&#039;Type:&#039;&#039;&#039; STRING&lt;br /&gt;
* &#039;&#039;&#039;Default:&#039;&#039;&#039;  &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/div&amp;gt;	&lt;br /&gt;
&lt;br /&gt;
This key is present in the [[#FILE subtree|FILE subtree]]  (whose [[#Type|Type]] key is set to &amp;quot;FILE&amp;quot;).&lt;br /&gt;
&lt;br /&gt;
It contains the name of the directory in which the FILE-history files are to be stored.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
--------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Logger Tree]] [[Category:History]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2988</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2988"/>
		<updated>2020-07-30T16:05:51Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: /opt/local/lib/mariadb-10.4/bin/mysqld&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use your own password instead of &amp;quot;writer_password&amp;quot; in this example&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader ### should connect without a password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=reader&lt;br /&gt;
#password=reader&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2987</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2987"/>
		<updated>2020-07-30T16:04:45Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
* setup the MySQL database:&lt;br /&gt;
* install mariadb-10.4&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos:&lt;br /&gt;
sudo port install mariadb-10.4&lt;br /&gt;
ln -s ln -fs /opt/local/lib/mariadb-10.4/bin/mysql_config ~/bin/&lt;br /&gt;
mysql_config --version&lt;br /&gt;
10.4.13&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* rebuild midas, check the cmake finds the correct mysql: MIDAS: Found MySQL version 10.4.13&lt;br /&gt;
* create $HOME/.my.cnf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
datadir=/Users/olchansk/mysql/db&lt;br /&gt;
pid-file=/Users/olchansk/mysql/mysqld.pid&lt;br /&gt;
&lt;br /&gt;
[client]&lt;br /&gt;
#port=3306&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* mkdir $HOME/mysql&lt;br /&gt;
* start mysql:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
macos: d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* configure the database: start the &amp;quot;mysql&amp;quot; utility (/opt/local/lib/mariadb-10.4/bin/mysql)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
NOTE: instructions thanks to Ben S.&lt;br /&gt;
NOTE: use your own password instead of &amp;quot;writer_password&amp;quot; in this example&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE DATABASE IF NOT EXISTS history;&lt;br /&gt;
Query OK, 1 row affected (0.003 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.027 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT ON history.* TO history_reader;&lt;br /&gt;
Query OK, 0 rows affected (0.016 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; CREATE USER &#039;history_writer&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;writer_password&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.014 sec)&lt;br /&gt;
&lt;br /&gt;
MariaDB [(none)]&amp;gt; GRANT SELECT,INSERT,CREATE,ALTER ON history.* TO &#039;history_writer&#039;@&#039;localhost&#039;;&lt;br /&gt;
Query OK, 0 rows affected (0.017 sec)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* try connecting to both users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_reader ### should connect without a password&lt;br /&gt;
/opt/local/lib/mariadb-10.4/bin/mysql -u history_writer -p ### should ask for password&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* create midas config files:&lt;br /&gt;
** mysql_writer.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=writer&lt;br /&gt;
password=writer_password ### change this!!!&lt;br /&gt;
#buffer=1000&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
** mysql_reader.txt&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#server=localhost&lt;br /&gt;
#port=xxx&lt;br /&gt;
database=history&lt;br /&gt;
socket=/Users/olchansk/mysql/mysql.sock&lt;br /&gt;
user=reader&lt;br /&gt;
#password=reader&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2986</id>
		<title>History System</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=History_System&amp;diff=2986"/>
		<updated>2020-07-30T15:45:52Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Write  MYSQL-history events */&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;
* [[/History ODB tree]]&lt;br /&gt;
* [[History Page]]&lt;br /&gt;
* [[Mhformat|MIDAS history file format]] &lt;br /&gt;
* [[Keys in the ODB /Logger tree|/Logger ODB tree]]&lt;br /&gt;
* [[Keys in the ODB /Logger/History subtree|/Logger/History subtree]]&lt;br /&gt;
* [[Image History]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;history file&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
The history system is an add-on capability built into the MIDAS data logger [[mlogger]] to record useful information in parallel to the data logging.&lt;br /&gt;
This information is recorded with a time stamp and saved into a &#039;&#039;&#039;history file&#039;&#039;&#039;  (see [[#History drivers|History drivers]]) for later retrieval. One set of files is created per day containing all the requested history events. The history data may be displayed in graphical form using the [[mhttpd]] MIDAS webserver utility, giving the user an easy way of seeing how experimental variables have changed with time.&lt;br /&gt;
The history logging will be in action only if the MIDAS data logger is running, but it is not necessary to have any [[Keys in the ODB /Logger tree#/Logger/Channels subtree|data logging channel]] enabled.&lt;br /&gt;
&lt;br /&gt;
Since June 2020, it is possible to also use the midas history system to record images (png/jpeg etc) periodically, for example to later produce a timelapse from a webcam - see the [[Image History]] page for more details.&lt;br /&gt;
&lt;br /&gt;
= MidasHistoryInterface =&lt;br /&gt;
&lt;br /&gt;
The new history configuration defines history channels similar to logger channels. Each history channel creates a history interface class (class MidasHistoryInterface). The [[mlogger|data logger]] can use this interface to write data into the history, mhttpd, mhist &amp;amp; co can use this interface to read data from the history. The interface is defined in history.h&lt;br /&gt;
&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas/include/history.h&lt;br /&gt;
&lt;br /&gt;
= History drivers =&lt;br /&gt;
&lt;br /&gt;
Presently, the MIDAS distribution contains these drivers:&lt;br /&gt;
&lt;br /&gt;
; MIDAS-History &lt;br /&gt;
: this is the traditional history driver, with data stored in the .hst binary files. (format is documented here [[mhformat]], see also [[mhist]] and [[mhdump]])&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MIDAS subtree |&amp;quot;MIDAS&amp;quot;]]&#039;&#039;&#039; is set up to write MIDAS-history. &lt;br /&gt;
&lt;br /&gt;
; ODBC-History  &lt;br /&gt;
: stores history data in SQL database using the ODBC abstraction layer. See [[#MIDAS ODBC SQL History system|ODBC SQL History system]].&lt;br /&gt;
&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#ODBC subtree|&amp;quot;ODBC&amp;quot;]]&#039;&#039;&#039; is set up to write ODBC-history.&lt;br /&gt;
&lt;br /&gt;
; SQLITE-History &lt;br /&gt;
: stores data in SQL database as SQLITE3 .sqlite3 files. The SQL table format is similar to ODBC-history, performance is similar, no database server required.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#SQLITE subtree|&amp;quot;SQLITE&amp;quot;]]&#039;&#039;&#039; is set up to write SQLITE-history.&lt;br /&gt;
&lt;br /&gt;
; MYSQL-History&lt;br /&gt;
:&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#MYSQL subtree|&amp;quot;MYSQL&amp;quot;]]&#039;&#039;&#039; is set up to write MYSQL-history.&lt;br /&gt;
&lt;br /&gt;
; FILE-History&lt;br /&gt;
: stores each variable in its own file, making it much easier to trace the history of a particular variable.&lt;br /&gt;
: By default ODB subtree &#039;&#039;&#039;[[Keys in the ODB /Logger/History subtree#FILE subtree|FILE]]&#039;&#039;&#039; is set up to write FILE-history.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
More drivers can be easily added by the user (create history_xxx.cxx, add constructor to hs_get_history(), create the ODB subtree  &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/Logger/History/xxx/channel&amp;lt;/span&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Location of History Files =&lt;br /&gt;
;MIDAS-history &lt;br /&gt;
:By default, the traditional MIDAS-history is enabled, writing history files into the MIDAS data directory path given by the ODB key [[Keys in the ODB /Logger tree#Data dir|Data dir]].&lt;br /&gt;
:If history data is important, it is recommended to write it to a directory that is backed up or archived. (The MIDAS data directory is usually located on a scratch data disk without backups).&lt;br /&gt;
 &lt;br /&gt;
:The location of the MIDAS-history data files can be changed by use of the ODB Key [[Keys in the ODB /Logger tree#History dir|History dir]]. &lt;br /&gt;
&lt;br /&gt;
;ODBC-History&lt;br /&gt;
:The location of ODBC-History files is ...&lt;br /&gt;
&lt;br /&gt;
;SQLITE-History &lt;br /&gt;
:The location of SQLITE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]].&lt;br /&gt;
&lt;br /&gt;
;MYSQL-History&lt;br /&gt;
:The location of MYSQL-History files is ...&lt;br /&gt;
&lt;br /&gt;
;FILE-History&lt;br /&gt;
:The location of FILE-History files is the directory path given by the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Types of History Events =&lt;br /&gt;
&lt;br /&gt;
There are two basic types of history events, which are defined in different ways:&lt;br /&gt;
&lt;br /&gt;
*    &amp;quot;[[#Frontend History Event|Frontend]]&amp;quot; (or &amp;quot;Equipment&amp;quot;) History event composed in the frontend. See [[#Frontend History Event|Frontend History Event]] for details.&lt;br /&gt;
*    &amp;quot;Virtual&amp;quot; (or &amp;quot;Links&amp;quot;) History event composed within the ODB under the  [[/History ODB tree#Links subtree|/History/Links subtree]]. See [[#Virtual History Event|Virtual History Event]] for details.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Both these history event definitions take effect when the data logger gets a start run [[Run States and Transitions|transition]]. Any modifications made during the run are not applied until the start of the next run.&lt;br /&gt;
&lt;br /&gt;
== Virtual History Event ==&lt;br /&gt;
The history of any ODB variable can be recorded in a &amp;quot;virtual&amp;quot; history event by creating a link to that variable in the [[/History ODB tree#Links subtree|/History/Links subtree]]. This is used for ODB variables that are not in an Equipment.&lt;br /&gt;
&lt;br /&gt;
; To enable Virtual History Events&lt;br /&gt;
: Create links as desired in [[/History ODB tree#Links subtree|/History/Links subtree]].&lt;br /&gt;
&lt;br /&gt;
History events are created for each entry under ODB subdirectory {{Odbpath|path=/History/Links}}.  &lt;br /&gt;
&lt;br /&gt;
Two types of links are permitted:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; ODB key {{Odbpath|path=/history/links/aaa}} is a link to a subdirectory&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt;&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; db_watch() is setup to watch this subdirectory&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each subdirectory entry (1 tag per entry)&amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;li&amp;gt; There is no possibility for naming array elements, so 1 tag per array, regardless of the number of elements.&amp;lt;/li&amp;gt; &amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt;ODB key {{Odbpath|path=/history/links/bbb}}  is a subdirectory with links to ODB values&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; &amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;db_watch is setup to watch each link target&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tags are created for each link (1 tag per link)&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; tag name is the link name (NOT the target name). There is no possibility for naming array elements&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mixing links and subdirectories is not permitted.&lt;br /&gt;
&lt;br /&gt;
The update period of history events created for {{Odbpath|path=/history/links}} is controlled by entries in  {{Odbpath|path=/history/links periods}}. Numeric values of periods are same as for a [[#Frontend History Event|Frontend History event]]. Numeric value 0 disables the history for a particular event.&lt;br /&gt;
&lt;br /&gt;
See [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087] for more information. &lt;br /&gt;
&lt;br /&gt;
== Frontend History Event ==&lt;br /&gt;
&lt;br /&gt;
Each  [[Frontend Operation#Equipments and Events|Equipment]] has the capability to generate &amp;quot;history data&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
; To enable Frontend History Events &lt;br /&gt;
&lt;br /&gt;
: Set the [[/Equipment ODB tree#Log history|Log history]] ODB key of each equipment to be logged &#039;&#039;&#039;non-zero&#039;&#039;&#039;. (See [[Equipment List Parameters#Log History|Log History parameter]]). (You may need to restart the frontend.)&lt;br /&gt;
&lt;br /&gt;
This causes the event contents to be copied to the  ODB [[/Equipment ODB tree#Variables subtree|/Equipment/&#039;&#039;&amp;lt;equipment-name&amp;gt;&#039;&#039;/Variables subtree]] for the use of the History system. history events are created by parsing the content of  {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/variables}}.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For each equipment, history is controlled by the value of {{Odbpath|path=/Equipment/&amp;lt;equipment-name&amp;gt;/common/period}} as follows:&lt;br /&gt;
* 0 = history disabled&lt;br /&gt;
* 1 = history is enabled&lt;br /&gt;
* &amp;gt;1 = history is enabled, throttled down&lt;br /&gt;
&lt;br /&gt;
The throttling is implemented in log_history()/watch_history() by this algorithm:&lt;br /&gt;
the very first history event is recorded, then all changed to the data are ignored until &amp;quot;period&amp;quot; seconds has elapsed. Then the next history event will be recorded, and following&lt;br /&gt;
changes will be ignored until &amp;quot;period&amp;quot; second elapses, and so forth. Period value &amp;quot;1&amp;quot; has special meaning - there is no throttling, all history events are logged. &lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
=== Sequence for frontend History Event ===&lt;br /&gt;
The main steps for the frontend History Event is as follows:&lt;br /&gt;
&lt;br /&gt;
* The user code in the frontend equipment Event Readout routines reads the data, placing it into a MIDAS data bank&lt;br /&gt;
* In mfe.c, if the key [[/Equipment ODB tree#Log history|Log history]] &amp;gt; 0 (i.e. the history system is enabled for this equipment), this data bank is written into ODB (by update_odb()).&lt;br /&gt;
* This ODB write triggers an ODB hot-link into mlogger&lt;br /&gt;
* The hot-link calls mlogger.c::log_history(), which calls hs_write() to write the data into the history file. The frequency of the history writes is specified by the number of seconds between writes stored in the ODB key [[/Equipment ODB tree#Log history|Log history]].&lt;br /&gt;
* history.c::hs_write() or history_odbc::hs_write_odbc() writes the data into a history file or into an SQL database.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= How to Write History events =&lt;br /&gt;
*  Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
*  [[#Select the history driver|Select the history driver]]&lt;br /&gt;
*  Follow instructions below for selected driver:&lt;br /&gt;
** [[#Write MIDAS-History events|Write MIDAS-history events]]&lt;br /&gt;
** [[#Write ODBC-History events|Write ODBC-history events]]&lt;br /&gt;
** [[#Write SQLITE-History events|Write SQLITE-history events]]&lt;br /&gt;
** [[#Write MYSQL-History events|Write MYSQL-history events]]&lt;br /&gt;
** [[#Write FILE-History events|Write FILE-history events]]&lt;br /&gt;
&lt;br /&gt;
== Select the history driver ==&lt;br /&gt;
&lt;br /&gt;
* Select the  &#039;&#039;&#039;[[#History drivers|history driver]]&#039;&#039;&#039; and therefore the [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to use to write the MIDAS-history files. &lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Active|Active]] ODB key in the selected  [[Keys in the ODB /Logger/History subtree#&amp;lt;history-logging-channel&amp;gt; subtrees|history-logging-channel]]  to &amp;quot;y&amp;quot;. All other logging channels should be disabled.&lt;br /&gt;
* set  [[/History ODB tree#LoggerHistoryChannel|LoggerHistoryChannel]] ODB key to the selected [[#History drivers|History channel]].&lt;br /&gt;
&lt;br /&gt;
== Write MIDAS-History events   ==&lt;br /&gt;
* Enable desired [[#To enable Frontend History Events|Frontend]] and/or [[#To enable Virtual History Events|Virtual]] history events&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MIDAS&amp;quot;.&lt;br /&gt;
* Restart [[mhttpd]] and [[mlogger]], start the run.&lt;br /&gt;
&lt;br /&gt;
MIDAS-history files will be saved into the  [[#Location of History Files|MIDAS-history data directory]]. &lt;br /&gt;
&lt;br /&gt;
== Write ODBC-History events  ==&lt;br /&gt;
&lt;br /&gt;
See [[#MIDAS ODBC SQL History system|MIDAS ODBC SQL History system]].&lt;br /&gt;
* If necessary, [[#Set up a MySQL database|set up a MySQL database]].&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps in [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;ODBC&amp;quot;.&lt;br /&gt;
* Check ODB Key [[Keys in the ODB /Logger/History subtree#Writer_ODBC_DSN|Writer_ODBC_DSN]] is set to &amp;quot;history writer&amp;quot; and Key [[Keys in the ODB /Logger/History subtree#Reader_ODBC_DSN|Reader_ODBC_DSN]] is set to &amp;quot;history reader&amp;quot; (the default values)&lt;br /&gt;
* set [[Keys in the ODB /Logger/History subtree#Debug|Debug]] to 1 if desired&lt;br /&gt;
* restart [[mlogger]] in verbose mode (i.e. mlogger -v), and observe how it issues SQL commands to create the tables and columns corresponding to MIDAS-history events and tags.&lt;br /&gt;
* restart [[mhttpd]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notes&#039;&#039;&#039;&lt;br /&gt;
# [[mlogger]] is programmed to raise alarms if connection to SQL database is interrupted or if some events cannot be written into the database (i.e. data type mismatch, SQL syntax errors, etc). The traditional MIDAS-history never raised alarms because it &amp;quot;never failed&amp;quot; - other than from &amp;quot;disk full&amp;quot; errors, which are immediately obvious.&lt;br /&gt;
# With ODBC History enabled, [[mhttpd]] will only use history information from the SQL database to make history plots and to extract history variable names for the history plot editor. The ODB  {{Odbpath|path=/History}}  subtrees[[/History ODB tree#Tags subtree|Tags]] and [[/History ODB tree#Events subtree|Events]]  are not used.&lt;br /&gt;
# variable names presented to the user may change from MIDAS names to SQL names (use the history panel &amp;quot;Label&amp;quot; text fields to create permanent plot labels).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Write  SQLITE-history events  ==&lt;br /&gt;
 &lt;br /&gt;
No special configuration required. &lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* Create a directory for storage of sqlite history files&lt;br /&gt;
* save its path in the ODB key  [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]&lt;br /&gt;
* restart [[mhttpd]] and [[mlogger]]&lt;br /&gt;
&lt;br /&gt;
In the history data directory (in [[Keys in the ODB /Logger/History subtree#Sqlite dir|Sqlite dir]]) you should see files with name &amp;quot;mh_xxx.sqlite3&amp;quot; corresponding to your equipment and variable names. &lt;br /&gt;
&lt;br /&gt;
== Write  MYSQL-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;MYSQL&amp;quot;.&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
== Write  FILE-history events  ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Enable desired virtual and frontend history events (see [[#Virtual History Event|Virtual history events]] and [[#Frontend History Event|Frontend history events]]).&lt;br /&gt;
* Perform steps to [[#Select the history driver|Select History Driver]] with [[#History drivers|history driver]] &amp;quot;SQLITE&amp;quot;.&lt;br /&gt;
* Assign directory path for saved files using the ODB key [[Keys in the ODB /Logger/History subtree#History dir|History dir]].&lt;br /&gt;
...........&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= History Events =&lt;br /&gt;
The following information is derived from [https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087].&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;history event&amp;quot; is a history atomic unit of data. Associated with each history event is a timestamp (unix time),&lt;br /&gt;
a name (limited to NAME_LENGTH in the old history) and a list of history tags that describe the individual data&lt;br /&gt;
values inside the history event.&lt;br /&gt;
&lt;br /&gt;
When making history plots in [[mhttpd]] (see [[History Page]]) for each curve on the plot, one selects a history event (from the list&lt;br /&gt;
of currently active events, recently active events or the list of all events that ever existed), then from the list of tags&lt;br /&gt;
inside the history event one selects the particular variable that will be plotted.&lt;br /&gt;
&lt;br /&gt;
== Old MIDAS history events ==&lt;br /&gt;
In the old MIDAS history, all history events are written into one history file (.hst file + optional .def and .idx event definition and time index files&lt;br /&gt;
which can be/are regenerated automatically from the .hst file). History events are identified by 16-bit history event IDs, the persistent mapping&lt;br /&gt;
from history event names and the 16-bit history event IDs is stored in ODB subtree {{Odbpath|path=/History/Events}}. In addition the list of all known history event tags is&lt;br /&gt;
stored in ODB subtree {{Odbpath|path=/History/Tags}}. For per-equipment history, the 16-bit history event ID is the value of ODB key [[/Equipment ODB tree#Event ID|/Equipment/&amp;lt;equipment-name&amp;gt;/Common/Event ID]].&lt;br /&gt;
&lt;br /&gt;
== SQL history events ==&lt;br /&gt;
In the SQL history (MySQL, SQLITE, etc), each history event is an SQL table. The history event tags are the SQL table columns.&lt;br /&gt;
&lt;br /&gt;
== FILE history events ==&lt;br /&gt;
In the new FILE history, each history event is written into a separate file, tag definition are recorded in text format in the file header, history event&lt;br /&gt;
data is appended to the file in binary format (fixed record size). If the history event definition is changed, a new file will be started.&lt;br /&gt;
&lt;br /&gt;
= History Event Construction =&lt;br /&gt;
The [[mlogger]] creates [[#Frontend history event]]s in open_history() by parsing the ODB subtree {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables}}. Each ODB entry under the {{Odbpath|path=variables/}} subtree is referred to as a &amp;quot;variable&amp;quot;. Each variable can be a single ODB value, an array of ODB values, or a subdirectory (corresponding to TID_STRUCT structured data banks). As each variable is processed, one or more tags are created to describe it. &lt;br /&gt;
&lt;br /&gt;
Single ODB values will generally produce a single tag, while arrays can produce (depending whether the array is &amp;quot;[[#Named Arrays|Named]]&amp;quot; or not)&lt;br /&gt;
* multiple tags  - one per array element (&amp;quot;Named&amp;quot; array) or&lt;br /&gt;
* one single tag - describing the whole array  &lt;br /&gt;
 &lt;br /&gt;
The code can generate two types of history:&lt;br /&gt;
&amp;lt;dl&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-equipment&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have the tags for all variables concatenated together into one single history event&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;dt&amp;gt; &amp;quot;per-variable&amp;quot; history&amp;lt;/dt&amp;gt;&lt;br /&gt;
&amp;lt;dd&amp;gt; will have one history event defined for each variable. Inside could be one tag (for single odb values and unnamed array)  or multiple tags (for named arrays and structured data &lt;br /&gt;
banks).&amp;lt;/dd&amp;gt;&lt;br /&gt;
&amp;lt;/dl&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Per-equipment history is the original MIDAS history implementation. Per-variable history was added to permit efficient data storage in SQL tables. Its initial implementation used 1 ODB hotlink for each variable and it was easy to exceed the maximum permitted number of ODB hotlinks (db_open_record()). To reduce consumption of hotlinks, db_watch() has been implemented and now per-variable history only uses 1 ODB hotlink per equipment.&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: With db_watch, per-equipment history is no longer available. &#039;&#039;&#039;Per-variable history is the new default&#039;&#039;&#039; (and the only option).&lt;br /&gt;
&lt;br /&gt;
[https://midas.triumf.ca/elog/Midas/1087 MidasElog#1087]&lt;br /&gt;
&lt;br /&gt;
= Construction of history event tags =&lt;br /&gt;
Currently,&lt;br /&gt;
* single ODB values are treated as arrays of length &amp;quot;1&amp;quot;&lt;br /&gt;
* string ODB entries are not permitted&lt;br /&gt;
&lt;br /&gt;
History event tags are constructed in the [[mlogger]] add_equipment(). Presently there are some quirks with the generation of history event tags (see  [https://midas.triumf.ca/elog/Midas/1088]),&lt;br /&gt;
e.g. single odb values are treated as arrays of length &amp;quot;1&amp;quot; and  &amp;quot;string&amp;quot; ODB entries are not permitted.&lt;br /&gt;
&lt;br /&gt;
For variables of type TID_KEY (subdirectories, corresponding to TID_STRUCT structured banks), one tag is generated for each subdirectory entry. Tag names for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa/bbb}} will be &amp;quot;aaa_bbb&amp;quot; (with an underscore). Subdirectory entries of type TID_KEY and TID_LINK are currently not supported.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Named Arrays]]&amp;quot;, individual tags are generated for each array element. Tag names are taken from the &#039;&#039;Names&#039;&#039; array. For empty tag names (empty names array), tags are &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc (for {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}). &lt;br /&gt;
&lt;br /&gt;
For &amp;quot;[[#Named Arrays|Single Names Arrays]]&amp;quot;, tag names have the variable name appended (with a space), for  {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and an empty names array, tags will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, etc. For a populated names array, the tags will be &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
For unnamed arrays and single odb variables (in ODB, single odb variables are arrays of length 1), a single tag is generated.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Named Arrays ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Named Arrays&#039;&#039;&#039; have a &amp;quot;Names&amp;quot; entry in {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings}}.&lt;br /&gt;
&lt;br /&gt;
For example, to add names to {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}}, create a string array {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names aaa}}. The names array should be at least as long as the corresponding data array. Individual entries in the names array can be left blank (tag names will be &amp;quot;aaa_0&amp;quot;, &amp;quot;aaa_1&amp;quot;, etc). Duplicate tag names are not permitted.&lt;br /&gt;
&lt;br /&gt;
A single &amp;quot;Names&amp;quot; entry can be created to name all arrays in variables with the same names (&#039;&#039;&#039;&amp;quot;Single Names&amp;quot;&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Create {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/settings/names}} and arrays {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/aaa}} and {{Odbpath|path=/equipment/&amp;lt;equipment-name&amp;gt;/variables/bbb}} will have &lt;br /&gt;
history tags &amp;quot;name0 aaa&amp;quot;, &amp;quot;name1 aaa&amp;quot;, &amp;quot;name0 bbb&amp;quot;, &amp;quot;name1 bbb&amp;quot;, etc. If &amp;quot;names&amp;quot; are left blank, tag names will be &amp;quot;aaa_0 aaa&amp;quot;, &amp;quot;aaa_1 aaa&amp;quot;, &amp;quot;bbb_0 bbb&amp;quot;, &amp;quot;bbb_1 bbb&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
In the [[mhttpd]] web server [[History Page]] variables viewer, &amp;quot;single name&amp;quot; arrays are displayed in a 2D table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This information is from [https://midas.triumf.ca/elog/Midas/1088].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Historical note on MIDAS-History Tag names =&lt;br /&gt;
Tags are only used for MIDAS-history events. &lt;br /&gt;
&lt;br /&gt;
The mlogger/mhttpd implementation of &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; has proved troublesome and we are moving away from it.&lt;br /&gt;
&lt;br /&gt;
;During the transition period:&lt;br /&gt;
:   Implementations starting with Version 4435 of [[mlogger]] and [[mhttpd]] (i.e. &amp;quot;new&amp;quot; versions) will now work &#039;&#039;&#039;without&#039;&#039;&#039; &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt;. The history tags are read directly from the history files themselves. To run in this mode, set  ODB key [[/History ODB tree#DisableTags|/History/DisableTags]] to &amp;quot;y&amp;quot;. Existing [[/History ODB tree#Tags subtree|/History/Tags subtree]] will be automatically deleted.&lt;br /&gt;
&lt;br /&gt;
Two downsides to running like this are&lt;br /&gt;
* it is slower and tags become non-persistent&lt;br /&gt;
* if some frontends have not been running for a while, their variables may vanish from the history panel editor.&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== New-style History Tags ==&lt;br /&gt;
For the above two reasons, using &amp;lt;span style=&amp;quot;color:purple; font-style:italic&amp;quot;&amp;gt;/History/Tags&amp;lt;/span&amp;gt; is still recommended.  &lt;br /&gt;
However, the format of the tags is now changed to simplify management and reduce ODB size. &lt;br /&gt;
&lt;br /&gt;
; For NEW implementations&lt;br /&gt;
: the key [[/History ODB tree#CreateOldTags|CreateOldTags]] will not be present. &amp;quot;New-style&amp;quot; history tags will be created automatically in the [[/History ODB tree#Tags subtree|Tags subtree]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;If you have old-style tags&lt;br /&gt;
: [[mlogger]] will automatically convert the old tags to this new format (this is why you should make a backup of your ODB).&lt;br /&gt;
&lt;br /&gt;
** using &amp;quot;old&amp;quot; (i.e. pre Version 4435) mlogger with &amp;quot;new&amp;quot; mhttpd is OK: new mhttpd understands both formats of /History/Tags.&lt;br /&gt;
** using &amp;quot;old&amp;quot; mhttpd with &amp;quot;new&amp;quot; mlogger is OK provided the ODB key [[/History ODB tree#CreateOldTags|/History/CreateOldTags]] is set to &amp;quot;y&amp;quot; before starting mlogger.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Old-style History Tags ==&lt;br /&gt;
Prior to versions 4435 of [[mlogger]] and [[mhttpd]], old-style history tags were generated.&lt;br /&gt;
See&lt;br /&gt;
* http://ladd00.triumf.ca/~daqweb/doc/midas-old/html/F_History_logging.html&lt;br /&gt;
for details.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
---------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= MIDAS ODBC SQL History system =&lt;br /&gt;
&lt;br /&gt;
This section describes the internal workings of the MIDAS SQL history system.&lt;br /&gt;
&lt;br /&gt;
The SQL history system implements the MIDAS history using a SQL database for data storage instead of flat binary files.&lt;br /&gt;
&lt;br /&gt;
The SQL history code lives in a separate files history.h and history_sql.cxx. The present implementation uses the ODBC API for accessing SQL databases. &lt;br /&gt;
MySQL is fully supported, Pgsql support is partially implemented, support for arbitrary ODBC drivers should be easy to add in history_sql and most SQL operations are done using an interface class.&lt;br /&gt;
&lt;br /&gt;
Preliminary testing with MySQL and PgSQL indicates that disk space requirements are the same for both storage mechanisms using flat binary files or either of the 2 SQL databases. All 3 tested storage mechanisms store the data uncompressed. (Observed gzip-1 compression ratios from CERN-ALPHA history files are 50% or better).&lt;br /&gt;
&lt;br /&gt;
Preliminary testing also indicates that MySQL database is &amp;quot;not too slow&amp;quot; for use by T2K/ND280 slow control system. Using MySQL, performance seems to improve somewhat compared to traditional MIDAS-history because each SQL table is stored into a separate file, compared to everything-in-one-file in traditional MIDAS-history.&lt;br /&gt;
&lt;br /&gt;
== Set up a MySQL database ==&lt;br /&gt;
&lt;br /&gt;
In order to setup a MySQL database, the following is needed:&lt;br /&gt;
&lt;br /&gt;
*    the server hostname and port number&lt;br /&gt;
*    database name&lt;br /&gt;
*    user name and password.&lt;br /&gt;
&lt;br /&gt;
It is recommended to create 3 different users:&lt;br /&gt;
&lt;br /&gt;
*    a &amp;quot;root&amp;quot; user with full priveleges,&lt;br /&gt;
*    a &amp;quot;reader&amp;quot; user with read-only priveleges&lt;br /&gt;
*    and a &amp;quot;writer&amp;quot; user with &amp;quot;insert, create table, and add column&amp;quot; priveleges (no permission to drop table, remove columns, etc)&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
#Setup a MySQL database (RHEL/SL 5)&lt;br /&gt;
&lt;br /&gt;
 ssh root@localhost&lt;br /&gt;
 service mysqld start&lt;br /&gt;
 /usr/bin/mysql_secure_installation (enter current password for root: press &amp;lt;enter&amp;gt;, then accept  default answer &amp;quot;Y&amp;quot; to all questions)&lt;br /&gt;
 mysqladmin -p create history&lt;br /&gt;
 using mysql-administrator, create 2 users:&lt;br /&gt;
 history_writer, with database &amp;quot;history&amp;quot; schema privileges: select, insert, create, alter, index&lt;br /&gt;
 history_reader, with database &amp;quot;history&amp;quot; schema privileges: select&lt;br /&gt;
&lt;br /&gt;
#Setup $HOME/.odbc.ini file:&lt;br /&gt;
&lt;br /&gt;
 cat $HOME/.odbc.ini&lt;br /&gt;
 [history_writer]&lt;br /&gt;
 Description  = history_writer&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_writer&lt;br /&gt;
 Password     = ******&lt;br /&gt;
 [history_reader]&lt;br /&gt;
 Description  = history_reader&lt;br /&gt;
 Driver       = /usr/lib64/libmyodbc3.so&lt;br /&gt;
 SERVER       = ladd05.triumf.ca&lt;br /&gt;
 PORT         =&lt;br /&gt;
 Database     = history&lt;br /&gt;
 OPTION       = 3&lt;br /&gt;
 SOCKET       =&lt;br /&gt;
 User         = history_reader&lt;br /&gt;
 Password     =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note: if you are using mhist you will need a separate .odbc.ini file for each user that you have connecting to the database (through MIDAS).&lt;br /&gt;
&lt;br /&gt;
== Layout of SQL tables ==&lt;br /&gt;
&lt;br /&gt;
* One table is created for each history event. Table name is the same as the history event name (as reported by [[mhdump]]).&lt;br /&gt;
* one column is created for each history tag (history variable). Column name is the same as the tag name (as reported by mhdump). For array tags, one column is created for each array element: array a[3] will produce columns a_0, a_1 and a_2.&lt;br /&gt;
* two special columns are always created: _i_time and _t_time are the timestamps in the UNIX-time integer format and in the SQL &amp;quot;time&amp;quot; format. (A priori, it is not clear which timestamp format is more useful for end users. mhttpd uses the _i_time integer time format). Note that this timestamp is the time when mlogger receives the hot-link signal (see above) and it can be a few seconds behind the time when the user placed the data into the MIDAS bank. For high precision (and sub-second time resolution) time stamps, users should generate their own timestamps and include them as part of the data itself.&lt;br /&gt;
* a special table called _history_index is created to remember the mapping between SQL names and MIDAS names for event names, variable name and tag names.&lt;br /&gt;
&lt;br /&gt;
=== Schema Evolution ===&lt;br /&gt;
&lt;br /&gt;
*    when new data fields are added, new SQL columns are created automatically&lt;br /&gt;
*    existing SQL columns are never deleted&lt;br /&gt;
*    arrays are expanded automatically, and arrays never shrink.&lt;br /&gt;
*    if the type of a data field changes, a conflict may occur with existing SQL columns, for example if previous type was &amp;quot;FLOAT&amp;quot; and new type is &amp;quot;DOUBLE&amp;quot;, the existing SQL columns would have the SQL data type &amp;quot;float&amp;quot;, too narrow to store new values. mlogger will complain about this. Such conflicts may be resolved by changing the type of the SQL column using SQL tools. In general, SQL names are created from MIDAS names by replacing all non-alphanumerical characters to an underscore &amp;quot;_&amp;quot;. If this procedure creates duplicate column names, the column names and made unique by appending them with a random number, i.e. MIDAS names &amp;quot;A+B&amp;quot; and &amp;quot;A-B&amp;quot; will be translated to &amp;quot;A_B&amp;quot; and &amp;quot;A_B_12345&amp;quot; (random integer). True MIDAS names are saved into the _history_index.&lt;br /&gt;
&lt;br /&gt;
[[Category:history]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2982</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2982"/>
		<updated>2020-07-11T15:23:49Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Related packages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket] Source code, bug tracking, etc&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum] Discussion, announcements, problem reports, requests for improvements&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
For news about bug fixes and new releases, go to the&lt;br /&gt;
[https://midas.triumf.ca/forum MIDAS forum] hosted by TRIUMF using&lt;br /&gt;
the [http://elog.psi.ch/elog ELOG] system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://elog.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2946</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2946"/>
		<updated>2020-04-26T14:54:57Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* News and Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket] Source code, bug tracking, etc&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum] Discussion, announcements, problem reports, requests for improvements&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
For news about bug fixes and new releases, go to the&lt;br /&gt;
[https://midas.triumf.ca/forum MIDAS forum] hosted by TRIUMF using&lt;br /&gt;
the [http://elog.psi.ch/elog ELOG] system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://midas.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2945</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2945"/>
		<updated>2020-04-26T14:54:31Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* News and Support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket] Source code, bug tracking, etc&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum] Discussion, announcements, problem reports, requests for improvements&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
For news about bug fixes and new releases of Midas go to the&lt;br /&gt;
[https://midas.triumf.ca/forum Midas forum] hosted by TRIUMF using&lt;br /&gt;
the [http://elog.psi.ch/elog ELOG] system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://midas.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2944</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2944"/>
		<updated>2020-04-26T14:52:48Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket] Source code, bug tracking, etc&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum] Discussion, announcements, problem reports, requests for improvements&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
News about bug fixes and new releases of Midas can be obtained from the&lt;br /&gt;
[https://midas.triumf.ca/forum Midas news group] located at &lt;br /&gt;
TRIUMF which uses the [http://elog.psi.ch/elog ELOG]&lt;br /&gt;
system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://midas.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2943</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2943"/>
		<updated>2020-04-26T14:51:40Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket]&lt;br /&gt;
* [https://midas.triumf.ca/forum MIDAS forum]&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
News about bug fixes and new releases of Midas can be obtained from the&lt;br /&gt;
[https://midas.triumf.ca/forum Midas news group] located at &lt;br /&gt;
TRIUMF which uses the [http://elog.psi.ch/elog ELOG]&lt;br /&gt;
system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://midas.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2942</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Main_Page&amp;diff=2942"/>
		<updated>2020-04-26T14:50:15Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Introduction =&lt;br /&gt;
&lt;br /&gt;
MIDAS is a modern data acquisition system developed at [http://www.psi.ch PSI] and [http://www.triumf.ca TRIUMF]. Supported hardware includes VME, Fastbus, CAMAC, RS232, GPIB, USB, ethernet, fiber optic and MSCB attached data acquisition devices. MIDAS is written in C/C++ and runs on Linux, MacOS and MS Windows. It is licensed under the [http://www.gnu.org/copyleft/gpl.html GNU Public License].&lt;br /&gt;
&lt;br /&gt;
= Documentation =&lt;br /&gt;
&lt;br /&gt;
* [[Midas documentation| Main Documentation]]&lt;br /&gt;
* [[Installation | Installation Instructions]]&lt;br /&gt;
* [[Changelog | Changelog / Upgrade Instructions]]&lt;br /&gt;
* [https://daq.triumf.ca/~daqweb/doc/midas-devel/html/modules.html &amp;lt;i&amp;gt;Doxygen&amp;lt;/i&amp;gt;] Code structure, functions, etc...&lt;br /&gt;
* [https://bitbucket.com/tmidas/midas git repository on bitbucket]&lt;br /&gt;
&lt;br /&gt;
= News and Support=&lt;br /&gt;
&lt;br /&gt;
News about bug fixes and new releases of Midas can be obtained from the&lt;br /&gt;
[https://midas.triumf.ca/forum Midas news group] located at &lt;br /&gt;
TRIUMF which uses the [http://elog.psi.ch/elog ELOG]&lt;br /&gt;
system. Users can register in this system to be notified automatically via &lt;br /&gt;
E-mail when new entries are submitted.&lt;br /&gt;
&lt;br /&gt;
Another source of information is the [https://bitbucket.com/tmidas/midas Bitbucket Repository] of MIDAS, where one can see the latest changes to the software.&lt;br /&gt;
&lt;br /&gt;
Finally, you can read presentations from&lt;br /&gt;
* [https://indico.psi.ch/conferenceDisplay.py?ovw=True&amp;amp;confId=3793 2015 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2342 2017 MIDAS Workshop]&lt;br /&gt;
* [https://indico.triumf.ca/conferenceDisplay.py?confId=2438 2019 MIDAS Workshop]&lt;br /&gt;
&lt;br /&gt;
= Related packages =&lt;br /&gt;
&lt;br /&gt;
* [http://midas.psi.ch/elog ELOG] - Electronics Logbook from PSI&lt;br /&gt;
* [[ROOT]] - data analysis package from CERN&lt;br /&gt;
* [[ROOTANA]] - ROOT-based analyzer for MIDAS&lt;br /&gt;
* [[ROODY]] - viewer for online histograms&lt;br /&gt;
* http://elog.psi.ch/rome/ - MEG/PSI data analysis package&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Marco.francesconi&amp;diff=2919</id>
		<title>User talk:Marco.francesconi</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Marco.francesconi&amp;diff=2919"/>
		<updated>2020-03-31T15:46:49Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 15:46, 31 March 2020 (UTC)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Jmckenna&amp;diff=2903</id>
		<title>User talk:Jmckenna</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Jmckenna&amp;diff=2903"/>
		<updated>2019-12-02T22:34:56Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 22:34, 2 December 2019 (UTC)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Bsmith&amp;diff=2873</id>
		<title>User talk:Bsmith</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Bsmith&amp;diff=2873"/>
		<updated>2019-06-14T18:39:59Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 18:39, 14 June 2019 (UTC)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Lmartin&amp;diff=2864</id>
		<title>User talk:Lmartin</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Lmartin&amp;diff=2864"/>
		<updated>2019-06-03T17:07:52Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 17:07, 3 June 2019 (UTC)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Gerritzen&amp;diff=2863</id>
		<title>User talk:Gerritzen</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=User_talk:Gerritzen&amp;diff=2863"/>
		<updated>2019-06-03T17:06:45Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: Welcome!&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to &#039;&#039;MidasWiki&#039;&#039;!&#039;&#039;&#039;&lt;br /&gt;
We hope you will contribute much and well.&lt;br /&gt;
You will probably want to read the [https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents help pages].&lt;br /&gt;
Again, welcome and have fun! [[User:Olchansk|Olchansk]] ([[User talk:Olchansk|talk]]) 17:06, 3 June 2019 (UTC)&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=/Alias_ODB_tree&amp;diff=2841</id>
		<title>/Alias ODB tree</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=/Alias_ODB_tree&amp;diff=2841"/>
		<updated>2019-02-11T19:03:54Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Symbolic Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;column-count:4;-moz-column-count:4;-webkit-column-count:4&amp;quot;&amp;gt;&lt;br /&gt;
* [[Midas_documentation|Midas Documentation]]&lt;br /&gt;
* [[Feature_listing|Feature Listing]]&lt;br /&gt;
* [[Application_listing|Application Listing]]&lt;br /&gt;
* [[Online_Database|Online Database]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Purpose ==&lt;br /&gt;
The ODB &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Alias&amp;lt;/span&amp;gt; tree  provides the user with a way to access other webpages via buttons placed on the [[mhttpd]] [[Status Page]]. It can provide links to external webpages, or symbolic links (short-cuts) to ODB sub-trees.&lt;br /&gt;
&lt;br /&gt;
== Creating the /Alias tree ==&lt;br /&gt;
The &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Alias&amp;lt;/span&amp;gt; tree is optional, and is not present until [[ODB#Creating ODB keys|created by the user]]. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div id=&amp;quot;Alias-Button&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
== Keys in the /Alias tree ==&lt;br /&gt;
Any key created under &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Alias&amp;lt;/span&amp;gt; will appear as a button (i.e. &#039;&#039;&#039;alias-button&#039;&#039;&#039;) on the [[Status Page]], with the same name as the key (except as noted below).&lt;br /&gt;
&lt;br /&gt;
By default, the clicking of an alias-button in the web interface will spawn a &#039;&#039;&#039;new frame&#039;&#039;&#039;. To force the display of the alias page in the &#039;&#039;&#039;same frame&#039;&#039;&#039;, an &amp;quot;&amp;amp;&amp;quot; has to be appended to the name of the alias key. The &amp;quot;&amp;amp;&amp;quot; is stripped off the alias name when it appears as an alias-button (see [[#Symbolic Links|example]]).&lt;br /&gt;
&lt;br /&gt;
=== External links ===&lt;br /&gt;
The following [[odbedit]] commands demonstrate how to make a link to an external webpage:&lt;br /&gt;
&lt;br /&gt;
 [local:t2kgas:S] cd /Alias&lt;br /&gt;
 [local:t2kgas:S]create string triumf&lt;br /&gt;
 String length [32]:&lt;br /&gt;
 [local:t2kgas:S] set triumf &amp;quot;http://triumf.ca&amp;quot;&lt;br /&gt;
&lt;br /&gt;
This will cause a button &amp;lt;span style=&amp;quot;color: #444444; background-color: #CCCCCC; font-style:italic; font-size: 90; padding:0.25em;&lt;br /&gt;
	padding-left: 0.5em;padding-right: 0.5em;border:1px solid #808080;border-radius: 5px;margin-bottom:1px;&amp;quot;&amp;gt;triumf&amp;lt;/span&amp;gt; &lt;br /&gt;
on the status page,  Clicking on this alias-button will show the contents of the link in a new frame.&lt;br /&gt;
&lt;br /&gt;
=== Links to ODB ===&lt;br /&gt;
The &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Alias&amp;lt;/span&amp;gt; tree may also contain a list of symbolic links to any desired ODB location.&lt;br /&gt;
&lt;br /&gt;
Create a string under /alias with this contents:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
?cmd=odb&amp;amp;odb_path=/Programs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:ODB Tree]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2632</id>
		<title>Setup MIDAS experiment at TRIUMF</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2632"/>
		<updated>2017-06-26T17:01:16Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This page describes setting up a MIDAS experiment at TRIUMF. This information can be adapted for other sites.&lt;br /&gt;
&lt;br /&gt;
== Environment variables ==&lt;br /&gt;
* &#039;&#039;&#039;MIDASSYS&#039;&#039;&#039; Base directory of the MIDAS package, midas and mxml should be at the same level.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPTAB&#039;&#039;&#039; Experiment definition file&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_SERVER_HOST&#039;&#039;&#039; MIDAS host server name for remote midas connections.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPT_NAME&#039;&#039;&#039; Experiment name&lt;br /&gt;
&lt;br /&gt;
== Standard layout of MIDAS experiment ==&lt;br /&gt;
The following shows the directory layout of a standard MIDAS experiment: &lt;br /&gt;
&lt;br /&gt;
 /home/exptuser/&lt;br /&gt;
                packages/&lt;br /&gt;
                        root                   &amp;lt;---- ROOT&lt;br /&gt;
                        mxml&lt;br /&gt;
                        mscb&lt;br /&gt;
                        midas/                 &amp;lt;---- MIDAS&lt;br /&gt;
                              linux/{lib,bin}       &amp;lt;---- binaries matching the selected 64-bit/32-bit flavour of ROOT&lt;br /&gt;
                              linux-m32/{lib,bin}   &amp;lt;---- limited function 32-bit binaries for 32-bit frontend machines, build by &amp;quot;make linux32&amp;quot;&lt;br /&gt;
                              linux-m64/{lib,bin}   &amp;lt;---- limited function 64-bit binaries (only needed if ROOT and linux/bin are 32-bit)&lt;br /&gt;
                              linux-arm/{lib,bin}   &amp;lt;---- full function ARM cross-compiled using &amp;quot;make linuxarm&amp;quot;&lt;br /&gt;
                              linux-crosscompile/{lib,bin}  &amp;lt;---- cross-compiled limited function binaries for PPC and ARM frontends (see Makefile)&lt;br /&gt;
                        rootana                &amp;lt;---- ROOT analyzer&lt;br /&gt;
                        roody                  &amp;lt;---- graphical online histogram viewer for MIDAS and ROOTANA&lt;br /&gt;
                 online/&lt;br /&gt;
                        exptab                         &amp;lt;---- experiment definition&lt;br /&gt;
                        {.ODB,.SYSTEM,.SYSMSG,etc}.SHM &amp;lt;---- MIDAS shared memory save files&lt;br /&gt;
                        src                            &amp;lt;---- experiment frontend sources&lt;br /&gt;
                        bin,scripts&lt;br /&gt;
                        elog                           &amp;lt;---- MIDAS elog&lt;br /&gt;
                        history                        &amp;lt;---- MIDAS history&lt;br /&gt;
                        data -&amp;gt; /data/exptname/current &amp;lt;---- symlink to the data directory&lt;br /&gt;
 /data/exptname/current                                &amp;lt;---- experiment data directory with ODB save files and MIDAS .mid/.mid.gz data files&lt;br /&gt;
&lt;br /&gt;
== Prepare computers ==&lt;br /&gt;
&lt;br /&gt;
On some operating systems, several MIDAS functions require administrator access:&lt;br /&gt;
&lt;br /&gt;
* on el7 linux (SL7/CC7/CentOS7/RHEL7) - access to mhttpd port 8443 requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - access to mserver to run frontends and other programs on some other computer requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - on the frontend machines (and other machines that will connect to the mserver, the same firewall rule needs to be created (use the IP address of the machine running the mserver)&lt;br /&gt;
&lt;br /&gt;
== Prepare the user account ==&lt;br /&gt;
&amp;lt;div id=&amp;quot;NOTES&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setup the user account for running this instance of midas. For machines part of the LADD cluster, follow these  [http://daq-plone.triumf.ca/SM/docs/local/NewLaddUser] instructions.&lt;br /&gt;
* check that the account is using the /bin/bash shell&lt;br /&gt;
* make $HOME/.profile look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/echo You must source&lt;br /&gt;
&lt;br /&gt;
export SVN_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export MIDASSYS=$HOME/packages/midas&lt;br /&gt;
export ROOTANASYS=$HOME/packages/rootana&lt;br /&gt;
export MIDAS_EXPTAB=$HOME/online/exptab&lt;br /&gt;
#&lt;br /&gt;
# setup the MIDAS mserver&lt;br /&gt;
#&lt;br /&gt;
case `hostname` in&lt;br /&gt;
daq07*)&lt;br /&gt;
   unset MIDAS_SERVER_HOST&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   export MIDAS_SERVER_HOST=daq07.triumf.ca:7070&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
# select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
#&lt;br /&gt;
case `uname -i` in&lt;br /&gt;
i386)&lt;br /&gt;
   source /daq/daqshare/olchansk/root/root_v5.34.01_SL62_32/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   #source /daq/daqshare/olchansk/root/root_v5.34.34_SL67_64/bin/thisroot.sh&lt;br /&gt;
   source $HOME/packages/root/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
export PATH=.:$HOME/online/bin:$HOME/packages/roody/bin:$PATH&lt;br /&gt;
#&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* mkdir $HOME/packages&lt;br /&gt;
* Logout and login again, for .cshrc changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Install ROOT ==&lt;br /&gt;
&lt;br /&gt;
* Identify the Linux version: RH9 (Red Hat Linux 9), FC3 (Fedora Core 3), RHEL4/SL4 (Red Hat Enterprise LInux 4/Scientific Linux 4), SL5x, SL6x, (CentOS/CC/SL) el7x: more /etc/redhat-release&lt;br /&gt;
* Decide to use 32-bit or 64-bit ROOT (&#039;uname -a&#039;)&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* ls -l /daq/daqshare/olchansk/root/ ### to see all available ROOT packages&lt;br /&gt;
* ln -s /daq/daqshare/olchansk/root/root_vNNN_VVV_BB root, where NNN is the latest available version of ROOT (&amp;quot;ls -l /daq/daqshare/olchansk/root&amp;quot;), VVV is the Linux version code (RH9, FC3, SL4, etc) and BB is &amp;quot;_32&amp;quot; or &amp;quot;_64&amp;quot; for 32-bit or 64-bit ROOT. For example: /daq/daqshare/olchansk/root/root_v5.10.00_SL40&lt;br /&gt;
* for example: ln -s /daq/daqshare/olchansk/root/root_v5.34.34_el72_64 $HOME/packages/root&lt;br /&gt;
* Check that ROOT works: &amp;quot;source $HOME/packages/root/bin/thisroot.sh; root&amp;quot;. Type &amp;quot;.q&amp;quot; to exit root.&lt;br /&gt;
&lt;br /&gt;
== Install MIDAS ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/midas/trunk midas, password &amp;quot;svn&amp;quot;. (password has to be entered twice)&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/mxml/trunk mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mscb&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mxml.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mscb.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/midas.git&lt;br /&gt;
* cd midas&lt;br /&gt;
* make&lt;br /&gt;
* (only if needed) make linux32 ### build the 32-bit MIDAS libraries&lt;br /&gt;
* ls -l linux/bin/odbedit ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&lt;br /&gt;
You can see a list of other installation problems at [[Common problems &amp;amp; Debugging recipes]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: Optional features in MIDAS can be explicitly disabled if desired when making MIDAS using the NO_xxx feature (NO_ROOT,NO_MYSQL,NO_ODBC,NO_SQLITE,NO_MSCB), e.g. &amp;quot;make NO_ROOT=1&amp;quot; to disable ROOT. These NO_xxx Makefile variables are only used to control autodetection.&lt;br /&gt;
&lt;br /&gt;
== Install ROOTANA ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
* cd rootana&lt;br /&gt;
* make&lt;br /&gt;
&lt;br /&gt;
== Install ROODY ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
* cd roody&lt;br /&gt;
* make&lt;br /&gt;
* $HOME/packages/roody/bin/roody, run the program&lt;br /&gt;
&lt;br /&gt;
== Install additional additional packages ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/ttriumfdaq/vme&lt;br /&gt;
* git clone https://bitbucket.org/ttriumfdaq/frontends&lt;br /&gt;
&lt;br /&gt;
== Build special versions of MIDAS ==&lt;br /&gt;
&lt;br /&gt;
Build special versions of MIDAS for the case when some MIDAS programs, such as VME frontends, will run on a different computer that may have a different flavour of operating system, i.e. 32-bit linux or an older version of Scientific Linux.&lt;br /&gt;
&lt;br /&gt;
* login to the computer where the frontends will run and:&lt;br /&gt;
* if it is a 32-bit linux: cd $HOME/packages/midas; make linux32&lt;br /&gt;
* if it is a 64-bit linux: cd $HOME/packages/midas; make linux64&lt;br /&gt;
&lt;br /&gt;
* login to the host computer to cross-compile ARM code:&lt;br /&gt;
* if it is an ARM linux: cd $HOME/packages/midas; make linuxarm # may need to install ARM cross compilers&lt;br /&gt;
&lt;br /&gt;
== Prepare VME hardware ==&lt;br /&gt;
&lt;br /&gt;
Hardware check list:&lt;br /&gt;
* VME crate&lt;br /&gt;
* VME processor (supported are V77xx, V7805, V7865)&lt;br /&gt;
* On all VME modules, set the VME address jumpers as described here: http://daq-plone.triumf.ca/SM/docs/local/vme_jumpers&lt;br /&gt;
* run vmescan to confirm correct VME addresses&lt;br /&gt;
** cd $HOME/packages&lt;br /&gt;
** svn checkout https://ladd00.triumf.ca/svn/daqsvn/trunk/vme&lt;br /&gt;
** cd vme&lt;br /&gt;
** make&lt;br /&gt;
** ./vmescan.exe (or _gef.exe, depending on the VME driver in use)&lt;br /&gt;
&lt;br /&gt;
== Install Universe-II VME driver (V7648, V7750, V7805, V7851) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7648.2C_V7750.2C_V7805.2C_V7851_:_Setup_vme_universe_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan.exe&lt;br /&gt;
&lt;br /&gt;
== Install Tsi-148 VME driver (V7865) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7865_and_XVB-602_:_Setup_gefvme.2Ftsi148_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan_gef.exe&lt;br /&gt;
&lt;br /&gt;
== Setup the experiment environment ==&lt;br /&gt;
&lt;br /&gt;
* Decide which computer will host MIDAS (where MIDAS shared memory buffers will reside). &lt;br /&gt;
: This computer will run the [[mserver]], [[mlogger]] and [[mhttpd]] applications. (It is usually the machine where the MIDAS,ROOT etc. packages have been downloaded). It will be referred to as the host machine (localhost).&lt;br /&gt;
&lt;br /&gt;
The environment is slightly different depending on whether all programs run on the host machine, or whether some programs run on remote host(s) : &lt;br /&gt;
=== ALL programs run on localhost ===&lt;br /&gt;
:If all programs run on the host machine (localhost), it is not necessary to run [[mserver]]. [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will not be assigned (see example .cshrc [[#Prepare the user account|above]]).&lt;br /&gt;
&lt;br /&gt;
=== Some programs run on REMOTE host(s) ===&lt;br /&gt;
: &#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; &lt;br /&gt;
# Since August 2015 &#039;&#039;&#039;you must explicitly allow access for clients running on remote machines&#039;&#039;&#039;. To do this, follow the &#039;&#039;&#039;[[Security#MIDAS programs on remote machines|instructions here]]&#039;&#039;&#039;.&lt;br /&gt;
# The example code .cshrc ([[#Prepare the user account|see above]]) should be present on both host and remote machine(s). This will ensure that [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will NOT be set for the host machine (localhost), but on a remote machine, MIDAS_SERVER_HOST will be set to the MIDAS host machine. &lt;br /&gt;
# The client [[mserver]] must be started on the MIDAS host machine. Note that multiple experiments can run on the same host machine by starting several instances of [[mserver]] (one for each experiment) running with different ports (and .cshrc would be edited so that MIDAS_SERVER_HOST is set to the appropriate port for the experiment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On the host machine:&lt;br /&gt;
* mkdir $HOME/online&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* create directories for local programs, sources, elog and history: mkdir bin src elog history&lt;br /&gt;
* create data directory: mkdir -p /ladd/data1/t2kvme5/data; ln -s /ladd/data1/t2kvme5/data $HOME/online&lt;br /&gt;
* create the exptab file &amp;quot;$HOME/online/exptab&amp;quot; following the example below. The first entry (exptname) is the name if the DAQ system (MIDAS experiment name), the second entry (/home/USER/online) is the location of MIDAS shared memory buffers (by convention, $HOME/online), the third entry (kopio03) is your username.&lt;br /&gt;
&amp;lt;pre&amp;gt;exptname /home/kopio03/online kopio03&amp;lt;/pre&amp;gt;&lt;br /&gt;
* logout and login again for all changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Setup experiment startup scripts ==&lt;br /&gt;
* login to the experiment host computer&lt;br /&gt;
* echo $MIDAS_SERVER_HOST ### to check correct value - should be blank&lt;br /&gt;
* create $HOME/online/bin/start_daq.sh, replacing XXX with the hostname of the machine running the experiment (and changing the mserver and mhttpd ports, as needed).&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 case `hostname` in XXX*)&lt;br /&gt;
    echo &amp;quot;Good, we are on XXX!&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
 *)&lt;br /&gt;
    echo &amp;quot;The start_daq script should be executed on XXX&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
    ;;&lt;br /&gt;
 esac&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start [[mhttpd]] on default port. (Mongoose https version - see [[mhttpd]] for other options)&lt;br /&gt;
 mhttpd  -D  -a localhost -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 #&lt;br /&gt;
 #   start [[mserver]] on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D   # access must now be specifically allowed - see [[#Setup the experiment environment|above]]&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;&lt;br /&gt;
 # OR ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
 # mhttpd  -p 8081 -D -a localhost -a XXX.triumf.ca      # optionally restrict access to specified hosts&lt;br /&gt;
 # mserver -p 7071 -D -a localhost -a lxdragon01.triumf.ca -a lxdragon02.triumf.ca -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
 #&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
Let&#039;s start the MIDAS webserver for the first time:&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the command printed by mhttpd:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL proxy.&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. If these ports are in use on your machine, start &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mhttpd&amp;lt;/span&amp;gt; with alternative ports, e.g.&lt;br /&gt;
       &amp;lt;small&amp;gt;[mhostpc] mhttpd --https 8448 --http 8089&amp;lt;/small&amp;gt;&lt;br /&gt;
: or see [[Mhttpd#Usage]] to change the default ports.&lt;br /&gt;
&lt;br /&gt;
== Setup experiment database (ODB) ==&lt;br /&gt;
&lt;br /&gt;
* run $HOME/online/bin/start_daq.sh&lt;br /&gt;
&lt;br /&gt;
* odbedit, run these commands: (replace user names and directory names)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set &amp;quot;/Logger/Message file&amp;quot; &amp;quot;/home/kopio03/online/midas.log&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Data Dir&amp;quot;     &amp;quot;/home/kopio03/online/data&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/History dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/History dir&amp;quot;  &amp;quot;/home/kopio03/online/history&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/Elog dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Elog dir&amp;quot;     &amp;quot;/home/kopio03/online/elog&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump file&amp;quot; &amp;quot;/home/kopio03/online/history/run%05d.xml&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Filename&amp;quot; &amp;quot;run%05dsub%03d.mid.gz&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Subrun byte limit&amp;quot; &amp;quot;1000000000&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Compression&amp;quot;   1&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/ODB Dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/Logger/Required&amp;quot; y&lt;br /&gt;
set &amp;quot;/Programs/Logger/Start command&amp;quot; &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Required&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Start command&amp;quot; &amp;quot;ssh -n lxdaq09 $HOME/online/src/fevme_gef.exe -O&amp;quot;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* open web browser e.g. firefox.&lt;br /&gt;
* go to the midas status page at https://localhost:8443  (default port). &lt;br /&gt;
** if running [[mhttpd]] with Mongoose HTTPS/OpenSSL (the default) for the first time, you will need to create a password file. Follow the instructions (see [[mhttpd#HTTPS/SSL server (Mongoose)]] for details).&lt;br /&gt;
** For other options (i.e. HTTPS/SSL proxy) see [[#Secure MIDAS and ELOG Web access]] &lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;OR open the midas status page at http://localhost:8081 ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
* midas status page will show most stuff &amp;quot;red&amp;quot; as nothing is running yet&lt;br /&gt;
* DON&#039;T DO THIS YET run ./fevme.exe (on the computer with the VME interface, could be different from computer hosting the experiment), observe that corresponding equipments have been created&lt;br /&gt;
* save the url bookmark to the &amp;quot;personal toolbar&amp;quot;&lt;br /&gt;
* go to the Programs page, stop mlogger, stop fevme, start mlogger, start fevme&lt;br /&gt;
* go to the Status page, start run, stop run&lt;br /&gt;
* go back to the Status page, everything should be green&lt;br /&gt;
* start a run&lt;br /&gt;
* send signals to the ADC gate&lt;br /&gt;
* you should be getting events&lt;br /&gt;
* to look at data, proceed with setting up the [[ROOTANA|ROOT Analyzer]].&lt;br /&gt;
&lt;br /&gt;
== Start DAQ programs at boot time ==&lt;br /&gt;
&lt;br /&gt;
* add this to /etc/rc.local (replace username and location of the start_daq script)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - alpha -c /home/alpha/online/bin/start_daq.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup local software version control ==&lt;br /&gt;
&lt;br /&gt;
Version control for experiment source code is setup using &amp;quot;git&amp;quot; (http://git-scm.com/)&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* git init&lt;br /&gt;
* git add exptab&lt;br /&gt;
* git add bin/start_daq.sh&lt;br /&gt;
* git add .gitignore ### contents can be&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*~&lt;br /&gt;
*.o&lt;br /&gt;
*.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* git add src/Makefile src/*.cxx ...&lt;br /&gt;
* git commit -a&lt;br /&gt;
&lt;br /&gt;
== Adjust MIDAS buffer sizes ==&lt;br /&gt;
&lt;br /&gt;
Default MIDAS SYSTEM buffer size is 8 Mbytes, fairly small for high-data-rate experiments. The rule of thumb is to have at least a few seconds worth of buffer space available. For example, if event size is 10 Kbytes and the event rate is 1 kHz, data rate is 10*10^3*1*10^3 = 10 Mbytes/sec. To buffer 10 seconds of data we need 100 Mbytes of buffer space.&lt;br /&gt;
&lt;br /&gt;
To resize the MIDAS event buffers (SYSTEM, etc) do this:&lt;br /&gt;
* stop all frontends, stop mlogger&lt;br /&gt;
* start odbedit:&lt;br /&gt;
** cd &amp;quot;/Experiment/Buffer sizes&amp;quot;&lt;br /&gt;
** set SYSTEM 100000000&lt;br /&gt;
* run &amp;quot;mdump -z SYSTEM&amp;quot;&lt;br /&gt;
* if mdump complains about the size of .SYSTEM.SHM, remove it, try again.&lt;br /&gt;
* ls -l /dev/shm ### to observe that the size of shared memory is correct&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Secure MIDAS and ELOG Web access  ==&lt;br /&gt;
In versions prior to May 2015, the default web access to MIDAS and ELOG uses the &amp;quot;http:&amp;quot; protocol which is insecure. In this case, all information is transmitted as clear text meaning that secret, confidential and sensitive information (such as the MIDAS and ELOG passwords and usernames) can be stolen &amp;quot;easily&amp;quot;. This means that even &amp;quot;password protected&amp;quot; MIDAS and ELOG pages are not really protected if accessed using the &amp;quot;http&amp;quot; method. &lt;br /&gt;
 &lt;br /&gt;
Better security for HTTP is gained by using a password protected &#039;&#039;&#039;SSL (https) proxy&#039;&#039;&#039;. (It does not provide absolute security because of remaining problems with the security of SSL certificates, security of passwords, etc). Setting up an SSL (https) proxy is described [[#Setting up an HTTP proxy|below]].&lt;br /&gt;
&lt;br /&gt;
Since May 2015, an &#039;&#039;alternative secure option&#039;&#039; to setting up an HTTP proxy is available to users of MIDAS. Recent versions of elogd (ELOG) do support SSL https:// connections, and [[#mhttpd with HTTPS/SSL server (Mongoose)]] is now available.  This option is the default, and provides a similar level of security to an HTTP proxy. &lt;br /&gt;
&lt;br /&gt;
See [[Security#Web Access]] for a comparison of these two secure options.&lt;br /&gt;
  &lt;br /&gt;
=== mhttpd with HTTPS/SSL server (Mongoose) ===&lt;br /&gt;
&lt;br /&gt;
Since May 2015 the MIDAS web server [[mhttpd]] is explicitly linked with OpenSSL to provide secure HTTPS connections via the [https://bitbucket.org/tmidas/midas/src/ecb9a8537448a8a43f7f9a2bfdb82e578208cde3/doc/mongoose/?at=develop Mongoose] web server (see [[mhttpd]]). With this version, default web access to MIDAS uses the &amp;quot;https&amp;quot; protocol. Web access to {{Utility|name=mhttpd}} can be restricted by using the  &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. The first time {{Utility|name=mhttpd}} is run, a password file must be created. An SSL certificate is also required. See [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]] for instructions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== mhttpd using an HTTPS/SSL proxy ===&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE WRONG, DO NOT DO THIS.&lt;br /&gt;
&lt;br /&gt;
An [[#Setting up an HTTP proxy|HTTP proxy]] must be set up. This is the only way of securing older version of [[mhttpd]] (pre August 2015). Older versions of mhttpd are started using the -p port option  e.g.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; mhttpd  -D -p 8080  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run a new version of mhttpd using an HTTP proxy, use the options provided to run the old (non-Mongoose) webserver on a given port, i.e.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;  mhttpd --oldserver 8080 --nomg   -D  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using an SSL proxy, only access from the SSL proxy (and maybe some special trusted machines) should be permitted. &lt;br /&gt;
This is done using the &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. Normally there will be only &amp;quot;-a localhost&amp;quot; switch, enabling access only for the local machine (where the SSL proxy is running). Additional &amp;quot;-a hostname&amp;quot; switches enable access from listed local machines. No &amp;quot;-a xxx&amp;quot; enables access from everywhere (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere, i.e. by a site firewall or by local firewall rules).&lt;br /&gt;
&lt;br /&gt;
== Setting up an HTTP proxy ==&lt;br /&gt;
In this example, we use APACHE HTTPD to password-protect a typical midas/mhttpd and elog installation.&lt;br /&gt;
&lt;br /&gt;
In this configuration, one uses the Linux stock httpd that accepts encrypted https:// connections and forwards them to mhttpd and elogd. Instead of (or in addition to) using mhttpd and elogd passwords, one configures password protection in httpd via the regular apache httpd password mechanisms (htpasswd, etc).&lt;br /&gt;
&lt;br /&gt;
Recent versions of elogd do support SSL https:// connections, but if one is running an SSL proxy for anyway, it is simpler to run both through the same SSL proxy using the same SSL host certificate and the same httpd password file.&lt;br /&gt;
&lt;br /&gt;
=== Restricting http: access to elogd ===&lt;br /&gt;
;Note&lt;br /&gt;
:Recent versions of elogd do support SSL https:// connections. The following information is for those using an HTTP proxy (see above).&lt;br /&gt;
&lt;br /&gt;
For elogd, this is done using the &amp;quot;-n localhost&amp;quot; switch with enables only access from the same machine if present, or access from anywhere is absent (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere).&lt;br /&gt;
&lt;br /&gt;
(It is recommended to run elogd from the same user as the main daq user and to keep elogd.cfg and all logbooks in the home directory of this user, where they are captured by the normal site backup system)&lt;br /&gt;
&lt;br /&gt;
== Install standalone elog ==&lt;br /&gt;
&lt;br /&gt;
* login into the user account that will run the elog&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/ritt/elog&lt;br /&gt;
* cd elog&lt;br /&gt;
* make&lt;br /&gt;
* create new file start_elogd with this contents:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
killall elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
killall -KILL elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
$HOME/packages/elog/elogd -n localhost -x -c $HOME/packages/elog/elogd.cfg -p 8082 -D&lt;br /&gt;
&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x start_elogd&lt;br /&gt;
* edit elogd.cfg to read:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
port = 8082&lt;br /&gt;
SMTP host = smtp.triumf.ca&lt;br /&gt;
URL = https://titan00.triumf.ca/elog/&lt;br /&gt;
&lt;br /&gt;
Reverse sort = 1&lt;br /&gt;
Display Mode = full&lt;br /&gt;
&lt;br /&gt;
#List Menu commands = New, Find, Admin, Help&lt;br /&gt;
#Menu commands = New, Edit, Reply, Find, Duplicate, Help&lt;br /&gt;
&lt;br /&gt;
Entries Per Page = 30&lt;br /&gt;
Supress Email on edit = 1&lt;br /&gt;
Default encoding = 1&lt;br /&gt;
Page title = TITAN ELOG&lt;br /&gt;
Resolve host names = 1&lt;br /&gt;
&lt;br /&gt;
Logfile = /home/titan/packages/elog/elogd.log&lt;br /&gt;
#Logging level = 3&lt;br /&gt;
&lt;br /&gt;
[midas]&lt;br /&gt;
&lt;br /&gt;
List page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
Comment = T2K M11 MIDAS ELOG&lt;br /&gt;
Page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
RSS Title = [$logbook - $type - $system] $subject, posted by $author&lt;br /&gt;
&lt;br /&gt;
Attributes = Author, Subject, Run, Type, System&lt;br /&gt;
Show Attributes Edit = Run, Author, Subject, Type, System&lt;br /&gt;
Required Attributes = Author, Type, System, Subject&lt;br /&gt;
&lt;br /&gt;
Options Type = Routine, Reply, Shift Summary, Modification, Question, Info, Problem&lt;br /&gt;
Options System = General, DAQ, Beamline&lt;br /&gt;
&lt;br /&gt;
Preset Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Preset On Reply Type = Reply&lt;br /&gt;
Preset On Reply Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
List Display = Date, Subject, Type, System, Author, ID&lt;br /&gt;
Quick Filter = Date, Type, ID&lt;br /&gt;
&lt;br /&gt;
Remove on reply = Author&lt;br /&gt;
Quote on reply = 1&lt;br /&gt;
&lt;br /&gt;
Use lock = 1&lt;br /&gt;
&lt;br /&gt;
************* Email Functionality ****************&lt;br /&gt;
&lt;br /&gt;
Use Email Subject = [T2KM11 - $System] $Subject&lt;br /&gt;
Omit Email To = 1&lt;br /&gt;
&lt;br /&gt;
Email System General = xxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* ./start_elogd &amp;amp;&lt;br /&gt;
* firefox http://localhost:8082 # hould show the elog message index&lt;br /&gt;
&lt;br /&gt;
To start elogd automatically when the machine is rebooted, login as root and&lt;br /&gt;
* add this text to /etc/rc.local:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - titan -c &amp;quot;/home/titan/packages/elog/start_elogd&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x /etc/rc.local&lt;br /&gt;
* systemctl start rc-local&lt;br /&gt;
&lt;br /&gt;
To import elog entries from the mhttpd elog, do this:&lt;br /&gt;
&lt;br /&gt;
* cd ~/packages/elog/logbooks&lt;br /&gt;
* ln -s /home/t2km11/online/elog midas&lt;br /&gt;
* cd midas&lt;br /&gt;
* ~/packages/elog/elconv)&lt;br /&gt;
&lt;br /&gt;
== Install https proxy ==&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE OBSOLETE, INSTEAD, &lt;br /&gt;
* GO HERE: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* AND GO HERE: https://midas.triumf.ca/MidasWiki/index.php/Quickstart_Linux#Run_the_MIDAS_Web_Server&lt;br /&gt;
&lt;br /&gt;
FOLLOWING INSTRUCTIONS ARE OBSOLETE...&lt;br /&gt;
&lt;br /&gt;
* login as root to the https proxy machine&lt;br /&gt;
* cd ~root&lt;br /&gt;
* yum install mod_ssl&lt;br /&gt;
* yum install crypto-utils # see http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_monitoring_of_HTTPS_certificates&lt;br /&gt;
* create a certificate request (replace ladd09 with your hostname): openssl req -new -nodes -newkey rsa:2048 -sha256 -out ladd09.csr -keyout ladd09.key (answer: CA, BC, Vancouver, TRIUMF, DAQ, ladd09.triumf.ca, email@email.com&lt;br /&gt;
* sign it by TRIUMF:&lt;br /&gt;
** mail -s &amp;quot;Certificate request&amp;quot; yourself@email.com &amp;amp;lt; ladd09.csr&lt;br /&gt;
** forward this request to Andrew Daviel&lt;br /&gt;
** he will email the signed crt file, copy it to this system as ladd09.crt&lt;br /&gt;
* sign it yourself: openssl x509 -req -days 365 -sha256 -in ladd09.csr -signkey ladd09.key -out ladd09.crt&lt;br /&gt;
* (if the certificate expires, renew it by signing it again)&lt;br /&gt;
* Additional commands for working with certificates:&lt;br /&gt;
** explore the private key: openssl pkey -in ladd09.key -text -noout&lt;br /&gt;
** explore the certificate request: openssl req -in ladd00.csr -text -noout&lt;br /&gt;
** explore the certificate: openssl x509 -in ladd09.crt -noout -text&lt;br /&gt;
* move certificate files to proper system locations:&lt;br /&gt;
* mv ladd09.key  /etc/pki/tls/private/&lt;br /&gt;
* mv ladd09.crt /etc/pki/tls/certs/&lt;br /&gt;
* if selinux is enabled, do this:&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/certs/&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/private/&lt;br /&gt;
** /usr/sbin/setsebool -P httpd_can_network_connect 1&lt;br /&gt;
* open /etc/httpd/conf.d/ssl.conf in a text editor, go to the very bottom and right before the &amp;quot;&amp;lt;/VirtualHost&amp;gt;&amp;quot; entry, add following text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateFile /etc/pki/tls/certs/ladd09.crt &lt;br /&gt;
SSLCertificateKeyFile /etc/pki/tls/private/ladd09.key &lt;br /&gt;
&lt;br /&gt;
ProxyPass /elog/ http://localhost:8082/ retry=1&lt;br /&gt;
ProxyPass /      http://localhost:8080/ retry=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Location /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SSLRequireSSL&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;password protected site&amp;quot;&lt;br /&gt;
Require valid-user&lt;br /&gt;
&lt;br /&gt;
# create password file: touch /etc/httpd/htpasswd&lt;br /&gt;
# to add new user or change password: htpasswd /etc/httpd/htpasswd username&lt;br /&gt;
AuthUserFile /etc/httpd/htpasswd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* comment out duplicate &amp;quot;SSLCertificateFile&amp;quot; and &amp;quot;SSLCertificateKeyFile&amp;quot; elsewhere in the file&lt;br /&gt;
* (optionally) If you got a certificate that is signed by DigiCert or RapidSSL then you&#039;ll need to add a line specifying the certificate chain file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateChainFile /etc/pki/tls/certs/DigiCertCA.crt&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* touch /etc/httpd/htpasswd&lt;br /&gt;
* htpasswd /etc/httpd/htpasswd midas # enter password midas&lt;br /&gt;
* chkconfig httpd on&lt;br /&gt;
* service httpd restart&lt;br /&gt;
* firewall-cmd --add-port=443/tcp --permanent&lt;br /&gt;
* firewall-cmd --reload&lt;br /&gt;
* firewall-cmd --list-all&lt;br /&gt;
* test it&lt;br /&gt;
** test the SSL proxy: https://host/ should yield the midas status page, https://host/elog/ should yield the elog message index&lt;br /&gt;
* in ODB, set &amp;quot;/Elog/URL&amp;quot; to &amp;quot;https://host/elog/&amp;quot;&lt;br /&gt;
* now from the midas status page, the &amp;quot;Elog&amp;quot; button should take us to the https Elog URL&lt;br /&gt;
&lt;br /&gt;
In needed, enable user directories: https://blah/~user in ~user/public_html&lt;br /&gt;
&lt;br /&gt;
* edit /etc/httpd/conf.d/userdir.conf, replace &amp;quot;UserDir disabled&amp;quot; with &amp;quot;UserDir enabled&amp;quot;&lt;br /&gt;
* setsebool -P httpd_enable_homedirs true&lt;br /&gt;
* systemctl restart httpd&lt;br /&gt;
&lt;br /&gt;
== Setup the history mhttpd for faster access to history plots ==&lt;br /&gt;
When running an SSL proxy,&lt;br /&gt;
* start the main mhttpd (&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;orange&amp;lt;/span&amp;gt; command for old mhttpd, &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;green&amp;lt;/span&amp;gt; for new mhttpd with Mongoose(post August2015):&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* start the history mhttpd&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; &amp;quot;mhttpd -p 8072 -D -H&amp;quot;&amp;lt;/span&amp;gt; or&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* set ODB /History/URL to &amp;quot;http://alphacpc09.cern.ch:8072/HS/&amp;quot;&lt;br /&gt;
* open the MIDAS status page&lt;br /&gt;
* go to the history section, try to open any history plot, observe that the history plot gif image loads correctly, inspect it&#039;s URL (use &amp;quot;copy image URL&amp;quot; or &amp;quot;view source&amp;quot;, etc), it should point to port 8072 causing connection to the history mhttpd.&lt;br /&gt;
* continue with these instructions to setup history mhttpd access through an SSL proxy:&lt;br /&gt;
* setup SSL proxy access (required mod_proxy_html)&lt;br /&gt;
** login as root to the SSL proxy machine&lt;br /&gt;
** on SL5, install the missing mod_proxy_html httpd module:&lt;br /&gt;
** yum install httpd-devel libxml2-devel&lt;br /&gt;
** wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.tar.bz2&lt;br /&gt;
** tar xjvf mod_proxy_html.tar.bz2 &lt;br /&gt;
** cd mod_proxy_html&lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_proxy_html.c &lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_xml2enc.c&lt;br /&gt;
** cd /etc/httpd/conf.d, add this to ssl.conf:&lt;br /&gt;
&lt;br /&gt;
;before the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# proxy the MIDAS web servers  &lt;br /&gt;
LoadModule  xml2enc_module       modules/mod_xml2enc.so  &lt;br /&gt;
LoadModule  proxy_html_module    modules/mod_proxy_html.so  &lt;br /&gt;
ProxyHTMLLinks  a               href  &lt;br /&gt;
ProxyHTMLLinks  link            href  &lt;br /&gt;
ProxyHTMLLinks  img             src  &lt;br /&gt;
#ProxyHTMLEnable On  &lt;br /&gt;
ProxyRequests off  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;after the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ALPHA1 history access &lt;br /&gt;
ProxyPass /alpha1/history/   http://alphacpc09.cern.ch:8072/HS/  retry=1 &lt;br /&gt;
ProxyPass /alpha1/           http://alphacpc09.cern.ch:8071/     retry=1 &lt;br /&gt;
 &lt;br /&gt;
ProxyHTMLEnable On  &lt;br /&gt;
ProxyHTMLURLMap http://alphacpc09.cern.ch:8072/HS/ /alpha1/history/ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;adjust:&lt;br /&gt;
*&amp;quot;alpha1&amp;quot; is the experiment name&lt;br /&gt;
*&amp;quot;alphacpc09.cern.ch&amp;quot; is the machine running mhttpd&lt;br /&gt;
*&amp;quot;8071&amp;quot; is the port number of the main mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* &amp;quot;8072&amp;quot; is the port number of the history mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8072 -D -H&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]] [[Category:Buffer]] [[Category:Driver]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2625</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2625"/>
		<updated>2017-03-02T00:21:28Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Start MIDAS on boot */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
&lt;br /&gt;
Install the ROOT analyzer package:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add ROOTANASYS=$HOME/packages/rootana to the login file.&lt;br /&gt;
&lt;br /&gt;
Install the JSROOT package:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://github.com/linev/jsroot.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add JSROOTSYS=$HOME/packages/jsroot to the login file.&lt;br /&gt;
&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page there will be 3 new equipment entries:&lt;br /&gt;
* test -&amp;gt; empty data bank for daq speed benchmarking&lt;br /&gt;
* slow -&amp;gt; example slow controls data for testing the midas history plots&lt;br /&gt;
* random -&amp;gt; example collection of data banks for testing the analyzer&lt;br /&gt;
&lt;br /&gt;
Start a run.&lt;br /&gt;
&lt;br /&gt;
Observe event counters are incrementing, output data file size is growing.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Create a history plot ==&lt;br /&gt;
&lt;br /&gt;
Go to the MIDAS &amp;quot;History&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
Say &amp;quot;new&amp;quot;, panel name &amp;quot;test&amp;quot;. In the history editor select event &amp;quot;slow&amp;quot;, say &amp;quot;save&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
History plot &amp;quot;test&amp;quot; should open with a sine-wave plot. Data on the plot should update as long as &amp;quot;fetest&amp;quot; is running. (there is no need to start a run).&lt;br /&gt;
&lt;br /&gt;
Press web browser &amp;quot;reload&amp;quot; to update the plot.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
== Start MIDAS on boot ==&lt;br /&gt;
&lt;br /&gt;
To start MIDAS mhttpd, mlogger and elogd at boot time, add following cron entries:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[iris@iris00 ~]$ crontab -l&lt;br /&gt;
@reboot /home/iris/packages/midas/linux/bin/mhttpd -D&lt;br /&gt;
@reboot /home/iris/packages/midas/linux/bin/mlogger -D&lt;br /&gt;
@reboot /home/iris/packages/elog/elogd -c /home/iris/packages/elog/elogd.cfgiris -D&lt;br /&gt;
[iris@iris00 ~]$ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2624</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2624"/>
		<updated>2017-03-02T00:19:30Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Customizing your experiment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
&lt;br /&gt;
Install the ROOT analyzer package:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add ROOTANASYS=$HOME/packages/rootana to the login file.&lt;br /&gt;
&lt;br /&gt;
Install the JSROOT package:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://github.com/linev/jsroot.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add JSROOTSYS=$HOME/packages/jsroot to the login file.&lt;br /&gt;
&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page there will be 3 new equipment entries:&lt;br /&gt;
* test -&amp;gt; empty data bank for daq speed benchmarking&lt;br /&gt;
* slow -&amp;gt; example slow controls data for testing the midas history plots&lt;br /&gt;
* random -&amp;gt; example collection of data banks for testing the analyzer&lt;br /&gt;
&lt;br /&gt;
Start a run.&lt;br /&gt;
&lt;br /&gt;
Observe event counters are incrementing, output data file size is growing.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Create a history plot ==&lt;br /&gt;
&lt;br /&gt;
Go to the MIDAS &amp;quot;History&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
Say &amp;quot;new&amp;quot;, panel name &amp;quot;test&amp;quot;. In the history editor select event &amp;quot;slow&amp;quot;, say &amp;quot;save&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
History plot &amp;quot;test&amp;quot; should open with a sine-wave plot. Data on the plot should update as long as &amp;quot;fetest&amp;quot; is running. (there is no need to start a run).&lt;br /&gt;
&lt;br /&gt;
Press web browser &amp;quot;reload&amp;quot; to update the plot.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
== Start MIDAS on boot ==&lt;br /&gt;
&lt;br /&gt;
AAA&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Security&amp;diff=2623</id>
		<title>Security</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Security&amp;diff=2623"/>
		<updated>2017-03-01T23:51:30Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MIDAS programs on remote machines */&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;
* [[mhttpd]] web server&lt;br /&gt;
* [[odbedit]]&lt;br /&gt;
* [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] ODB subtree&lt;br /&gt;
* [[mserver]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
= Access Control to a MIDAS experiment =&lt;br /&gt;
&lt;br /&gt;
Historically, by default there has been no restriction for any user to connect locally or remotely to a given experiment.  This has now changed (August 2015). &lt;br /&gt;
The Web Server [[mhttpd]] by default now requires an SSL Certificate and a username and password (see [[#Web Access]]).&lt;br /&gt;
&lt;br /&gt;
Other network security issues have also been addressed (see  [https://midas.triumf.ca/elog/Midas/1088 Note 1088]). Changes to [[mserver]] (August 2015) make the default behaviour to reject all external network connections ([https://midas.triumf.ca/elog/Midas/1090 Note 1090]), so that only programs running on the localhost will be allowed. To allow access from remote machines, the user will have to take action as described [[#MIDAS programs on remote machines|below]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Web Access ==&lt;br /&gt;
In versions prior to May 2015, the default web access to MIDAS and ELOG uses the &amp;quot;http:&amp;quot; protocol which is insecure. In this case, all information is transmitted as clear text meaning that secret, confidential and sensitive information (such as the MIDAS and ELOG passwords and usernames) can be stolen &amp;quot;easily&amp;quot;. This means that even &amp;quot;password protected&amp;quot; MIDAS and ELOG pages are not adequately protected if accessed using the &amp;quot;http&amp;quot; method. Until now, an SSL (https) proxy had to be set up to provide reasonable security for experiments.&lt;br /&gt;
&lt;br /&gt;
Recent versions of elogd (ELOG) do support SSL https:// connections, and&lt;br /&gt;
the Web Server [[mhttpd]] has recently (May 2015) been updated to use OpenSSL to provide secure HTTPS connections via the [https://bitbucket.org/tmidas/midas/src/ecb9a8537448a8a43f7f9a2bfdb82e578208cde3/doc/mongoose/?at=develop Mongoose] web server. This limits access by default, by requiring a username and password - see [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]] for more information. This option provides a similar level of security to an HTTP proxy.&lt;br /&gt;
 &lt;br /&gt;
=== Which security option to choose? ===&lt;br /&gt;
&lt;br /&gt;
For a small operation that does not require root access to the host computer, mhttpd with mongoose is a good light weight solution. It is ideal for small experiments that until now have been using the &amp;quot;http:&amp;quot; protocol for mhttpd.&lt;br /&gt;
&lt;br /&gt;
For a more elaborate setup with private networks etc., APACHE https proxy is probably better. For big experiments, resources like webcams,ganglia, couchdb, etc. also need password protection and APACHE https can provide all this.&lt;br /&gt;
&lt;br /&gt;
=== Which one is easier to setup? ===&lt;br /&gt;
&lt;br /&gt;
*  mhttpd with mongoose is fairly simple - you have to create a password file and provide a properly signed https certificate - see [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]]&lt;br /&gt;
*  apache httpd is fairly straightforward if you follow well written instructions (such as we provide for using it with midas), but you do need root access and you do have to edit a good number of config files. Note that mhttpd with mongoose can be run with an SSL proxy - see [[Setup MIDAS experiment#using an HTTPS/SSL proxy]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== MIDAS programs running on localhost ==&lt;br /&gt;
&lt;br /&gt;
Out-of-the-box MIDAS is now secure (August 2015). By default, connections from the outside are not possible.  MIDAS RPC TCP ports are bound to the localhost interface.&lt;br /&gt;
This configuration is suitable for testing MIDAS on a laptop and for running a simple experiment where all programs run on one machine.&lt;br /&gt;
MIDAS ports (except for the mhttpd web ports) do not show up on network port scans.&lt;br /&gt;
&lt;br /&gt;
The change in binding UDP ports is generally incompatible with previous versions of MIDAS, so all MIDAS programs should be rebuild and restarted. If rebuilding all MIDAS programs is &lt;br /&gt;
impossible see  [https://midas.triumf.ca/elog/Midas/1090 Note 1090]).&lt;br /&gt;
&lt;br /&gt;
[[mserver]] will still work in this localhost-restricted configuration - one should use  &amp;quot;[[odbedit]] -h localhost&amp;quot; to connect. Multiple mserver instances on &lt;br /&gt;
the same machine - using different TCP ports via &amp;quot;-p&amp;quot; and ODB [[/Experiment ODB tree#midas server port|/Experiment/midas server port]] - are still supported.&lt;br /&gt;
&lt;br /&gt;
== MIDAS programs on remote machines ==&lt;br /&gt;
&lt;br /&gt;
To run MIDAS programs on remote machines the following is now required:&lt;br /&gt;
# change the ODB setting [[/Experiment ODB tree#Enable non-localhost RPC|/Experiment/Security/Enable non-localhost RPC]] to &amp;quot;yes&amp;quot; and restart [[mserver]]&lt;br /&gt;
# add the hostnames of all remote machines that will run MIDAS programs to the MIDAS RPC access control list in ODB key [[/Experiment ODB tree#Allowed hosts|/Experiment/Security/RPC hosts/Allowed hosts]].&lt;br /&gt;
# if needed, add firewall rules on both the MIDAS host and on all the MIDAS client machines - each machine running MIDAS programs must have permission to connect to all other machines running MIDAS programs.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
firewall-cmd --permanent --add-rich-rule=&amp;quot;rule family=&amp;quot;ipv4&amp;quot; source address=&amp;quot;x.y.z.w/32&amp;quot; port protocol=&amp;quot;tcp&amp;quot; port=&amp;quot;0-65535&amp;quot; accept&amp;quot;&lt;br /&gt;
... repeat for the midas host and for all client machines, replace x.y.z.w with the actual IP addresses.&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To avoid &amp;quot;guessing&amp;quot; the host names expected by MIDAS, follow the following procedure: &lt;br /&gt;
* On the local machine (&amp;quot;daq06&amp;quot;) set ODB key &amp;quot;enable non-localhost rpc&amp;quot; to &amp;quot;yes&amp;quot; and restart the [[mserver]] (step 1 above)&lt;br /&gt;
* go to the remote machine (&amp;quot;ladd21&amp;quot;) and try to start the MIDAS program, i.e. &amp;quot;[[odbedit]] -h daq06&amp;quot;. This will bomb and there will be a message in the [[Message System#midas.log|Midas log file]] rejecting the connection from unallowed host &#039;ladd21.triumf.ca&#039;. &lt;br /&gt;
* Add this host to &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Experiment/Security/RPC hosts/Allowed hosts&amp;lt;/span&amp;gt;. &lt;br /&gt;
* After you add this hostname to &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;RPC hosts&amp;lt;/span&amp;gt;, you should see messages in the [[Message System#midas.log|Midas log file]] about reloading the access control list&lt;br /&gt;
* try connecting again, it should work now.&lt;br /&gt;
 &lt;br /&gt;
;NOTE&lt;br /&gt;
If MIDAS clients have to connect from random hosts (i.e. dynamically assigned random DHCP addresses), one can disable the host name checks by setting ODB key [[/Experiment ODB tree#Disable RPC hosts check|/experiment/security/Disable RPC hosts check]] to &amp;quot;yes&amp;quot;. This configuration is insecure and should only be done on a private network behind a firewall.&lt;br /&gt;
&lt;br /&gt;
= ODB access control =&lt;br /&gt;
Note that &#039;&#039;&#039;other forms of ODB access control&#039;&#039;&#039; independent of these security features is also available which can protect the experiment from accidental access by authorized users:&lt;br /&gt;
*    Write access can be restricted while a run is in progress (see [[Lock when running]] )&lt;br /&gt;
*    Individual keys or subtrees in the experiment&#039;s ODB can be set &amp;quot;read only&amp;quot; with the [[odbedit]] command chmod.&lt;br /&gt;
*    [[Custom Page|Custom web pages]] can provide experimenters with access to a subset of ODB keys necessary for the experiment. By [[Status Page#suppressed|hiding]] the [[ODB Page]] access button, the ODB can be protected from non-expert access via the web server.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color:whitesmoke&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Security on OLDER (pre-August 2015) versions of MIDAS =&lt;br /&gt;
&lt;br /&gt;
Versions of MIDAS older than August 2015 are vulnerable to malicious/unauthorized access. Network security on old versions can be enhanced by implementing a &#039;&#039;&#039;firewall&#039;&#039;&#039; and/or restrictions on off-site access. This kind of security can be provided by [[Setup MIDAS experiment#Setting up an HTTP proxy|setting up an HTTP proxy]] to [[mhttpd]] .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Protect experiment from accidental access (old MIDAS versions) ==&lt;br /&gt;
&lt;br /&gt;
The MIDAS system provides a means to setup access restrictions using the ODB in order to protect the experiment from accidental or unauthorized access. &#039;&#039;&#039;This will not stop malicious or determined hackers&#039;&#039;&#039; but may prevent mistakes by authorized users.  These security features are still available, but their usefulness has largely been superceded by the improved security features implemented August 2015 (see [[#Access Control to a MIDAS experiment]]);&lt;br /&gt;
&lt;br /&gt;
There are two levels of access restriction available each of which can be enabled independently:&lt;br /&gt;
&lt;br /&gt;
*    To restrict write access via the web by requiring a password before any parameter can be changed.&lt;br /&gt;
*    To require a password before MIDAS clients can start running on the host.&lt;br /&gt;
&lt;br /&gt;
The user can select either or both of these security features.&lt;br /&gt;
&lt;br /&gt;
== Restrict user access (old MIDAS versions) ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: this is not proof against malicious access.&#039;&#039;&#039; See [[#Access Control to a MIDAS experiment]].&lt;br /&gt;
&lt;br /&gt;
The ODB [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] subtree can also be used to restrict access to the experiment via the Web. This subtree is automatically created (if not already present) when the   {{Odbedit cmd|cmd=webpasswd}} is issued as follows:&lt;br /&gt;
&lt;br /&gt;
  C:\online&amp;gt;odbedit&lt;br /&gt;
  [local:Default:S]/&amp;gt;cd Experiment/&lt;br /&gt;
  [local]/&amp;gt;webpasswd&lt;br /&gt;
  Password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
  Retype password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the {{Odbedit cmd|cmd=webpasswd}}, a new ODB key i.e. [[/Experiment ODB tree #/Experiment/Security/Web Password |/Experiment/Security/Web Password]] will &lt;br /&gt;
be present containing the encrypted web password.&lt;br /&gt;
&lt;br /&gt;
If this web access restriction is set up, the user will be requested to provide the &amp;quot;Web Password&amp;quot; when accessing the requested experiment in &amp;quot;Write Access&amp;quot; mode. The &amp;quot;Read Only Access&amp;quot; mode is still available to all users of older versions of [[mhttpd]], or those who supply the username and password now required by [[mhttpd]] (May 2015). &lt;br /&gt;
&lt;br /&gt;
 [local:bnqr:S]/Experiment&amp;gt;ls Security/&lt;br /&gt;
 Web Password                    pon4@#@%SSDF2&lt;br /&gt;
&lt;br /&gt;
== Restrict client access (old MIDAS versions) ==&lt;br /&gt;
&#039;&#039;&#039;NOTE: this is not proof against malicious access.&#039;&#039;&#039; See [[#Access Control to a MIDAS experiment]].&lt;br /&gt;
&lt;br /&gt;
In order to restrict accidental access to the experiment, a password mechanism can to be defined. This is provided by the [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] subtree in odb. This subtree is automatically created (if not already present) when the [[odbedit]] command passwd is issued as follows:&lt;br /&gt;
&lt;br /&gt;
  C:\online&amp;gt;odbedit&lt;br /&gt;
  [local:Default:S]/&amp;gt;cd Experiment/&lt;br /&gt;
  [local]/&amp;gt;passwd&lt;br /&gt;
  Password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
  Retype password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the {{Odbedit cmd|cmd=passwd}}, the  {{Odbpath|path=/Experiment/Security}} subtree will be present.&lt;br /&gt;
&lt;br /&gt;
=== Allowing access without password (old MIDAS versions) ===&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
While  [[#Restrict client access|restricting access]] can make sense to deny access to outsider to a given experiment, it can be annoying for the people working directly at the back-end computer or for an automatic frontend reloading mechanism. To address this problem, specific hosts and clients can be exempt from having to supply a password before being granted full access.&lt;br /&gt;
&lt;br /&gt;
==== Allowed hosts (old MIDAS versions) ====&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
Hostnames to be allowed full access to the ODB are listed in the [[/Experiment ODB tree #/Experiment/Security/Allowed hosts subtree |/Experiment/Security/Allowed hosts]] subtree, e.g.&lt;br /&gt;
&lt;br /&gt;
  [local]/&amp;gt;cd &amp;quot;/Experiment/Security/Allowed hosts&amp;quot;&lt;br /&gt;
  [local]rhosts&amp;gt;create int myhost.domain&lt;br /&gt;
  [local]rhosts&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;myHost.domain&amp;gt; is to be replaced by the full IP address of the host requesting full clearance, e.g &amp;quot;pierre.triumf.ca&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Allowed programs (old MIDAS versions) ====&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
Programs (i.e. clients) to be allowed full access to the ODB (regardless of the node on which they are running) can be listed in the&lt;br /&gt;
[[/Experiment ODB tree #/Experiment/Security/Allowed programs subtree |/Experiment/Security/Allowed programs]] subtree, &lt;br /&gt;
&lt;br /&gt;
  [local]/&amp;gt;cd &amp;quot;/Experiment/Security/Allowed programs&amp;quot;&lt;br /&gt;
  [local]:S&amp;gt;create int mstat&lt;br /&gt;
  [local]:S&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;  &amp;lt;!-- obsolescent - silver --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Experiment]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Security&amp;diff=2622</id>
		<title>Security</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Security&amp;diff=2622"/>
		<updated>2017-03-01T23:50:00Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* MIDAS programs on remote machines */&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;
* [[mhttpd]] web server&lt;br /&gt;
* [[odbedit]]&lt;br /&gt;
* [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] ODB subtree&lt;br /&gt;
* [[mserver]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
= Access Control to a MIDAS experiment =&lt;br /&gt;
&lt;br /&gt;
Historically, by default there has been no restriction for any user to connect locally or remotely to a given experiment.  This has now changed (August 2015). &lt;br /&gt;
The Web Server [[mhttpd]] by default now requires an SSL Certificate and a username and password (see [[#Web Access]]).&lt;br /&gt;
&lt;br /&gt;
Other network security issues have also been addressed (see  [https://midas.triumf.ca/elog/Midas/1088 Note 1088]). Changes to [[mserver]] (August 2015) make the default behaviour to reject all external network connections ([https://midas.triumf.ca/elog/Midas/1090 Note 1090]), so that only programs running on the localhost will be allowed. To allow access from remote machines, the user will have to take action as described [[#MIDAS programs on remote machines|below]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Web Access ==&lt;br /&gt;
In versions prior to May 2015, the default web access to MIDAS and ELOG uses the &amp;quot;http:&amp;quot; protocol which is insecure. In this case, all information is transmitted as clear text meaning that secret, confidential and sensitive information (such as the MIDAS and ELOG passwords and usernames) can be stolen &amp;quot;easily&amp;quot;. This means that even &amp;quot;password protected&amp;quot; MIDAS and ELOG pages are not adequately protected if accessed using the &amp;quot;http&amp;quot; method. Until now, an SSL (https) proxy had to be set up to provide reasonable security for experiments.&lt;br /&gt;
&lt;br /&gt;
Recent versions of elogd (ELOG) do support SSL https:// connections, and&lt;br /&gt;
the Web Server [[mhttpd]] has recently (May 2015) been updated to use OpenSSL to provide secure HTTPS connections via the [https://bitbucket.org/tmidas/midas/src/ecb9a8537448a8a43f7f9a2bfdb82e578208cde3/doc/mongoose/?at=develop Mongoose] web server. This limits access by default, by requiring a username and password - see [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]] for more information. This option provides a similar level of security to an HTTP proxy.&lt;br /&gt;
 &lt;br /&gt;
=== Which security option to choose? ===&lt;br /&gt;
&lt;br /&gt;
For a small operation that does not require root access to the host computer, mhttpd with mongoose is a good light weight solution. It is ideal for small experiments that until now have been using the &amp;quot;http:&amp;quot; protocol for mhttpd.&lt;br /&gt;
&lt;br /&gt;
For a more elaborate setup with private networks etc., APACHE https proxy is probably better. For big experiments, resources like webcams,ganglia, couchdb, etc. also need password protection and APACHE https can provide all this.&lt;br /&gt;
&lt;br /&gt;
=== Which one is easier to setup? ===&lt;br /&gt;
&lt;br /&gt;
*  mhttpd with mongoose is fairly simple - you have to create a password file and provide a properly signed https certificate - see [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]]&lt;br /&gt;
*  apache httpd is fairly straightforward if you follow well written instructions (such as we provide for using it with midas), but you do need root access and you do have to edit a good number of config files. Note that mhttpd with mongoose can be run with an SSL proxy - see [[Setup MIDAS experiment#using an HTTPS/SSL proxy]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== MIDAS programs running on localhost ==&lt;br /&gt;
&lt;br /&gt;
Out-of-the-box MIDAS is now secure (August 2015). By default, connections from the outside are not possible.  MIDAS RPC TCP ports are bound to the localhost interface.&lt;br /&gt;
This configuration is suitable for testing MIDAS on a laptop and for running a simple experiment where all programs run on one machine.&lt;br /&gt;
MIDAS ports (except for the mhttpd web ports) do not show up on network port scans.&lt;br /&gt;
&lt;br /&gt;
The change in binding UDP ports is generally incompatible with previous versions of MIDAS, so all MIDAS programs should be rebuild and restarted. If rebuilding all MIDAS programs is &lt;br /&gt;
impossible see  [https://midas.triumf.ca/elog/Midas/1090 Note 1090]).&lt;br /&gt;
&lt;br /&gt;
[[mserver]] will still work in this localhost-restricted configuration - one should use  &amp;quot;[[odbedit]] -h localhost&amp;quot; to connect. Multiple mserver instances on &lt;br /&gt;
the same machine - using different TCP ports via &amp;quot;-p&amp;quot; and ODB [[/Experiment ODB tree#midas server port|/Experiment/midas server port]] - are still supported.&lt;br /&gt;
&lt;br /&gt;
== MIDAS programs on remote machines ==&lt;br /&gt;
&lt;br /&gt;
To run MIDAS programs on remote machines the following is now required:&lt;br /&gt;
# change the ODB setting [[/Experiment ODB tree#Enable non-localhost RPC|/Experiment/Security/Enable non-localhost RPC]] to &amp;quot;yes&amp;quot; and restart [[mserver]]&lt;br /&gt;
# add the hostnames of all remote machines that will run MIDAS programs to the MIDAS RPC access control list in ODB key [[/Experiment ODB tree#Allowed hosts|/Experiment/Security/RPC hosts/Allowed hosts]].&lt;br /&gt;
# if needed, add firewall rules on both the MIDAS host and on all the MIDAS client machines:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
firewall-cmd --permanent --add-rich-rule=&amp;quot;rule family=&amp;quot;ipv4&amp;quot; source address=&amp;quot;x.y.z.w/32&amp;quot; port protocol=&amp;quot;tcp&amp;quot; port=&amp;quot;0-65535&amp;quot; accept&amp;quot;&lt;br /&gt;
... repeat for all client machines&lt;br /&gt;
firewall-cmd --reload&lt;br /&gt;
firewall-cmd --list-all&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To avoid &amp;quot;guessing&amp;quot; the host names expected by MIDAS, follow the following procedure: &lt;br /&gt;
* On the local machine (&amp;quot;daq06&amp;quot;) set ODB key &amp;quot;enable non-localhost rpc&amp;quot; to &amp;quot;yes&amp;quot; and restart the [[mserver]] (step 1 above)&lt;br /&gt;
* go to the remote machine (&amp;quot;ladd21&amp;quot;) and try to start the MIDAS program, i.e. &amp;quot;[[odbedit]] -h daq06&amp;quot;. This will bomb and there will be a message in the [[Message System#midas.log|Midas log file]] rejecting the connection from unallowed host &#039;ladd21.triumf.ca&#039;. &lt;br /&gt;
* Add this host to &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;/Experiment/Security/RPC hosts/Allowed hosts&amp;lt;/span&amp;gt;. &lt;br /&gt;
* After you add this hostname to &amp;lt;span style=&amp;quot;color: purple; font-style:italic;&amp;quot;&amp;gt;RPC hosts&amp;lt;/span&amp;gt;, you should see messages in the [[Message System#midas.log|Midas log file]] about reloading the access control list&lt;br /&gt;
* try connecting again, it should work now.&lt;br /&gt;
 &lt;br /&gt;
;NOTE&lt;br /&gt;
If MIDAS clients have to connect from random hosts (i.e. dynamically assigned random DHCP addresses), one can disable the host name checks by setting ODB key [[/Experiment ODB tree#Disable RPC hosts check|/experiment/security/Disable RPC hosts check]] to &amp;quot;yes&amp;quot;. This configuration is insecure and should only be done on a private network behind a firewall.&lt;br /&gt;
&lt;br /&gt;
= ODB access control =&lt;br /&gt;
Note that &#039;&#039;&#039;other forms of ODB access control&#039;&#039;&#039; independent of these security features is also available which can protect the experiment from accidental access by authorized users:&lt;br /&gt;
*    Write access can be restricted while a run is in progress (see [[Lock when running]] )&lt;br /&gt;
*    Individual keys or subtrees in the experiment&#039;s ODB can be set &amp;quot;read only&amp;quot; with the [[odbedit]] command chmod.&lt;br /&gt;
*    [[Custom Page|Custom web pages]] can provide experimenters with access to a subset of ODB keys necessary for the experiment. By [[Status Page#suppressed|hiding]] the [[ODB Page]] access button, the ODB can be protected from non-expert access via the web server.   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
------------&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;background-color:whitesmoke&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Security on OLDER (pre-August 2015) versions of MIDAS =&lt;br /&gt;
&lt;br /&gt;
Versions of MIDAS older than August 2015 are vulnerable to malicious/unauthorized access. Network security on old versions can be enhanced by implementing a &#039;&#039;&#039;firewall&#039;&#039;&#039; and/or restrictions on off-site access. This kind of security can be provided by [[Setup MIDAS experiment#Setting up an HTTP proxy|setting up an HTTP proxy]] to [[mhttpd]] .&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Protect experiment from accidental access (old MIDAS versions) ==&lt;br /&gt;
&lt;br /&gt;
The MIDAS system provides a means to setup access restrictions using the ODB in order to protect the experiment from accidental or unauthorized access. &#039;&#039;&#039;This will not stop malicious or determined hackers&#039;&#039;&#039; but may prevent mistakes by authorized users.  These security features are still available, but their usefulness has largely been superceded by the improved security features implemented August 2015 (see [[#Access Control to a MIDAS experiment]]);&lt;br /&gt;
&lt;br /&gt;
There are two levels of access restriction available each of which can be enabled independently:&lt;br /&gt;
&lt;br /&gt;
*    To restrict write access via the web by requiring a password before any parameter can be changed.&lt;br /&gt;
*    To require a password before MIDAS clients can start running on the host.&lt;br /&gt;
&lt;br /&gt;
The user can select either or both of these security features.&lt;br /&gt;
&lt;br /&gt;
== Restrict user access (old MIDAS versions) ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NOTE: this is not proof against malicious access.&#039;&#039;&#039; See [[#Access Control to a MIDAS experiment]].&lt;br /&gt;
&lt;br /&gt;
The ODB [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] subtree can also be used to restrict access to the experiment via the Web. This subtree is automatically created (if not already present) when the   {{Odbedit cmd|cmd=webpasswd}} is issued as follows:&lt;br /&gt;
&lt;br /&gt;
  C:\online&amp;gt;odbedit&lt;br /&gt;
  [local:Default:S]/&amp;gt;cd Experiment/&lt;br /&gt;
  [local]/&amp;gt;webpasswd&lt;br /&gt;
  Password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
  Retype password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the {{Odbedit cmd|cmd=webpasswd}}, a new ODB key i.e. [[/Experiment ODB tree #/Experiment/Security/Web Password |/Experiment/Security/Web Password]] will &lt;br /&gt;
be present containing the encrypted web password.&lt;br /&gt;
&lt;br /&gt;
If this web access restriction is set up, the user will be requested to provide the &amp;quot;Web Password&amp;quot; when accessing the requested experiment in &amp;quot;Write Access&amp;quot; mode. The &amp;quot;Read Only Access&amp;quot; mode is still available to all users of older versions of [[mhttpd]], or those who supply the username and password now required by [[mhttpd]] (May 2015). &lt;br /&gt;
&lt;br /&gt;
 [local:bnqr:S]/Experiment&amp;gt;ls Security/&lt;br /&gt;
 Web Password                    pon4@#@%SSDF2&lt;br /&gt;
&lt;br /&gt;
== Restrict client access (old MIDAS versions) ==&lt;br /&gt;
&#039;&#039;&#039;NOTE: this is not proof against malicious access.&#039;&#039;&#039; See [[#Access Control to a MIDAS experiment]].&lt;br /&gt;
&lt;br /&gt;
In order to restrict accidental access to the experiment, a password mechanism can to be defined. This is provided by the [[/Experiment ODB tree #/Experiment/Security |/Experiment/Security]] subtree in odb. This subtree is automatically created (if not already present) when the [[odbedit]] command passwd is issued as follows:&lt;br /&gt;
&lt;br /&gt;
  C:\online&amp;gt;odbedit&lt;br /&gt;
  [local:Default:S]/&amp;gt;cd Experiment/&lt;br /&gt;
  [local]/&amp;gt;passwd&lt;br /&gt;
  Password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
  Retype password:&amp;lt;xxxx&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After running the {{Odbedit cmd|cmd=passwd}}, the  {{Odbpath|path=/Experiment/Security}} subtree will be present.&lt;br /&gt;
&lt;br /&gt;
=== Allowing access without password (old MIDAS versions) ===&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
While  [[#Restrict client access|restricting access]] can make sense to deny access to outsider to a given experiment, it can be annoying for the people working directly at the back-end computer or for an automatic frontend reloading mechanism. To address this problem, specific hosts and clients can be exempt from having to supply a password before being granted full access.&lt;br /&gt;
&lt;br /&gt;
==== Allowed hosts (old MIDAS versions) ====&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
Hostnames to be allowed full access to the ODB are listed in the [[/Experiment ODB tree #/Experiment/Security/Allowed hosts subtree |/Experiment/Security/Allowed hosts]] subtree, e.g.&lt;br /&gt;
&lt;br /&gt;
  [local]/&amp;gt;cd &amp;quot;/Experiment/Security/Allowed hosts&amp;quot;&lt;br /&gt;
  [local]rhosts&amp;gt;create int myhost.domain&lt;br /&gt;
  [local]rhosts&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;myHost.domain&amp;gt; is to be replaced by the full IP address of the host requesting full clearance, e.g &amp;quot;pierre.triumf.ca&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Allowed programs (old MIDAS versions) ====&lt;br /&gt;
NOTE: This feature has been superceded by [[#Access Control to a MIDAS experiment]] for [[mhttpd]] versions May 2015 or later.&lt;br /&gt;
&lt;br /&gt;
Programs (i.e. clients) to be allowed full access to the ODB (regardless of the node on which they are running) can be listed in the&lt;br /&gt;
[[/Experiment ODB tree #/Experiment/Security/Allowed programs subtree |/Experiment/Security/Allowed programs]] subtree, &lt;br /&gt;
&lt;br /&gt;
  [local]/&amp;gt;cd &amp;quot;/Experiment/Security/Allowed programs&amp;quot;&lt;br /&gt;
  [local]:S&amp;gt;create int mstat&lt;br /&gt;
  [local]:S&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;  &amp;lt;!-- obsolescent - silver --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Security]] [[Category:Experiment]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2567</id>
		<title>Setup MIDAS experiment at TRIUMF</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2567"/>
		<updated>2016-11-21T21:44:12Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Prepare the user account */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This page describes setting up a MIDAS experiment at TRIUMF. This information can be adapted for other sites.&lt;br /&gt;
&lt;br /&gt;
== Environment variables ==&lt;br /&gt;
* &#039;&#039;&#039;MIDASSYS&#039;&#039;&#039; Base directory of the MIDAS package, midas and mxml should be at the same level.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPTAB&#039;&#039;&#039; Experiment definition file&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_SERVER_HOST&#039;&#039;&#039; MIDAS host server name for remote midas connections.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPT_NAME&#039;&#039;&#039; Experiment name&lt;br /&gt;
&lt;br /&gt;
== Standard layout of MIDAS experiment ==&lt;br /&gt;
The following shows the directory layout of a standard MIDAS experiment: &lt;br /&gt;
&lt;br /&gt;
 /home/exptuser/&lt;br /&gt;
                packages/&lt;br /&gt;
                        root                   &amp;lt;---- ROOT&lt;br /&gt;
                        mxml&lt;br /&gt;
                        mscb&lt;br /&gt;
                        midas/                 &amp;lt;---- MIDAS&lt;br /&gt;
                              linux/{lib,bin}       &amp;lt;---- binaries matching the selected 64-bit/32-bit flavour of ROOT&lt;br /&gt;
                              linux-m32/{lib,bin}   &amp;lt;---- limited function 32-bit binaries for 32-bit frontend machines, build by &amp;quot;make linux32&amp;quot;&lt;br /&gt;
                              linux-m64/{lib,bin}   &amp;lt;---- limited function 64-bit binaries (only needed if ROOT and linux/bin are 32-bit)&lt;br /&gt;
                              linux-arm/{lib,bin}   &amp;lt;---- full function ARM cross-compiled using &amp;quot;make linuxarm&amp;quot;&lt;br /&gt;
                              linux-crosscompile/{lib,bin}  &amp;lt;---- cross-compiled limited function binaries for PPC and ARM frontends (see Makefile)&lt;br /&gt;
                        rootana                &amp;lt;---- ROOT analyzer&lt;br /&gt;
                        roody                  &amp;lt;---- graphical online histogram viewer for MIDAS and ROOTANA&lt;br /&gt;
                 online/&lt;br /&gt;
                        exptab                         &amp;lt;---- experiment definition&lt;br /&gt;
                        {.ODB,.SYSTEM,.SYSMSG,etc}.SHM &amp;lt;---- MIDAS shared memory save files&lt;br /&gt;
                        src                            &amp;lt;---- experiment frontend sources&lt;br /&gt;
                        bin,scripts&lt;br /&gt;
                        elog                           &amp;lt;---- MIDAS elog&lt;br /&gt;
                        history                        &amp;lt;---- MIDAS history&lt;br /&gt;
                        data -&amp;gt; /data/exptname/current &amp;lt;---- symlink to the data directory&lt;br /&gt;
 /data/exptname/current                                &amp;lt;---- experiment data directory with ODB save files and MIDAS .mid/.mid.gz data files&lt;br /&gt;
&lt;br /&gt;
== Prepare computers ==&lt;br /&gt;
&lt;br /&gt;
On some operating systems, several MIDAS functions require administrator access:&lt;br /&gt;
&lt;br /&gt;
* on el7 linux (SL7/CC7/CentOS7/RHEL7) - access to mhttpd port 8443 requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - access to mserver to run frontends and other programs on some other computer requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - on the frontend machines (and other machines that will connect to the mserver, the same firewall rule needs to be created (use the IP address of the machine running the mserver)&lt;br /&gt;
&lt;br /&gt;
== Prepare the user account ==&lt;br /&gt;
&amp;lt;div id=&amp;quot;NOTES&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Setup the user account for running this instance of midas. For machines part of the LADD cluster, follow these  [http://daq-plone.triumf.ca/SM/docs/local/NewLaddUser] instructions.&lt;br /&gt;
* check that the account is using the /bin/bash shell&lt;br /&gt;
* make $HOME/.profile look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/echo You must source&lt;br /&gt;
&lt;br /&gt;
export SVN_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export MIDASSYS=$HOME/packages/midas&lt;br /&gt;
export ROOTANASYS=$HOME/packages/rootana&lt;br /&gt;
export MIDAS_EXPTAB=$HOME/online/exptab&lt;br /&gt;
#&lt;br /&gt;
# setup the MIDAS mserver&lt;br /&gt;
#&lt;br /&gt;
case `hostname` in&lt;br /&gt;
daq07*)&lt;br /&gt;
   unset MIDAS_SERVER_HOST&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   export MIDAS_SERVER_HOST=daq07.triumf.ca:7070&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
# select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
#&lt;br /&gt;
case `uname -i` in&lt;br /&gt;
i386)&lt;br /&gt;
   source /daq/daqshare/olchansk/root/root_v5.34.01_SL62_32/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   #source /daq/daqshare/olchansk/root/root_v5.34.34_SL67_64/bin/thisroot.sh&lt;br /&gt;
   source $HOME/packages/root/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
export PATH=.:$HOME/online/bin:$HOME/packages/roody/bin:$PATH&lt;br /&gt;
#&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* mkdir $HOME/packages&lt;br /&gt;
* Logout and login again, for .cshrc changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Install ROOT ==&lt;br /&gt;
&lt;br /&gt;
* Identify the Linux version: RH9 (Red Hat Linux 9), FC3 (Fedora Core 3), RHEL4/SL4 (Red Hat Enterprise LInux 4/Scientific Linux 4), SL5x, SL6x, (CentOS/CC/SL) el7x: more /etc/redhat-release&lt;br /&gt;
* Decide to use 32-bit or 64-bit ROOT (&#039;uname -a&#039;)&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* ls -l /daq/daqshare/olchansk/root/ ### to see all available ROOT packages&lt;br /&gt;
* ln -s /daq/daqshare/olchansk/root/root_vNNN_VVV_BB root, where NNN is the latest available version of ROOT (&amp;quot;ls -l /daq/daqshare/olchansk/root&amp;quot;), VVV is the Linux version code (RH9, FC3, SL4, etc) and BB is &amp;quot;_32&amp;quot; or &amp;quot;_64&amp;quot; for 32-bit or 64-bit ROOT. For example: /daq/daqshare/olchansk/root/root_v5.10.00_SL40&lt;br /&gt;
* for example: ln -s /daq/daqshare/olchansk/root/root_v5.34.34_el72_64 $HOME/packages/root&lt;br /&gt;
* Check that ROOT works: &amp;quot;source $HOME/packages/root/bin/thisroot.sh; root&amp;quot;. Type &amp;quot;.q&amp;quot; to exit root.&lt;br /&gt;
&lt;br /&gt;
== Install MIDAS ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/midas/trunk midas, password &amp;quot;svn&amp;quot;. (password has to be entered twice)&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/mxml/trunk mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mscb&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mxml.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mscb.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/midas.git&lt;br /&gt;
* cd midas&lt;br /&gt;
* make&lt;br /&gt;
* (only if needed) make linux32 ### build the 32-bit MIDAS libraries&lt;br /&gt;
* ls -l linux/bin/odbedit ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&lt;br /&gt;
You can see a list of other installation problems at [[Common problems &amp;amp; Debugging recipes]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: Optional features in MIDAS can be explicitly disabled if desired when making MIDAS using the NO_xxx feature (NO_ROOT,NO_MYSQL,NO_ODBC,NO_SQLITE,NO_MSCB), e.g. &amp;quot;make NO_ROOT=1&amp;quot; to disable ROOT. These NO_xxx Makefile variables are only used to control autodetection.&lt;br /&gt;
&lt;br /&gt;
== Install ROOTANA ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
* cd rootana&lt;br /&gt;
* make&lt;br /&gt;
&lt;br /&gt;
== Install ROODY ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
* cd roody&lt;br /&gt;
* make&lt;br /&gt;
* $HOME/packages/roody/bin/roody, run the program&lt;br /&gt;
&lt;br /&gt;
== Build special versions of MIDAS ==&lt;br /&gt;
&lt;br /&gt;
Build special versions of MIDAS for the case when some MIDAS programs, such as VME frontends, will run on a different computer that may have a different flavour of operating system, i.e. 32-bit linux or an older version of Scientific Linux.&lt;br /&gt;
&lt;br /&gt;
* login to the computer where the frontends will run and:&lt;br /&gt;
* if it is a 32-bit linux: cd $HOME/packages/midas; make linux32&lt;br /&gt;
* if it is a 64-bit linux: cd $HOME/packages/midas; make linux64&lt;br /&gt;
&lt;br /&gt;
* login to the host computer to cross-compile ARM code:&lt;br /&gt;
* if it is an ARM linux: cd $HOME/packages/midas; make linuxarm # may need to install ARM cross compilers&lt;br /&gt;
&lt;br /&gt;
== Prepare VME hardware ==&lt;br /&gt;
&lt;br /&gt;
Hardware check list:&lt;br /&gt;
* VME crate&lt;br /&gt;
* VME processor (supported are V77xx, V7805, V7865)&lt;br /&gt;
* On all VME modules, set the VME address jumpers as described here: http://daq-plone.triumf.ca/SM/docs/local/vme_jumpers&lt;br /&gt;
* run vmescan to confirm correct VME addresses&lt;br /&gt;
** cd $HOME/packages&lt;br /&gt;
** svn checkout https://ladd00.triumf.ca/svn/daqsvn/trunk/vme&lt;br /&gt;
** cd vme&lt;br /&gt;
** make&lt;br /&gt;
** ./vmescan.exe (or _gef.exe, depending on the VME driver in use)&lt;br /&gt;
&lt;br /&gt;
== Install Universe-II VME driver (V7648, V7750, V7805, V7851) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7648.2C_V7750.2C_V7805.2C_V7851_:_Setup_vme_universe_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan.exe&lt;br /&gt;
&lt;br /&gt;
== Install Tsi-148 VME driver (V7865) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7865_and_XVB-602_:_Setup_gefvme.2Ftsi148_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan_gef.exe&lt;br /&gt;
&lt;br /&gt;
== Setup the experiment environment ==&lt;br /&gt;
&lt;br /&gt;
* Decide which computer will host MIDAS (where MIDAS shared memory buffers will reside). &lt;br /&gt;
: This computer will run the [[mserver]], [[mlogger]] and [[mhttpd]] applications. (It is usually the machine where the MIDAS,ROOT etc. packages have been downloaded). It will be referred to as the host machine (localhost).&lt;br /&gt;
&lt;br /&gt;
The environment is slightly different depending on whether all programs run on the host machine, or whether some programs run on remote host(s) : &lt;br /&gt;
=== ALL programs run on localhost ===&lt;br /&gt;
:If all programs run on the host machine (localhost), it is not necessary to run [[mserver]]. [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will not be assigned (see example .cshrc [[#Prepare the user account|above]]).&lt;br /&gt;
&lt;br /&gt;
=== Some programs run on REMOTE host(s) ===&lt;br /&gt;
: &#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; &lt;br /&gt;
# Since August 2015 &#039;&#039;&#039;you must explicitly allow access for clients running on remote machines&#039;&#039;&#039;. To do this, follow the &#039;&#039;&#039;[[Security#MIDAS programs on remote machines|instructions here]]&#039;&#039;&#039;.&lt;br /&gt;
# The example code .cshrc ([[#Prepare the user account|see above]]) should be present on both host and remote machine(s). This will ensure that [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will NOT be set for the host machine (localhost), but on a remote machine, MIDAS_SERVER_HOST will be set to the MIDAS host machine. &lt;br /&gt;
# The client [[mserver]] must be started on the MIDAS host machine. Note that multiple experiments can run on the same host machine by starting several instances of [[mserver]] (one for each experiment) running with different ports (and .cshrc would be edited so that MIDAS_SERVER_HOST is set to the appropriate port for the experiment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On the host machine:&lt;br /&gt;
* mkdir $HOME/online&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* create directories for local programs, sources, elog and history: mkdir bin src elog history&lt;br /&gt;
* create data directory: mkdir -p /ladd/data1/t2kvme5/data; ln -s /ladd/data1/t2kvme5/data $HOME/online&lt;br /&gt;
* create the exptab file &amp;quot;$HOME/online/exptab&amp;quot; following the example below. The first entry (exptname) is the name if the DAQ system (MIDAS experiment name), the second entry (/home/USER/online) is the location of MIDAS shared memory buffers (by convention, $HOME/online), the third entry (kopio03) is your username.&lt;br /&gt;
&amp;lt;pre&amp;gt;exptname /home/kopio03/online kopio03&amp;lt;/pre&amp;gt;&lt;br /&gt;
* logout and login again for all changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Setup experiment startup scripts ==&lt;br /&gt;
* login to the experiment host computer&lt;br /&gt;
* echo $MIDAS_SERVER_HOST ### to check correct value - should be blank&lt;br /&gt;
* create $HOME/online/bin/start_daq.sh, replacing XXX with the hostname of the machine running the experiment (and changing the mserver and mhttpd ports, as needed).&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 case `hostname` in XXX*)&lt;br /&gt;
    echo &amp;quot;Good, we are on XXX!&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
 *)&lt;br /&gt;
    echo &amp;quot;The start_daq script should be executed on XXX&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
    ;;&lt;br /&gt;
 esac&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start [[mhttpd]] on default port. (Mongoose https version - see [[mhttpd]] for other options)&lt;br /&gt;
 mhttpd  -D  -a localhost -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 #&lt;br /&gt;
 #   start [[mserver]] on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D   # access must now be specifically allowed - see [[#Setup the experiment environment|above]]&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;&lt;br /&gt;
 # OR ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
 # mhttpd  -p 8081 -D -a localhost -a XXX.triumf.ca      # optionally restrict access to specified hosts&lt;br /&gt;
 # mserver -p 7071 -D -a localhost -a lxdragon01.triumf.ca -a lxdragon02.triumf.ca -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
 #&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
Let&#039;s start the MIDAS webserver for the first time:&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the command printed by mhttpd:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL proxy.&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. If these ports are in use on your machine, start &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mhttpd&amp;lt;/span&amp;gt; with alternative ports, e.g.&lt;br /&gt;
       &amp;lt;small&amp;gt;[mhostpc] mhttpd --https 8448 --http 8089&amp;lt;/small&amp;gt;&lt;br /&gt;
: or see [[Mhttpd#Usage]] to change the default ports.&lt;br /&gt;
&lt;br /&gt;
== Setup experiment database (ODB) ==&lt;br /&gt;
&lt;br /&gt;
* run $HOME/online/bin/start_daq.sh&lt;br /&gt;
&lt;br /&gt;
* odbedit, run these commands: (replace user names and directory names)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set &amp;quot;/Logger/Message file&amp;quot; &amp;quot;/home/kopio03/online/midas.log&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Data Dir&amp;quot;     &amp;quot;/home/kopio03/online/data&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/History dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/History dir&amp;quot;  &amp;quot;/home/kopio03/online/history&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/Elog dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Elog dir&amp;quot;     &amp;quot;/home/kopio03/online/elog&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump file&amp;quot; &amp;quot;/home/kopio03/online/history/run%05d.xml&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Filename&amp;quot; &amp;quot;run%05dsub%03d.mid.gz&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Subrun byte limit&amp;quot; &amp;quot;1000000000&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Compression&amp;quot;   1&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/ODB Dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/Logger/Required&amp;quot; y&lt;br /&gt;
set &amp;quot;/Programs/Logger/Start command&amp;quot; &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Required&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Start command&amp;quot; &amp;quot;ssh -n lxdaq09 $HOME/online/src/fevme_gef.exe -O&amp;quot;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* open web browser e.g. firefox.&lt;br /&gt;
* go to the midas status page at https://localhost:8443  (default port). &lt;br /&gt;
** if running [[mhttpd]] with Mongoose HTTPS/OpenSSL (the default) for the first time, you will need to create a password file. Follow the instructions (see [[mhttpd#HTTPS/SSL server (Mongoose)]] for details).&lt;br /&gt;
** For other options (i.e. HTTPS/SSL proxy) see [[#Secure MIDAS and ELOG Web access]] &lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;OR open the midas status page at http://localhost:8081 ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
* midas status page will show most stuff &amp;quot;red&amp;quot; as nothing is running yet&lt;br /&gt;
* DON&#039;T DO THIS YET run ./fevme.exe (on the computer with the VME interface, could be different from computer hosting the experiment), observe that corresponding equipments have been created&lt;br /&gt;
* save the url bookmark to the &amp;quot;personal toolbar&amp;quot;&lt;br /&gt;
* go to the Programs page, stop mlogger, stop fevme, start mlogger, start fevme&lt;br /&gt;
* go to the Status page, start run, stop run&lt;br /&gt;
* go back to the Status page, everything should be green&lt;br /&gt;
* start a run&lt;br /&gt;
* send signals to the ADC gate&lt;br /&gt;
* you should be getting events&lt;br /&gt;
* to look at data, proceed with setting up the [[ROOTANA|ROOT Analyzer]].&lt;br /&gt;
&lt;br /&gt;
== Start DAQ programs at boot time ==&lt;br /&gt;
&lt;br /&gt;
* add this to /etc/rc.local (replace username and location of the start_daq script)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - alpha -c /home/alpha/online/bin/start_daq.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup local software version control ==&lt;br /&gt;
&lt;br /&gt;
Version control for experiment source code is setup using &amp;quot;git&amp;quot; (http://git-scm.com/)&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* git init&lt;br /&gt;
* git add exptab&lt;br /&gt;
* git add bin/start_daq.sh&lt;br /&gt;
* git add .gitignore ### contents can be&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*~&lt;br /&gt;
*.o&lt;br /&gt;
*.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* git add src/Makefile src/*.cxx ...&lt;br /&gt;
* git commit -a&lt;br /&gt;
&lt;br /&gt;
== Adjust MIDAS buffer sizes ==&lt;br /&gt;
&lt;br /&gt;
Default MIDAS SYSTEM buffer size is 8 Mbytes, fairly small for high-data-rate experiments. The rule of thumb is to have at least a few seconds worth of buffer space available. For example, if event size is 10 Kbytes and the event rate is 1 kHz, data rate is 10*10^3*1*10^3 = 10 Mbytes/sec. To buffer 10 seconds of data we need 100 Mbytes of buffer space.&lt;br /&gt;
&lt;br /&gt;
To resize the MIDAS event buffers (SYSTEM, etc) do this:&lt;br /&gt;
* stop all frontends, stop mlogger&lt;br /&gt;
* start odbedit:&lt;br /&gt;
** cd &amp;quot;/Experiment/Buffer sizes&amp;quot;&lt;br /&gt;
** set SYSTEM 100000000&lt;br /&gt;
* run &amp;quot;mdump -z SYSTEM&amp;quot;&lt;br /&gt;
* if mdump complains about the size of .SYSTEM.SHM, remove it, try again.&lt;br /&gt;
* ls -l /dev/shm ### to observe that the size of shared memory is correct&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Secure MIDAS and ELOG Web access  ==&lt;br /&gt;
In versions prior to May 2015, the default web access to MIDAS and ELOG uses the &amp;quot;http:&amp;quot; protocol which is insecure. In this case, all information is transmitted as clear text meaning that secret, confidential and sensitive information (such as the MIDAS and ELOG passwords and usernames) can be stolen &amp;quot;easily&amp;quot;. This means that even &amp;quot;password protected&amp;quot; MIDAS and ELOG pages are not really protected if accessed using the &amp;quot;http&amp;quot; method. &lt;br /&gt;
 &lt;br /&gt;
Better security for HTTP is gained by using a password protected &#039;&#039;&#039;SSL (https) proxy&#039;&#039;&#039;. (It does not provide absolute security because of remaining problems with the security of SSL certificates, security of passwords, etc). Setting up an SSL (https) proxy is described [[#Setting up an HTTP proxy|below]].&lt;br /&gt;
&lt;br /&gt;
Since May 2015, an &#039;&#039;alternative secure option&#039;&#039; to setting up an HTTP proxy is available to users of MIDAS. Recent versions of elogd (ELOG) do support SSL https:// connections, and [[#mhttpd with HTTPS/SSL server (Mongoose)]] is now available.  This option is the default, and provides a similar level of security to an HTTP proxy. &lt;br /&gt;
&lt;br /&gt;
See [[Security#Web Access]] for a comparison of these two secure options.&lt;br /&gt;
  &lt;br /&gt;
=== mhttpd with HTTPS/SSL server (Mongoose) ===&lt;br /&gt;
&lt;br /&gt;
Since May 2015 the MIDAS web server [[mhttpd]] is explicitly linked with OpenSSL to provide secure HTTPS connections via the [https://bitbucket.org/tmidas/midas/src/ecb9a8537448a8a43f7f9a2bfdb82e578208cde3/doc/mongoose/?at=develop Mongoose] web server (see [[mhttpd]]). With this version, default web access to MIDAS uses the &amp;quot;https&amp;quot; protocol. Web access to {{Utility|name=mhttpd}} can be restricted by using the  &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. The first time {{Utility|name=mhttpd}} is run, a password file must be created. An SSL certificate is also required. See [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]] for instructions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== mhttpd using an HTTPS/SSL proxy ===&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE WRONG, DO NOT DO THIS.&lt;br /&gt;
&lt;br /&gt;
An [[#Setting up an HTTP proxy|HTTP proxy]] must be set up. This is the only way of securing older version of [[mhttpd]] (pre August 2015). Older versions of mhttpd are started using the -p port option  e.g.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; mhttpd  -D -p 8080  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run a new version of mhttpd using an HTTP proxy, use the options provided to run the old (non-Mongoose) webserver on a given port, i.e.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;  mhttpd --oldserver 8080 --nomg   -D  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using an SSL proxy, only access from the SSL proxy (and maybe some special trusted machines) should be permitted. &lt;br /&gt;
This is done using the &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. Normally there will be only &amp;quot;-a localhost&amp;quot; switch, enabling access only for the local machine (where the SSL proxy is running). Additional &amp;quot;-a hostname&amp;quot; switches enable access from listed local machines. No &amp;quot;-a xxx&amp;quot; enables access from everywhere (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere, i.e. by a site firewall or by local firewall rules).&lt;br /&gt;
&lt;br /&gt;
== Setting up an HTTP proxy ==&lt;br /&gt;
In this example, we use APACHE HTTPD to password-protect a typical midas/mhttpd and elog installation.&lt;br /&gt;
&lt;br /&gt;
In this configuration, one uses the Linux stock httpd that accepts encrypted https:// connections and forwards them to mhttpd and elogd. Instead of (or in addition to) using mhttpd and elogd passwords, one configures password protection in httpd via the regular apache httpd password mechanisms (htpasswd, etc).&lt;br /&gt;
&lt;br /&gt;
Recent versions of elogd do support SSL https:// connections, but if one is running an SSL proxy for anyway, it is simpler to run both through the same SSL proxy using the same SSL host certificate and the same httpd password file.&lt;br /&gt;
&lt;br /&gt;
=== Restricting http: access to elogd ===&lt;br /&gt;
;Note&lt;br /&gt;
:Recent versions of elogd do support SSL https:// connections. The following information is for those using an HTTP proxy (see above).&lt;br /&gt;
&lt;br /&gt;
For elogd, this is done using the &amp;quot;-n localhost&amp;quot; switch with enables only access from the same machine if present, or access from anywhere is absent (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere).&lt;br /&gt;
&lt;br /&gt;
(It is recommended to run elogd from the same user as the main daq user and to keep elogd.cfg and all logbooks in the home directory of this user, where they are captured by the normal site backup system)&lt;br /&gt;
&lt;br /&gt;
== Install standalone elog ==&lt;br /&gt;
&lt;br /&gt;
* login into the user account that will run the elog&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/ritt/elog&lt;br /&gt;
* cd elog&lt;br /&gt;
* make&lt;br /&gt;
* create new file start_elogd with this contents:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
killall elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
killall -KILL elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
$HOME/packages/elog/elogd -n localhost -x -c $HOME/packages/elog/elogd.cfg -p 8082 -D&lt;br /&gt;
&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x start_elogd&lt;br /&gt;
* edit elogd.cfg to read:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
port = 8082&lt;br /&gt;
SMTP host = smtp.triumf.ca&lt;br /&gt;
URL = https://titan00.triumf.ca/elog/&lt;br /&gt;
&lt;br /&gt;
Reverse sort = 1&lt;br /&gt;
Display Mode = full&lt;br /&gt;
&lt;br /&gt;
#List Menu commands = New, Find, Admin, Help&lt;br /&gt;
#Menu commands = New, Edit, Reply, Find, Duplicate, Help&lt;br /&gt;
&lt;br /&gt;
Entries Per Page = 30&lt;br /&gt;
Supress Email on edit = 1&lt;br /&gt;
Default encoding = 1&lt;br /&gt;
Page title = TITAN ELOG&lt;br /&gt;
Resolve host names = 1&lt;br /&gt;
&lt;br /&gt;
Logfile = /home/titan/packages/elog/elogd.log&lt;br /&gt;
#Logging level = 3&lt;br /&gt;
&lt;br /&gt;
[midas]&lt;br /&gt;
&lt;br /&gt;
List page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
Comment = T2K M11 MIDAS ELOG&lt;br /&gt;
Page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
RSS Title = [$logbook - $type - $system] $subject, posted by $author&lt;br /&gt;
&lt;br /&gt;
Attributes = Author, Subject, Run, Type, System&lt;br /&gt;
Show Attributes Edit = Run, Author, Subject, Type, System&lt;br /&gt;
Required Attributes = Author, Type, System, Subject&lt;br /&gt;
&lt;br /&gt;
Options Type = Routine, Reply, Shift Summary, Modification, Question, Info, Problem&lt;br /&gt;
Options System = General, DAQ, Beamline&lt;br /&gt;
&lt;br /&gt;
Preset Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Preset On Reply Type = Reply&lt;br /&gt;
Preset On Reply Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
List Display = Date, Subject, Type, System, Author, ID&lt;br /&gt;
Quick Filter = Date, Type, ID&lt;br /&gt;
&lt;br /&gt;
Remove on reply = Author&lt;br /&gt;
Quote on reply = 1&lt;br /&gt;
&lt;br /&gt;
Use lock = 1&lt;br /&gt;
&lt;br /&gt;
************* Email Functionality ****************&lt;br /&gt;
&lt;br /&gt;
Use Email Subject = [T2KM11 - $System] $Subject&lt;br /&gt;
Omit Email To = 1&lt;br /&gt;
&lt;br /&gt;
Email System General = xxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* ./start_elogd &amp;amp;&lt;br /&gt;
* firefox http://localhost:8082 # hould show the elog message index&lt;br /&gt;
&lt;br /&gt;
To start elogd automatically when the machine is rebooted, login as root and&lt;br /&gt;
* add this text to /etc/rc.local:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - titan -c &amp;quot;/home/titan/packages/elog/start_elogd&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x /etc/rc.local&lt;br /&gt;
* systemctl start rc-local&lt;br /&gt;
&lt;br /&gt;
To import elog entries from the mhttpd elog, do this:&lt;br /&gt;
&lt;br /&gt;
* cd ~/packages/elog/logbooks&lt;br /&gt;
* ln -s /home/t2km11/online/elog midas&lt;br /&gt;
* cd midas&lt;br /&gt;
* ~/packages/elog/elconv)&lt;br /&gt;
&lt;br /&gt;
== Install https proxy ==&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE OBSOLETE, INSTEAD, &lt;br /&gt;
* GO HERE: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* AND GO HERE: https://midas.triumf.ca/MidasWiki/index.php/Quickstart_Linux#Run_the_MIDAS_Web_Server&lt;br /&gt;
&lt;br /&gt;
FOLLOWING INSTRUCTIONS ARE OBSOLETE...&lt;br /&gt;
&lt;br /&gt;
* login as root to the https proxy machine&lt;br /&gt;
* cd ~root&lt;br /&gt;
* yum install mod_ssl&lt;br /&gt;
* yum install crypto-utils # see http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_monitoring_of_HTTPS_certificates&lt;br /&gt;
* create a certificate request (replace ladd09 with your hostname): openssl req -new -nodes -newkey rsa:2048 -sha256 -out ladd09.csr -keyout ladd09.key (answer: CA, BC, Vancouver, TRIUMF, DAQ, ladd09.triumf.ca, email@email.com&lt;br /&gt;
* sign it by TRIUMF:&lt;br /&gt;
** mail -s &amp;quot;Certificate request&amp;quot; yourself@email.com &amp;amp;lt; ladd09.csr&lt;br /&gt;
** forward this request to Andrew Daviel&lt;br /&gt;
** he will email the signed crt file, copy it to this system as ladd09.crt&lt;br /&gt;
* sign it yourself: openssl x509 -req -days 365 -sha256 -in ladd09.csr -signkey ladd09.key -out ladd09.crt&lt;br /&gt;
* (if the certificate expires, renew it by signing it again)&lt;br /&gt;
* Additional commands for working with certificates:&lt;br /&gt;
** explore the private key: openssl pkey -in ladd09.key -text -noout&lt;br /&gt;
** explore the certificate request: openssl req -in ladd00.csr -text -noout&lt;br /&gt;
** explore the certificate: openssl x509 -in ladd09.crt -noout -text&lt;br /&gt;
* move certificate files to proper system locations:&lt;br /&gt;
* mv ladd09.key  /etc/pki/tls/private/&lt;br /&gt;
* mv ladd09.crt /etc/pki/tls/certs/&lt;br /&gt;
* if selinux is enabled, do this:&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/certs/&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/private/&lt;br /&gt;
** /usr/sbin/setsebool -P httpd_can_network_connect 1&lt;br /&gt;
* open /etc/httpd/conf.d/ssl.conf in a text editor, go to the very bottom and right before the &amp;quot;&amp;lt;/VirtualHost&amp;gt;&amp;quot; entry, add following text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateFile /etc/pki/tls/certs/ladd09.crt &lt;br /&gt;
SSLCertificateKeyFile /etc/pki/tls/private/ladd09.key &lt;br /&gt;
&lt;br /&gt;
ProxyPass /elog/ http://localhost:8082/ retry=1&lt;br /&gt;
ProxyPass /      http://localhost:8080/ retry=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Location /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SSLRequireSSL&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;password protected site&amp;quot;&lt;br /&gt;
Require valid-user&lt;br /&gt;
&lt;br /&gt;
# create password file: touch /etc/httpd/htpasswd&lt;br /&gt;
# to add new user or change password: htpasswd /etc/httpd/htpasswd username&lt;br /&gt;
AuthUserFile /etc/httpd/htpasswd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* comment out duplicate &amp;quot;SSLCertificateFile&amp;quot; and &amp;quot;SSLCertificateKeyFile&amp;quot; elsewhere in the file&lt;br /&gt;
* (optionally) If you got a certificate that is signed by DigiCert or RapidSSL then you&#039;ll need to add a line specifying the certificate chain file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateChainFile /etc/pki/tls/certs/DigiCertCA.crt&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* touch /etc/httpd/htpasswd&lt;br /&gt;
* htpasswd /etc/httpd/htpasswd midas # enter password midas&lt;br /&gt;
* chkconfig httpd on&lt;br /&gt;
* service httpd restart&lt;br /&gt;
* firewall-cmd --add-port=443/tcp --permanent&lt;br /&gt;
* firewall-cmd --reload&lt;br /&gt;
* firewall-cmd --list-all&lt;br /&gt;
* test it&lt;br /&gt;
** test the SSL proxy: https://host/ should yield the midas status page, https://host/elog/ should yield the elog message index&lt;br /&gt;
* in ODB, set &amp;quot;/Elog/URL&amp;quot; to &amp;quot;https://host/elog/&amp;quot;&lt;br /&gt;
* now from the midas status page, the &amp;quot;Elog&amp;quot; button should take us to the https Elog URL&lt;br /&gt;
&lt;br /&gt;
In needed, enable user directories: https://blah/~user in ~user/public_html&lt;br /&gt;
&lt;br /&gt;
* edit /etc/httpd/conf.d/userdir.conf, replace &amp;quot;UserDir disabled&amp;quot; with &amp;quot;UserDir enabled&amp;quot;&lt;br /&gt;
* setsebool -P httpd_enable_homedirs true&lt;br /&gt;
* systemctl restart httpd&lt;br /&gt;
&lt;br /&gt;
== Setup the history mhttpd for faster access to history plots ==&lt;br /&gt;
When running an SSL proxy,&lt;br /&gt;
* start the main mhttpd (&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;orange&amp;lt;/span&amp;gt; command for old mhttpd, &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;green&amp;lt;/span&amp;gt; for new mhttpd with Mongoose(post August2015):&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* start the history mhttpd&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; &amp;quot;mhttpd -p 8072 -D -H&amp;quot;&amp;lt;/span&amp;gt; or&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* set ODB /History/URL to &amp;quot;http://alphacpc09.cern.ch:8072/HS/&amp;quot;&lt;br /&gt;
* open the MIDAS status page&lt;br /&gt;
* go to the history section, try to open any history plot, observe that the history plot gif image loads correctly, inspect it&#039;s URL (use &amp;quot;copy image URL&amp;quot; or &amp;quot;view source&amp;quot;, etc), it should point to port 8072 causing connection to the history mhttpd.&lt;br /&gt;
* continue with these instructions to setup history mhttpd access through an SSL proxy:&lt;br /&gt;
* setup SSL proxy access (required mod_proxy_html)&lt;br /&gt;
** login as root to the SSL proxy machine&lt;br /&gt;
** on SL5, install the missing mod_proxy_html httpd module:&lt;br /&gt;
** yum install httpd-devel libxml2-devel&lt;br /&gt;
** wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.tar.bz2&lt;br /&gt;
** tar xjvf mod_proxy_html.tar.bz2 &lt;br /&gt;
** cd mod_proxy_html&lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_proxy_html.c &lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_xml2enc.c&lt;br /&gt;
** cd /etc/httpd/conf.d, add this to ssl.conf:&lt;br /&gt;
&lt;br /&gt;
;before the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# proxy the MIDAS web servers  &lt;br /&gt;
LoadModule  xml2enc_module       modules/mod_xml2enc.so  &lt;br /&gt;
LoadModule  proxy_html_module    modules/mod_proxy_html.so  &lt;br /&gt;
ProxyHTMLLinks  a               href  &lt;br /&gt;
ProxyHTMLLinks  link            href  &lt;br /&gt;
ProxyHTMLLinks  img             src  &lt;br /&gt;
#ProxyHTMLEnable On  &lt;br /&gt;
ProxyRequests off  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;after the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ALPHA1 history access &lt;br /&gt;
ProxyPass /alpha1/history/   http://alphacpc09.cern.ch:8072/HS/  retry=1 &lt;br /&gt;
ProxyPass /alpha1/           http://alphacpc09.cern.ch:8071/     retry=1 &lt;br /&gt;
 &lt;br /&gt;
ProxyHTMLEnable On  &lt;br /&gt;
ProxyHTMLURLMap http://alphacpc09.cern.ch:8072/HS/ /alpha1/history/ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;adjust:&lt;br /&gt;
*&amp;quot;alpha1&amp;quot; is the experiment name&lt;br /&gt;
*&amp;quot;alphacpc09.cern.ch&amp;quot; is the machine running mhttpd&lt;br /&gt;
*&amp;quot;8071&amp;quot; is the port number of the main mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* &amp;quot;8072&amp;quot; is the port number of the history mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8072 -D -H&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]] [[Category:Buffer]] [[Category:Driver]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2566</id>
		<title>Setup MIDAS experiment at TRIUMF</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Setup_MIDAS_experiment_at_TRIUMF&amp;diff=2566"/>
		<updated>2016-11-21T21:43:50Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Prepare the user account */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This page describes setting up a MIDAS experiment at TRIUMF. This information can be adapted for other sites.&lt;br /&gt;
&lt;br /&gt;
== Environment variables ==&lt;br /&gt;
* &#039;&#039;&#039;MIDASSYS&#039;&#039;&#039; Base directory of the MIDAS package, midas and mxml should be at the same level.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPTAB&#039;&#039;&#039; Experiment definition file&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_SERVER_HOST&#039;&#039;&#039; MIDAS host server name for remote midas connections.&lt;br /&gt;
* &#039;&#039;&#039;MIDAS_EXPT_NAME&#039;&#039;&#039; Experiment name&lt;br /&gt;
&lt;br /&gt;
== Standard layout of MIDAS experiment ==&lt;br /&gt;
The following shows the directory layout of a standard MIDAS experiment: &lt;br /&gt;
&lt;br /&gt;
 /home/exptuser/&lt;br /&gt;
                packages/&lt;br /&gt;
                        root                   &amp;lt;---- ROOT&lt;br /&gt;
                        mxml&lt;br /&gt;
                        mscb&lt;br /&gt;
                        midas/                 &amp;lt;---- MIDAS&lt;br /&gt;
                              linux/{lib,bin}       &amp;lt;---- binaries matching the selected 64-bit/32-bit flavour of ROOT&lt;br /&gt;
                              linux-m32/{lib,bin}   &amp;lt;---- limited function 32-bit binaries for 32-bit frontend machines, build by &amp;quot;make linux32&amp;quot;&lt;br /&gt;
                              linux-m64/{lib,bin}   &amp;lt;---- limited function 64-bit binaries (only needed if ROOT and linux/bin are 32-bit)&lt;br /&gt;
                              linux-arm/{lib,bin}   &amp;lt;---- full function ARM cross-compiled using &amp;quot;make linuxarm&amp;quot;&lt;br /&gt;
                              linux-crosscompile/{lib,bin}  &amp;lt;---- cross-compiled limited function binaries for PPC and ARM frontends (see Makefile)&lt;br /&gt;
                        rootana                &amp;lt;---- ROOT analyzer&lt;br /&gt;
                        roody                  &amp;lt;---- graphical online histogram viewer for MIDAS and ROOTANA&lt;br /&gt;
                 online/&lt;br /&gt;
                        exptab                         &amp;lt;---- experiment definition&lt;br /&gt;
                        {.ODB,.SYSTEM,.SYSMSG,etc}.SHM &amp;lt;---- MIDAS shared memory save files&lt;br /&gt;
                        src                            &amp;lt;---- experiment frontend sources&lt;br /&gt;
                        bin,scripts&lt;br /&gt;
                        elog                           &amp;lt;---- MIDAS elog&lt;br /&gt;
                        history                        &amp;lt;---- MIDAS history&lt;br /&gt;
                        data -&amp;gt; /data/exptname/current &amp;lt;---- symlink to the data directory&lt;br /&gt;
 /data/exptname/current                                &amp;lt;---- experiment data directory with ODB save files and MIDAS .mid/.mid.gz data files&lt;br /&gt;
&lt;br /&gt;
== Prepare computers ==&lt;br /&gt;
&lt;br /&gt;
On some operating systems, several MIDAS functions require administrator access:&lt;br /&gt;
&lt;br /&gt;
* on el7 linux (SL7/CC7/CentOS7/RHEL7) - access to mhttpd port 8443 requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - access to mserver to run frontends and other programs on some other computer requires special firewall rules, see here: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
* on el7 linux - on the frontend machines (and other machines that will connect to the mserver, the same firewall rule needs to be created (use the IP address of the machine running the mserver)&lt;br /&gt;
&lt;br /&gt;
== Prepare the user account ==&lt;br /&gt;
&amp;lt;div id=&amp;quot;NOTES&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
;NOTES&lt;br /&gt;
* Instructions are given for recent MIDAS versions (August 2015 and later) which have enhanced [[Security]]. Instructions for older versions differ slightly.&lt;br /&gt;
** follow the  &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;orange&amp;lt;/span&amp;gt; instructions for older versions&lt;br /&gt;
&lt;br /&gt;
* Setup the user account for running this instance of midas. For machines part of the LADD cluster, follow these  [http://daq-plone.triumf.ca/SM/docs/local/NewLaddUser] instructions.&lt;br /&gt;
* check that the account is using the /bin/bash shell&lt;br /&gt;
* make $HOME/.profile look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/echo You must source&lt;br /&gt;
&lt;br /&gt;
export SVN_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot;&lt;br /&gt;
export MIDASSYS=$HOME/packages/midas&lt;br /&gt;
export ROOTANASYS=$HOME/packages/rootana&lt;br /&gt;
export MIDAS_EXPTAB=$HOME/online/exptab&lt;br /&gt;
#&lt;br /&gt;
# setup the MIDAS mserver&lt;br /&gt;
#&lt;br /&gt;
case `hostname` in&lt;br /&gt;
daq07*)&lt;br /&gt;
   unset MIDAS_SERVER_HOST&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   export MIDAS_SERVER_HOST=daq07.triumf.ca:7070&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
# select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
#&lt;br /&gt;
case `uname -i` in&lt;br /&gt;
i386)&lt;br /&gt;
   source /daq/daqshare/olchansk/root/root_v5.34.01_SL62_32/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
*)&lt;br /&gt;
   #source /daq/daqshare/olchansk/root/root_v5.34.34_SL67_64/bin/thisroot.sh&lt;br /&gt;
   source $HOME/packages/root/bin/thisroot.sh&lt;br /&gt;
   export PATH=.:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
   ;;&lt;br /&gt;
esac&lt;br /&gt;
#&lt;br /&gt;
export PATH=.:$HOME/online/bin:$HOME/packages/roody/bin:$PATH&lt;br /&gt;
#&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* mkdir $HOME/packages&lt;br /&gt;
* Logout and login again, for .cshrc changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Install ROOT ==&lt;br /&gt;
&lt;br /&gt;
* Identify the Linux version: RH9 (Red Hat Linux 9), FC3 (Fedora Core 3), RHEL4/SL4 (Red Hat Enterprise LInux 4/Scientific Linux 4), SL5x, SL6x, (CentOS/CC/SL) el7x: more /etc/redhat-release&lt;br /&gt;
* Decide to use 32-bit or 64-bit ROOT (&#039;uname -a&#039;)&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* ls -l /daq/daqshare/olchansk/root/ ### to see all available ROOT packages&lt;br /&gt;
* ln -s /daq/daqshare/olchansk/root/root_vNNN_VVV_BB root, where NNN is the latest available version of ROOT (&amp;quot;ls -l /daq/daqshare/olchansk/root&amp;quot;), VVV is the Linux version code (RH9, FC3, SL4, etc) and BB is &amp;quot;_32&amp;quot; or &amp;quot;_64&amp;quot; for 32-bit or 64-bit ROOT. For example: /daq/daqshare/olchansk/root/root_v5.10.00_SL40&lt;br /&gt;
* for example: ln -s /daq/daqshare/olchansk/root/root_v5.34.34_el72_64 $HOME/packages/root&lt;br /&gt;
* Check that ROOT works: &amp;quot;source $HOME/packages/root/bin/thisroot.sh; root&amp;quot;. Type &amp;quot;.q&amp;quot; to exit root.&lt;br /&gt;
&lt;br /&gt;
== Install MIDAS ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/midas/trunk midas, password &amp;quot;svn&amp;quot;. (password has to be entered twice)&lt;br /&gt;
* (OBSOLETE) svn co svn+ssh://svn@savannah.psi.ch/repos/meg/mxml/trunk mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/mscb&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mxml.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/mscb.git&lt;br /&gt;
* (IF BITBUCKET IS DOWN) git clone -v --progress https://daq.triumf.ca/~daqweb/git/midas.git&lt;br /&gt;
* cd midas&lt;br /&gt;
* make&lt;br /&gt;
* (only if needed) make linux32 ### build the 32-bit MIDAS libraries&lt;br /&gt;
* ls -l linux/bin/odbedit ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&lt;br /&gt;
You can see a list of other installation problems at [[Common problems &amp;amp; Debugging recipes]].&lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: Optional features in MIDAS can be explicitly disabled if desired when making MIDAS using the NO_xxx feature (NO_ROOT,NO_MYSQL,NO_ODBC,NO_SQLITE,NO_MSCB), e.g. &amp;quot;make NO_ROOT=1&amp;quot; to disable ROOT. These NO_xxx Makefile variables are only used to control autodetection.&lt;br /&gt;
&lt;br /&gt;
== Install ROOTANA ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
* cd rootana&lt;br /&gt;
* make&lt;br /&gt;
&lt;br /&gt;
== Install ROODY ==&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
* cd roody&lt;br /&gt;
* make&lt;br /&gt;
* $HOME/packages/roody/bin/roody, run the program&lt;br /&gt;
&lt;br /&gt;
== Build special versions of MIDAS ==&lt;br /&gt;
&lt;br /&gt;
Build special versions of MIDAS for the case when some MIDAS programs, such as VME frontends, will run on a different computer that may have a different flavour of operating system, i.e. 32-bit linux or an older version of Scientific Linux.&lt;br /&gt;
&lt;br /&gt;
* login to the computer where the frontends will run and:&lt;br /&gt;
* if it is a 32-bit linux: cd $HOME/packages/midas; make linux32&lt;br /&gt;
* if it is a 64-bit linux: cd $HOME/packages/midas; make linux64&lt;br /&gt;
&lt;br /&gt;
* login to the host computer to cross-compile ARM code:&lt;br /&gt;
* if it is an ARM linux: cd $HOME/packages/midas; make linuxarm # may need to install ARM cross compilers&lt;br /&gt;
&lt;br /&gt;
== Prepare VME hardware ==&lt;br /&gt;
&lt;br /&gt;
Hardware check list:&lt;br /&gt;
* VME crate&lt;br /&gt;
* VME processor (supported are V77xx, V7805, V7865)&lt;br /&gt;
* On all VME modules, set the VME address jumpers as described here: http://daq-plone.triumf.ca/SM/docs/local/vme_jumpers&lt;br /&gt;
* run vmescan to confirm correct VME addresses&lt;br /&gt;
** cd $HOME/packages&lt;br /&gt;
** svn checkout https://ladd00.triumf.ca/svn/daqsvn/trunk/vme&lt;br /&gt;
** cd vme&lt;br /&gt;
** make&lt;br /&gt;
** ./vmescan.exe (or _gef.exe, depending on the VME driver in use)&lt;br /&gt;
&lt;br /&gt;
== Install Universe-II VME driver (V7648, V7750, V7805, V7851) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7648.2C_V7750.2C_V7805.2C_V7851_:_Setup_vme_universe_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan.exe&lt;br /&gt;
&lt;br /&gt;
== Install Tsi-148 VME driver (V7865) ==&lt;br /&gt;
&lt;br /&gt;
* login as root (ssh root@localhost)&lt;br /&gt;
* follow instructions: https://www.triumf.info/wiki/DAQwiki/index.php/VME-CPU#V7865_and_XVB-602_:_Setup_gefvme.2Ftsi148_VME_drivers&lt;br /&gt;
* cd ~/packages/vme; vmescan_gef.exe&lt;br /&gt;
&lt;br /&gt;
== Setup the experiment environment ==&lt;br /&gt;
&lt;br /&gt;
* Decide which computer will host MIDAS (where MIDAS shared memory buffers will reside). &lt;br /&gt;
: This computer will run the [[mserver]], [[mlogger]] and [[mhttpd]] applications. (It is usually the machine where the MIDAS,ROOT etc. packages have been downloaded). It will be referred to as the host machine (localhost).&lt;br /&gt;
&lt;br /&gt;
The environment is slightly different depending on whether all programs run on the host machine, or whether some programs run on remote host(s) : &lt;br /&gt;
=== ALL programs run on localhost ===&lt;br /&gt;
:If all programs run on the host machine (localhost), it is not necessary to run [[mserver]]. [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will not be assigned (see example .cshrc [[#Prepare the user account|above]]).&lt;br /&gt;
&lt;br /&gt;
=== Some programs run on REMOTE host(s) ===&lt;br /&gt;
: &#039;&#039;&#039;IMPORTANT:&#039;&#039;&#039; &lt;br /&gt;
# Since August 2015 &#039;&#039;&#039;you must explicitly allow access for clients running on remote machines&#039;&#039;&#039;. To do this, follow the &#039;&#039;&#039;[[Security#MIDAS programs on remote machines|instructions here]]&#039;&#039;&#039;.&lt;br /&gt;
# The example code .cshrc ([[#Prepare the user account|see above]]) should be present on both host and remote machine(s). This will ensure that [[Environment Variables#MIDAS_SERVER_HOST|MIDAS_SERVER_HOST]] will NOT be set for the host machine (localhost), but on a remote machine, MIDAS_SERVER_HOST will be set to the MIDAS host machine. &lt;br /&gt;
# The client [[mserver]] must be started on the MIDAS host machine. Note that multiple experiments can run on the same host machine by starting several instances of [[mserver]] (one for each experiment) running with different ports (and .cshrc would be edited so that MIDAS_SERVER_HOST is set to the appropriate port for the experiment).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On the host machine:&lt;br /&gt;
* mkdir $HOME/online&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* create directories for local programs, sources, elog and history: mkdir bin src elog history&lt;br /&gt;
* create data directory: mkdir -p /ladd/data1/t2kvme5/data; ln -s /ladd/data1/t2kvme5/data $HOME/online&lt;br /&gt;
* create the exptab file &amp;quot;$HOME/online/exptab&amp;quot; following the example below. The first entry (exptname) is the name if the DAQ system (MIDAS experiment name), the second entry (/home/USER/online) is the location of MIDAS shared memory buffers (by convention, $HOME/online), the third entry (kopio03) is your username.&lt;br /&gt;
&amp;lt;pre&amp;gt;exptname /home/kopio03/online kopio03&amp;lt;/pre&amp;gt;&lt;br /&gt;
* logout and login again for all changes to take effect&lt;br /&gt;
&lt;br /&gt;
== Setup experiment startup scripts ==&lt;br /&gt;
* login to the experiment host computer&lt;br /&gt;
* echo $MIDAS_SERVER_HOST ### to check correct value - should be blank&lt;br /&gt;
* create $HOME/online/bin/start_daq.sh, replacing XXX with the hostname of the machine running the experiment (and changing the mserver and mhttpd ports, as needed).&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 case `hostname` in XXX*)&lt;br /&gt;
    echo &amp;quot;Good, we are on XXX!&amp;quot;&lt;br /&gt;
    ;;&lt;br /&gt;
 *)&lt;br /&gt;
    echo &amp;quot;The start_daq script should be executed on XXX&amp;quot;&lt;br /&gt;
    exit 1&lt;br /&gt;
    ;;&lt;br /&gt;
 esac&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start [[mhttpd]] on default port. (Mongoose https version - see [[mhttpd]] for other options)&lt;br /&gt;
 mhttpd  -D  -a localhost -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 #&lt;br /&gt;
 #   start [[mserver]] on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D   # access must now be specifically allowed - see [[#Setup the experiment environment|above]]&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;&lt;br /&gt;
 # OR ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
 # mhttpd  -p 8081 -D -a localhost -a XXX.triumf.ca      # optionally restrict access to specified hosts&lt;br /&gt;
 # mserver -p 7071 -D -a localhost -a lxdragon01.triumf.ca -a lxdragon02.triumf.ca -a XXX.triumf.ca # optionally restrict access to specified hosts&lt;br /&gt;
 &amp;lt;/span&amp;gt;&lt;br /&gt;
 #&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
Let&#039;s start the MIDAS webserver for the first time:&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the command printed by mhttpd:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL proxy.&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhttpd,INFO] ODB subtree /Runinfo corrected successfully&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. If these ports are in use on your machine, start &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mhttpd&amp;lt;/span&amp;gt; with alternative ports, e.g.&lt;br /&gt;
       &amp;lt;small&amp;gt;[mhostpc] mhttpd --https 8448 --http 8089&amp;lt;/small&amp;gt;&lt;br /&gt;
: or see [[Mhttpd#Usage]] to change the default ports.&lt;br /&gt;
&lt;br /&gt;
== Setup experiment database (ODB) ==&lt;br /&gt;
&lt;br /&gt;
* run $HOME/online/bin/start_daq.sh&lt;br /&gt;
&lt;br /&gt;
* odbedit, run these commands: (replace user names and directory names)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set &amp;quot;/Logger/Message file&amp;quot; &amp;quot;/home/kopio03/online/midas.log&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Data Dir&amp;quot;     &amp;quot;/home/kopio03/online/data&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/History dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/History dir&amp;quot;  &amp;quot;/home/kopio03/online/history&amp;quot;&lt;br /&gt;
create STRING &amp;quot;/Logger/Elog dir&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Elog dir&amp;quot;     &amp;quot;/home/kopio03/online/elog&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump file&amp;quot; &amp;quot;/home/kopio03/online/history/run%05d.xml&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/ODB dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Filename&amp;quot; &amp;quot;run%05dsub%03d.mid.gz&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Subrun byte limit&amp;quot; &amp;quot;1000000000&amp;quot;&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/Compression&amp;quot;   1&lt;br /&gt;
set &amp;quot;/Logger/Channels/0/Settings/ODB Dump&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/Logger/Required&amp;quot; y&lt;br /&gt;
set &amp;quot;/Programs/Logger/Start command&amp;quot; &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Required&amp;quot; &amp;quot;y&amp;quot;&lt;br /&gt;
set &amp;quot;/Programs/fevme/Start command&amp;quot; &amp;quot;ssh -n lxdaq09 $HOME/online/src/fevme_gef.exe -O&amp;quot;&lt;br /&gt;
exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* open web browser e.g. firefox.&lt;br /&gt;
* go to the midas status page at https://localhost:8443  (default port). &lt;br /&gt;
** if running [[mhttpd]] with Mongoose HTTPS/OpenSSL (the default) for the first time, you will need to create a password file. Follow the instructions (see [[mhttpd#HTTPS/SSL server (Mongoose)]] for details).&lt;br /&gt;
** For other options (i.e. HTTPS/SSL proxy) see [[#Secure MIDAS and ELOG Web access]] &lt;br /&gt;
*&amp;lt;span style=&amp;quot;color:orange;&amp;quot;&amp;gt;OR open the midas status page at http://localhost:8081 ([[#NOTES|older MIDAS versions]])&lt;br /&gt;
* midas status page will show most stuff &amp;quot;red&amp;quot; as nothing is running yet&lt;br /&gt;
* DON&#039;T DO THIS YET run ./fevme.exe (on the computer with the VME interface, could be different from computer hosting the experiment), observe that corresponding equipments have been created&lt;br /&gt;
* save the url bookmark to the &amp;quot;personal toolbar&amp;quot;&lt;br /&gt;
* go to the Programs page, stop mlogger, stop fevme, start mlogger, start fevme&lt;br /&gt;
* go to the Status page, start run, stop run&lt;br /&gt;
* go back to the Status page, everything should be green&lt;br /&gt;
* start a run&lt;br /&gt;
* send signals to the ADC gate&lt;br /&gt;
* you should be getting events&lt;br /&gt;
* to look at data, proceed with setting up the [[ROOTANA|ROOT Analyzer]].&lt;br /&gt;
&lt;br /&gt;
== Start DAQ programs at boot time ==&lt;br /&gt;
&lt;br /&gt;
* add this to /etc/rc.local (replace username and location of the start_daq script)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - alpha -c /home/alpha/online/bin/start_daq.sh&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setup local software version control ==&lt;br /&gt;
&lt;br /&gt;
Version control for experiment source code is setup using &amp;quot;git&amp;quot; (http://git-scm.com/)&lt;br /&gt;
&lt;br /&gt;
* cd $HOME/online&lt;br /&gt;
* git init&lt;br /&gt;
* git add exptab&lt;br /&gt;
* git add bin/start_daq.sh&lt;br /&gt;
* git add .gitignore ### contents can be&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*~&lt;br /&gt;
*.o&lt;br /&gt;
*.exe&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* git add src/Makefile src/*.cxx ...&lt;br /&gt;
* git commit -a&lt;br /&gt;
&lt;br /&gt;
== Adjust MIDAS buffer sizes ==&lt;br /&gt;
&lt;br /&gt;
Default MIDAS SYSTEM buffer size is 8 Mbytes, fairly small for high-data-rate experiments. The rule of thumb is to have at least a few seconds worth of buffer space available. For example, if event size is 10 Kbytes and the event rate is 1 kHz, data rate is 10*10^3*1*10^3 = 10 Mbytes/sec. To buffer 10 seconds of data we need 100 Mbytes of buffer space.&lt;br /&gt;
&lt;br /&gt;
To resize the MIDAS event buffers (SYSTEM, etc) do this:&lt;br /&gt;
* stop all frontends, stop mlogger&lt;br /&gt;
* start odbedit:&lt;br /&gt;
** cd &amp;quot;/Experiment/Buffer sizes&amp;quot;&lt;br /&gt;
** set SYSTEM 100000000&lt;br /&gt;
* run &amp;quot;mdump -z SYSTEM&amp;quot;&lt;br /&gt;
* if mdump complains about the size of .SYSTEM.SHM, remove it, try again.&lt;br /&gt;
* ls -l /dev/shm ### to observe that the size of shared memory is correct&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Secure MIDAS and ELOG Web access  ==&lt;br /&gt;
In versions prior to May 2015, the default web access to MIDAS and ELOG uses the &amp;quot;http:&amp;quot; protocol which is insecure. In this case, all information is transmitted as clear text meaning that secret, confidential and sensitive information (such as the MIDAS and ELOG passwords and usernames) can be stolen &amp;quot;easily&amp;quot;. This means that even &amp;quot;password protected&amp;quot; MIDAS and ELOG pages are not really protected if accessed using the &amp;quot;http&amp;quot; method. &lt;br /&gt;
 &lt;br /&gt;
Better security for HTTP is gained by using a password protected &#039;&#039;&#039;SSL (https) proxy&#039;&#039;&#039;. (It does not provide absolute security because of remaining problems with the security of SSL certificates, security of passwords, etc). Setting up an SSL (https) proxy is described [[#Setting up an HTTP proxy|below]].&lt;br /&gt;
&lt;br /&gt;
Since May 2015, an &#039;&#039;alternative secure option&#039;&#039; to setting up an HTTP proxy is available to users of MIDAS. Recent versions of elogd (ELOG) do support SSL https:// connections, and [[#mhttpd with HTTPS/SSL server (Mongoose)]] is now available.  This option is the default, and provides a similar level of security to an HTTP proxy. &lt;br /&gt;
&lt;br /&gt;
See [[Security#Web Access]] for a comparison of these two secure options.&lt;br /&gt;
  &lt;br /&gt;
=== mhttpd with HTTPS/SSL server (Mongoose) ===&lt;br /&gt;
&lt;br /&gt;
Since May 2015 the MIDAS web server [[mhttpd]] is explicitly linked with OpenSSL to provide secure HTTPS connections via the [https://bitbucket.org/tmidas/midas/src/ecb9a8537448a8a43f7f9a2bfdb82e578208cde3/doc/mongoose/?at=develop Mongoose] web server (see [[mhttpd]]). With this version, default web access to MIDAS uses the &amp;quot;https&amp;quot; protocol. Web access to {{Utility|name=mhttpd}} can be restricted by using the  &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. The first time {{Utility|name=mhttpd}} is run, a password file must be created. An SSL certificate is also required. See [[mhttpd#HTTPS/SSL server (Mongoose)|HTTPS/SSL server (Mongoose)]] for instructions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== mhttpd using an HTTPS/SSL proxy ===&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE WRONG, DO NOT DO THIS.&lt;br /&gt;
&lt;br /&gt;
An [[#Setting up an HTTP proxy|HTTP proxy]] must be set up. This is the only way of securing older version of [[mhttpd]] (pre August 2015). Older versions of mhttpd are started using the -p port option  e.g.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; mhttpd  -D -p 8080  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To run a new version of mhttpd using an HTTP proxy, use the options provided to run the old (non-Mongoose) webserver on a given port, i.e.&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;  mhttpd --oldserver 8080 --nomg   -D  &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using an SSL proxy, only access from the SSL proxy (and maybe some special trusted machines) should be permitted. &lt;br /&gt;
This is done using the &amp;quot;-a hostname&amp;quot; switch of [[mhttpd]]. Normally there will be only &amp;quot;-a localhost&amp;quot; switch, enabling access only for the local machine (where the SSL proxy is running). Additional &amp;quot;-a hostname&amp;quot; switches enable access from listed local machines. No &amp;quot;-a xxx&amp;quot; enables access from everywhere (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere, i.e. by a site firewall or by local firewall rules).&lt;br /&gt;
&lt;br /&gt;
== Setting up an HTTP proxy ==&lt;br /&gt;
In this example, we use APACHE HTTPD to password-protect a typical midas/mhttpd and elog installation.&lt;br /&gt;
&lt;br /&gt;
In this configuration, one uses the Linux stock httpd that accepts encrypted https:// connections and forwards them to mhttpd and elogd. Instead of (or in addition to) using mhttpd and elogd passwords, one configures password protection in httpd via the regular apache httpd password mechanisms (htpasswd, etc).&lt;br /&gt;
&lt;br /&gt;
Recent versions of elogd do support SSL https:// connections, but if one is running an SSL proxy for anyway, it is simpler to run both through the same SSL proxy using the same SSL host certificate and the same httpd password file.&lt;br /&gt;
&lt;br /&gt;
=== Restricting http: access to elogd ===&lt;br /&gt;
;Note&lt;br /&gt;
:Recent versions of elogd do support SSL https:// connections. The following information is for those using an HTTP proxy (see above).&lt;br /&gt;
&lt;br /&gt;
For elogd, this is done using the &amp;quot;-n localhost&amp;quot; switch with enables only access from the same machine if present, or access from anywhere is absent (defeating the purpose of the SSL proxy, unless access controls are enforced elsewhere).&lt;br /&gt;
&lt;br /&gt;
(It is recommended to run elogd from the same user as the main daq user and to keep elogd.cfg and all logbooks in the home directory of this user, where they are captured by the normal site backup system)&lt;br /&gt;
&lt;br /&gt;
== Install standalone elog ==&lt;br /&gt;
&lt;br /&gt;
* login into the user account that will run the elog&lt;br /&gt;
* cd $HOME/packages&lt;br /&gt;
* git clone https://bitbucket.org/ritt/elog&lt;br /&gt;
* cd elog&lt;br /&gt;
* make&lt;br /&gt;
* create new file start_elogd with this contents:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
&lt;br /&gt;
killall elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
killall -KILL elogd&lt;br /&gt;
sleep 1&lt;br /&gt;
$HOME/packages/elog/elogd -n localhost -x -c $HOME/packages/elog/elogd.cfg -p 8082 -D&lt;br /&gt;
&lt;br /&gt;
#end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x start_elogd&lt;br /&gt;
* edit elogd.cfg to read:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
port = 8082&lt;br /&gt;
SMTP host = smtp.triumf.ca&lt;br /&gt;
URL = https://titan00.triumf.ca/elog/&lt;br /&gt;
&lt;br /&gt;
Reverse sort = 1&lt;br /&gt;
Display Mode = full&lt;br /&gt;
&lt;br /&gt;
#List Menu commands = New, Find, Admin, Help&lt;br /&gt;
#Menu commands = New, Edit, Reply, Find, Duplicate, Help&lt;br /&gt;
&lt;br /&gt;
Entries Per Page = 30&lt;br /&gt;
Supress Email on edit = 1&lt;br /&gt;
Default encoding = 1&lt;br /&gt;
Page title = TITAN ELOG&lt;br /&gt;
Resolve host names = 1&lt;br /&gt;
&lt;br /&gt;
Logfile = /home/titan/packages/elog/elogd.log&lt;br /&gt;
#Logging level = 3&lt;br /&gt;
&lt;br /&gt;
[midas]&lt;br /&gt;
&lt;br /&gt;
List page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
Comment = T2K M11 MIDAS ELOG&lt;br /&gt;
Page Title = T2K M11 MIDAS ELOG&lt;br /&gt;
RSS Title = [$logbook - $type - $system] $subject, posted by $author&lt;br /&gt;
&lt;br /&gt;
Attributes = Author, Subject, Run, Type, System&lt;br /&gt;
Show Attributes Edit = Run, Author, Subject, Type, System&lt;br /&gt;
Required Attributes = Author, Type, System, Subject&lt;br /&gt;
&lt;br /&gt;
Options Type = Routine, Reply, Shift Summary, Modification, Question, Info, Problem&lt;br /&gt;
Options System = General, DAQ, Beamline&lt;br /&gt;
&lt;br /&gt;
Preset Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
Preset On Reply Type = Reply&lt;br /&gt;
Preset On Reply Run = $shell(MIDASSYS=. /home/t2km11/packages/midas/linux/bin/odbedit -d Runinfo -c &#039;ls -v \&amp;quot;run number\&amp;quot;&#039;)&lt;br /&gt;
&lt;br /&gt;
List Display = Date, Subject, Type, System, Author, ID&lt;br /&gt;
Quick Filter = Date, Type, ID&lt;br /&gt;
&lt;br /&gt;
Remove on reply = Author&lt;br /&gt;
Quote on reply = 1&lt;br /&gt;
&lt;br /&gt;
Use lock = 1&lt;br /&gt;
&lt;br /&gt;
************* Email Functionality ****************&lt;br /&gt;
&lt;br /&gt;
Use Email Subject = [T2KM11 - $System] $Subject&lt;br /&gt;
Omit Email To = 1&lt;br /&gt;
&lt;br /&gt;
Email System General = xxx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* ./start_elogd &amp;amp;&lt;br /&gt;
* firefox http://localhost:8082 # hould show the elog message index&lt;br /&gt;
&lt;br /&gt;
To start elogd automatically when the machine is rebooted, login as root and&lt;br /&gt;
* add this text to /etc/rc.local:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
su - titan -c &amp;quot;/home/titan/packages/elog/start_elogd&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* chmod a+x /etc/rc.local&lt;br /&gt;
* systemctl start rc-local&lt;br /&gt;
&lt;br /&gt;
To import elog entries from the mhttpd elog, do this:&lt;br /&gt;
&lt;br /&gt;
* cd ~/packages/elog/logbooks&lt;br /&gt;
* ln -s /home/t2km11/online/elog midas&lt;br /&gt;
* cd midas&lt;br /&gt;
* ~/packages/elog/elconv)&lt;br /&gt;
&lt;br /&gt;
== Install https proxy ==&lt;br /&gt;
&lt;br /&gt;
THESE INSTRUCTIONS ARE OBSOLETE, INSTEAD, &lt;br /&gt;
* GO HERE: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* AND GO HERE: https://midas.triumf.ca/MidasWiki/index.php/Quickstart_Linux#Run_the_MIDAS_Web_Server&lt;br /&gt;
&lt;br /&gt;
FOLLOWING INSTRUCTIONS ARE OBSOLETE...&lt;br /&gt;
&lt;br /&gt;
* login as root to the https proxy machine&lt;br /&gt;
* cd ~root&lt;br /&gt;
* yum install mod_ssl&lt;br /&gt;
* yum install crypto-utils # see http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_monitoring_of_HTTPS_certificates&lt;br /&gt;
* create a certificate request (replace ladd09 with your hostname): openssl req -new -nodes -newkey rsa:2048 -sha256 -out ladd09.csr -keyout ladd09.key (answer: CA, BC, Vancouver, TRIUMF, DAQ, ladd09.triumf.ca, email@email.com&lt;br /&gt;
* sign it by TRIUMF:&lt;br /&gt;
** mail -s &amp;quot;Certificate request&amp;quot; yourself@email.com &amp;amp;lt; ladd09.csr&lt;br /&gt;
** forward this request to Andrew Daviel&lt;br /&gt;
** he will email the signed crt file, copy it to this system as ladd09.crt&lt;br /&gt;
* sign it yourself: openssl x509 -req -days 365 -sha256 -in ladd09.csr -signkey ladd09.key -out ladd09.crt&lt;br /&gt;
* (if the certificate expires, renew it by signing it again)&lt;br /&gt;
* Additional commands for working with certificates:&lt;br /&gt;
** explore the private key: openssl pkey -in ladd09.key -text -noout&lt;br /&gt;
** explore the certificate request: openssl req -in ladd00.csr -text -noout&lt;br /&gt;
** explore the certificate: openssl x509 -in ladd09.crt -noout -text&lt;br /&gt;
* move certificate files to proper system locations:&lt;br /&gt;
* mv ladd09.key  /etc/pki/tls/private/&lt;br /&gt;
* mv ladd09.crt /etc/pki/tls/certs/&lt;br /&gt;
* if selinux is enabled, do this:&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/certs/&lt;br /&gt;
** restorecon -Rv /etc/pki/tls/private/&lt;br /&gt;
** /usr/sbin/setsebool -P httpd_can_network_connect 1&lt;br /&gt;
* open /etc/httpd/conf.d/ssl.conf in a text editor, go to the very bottom and right before the &amp;quot;&amp;lt;/VirtualHost&amp;gt;&amp;quot; entry, add following text:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateFile /etc/pki/tls/certs/ladd09.crt &lt;br /&gt;
SSLCertificateKeyFile /etc/pki/tls/private/ladd09.key &lt;br /&gt;
&lt;br /&gt;
ProxyPass /elog/ http://localhost:8082/ retry=1&lt;br /&gt;
ProxyPass /      http://localhost:8080/ retry=1&lt;br /&gt;
&lt;br /&gt;
&amp;lt;Location /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SSLRequireSSL&lt;br /&gt;
AuthType Basic&lt;br /&gt;
AuthName &amp;quot;password protected site&amp;quot;&lt;br /&gt;
Require valid-user&lt;br /&gt;
&lt;br /&gt;
# create password file: touch /etc/httpd/htpasswd&lt;br /&gt;
# to add new user or change password: htpasswd /etc/httpd/htpasswd username&lt;br /&gt;
AuthUserFile /etc/httpd/htpasswd&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/Location&amp;gt;&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* comment out duplicate &amp;quot;SSLCertificateFile&amp;quot; and &amp;quot;SSLCertificateKeyFile&amp;quot; elsewhere in the file&lt;br /&gt;
* (optionally) If you got a certificate that is signed by DigiCert or RapidSSL then you&#039;ll need to add a line specifying the certificate chain file:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
SSLCertificateChainFile /etc/pki/tls/certs/DigiCertCA.crt&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* touch /etc/httpd/htpasswd&lt;br /&gt;
* htpasswd /etc/httpd/htpasswd midas # enter password midas&lt;br /&gt;
* chkconfig httpd on&lt;br /&gt;
* service httpd restart&lt;br /&gt;
* firewall-cmd --add-port=443/tcp --permanent&lt;br /&gt;
* firewall-cmd --reload&lt;br /&gt;
* firewall-cmd --list-all&lt;br /&gt;
* test it&lt;br /&gt;
** test the SSL proxy: https://host/ should yield the midas status page, https://host/elog/ should yield the elog message index&lt;br /&gt;
* in ODB, set &amp;quot;/Elog/URL&amp;quot; to &amp;quot;https://host/elog/&amp;quot;&lt;br /&gt;
* now from the midas status page, the &amp;quot;Elog&amp;quot; button should take us to the https Elog URL&lt;br /&gt;
&lt;br /&gt;
In needed, enable user directories: https://blah/~user in ~user/public_html&lt;br /&gt;
&lt;br /&gt;
* edit /etc/httpd/conf.d/userdir.conf, replace &amp;quot;UserDir disabled&amp;quot; with &amp;quot;UserDir enabled&amp;quot;&lt;br /&gt;
* setsebool -P httpd_enable_homedirs true&lt;br /&gt;
* systemctl restart httpd&lt;br /&gt;
&lt;br /&gt;
== Setup the history mhttpd for faster access to history plots ==&lt;br /&gt;
When running an SSL proxy,&lt;br /&gt;
* start the main mhttpd (&amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;orange&amp;lt;/span&amp;gt; command for old mhttpd, &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;green&amp;lt;/span&amp;gt; for new mhttpd with Mongoose(post August2015):&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* start the history mhttpd&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt; &amp;quot;mhttpd -p 8072 -D -H&amp;quot;&amp;lt;/span&amp;gt; or&lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* set ODB /History/URL to &amp;quot;http://alphacpc09.cern.ch:8072/HS/&amp;quot;&lt;br /&gt;
* open the MIDAS status page&lt;br /&gt;
* go to the history section, try to open any history plot, observe that the history plot gif image loads correctly, inspect it&#039;s URL (use &amp;quot;copy image URL&amp;quot; or &amp;quot;view source&amp;quot;, etc), it should point to port 8072 causing connection to the history mhttpd.&lt;br /&gt;
* continue with these instructions to setup history mhttpd access through an SSL proxy:&lt;br /&gt;
* setup SSL proxy access (required mod_proxy_html)&lt;br /&gt;
** login as root to the SSL proxy machine&lt;br /&gt;
** on SL5, install the missing mod_proxy_html httpd module:&lt;br /&gt;
** yum install httpd-devel libxml2-devel&lt;br /&gt;
** wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.tar.bz2&lt;br /&gt;
** tar xjvf mod_proxy_html.tar.bz2 &lt;br /&gt;
** cd mod_proxy_html&lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_proxy_html.c &lt;br /&gt;
** apxs -c -I. -I/usr/include/libxml2 -i mod_xml2enc.c&lt;br /&gt;
** cd /etc/httpd/conf.d, add this to ssl.conf:&lt;br /&gt;
&lt;br /&gt;
;before the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# proxy the MIDAS web servers  &lt;br /&gt;
LoadModule  xml2enc_module       modules/mod_xml2enc.so  &lt;br /&gt;
LoadModule  proxy_html_module    modules/mod_proxy_html.so  &lt;br /&gt;
ProxyHTMLLinks  a               href  &lt;br /&gt;
ProxyHTMLLinks  link            href  &lt;br /&gt;
ProxyHTMLLinks  img             src  &lt;br /&gt;
#ProxyHTMLEnable On  &lt;br /&gt;
ProxyRequests off  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;after the ProxyPass statements:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ALPHA1 history access &lt;br /&gt;
ProxyPass /alpha1/history/   http://alphacpc09.cern.ch:8072/HS/  retry=1 &lt;br /&gt;
ProxyPass /alpha1/           http://alphacpc09.cern.ch:8071/     retry=1 &lt;br /&gt;
 &lt;br /&gt;
ProxyHTMLEnable On  &lt;br /&gt;
ProxyHTMLURLMap http://alphacpc09.cern.ch:8072/HS/ /alpha1/history/ &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
;adjust:&lt;br /&gt;
*&amp;quot;alpha1&amp;quot; is the experiment name&lt;br /&gt;
*&amp;quot;alphacpc09.cern.ch&amp;quot; is the machine running mhttpd&lt;br /&gt;
*&amp;quot;8071&amp;quot; is the port number of the main mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8071 -D&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D --oldserver 8071 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
* &amp;quot;8072&amp;quot; is the port number of the history mhttpd &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:orange&amp;quot;&amp;gt;&amp;quot;mhttpd -p 8072 -D -H&amp;quot; &amp;lt;/span&amp;gt;  or  &lt;br /&gt;
** &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; &amp;quot;mhttpd  -D -H --oldserver 8072 --nomg&amp;quot; &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]] [[Category:Buffer]] [[Category:Driver]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2565</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2565"/>
		<updated>2016-11-16T23:41:26Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* ROOTANA Package Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
&lt;br /&gt;
Install the ROOT analyzer package:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add ROOTANASYS=$HOME/packages/rootana to the login file.&lt;br /&gt;
&lt;br /&gt;
Install the JSROOT package:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cd $HOME/packages&lt;br /&gt;
git clone https://github.com/linev/jsroot.git&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
add JSROOTSYS=$HOME/packages/jsroot to the login file.&lt;br /&gt;
&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page there will be 3 new equipment entries:&lt;br /&gt;
* test -&amp;gt; empty data bank for daq speed benchmarking&lt;br /&gt;
* slow -&amp;gt; example slow controls data for testing the midas history plots&lt;br /&gt;
* random -&amp;gt; example collection of data banks for testing the analyzer&lt;br /&gt;
&lt;br /&gt;
Start a run.&lt;br /&gt;
&lt;br /&gt;
Observe event counters are incrementing, output data file size is growing.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Create a history plot ==&lt;br /&gt;
&lt;br /&gt;
Go to the MIDAS &amp;quot;History&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
Say &amp;quot;new&amp;quot;, panel name &amp;quot;test&amp;quot;. In the history editor select event &amp;quot;slow&amp;quot;, say &amp;quot;save&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
History plot &amp;quot;test&amp;quot; should open with a sine-wave plot. Data on the plot should update as long as &amp;quot;fetest&amp;quot; is running. (there is no need to start a run).&lt;br /&gt;
&lt;br /&gt;
Press web browser &amp;quot;reload&amp;quot; to update the plot.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2564</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2564"/>
		<updated>2016-11-08T01:28:22Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Run test frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
If ROOTANA is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page there will be 3 new equipment entries:&lt;br /&gt;
* test -&amp;gt; empty data bank for daq speed benchmarking&lt;br /&gt;
* slow -&amp;gt; example slow controls data for testing the midas history plots&lt;br /&gt;
* random -&amp;gt; example collection of data banks for testing the analyzer&lt;br /&gt;
&lt;br /&gt;
Start a run.&lt;br /&gt;
&lt;br /&gt;
Observe event counters are incrementing, output data file size is growing.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Create a history plot ==&lt;br /&gt;
&lt;br /&gt;
Go to the MIDAS &amp;quot;History&amp;quot; page.&lt;br /&gt;
&lt;br /&gt;
Say &amp;quot;new&amp;quot;, panel name &amp;quot;test&amp;quot;. In the history editor select event &amp;quot;slow&amp;quot;, say &amp;quot;save&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
History plot &amp;quot;test&amp;quot; should open with a sine-wave plot. Data on the plot should update as long as &amp;quot;fetest&amp;quot; is running. (there is no need to start a run).&lt;br /&gt;
&lt;br /&gt;
Press web browser &amp;quot;reload&amp;quot; to update the plot.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2563</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2563"/>
		<updated>2016-11-08T01:24:44Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Run test frontend */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
If ROOTANA is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page there will be 3 new equipment entries:&lt;br /&gt;
* test -&amp;gt; empty data bank for daq speed benchmarking&lt;br /&gt;
* slow -&amp;gt; example slow controls data for testing the midas history plots&lt;br /&gt;
* random -&amp;gt; example collection of data banks for testing the analyzer&lt;br /&gt;
&lt;br /&gt;
Start a run.&lt;br /&gt;
&lt;br /&gt;
Observe event counters are incrementing, output data file size is growing.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2562</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2562"/>
		<updated>2016-11-08T01:21:06Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Clients run on Localhost only */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
If ROOTANA is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Run test frontend ==&lt;br /&gt;
&lt;br /&gt;
Run fetest&lt;br /&gt;
&lt;br /&gt;
On the MIDAS &amp;quot;Status&amp;quot; page...&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2561</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2561"/>
		<updated>2016-11-08T01:16:33Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Run the MIDAS logger */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
If ROOTANA is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Start a run, wait 10 seconds, stop the run.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS &amp;quot;Status&amp;quot; page, go to the &amp;quot;logging channels -&amp;gt; channel #0&amp;quot; and set ODB variables:&lt;br /&gt;
* Output -&amp;gt; &amp;quot;FILE&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Start a run, go to the &amp;quot;Status&amp;quot; page, observe that the output file is written with gzip compression and has the &amp;quot;mid.gz&amp;quot; extension.&lt;br /&gt;
&lt;br /&gt;
Stop the run.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
	<entry>
		<id>https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2560</id>
		<title>Quickstart Linux</title>
		<link rel="alternate" type="text/html" href="https://daq00.triumf.ca/MidasWiki/index.php?title=Quickstart_Linux&amp;diff=2560"/>
		<updated>2016-11-08T01:12:32Z</updated>

		<summary type="html">&lt;p&gt;Olchansk: /* Run the MIDAS logger */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Pagelinks}}&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This quickstart shows you how to install the MIDAS packages on a linux box and create a &#039;&#039;&#039;MIDAS experiment&#039;&#039;&#039;. &lt;br /&gt;
The linux box will be called the MIDAS &#039;&#039;&#039;&#039;&#039;experiment host&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
Log on to the &#039;&#039;[[#Introduction|Experiment Host]]&#039;&#039; and decide on a name for the MIDAS experiment (the &#039;&#039;experiment name&#039;&#039;).&lt;br /&gt;
In these instructions, the MIDAS packages and experiment will be installed under the username &amp;quot;johnfoo&amp;quot;. &lt;br /&gt;
The ODB and other shared memory buffers for the MIDAS experiment will reside on the &#039;&#039;experiment host&#039;&#039; (localhost).&lt;br /&gt;
MIDAS and the other required packages will be installed under directory  {{Filepath|path=$HOME/packages}}. The MIDAS &#039;&#039;experiment directory&#039;&#039; will be  {{Filepath|path=$HOME/online}} and the MIDAS &#039;&#039;experiment name&#039;&#039; will be &amp;quot;e777&amp;quot;. The name of the &#039;&#039;experiment host&#039;&#039; will be &amp;quot;mhostpc&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
;NOTE&lt;br /&gt;
: The user should substitute directory paths for the MIDAS packages and experiment directory as required, and names for &#039;&#039;experiment host&#039;&#039;, username, &#039;&#039;experiment name&#039;&#039; appropriate to his/her own setup.&lt;br /&gt;
&lt;br /&gt;
== Experimental setup ==&lt;br /&gt;
These instructions describe setting up an experiment that will run ONLY on the MIDAS &#039;&#039;experiment host&#039;&#039; computer (i.e. &#039;&#039;&#039;localhost only&#039;&#039;&#039;). In this case, the MIDAS &#039;&#039;experiment host&#039;&#039; has access to any hardware required, and all frontends, logger, analyzer etc. run on the one computer. &lt;br /&gt;
&lt;br /&gt;
Modifications to run an experiment with additional frontend(s) running &#039;&#039;&#039;remotely&#039;&#039;&#039; (i.e. on remote cpu(s)) will also be described.&lt;br /&gt;
Follow the instructions for setting up a localhost-only experiment until indicated. &lt;br /&gt;
 &lt;br /&gt;
In both cases, the main MIDAS applications (e.g. [[mlogger]], [[mhttpd]]) run on the MIDAS &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Environment Variables==&lt;br /&gt;
The following Environment variables should to be added to the  {{File|name=.cshrc}} or {{File|name=.bashrc}} file (depending on your shell) in the {{Filepath|path=$HOME}} directory on the &#039;&#039;experiment host&#039;&#039;,  so that they will be defined at login. &#039;&#039;&#039;Substitute appropriate values for your own setup&#039;&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! csh  !! bash !! comment&lt;br /&gt;
|-&lt;br /&gt;
| setenv GIT_EDITOR &amp;quot;emacs -nw&amp;quot; || export GIT_EDITOR=&amp;quot;emacs -nw&amp;quot; ||&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDASSYS $HOME/packages/midas ||  export MIDASSYS=$HOME/packages/midas ||Base directory of the MIDAS package&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPTAB $HOME/online/exptab || export MIDAS_EXPTAB=$HOME/online/exptab  || MIDAS experiment table &lt;br /&gt;
|-&lt;br /&gt;
|-&lt;br /&gt;
| setenv MIDAS_EXPT_NAME e777  || export MIDAS_EXPT_NAME=e777  || MIDAS experiment name&lt;br /&gt;
|-&lt;br /&gt;
| setenv PATH .:$MIDASSYS/linux/bin:$PATH  || export PATH=$PATH:$MIDASSYS/linux/bin || path&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Logout and login again, or source {{File|name=.cshrc}} (source {{File|name=.bashrc}}) for the changes to take effect.&lt;br /&gt;
;NOTE&lt;br /&gt;
: See [[MIDAS environment variables]] for a list of environment variables used by MIDAS.&lt;br /&gt;
&lt;br /&gt;
== ROOT Package Installation ==&lt;br /&gt;
For full MIDAS operation, ROOT is needed for the data logging and analysis packages. It needed to build the example analyzer in this Quickstart.  However, ROOT is not essential to run MIDAS. If ROOT is NOT installed, the environment variable ROOTSYS should be undefined.&lt;br /&gt;
&lt;br /&gt;
If ROOT is needed, see [[Setup MIDAS experiment#Install ROOT|Install ROOT]].&lt;br /&gt;
&lt;br /&gt;
== MIDAS Package Installation ==&lt;br /&gt;
The MIDAS package will be installed on the &#039;&#039;experiment host&#039;&#039; in the directory given by MIDASSYS - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
Install the MIDAS and other package(s) from the MIDAS git repository in an xterm as follows:&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/packages&lt;br /&gt;
   [mhostpc] cd $HOME/packages&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/midas&lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mxml&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Install the MSCB  package &#039;&#039;&#039;only&#039;&#039;&#039; if you will be using the MSCB system for slow-controls (see [[MSCB Page]]):&lt;br /&gt;
&amp;lt;small&amp;gt; &lt;br /&gt;
   [mhostpc] git clone https://bitbucket.org/tmidas/mscb    ## MSCB package&lt;br /&gt;
   [mhostpc] cd mscb&lt;br /&gt;
   [mhostpc] make        ## Build the MSCB package&lt;br /&gt;
   [mhostpc] cd ../&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
The MIDAS Makefile will auto-detect whether MSCB, ROOT, MYSQL, SQLITE, ODBC etc. are available (or have been installed). If you need these features, make sure they are available before building the MIDAS package.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cd midas&lt;br /&gt;
   [mhostpc] make          ## Build the MIDAS package&lt;br /&gt;
   [mhostpc] ls -l linux/bin/odbedit      ### check that odbedit has been created (do not run it yet)&lt;br /&gt;
&amp;lt;/small&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
In case of problems see &lt;br /&gt;
* [[Installation#Installing MIDAS|bitbucket is down]] or &lt;br /&gt;
* [[Installation/Compilation problems#SSL certificate errors|SSL certificate errors]].&lt;br /&gt;
&lt;br /&gt;
==ROOTANA Package Installation==&lt;br /&gt;
If ROOTANA is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/rootana&lt;br /&gt;
    [mhostpc] cd rootana&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
==ROODY Package Installation==&lt;br /&gt;
If ROODY is needed,&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd $HOME/packages&lt;br /&gt;
    [mhostpc] git clone https://bitbucket.org/tmidas/roody&lt;br /&gt;
    [mhostpc] cd roody&lt;br /&gt;
    [mhostpc] make&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
== Create the Experiment file exptab ==&lt;br /&gt;
In this example, the experimental directory is {{Filepath|path=$HOME/online}}. Create this directory on the &#039;&#039;experiment host&#039;&#039; (localhost):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] mkdir $HOME/online&lt;br /&gt;
   [mhostpc] cd $HOME/online&amp;lt;/small&amp;gt;&lt;br /&gt;
Then create the [[exptab]] file {{Filepath|path=$HOME/online/exptab}} containing the three parameters:&lt;br /&gt;
# the experiment name &lt;br /&gt;
# location of MIDAS shared memory buffers&lt;br /&gt;
# username&lt;br /&gt;
as follows (using parameters for your own experiment):&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] cat &amp;gt; exptab&lt;br /&gt;
    e777 /home/johnfoo/online johnfoo&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The path of the  {{File|name=exptab}} file is given by MIDAS_EXPTAB - see [[#Environment Variables]].&lt;br /&gt;
&lt;br /&gt;
== Create shared memory files  ==&lt;br /&gt;
At this point you should be able to run [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; (localhost). The first time  {{Utility|name=odbedit}} is run, it will create the required  {{File|name=.*.SHM}} files  in the MIDAS experiment directory  {{Filepath|path=$HOME/online}}. These are the saved files for the MIDAS shared memory.&lt;br /&gt;
&lt;br /&gt;
The default directory  {{Filepath|path=$HOME/online}} will contain the MIDAS messages file ({{File|name=midas.log}}) and&lt;br /&gt;
any data files you may create. If you want an alternative location for the data files see [[#Customizing your experiment]].&lt;br /&gt;
  &lt;br /&gt;
Run {{Utility|name=odbedit}}, and type {{Odbedit cmd|cmd=ls}} to list the default directories. &lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] odbedit&lt;br /&gt;
 [local:e777:S]/&amp;gt;ls&lt;br /&gt;
 Experiment&lt;br /&gt;
 System&lt;br /&gt;
 Programs&lt;br /&gt;
 Logger&lt;br /&gt;
 Runinfo&lt;br /&gt;
 Alarms&amp;lt;/small&amp;gt; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS Web Server ==&lt;br /&gt;
&lt;br /&gt;
Recommended for production systems with maximum security is to run mhttpd behind an industry-standard SSL/https proxy with password protection.&lt;br /&gt;
&lt;br /&gt;
To do this using apache httpd on CentOS-7, do this:&lt;br /&gt;
* configure apache httpd per instructions at https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Configure_HTTPS_server_.28CentOS7.29&lt;br /&gt;
* run odbedit, change values of&lt;br /&gt;
** &amp;quot;/experiment/http redirect to https&amp;quot; set to &amp;quot;n&amp;quot;&lt;br /&gt;
** &amp;quot;/experiment/midas https port&amp;quot; set to 0&lt;br /&gt;
* run mhttpd&lt;br /&gt;
* use web browser to connect to https://mhostpc/&lt;br /&gt;
* enter the user name and password configured in apache httpd&lt;br /&gt;
* the midas status page should open&lt;br /&gt;
&lt;br /&gt;
For simplified installation, one can use standalone mhttpd with built-in https and password protection. This configuration&lt;br /&gt;
is only as secure as the underlying mongoose and OpenSSL web server and encryption packages.&lt;br /&gt;
&lt;br /&gt;
Many current operating systems implement a built-in firewall which will block outside access to mhttpd.&lt;br /&gt;
&lt;br /&gt;
On CentOS-7, so this: https://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
Start [[mhttpd]] on the &#039;&#039;experiment host&#039;&#039; (localhost) like this:&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&amp;lt;/small&amp;gt;&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17892:mongoose,ERROR] cannot find SSL certificate file &amp;quot;/home/agdaq/online/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17893:mongoose,ERROR] please create SSL certificate file: openssl req -new -nodes -newkey rsa:2048 -sha256 -out ssl_cert.csr -keyout ssl_cert.key; openssl x509 -req -days 365 -sha256 -in ssl_cert.csr -signkey ssl_cert.key -out ssl_cert.pem; cat ssl_cert.key &amp;gt;&amp;gt; ssl_cert.pem&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create a self-signed certificate suitable for initial testing by executing the commands printed by mhttpd.&lt;br /&gt;
&lt;br /&gt;
For production use, you should create a properly signed certificate, see [[Mhttpd#Create an SSL certificate|create your own SSL certificate]] or you should run mhttpd behind an SSL/https proxy (apache httpd).&lt;br /&gt;
&lt;br /&gt;
Run mhttpd again.&lt;br /&gt;
&lt;br /&gt;
You will get the following messages: &lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot;&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/johnfoo/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17633:mongoose,ERROR] mongoose web server cannot find password file &amp;quot;/home/johnfoo/online/htpasswd.txt&amp;quot;&lt;br /&gt;
 [mhttpd,ERROR] [mhttpd.cxx:17634:mongoose,ERROR] please create password file: htdigest -c /home/johnfoo/online/htpasswd.txt Default midas&lt;br /&gt;
 could not start the mongoose web server, see messages and midas.log, bye!&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Create the password file by following the instructions printed by mhttpd. The http digest domain name is the experiment name, suggested default user name is &amp;quot;midas&amp;quot;. You will be asked to type in a password. (htdigest is part of the httpd-tools package)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 [mhostpc] htdigest -c /home/johnfoo/online/htpasswd.txt exptname midas&lt;br /&gt;
 Adding password for midas in realm exptname.&lt;br /&gt;
 New password:&lt;br /&gt;
 Re-type new password:&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
It is a good idea to set the password file {{Filepath|path=htpasswd.txt}} readable and writable by owner only.&lt;br /&gt;
&lt;br /&gt;
Now restart  {{Utility|name=mhttpd}}&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mhttpd&lt;br /&gt;
 Mongoose web server will listen on ports &amp;quot;8080r,8443s&amp;quot; **see note&lt;br /&gt;
 Mongoose web server will use SSL certificate file &amp;quot;/home/suz/packages/midas/ssl_cert.pem&amp;quot;&lt;br /&gt;
 Mongoose web server will use authentication realm &amp;quot;Default&amp;quot;, password file &amp;quot;./htpasswd.txt&amp;quot;&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Now point a web browser running on the same host computer (localhost) to https://localhost:8443&lt;br /&gt;
If the web browser is running on a different computer, go to URL of the form&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 https://mhostpc.triumf.ca:8443  (substitute your host machine name and domain for &amp;quot;mhostpc.triumf.ca&amp;quot;)&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
If you are using the default SSL certificate you will probably get a message: &amp;quot;This Connection is Untrusted&amp;quot;.  Click &amp;quot;I understand the risks&amp;quot; and add an exception. This is because the test certificate is self-signed. Then confirm an exception. &lt;br /&gt;
&lt;br /&gt;
If instead you get a &amp;quot;connection refused&amp;quot; error, the midas host pc may have the firewall enabled. To make a firewall exception for MIDAS, follow instructions here http://www.triumf.info/wiki/DAQwiki/index.php/SLinstall#Enable_firewall_for_MIDAS_.28CentOS7.29&lt;br /&gt;
&lt;br /&gt;
You should then see an authentication box asking you for the user name and password. The user name is &amp;quot;midas&amp;quot;. Enter the password you just created. The Midas [[Status Page]] should appear with multiple buttons for run control as well as equipment listing (no equipments will be listed as yet) and application listings. Please refer to [[mhttpd]] (the MIDAS Web-based Run Control utility) for further information. You can start and stop runs from the main status page, and use the [[ODB Page]] to access the database (ODB).&lt;br /&gt;
&lt;br /&gt;
; Note &lt;br /&gt;
: Default ports of 8080 and 8443 are used by [[mhttpd]]. To use some other ports, change the values of ODB &amp;quot;/experiment/midas http port&amp;quot; and &amp;quot;midas https port&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Run the MIDAS logger ==&lt;br /&gt;
Start the MIDAS logger [[mlogger]] on the &#039;&#039;experiment host&#039;&#039; (localhost) :&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] mlogger&amp;lt;/small&amp;gt; &lt;br /&gt;
This should start without error. It is usually run as a daemon, however in this case it is run in a terminal to check for errors. Starting the midas logger [[mlogger]] will automatically create more keys in the  {{Odbpath|path=/Logger}} ODB tree.&lt;br /&gt;
&lt;br /&gt;
From the MIDAS status page, go to the &amp;quot;Programs&amp;quot; page, then the &amp;quot;Logger&amp;quot; page and set ODB variables:&lt;br /&gt;
* Required -&amp;gt; set to &amp;quot;y&amp;quot;&lt;br /&gt;
* Start command -&amp;gt; set to &amp;quot;mlogger -D&amp;quot;&lt;br /&gt;
* Alarm Class -&amp;gt; set to &amp;quot;Alarm&amp;quot;&lt;br /&gt;
&lt;br /&gt;
To test this, go to the &amp;quot;Programs&amp;quot; page, press &amp;quot;stop logger&amp;quot;, then &amp;quot;start logger&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== Clients run on Localhost only ==&lt;br /&gt;
;NOTE: &lt;br /&gt;
* If creating a MIDAS experiment with a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend, &#039;&#039;&#039;continue by following the instructions&#039;&#039;&#039; [[#Running with one or more REMOTE frontends]].&lt;br /&gt;
* If all clients are running on the Experiment Host (i.e. &#039;&#039;&#039;localhost&#039;&#039;&#039;), continue with the following instructions:&lt;br /&gt;
&lt;br /&gt;
=== Frontend and Analyzer (localhost) ===&lt;br /&gt;
&lt;br /&gt;
THIS SECTION IS VERY OBSOLETE&lt;br /&gt;
&lt;br /&gt;
There are several examples of [[Frontend user code]] ({{File|name=frontend.c}}) in the MIDAS package available under {{Filepath|path=$MIDASSYS/examples/}}. Choose a suitable example from this directory that you can later modify for your own particular setup (e.g. for a slow control, choose the {{Filepath|path=../slowcont/}} example). &lt;br /&gt;
&lt;br /&gt;
A &#039;&#039;&#039;frontend&#039;&#039;&#039; is a program that usually reads data from the hardware and sends it to a buffer to be logged and analyzed. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]].&lt;br /&gt;
&lt;br /&gt;
The example chosen here is from  {{Filepath|path=$MIDASSYS/examples/experiment/}}. It does &#039;&#039;&#039;not need any hardware&#039;&#039;&#039; and produces simulated events.  &lt;br /&gt;
&lt;br /&gt;
On the MIDAS &#039;&#039;experiment host&#039;&#039; (localhost), copy the example to the experiment directory and build it.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] cd $HOME/online&lt;br /&gt;
      [mhostpc] cp $MIDASSYS/examples/experiment/* .&lt;br /&gt;
      [mhostpc] make&amp;lt;/small&amp;gt;&lt;br /&gt;
The analyzer will only build if ROOT has previously been installed.&lt;br /&gt;
At this point the frontend and the analyzer should be ready if no errors were generated during the build. Try the frontend and analyzer by starting them in xterms. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
      [mhostpc] frontend&lt;br /&gt;
      [mhostpc] analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Equipment ODB tree ===&lt;br /&gt;
Starting the frontend will automatically create the  {{Odbpath|path=/Equipment}} ODB tree and one or more equipments. In this case, the equipments &amp;quot;trigger&amp;quot; and &amp;quot;scaler&amp;quot; have been defined by code in  {{File|name=frontend.c}} and created the first time frontend runs.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
     [mhostpc] odbedit&lt;br /&gt;
     [local:e777:S]/&amp;gt;ls /equipment&lt;br /&gt;
     Trigger                         &lt;br /&gt;
     Scaler  &amp;lt;/small&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
View the MIDAS main status web page (by pointing your browser to https://localhost:8443/ or appropriate port if not using the default).&lt;br /&gt;
Observe on the [[Status Page]] that the two Equipments (Trigger, Scaler) have appeared in the Equipment section (Figure 1) and are coloured green.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:quickstart_status_page.png|thumb|left|Figure 1: web server status page showing example frontend equipments]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rather than using odbedit,  you can view the contents of these equipments by clicking on the ODB button, then on {{Odbpath|path=/Equipment}}, then {{Odbpath|path=Trigger}} or {{Odbpath|path=Scaler}}. See [[ODB Page]] for more information.&lt;br /&gt;
&lt;br /&gt;
=== Start a run ===&lt;br /&gt;
Start a run by pressing the Start button on the [[Status Page]].&lt;br /&gt;
The Equipment display on the Status Page will now show some event statistics (Figure 2)&lt;br /&gt;
&#039;&#039;&#039;Click thumbnail to enlarge&#039;&#039;&#039;&lt;br /&gt;
[[File:sample_frontend_status.png|thumb|left|Figure 2: Equipments shown on Status Page showing event statistics]]&lt;br /&gt;
&amp;lt;div style=&amp;quot;clear: both&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;  &amp;lt;!-- clear wraparound after thumbnail --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The frontend will show an event display that will update when a run is started, e.g.&lt;br /&gt;
&lt;br /&gt;
 Sample Frontend connected to &amp;lt;local&amp;gt;. Press &amp;quot;!&amp;quot; to exit      18:48:2546:08&lt;br /&gt;
 ==========================================================================&lt;br /&gt;
 Run status:   Running    Run number 2                                   |/   /&lt;br /&gt;
 ===========================================================================&lt;br /&gt;
 Equipment     Status     Events     Events/sec Rate[B/s]  ODB-&amp;gt;FE FE-&amp;gt;OD&lt;br /&gt;
 ---------------------------------------------------------------------------&lt;br /&gt;
 Trigger       OK         13948      99.0       5413.0     0          140         &lt;br /&gt;
 Scaler        OK         15         0.3         15.4      0          15    &lt;br /&gt;
&lt;br /&gt;
The [[Status Page]] will also show events being generated (click the refresh button if necessary). &lt;br /&gt;
&lt;br /&gt;
=== Event Dump ===&lt;br /&gt;
While a run is in progress, the midas application [[mdump]] will provide you an event dump of the collected data from the running frontend, e.g.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
  mhostpc&amp;gt; mdump -l 50&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 - MIDAS revision: Mon Nov 2 11:50:51 2015 -0800 - 3b66779 -- Enter &amp;lt;!&amp;gt; to Exit ------- Midas Dump ---&lt;br /&gt;
 ------------------------ Event# 1 ------------------------&lt;br /&gt;
 Evid:0001- Mask:0000- Serial:0- Time:0x567a0c5d- Dsize:40/0x28&lt;br /&gt;
 #banks:2 - Bank list:-ADC0TDC0-&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:ADC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0167 0x03c6 0x0069 0x0073 &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:whitesmoke&amp;quot;&amp;gt;blank&amp;lt;/span&amp;gt;&lt;br /&gt;
 Bank:TDC0 Length: 8(I*1)/2(I*4)/4(Type) Type:Unsigned Integer*2&lt;br /&gt;
   1-&amp;gt; 0x0051 0x00ff 0x004a 0x00ec &lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
For further data processing/analysis, either the midas analyzer or the rootana can used for data display as well. &lt;br /&gt;
&lt;br /&gt;
=== Create a startup script (localhost) ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script. Here, the startup script will be  {{File|name=start_daq.sh}} (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows (supply the [[mhttpd]] ports if default is not used):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;small&amp;gt;#!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port. (Mongoose https version)&lt;br /&gt;
 mhttpd  -D  # you can optionally restrict access to localhost and other specified hosts - see [[mhttpd]]&lt;br /&gt;
 xterm -e ./frontend &amp;amp;&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Before running this script, you will need to shutdown any running clients:&lt;br /&gt;
 &amp;lt;small&amp;gt;mhostpc&amp;gt; odbedit -c &amp;quot;sh all&amp;quot;&amp;lt;/small&amp;gt;&lt;br /&gt;
or you can use the  {{Utility|name=mhttpd}} [[Programs Page]] to shut them down.&lt;br /&gt;
&lt;br /&gt;
The script will start them as daemons. &lt;br /&gt;
By running the startup script start_daq.sh, several MIDAS applications will be started in sequence:&lt;br /&gt;
# Cleanup previous MIDAS application (if any).&lt;br /&gt;
# Start the MIDAS web server [mhttpd]&lt;br /&gt;
# Start the frontend application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the analyzer application in its own xterm (for debugging purpose).&lt;br /&gt;
# Start the MIDAS Data logger [mlogger]&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] sh ./start_daq&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only. &lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running with one or more REMOTE frontends ==&lt;br /&gt;
These instructions assume you have already followed the instructions to setup an experiment running on the MIDAS experiment host (localhost), i.e. you have setup the MIDAS Environment variables, downloaded MIDAS packages, setup the [[mhttpd]] password and have {{Utility|name=mhttpd}} running successfully.&lt;br /&gt;
&lt;br /&gt;
In the case of &#039;&#039;&#039;remote&#039;&#039;&#039; frontend(s), the remote cpu(s) typically have access to some or all of the hardware. They might be VMIC cpus running in VME crates for example, connected to the MIDAS Host via Ethernet.  They read data from the hardware and send it back to the MIDAS &#039;&#039;experiment host&#039;&#039; to be logged and analyzed.&lt;br /&gt;
&lt;br /&gt;
=== Experimental setup (Remote) ===&lt;br /&gt;
These instructions assume that the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 64-bit (if not see [[#Build 32-bit MIDAS libraries|note below]]), and there is one &#039;&#039;remote host&#039;&#039;, a 32-bit machine named &amp;quot;rlxhost&amp;quot;. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;remote host&#039;&#039; mounts the {{Filepath|path=/home}} disk of the &#039;&#039;experiment host&#039;&#039;, so that it &#039;&#039;&#039;has access to the MIDAS packages&#039;&#039;&#039;, the {{Filepath|path=$HOME/online}} directory and shares the .cshrc (or .bashrc) script. It is convenient to set up ssh keys (use ssh-keygen) so that the &#039;&#039;remote host&#039;&#039; can be accessed without supplying the password from the &#039;&#039;experiment host&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If your setup is different, you will have to make changes as appropriate.  &lt;br /&gt;
&lt;br /&gt;
=== Build 32-bit MIDAS libraries ===&lt;br /&gt;
NOTE&lt;br /&gt;
&amp;lt;p style=&amp;quot;margin-left:40px;margin-right:40px;&amp;quot;&amp;gt;&lt;br /&gt;
If the MIDAS &#039;&#039;experiment host&#039;&#039; computer is 32-bit (i.e. the same as the &#039;&#039;remote host&#039;&#039;), which is a simpler setup, you will have built the 32-bit MIDAS libraries already, and can skip the rest of this section. Note however, that in the .cshrc file in the  [[#Modify .cshrc (.bashrc) for Remote host|following section]] you will not need the lines starting &amp;quot;# select 64-bit or 32-bit MIDAS and ROOT&amp;quot;.  The PATH should contain &amp;lt;span style=&amp;quot;color:#214200; font-weight:normal; font-style:italic&amp;quot;&amp;gt;$MIDASSYS/linux/bin&amp;lt;/span&amp;gt; on both experiment host and remote host. This will point to the 32-bit MIDAS libraries. &lt;br /&gt;
------------------------------&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Assuming the MIDAS host computer is 64-bit, you will have already built the 64-bit MIDAS libraries.&lt;br /&gt;
In this case, if the remote frontend is 32-bit, you will need to build the 32-bit MIDAS libraries on the 64-bit machine, i.e.&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] cd /home/packages/midas&lt;br /&gt;
    [mhostpc] make linux32                ### build the 32-bit MIDAS libraries on 64-bit machine&lt;br /&gt;
    [mhostpc] ls -l linux-m32/bin/odbedit ### check that the 32-bit odbedit has been created &amp;lt;/small&amp;gt;&lt;br /&gt;
Do not run  {{Utility|name=odbedit}} yet on the &#039;&#039;remote host&#039;&#039;!&lt;br /&gt;
&lt;br /&gt;
=== Modify .cshrc (.bashrc) for Remote host ===&lt;br /&gt;
Add the following to the {{File|name=.cshrc}} (modified appropriately if using {{File|name=.bashrc}}).  When running with a REMOTE Host, the application [[mserver]] will be started (using a particular port) on the MIDAS &#039;&#039;experiment host&#039;&#039; machine only.  Note that the environment variable MIDAS_SERVER_HOST is defined on the remote machine(s) but NOT on the &#039;&#039;experiment host&#039;&#039;. &lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 # setenv MIDAS_HOST mhostpc   # substitute your experiment host name&lt;br /&gt;
 # setenv REMOTE_HOST rlxhost  # substitute your remote host name&lt;br /&gt;
 # setup the MIDAS mserver host&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
 case $MIDAS_HOST*:                &lt;br /&gt;
   unsetenv MIDAS_SERVER_HOST     ## MIDAS_SERVER_HOST not defined&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
 setenv MIDAS_SERVER_HOST $MIDAS_HOST.triumf.ca:1175  ## for remote host, define MIDAS_SERVER_HOST&lt;br /&gt;
                                                      ## as hostname + domain name + default mserver port&lt;br /&gt;
                                                      ## port must match that of [[mserver]] used in start_daq.sh &lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 # select 64-bit or 32-bit MIDAS and ROOT&lt;br /&gt;
 #&lt;br /&gt;
 switch (`uname -i`)&lt;br /&gt;
 case i386:&lt;br /&gt;
   setenv ROOTSYS /triumfcs/trshare/olchansk/root/root_v5.28.00_SL55_32   ## or appropriate path&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux-m32/bin:$PATH&lt;br /&gt;
   breaksw&lt;br /&gt;
 default:&lt;br /&gt;
   setenv ROOTSYS $HOME/packages/root&lt;br /&gt;
   setenv PATH .:$MIDASSYS/linux/bin:$PATH&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 setenv PATH .:$HOME/online/bin:$HOME/packages/roody/bin:$ROOTSYS/bin:$PATH&lt;br /&gt;
 #&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
After executing {{File|name=.cshrc}} (or {{File|name=.bashrc}}) or logging out, on the MIDAS host (mhostpc) make sure environment variable MIDAS_SERVER_HOST is NOT defined&lt;br /&gt;
 &amp;lt;small&amp;gt;[mhostpc] echo $MIDAS_SERVER_HOST&lt;br /&gt;
 [mhostpc] MIDAS_SERVER_HOST: Undefined variable.&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and on the  &#039;&#039;&#039;&#039;&#039;remote host&#039;&#039;&#039;&#039;&#039;, make sure MIDAS_SERVER_HOST IS defined: &lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] echo $MIDAS_SERVER_HOST&lt;br /&gt;
  [rlxhost] MIDAS_SERVER_HOST&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Also on the &#039;&#039;remote host&#039;&#039;, make sure that the correct (32-bit)  {{Utility|name=odbedit}} will be used (do not run it yet!)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] which odbedit&lt;br /&gt;
 /home/johnfoo/packages/midas/linux-m32/bin/odbedit&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Grant Remote host access permission === &lt;br /&gt;
Give permission for the remote host(s) to access the experiment by following the instructions to [[Security#MIDAS programs on remote machines|allow MIDAS programs on remote machines]].  If the MIDAS web server [[mhttpd]] is running, use [[ODB Page]] to edit the ODB keys listed, otherwise use [[odbedit]] on the &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
 &lt;br /&gt;
=== Start mserver on Experiment Host ===&lt;br /&gt;
The application [[mserver]] is not required when running an experiment on the &#039;&#039;experiment host&#039;&#039; (localhost) only, but it &#039;&#039;&#039;IS required&#039;&#039;&#039; for access from a &#039;&#039;&#039;REMOTE&#039;&#039;&#039; frontend.&lt;br /&gt;
Start [[mserver]] on MIDAS host (default port 1175) or use the &amp;quot;-p&amp;quot; option for a different port.&lt;br /&gt;
The port must match the port defined for environment variable MIDAS_SERVER_HOST in {{File|name=.cshrc}} (or {{File|name=.bashrc}}) [[#Modify .cshrc (.bashrc) for Remote host|above]].&lt;br /&gt;
  &amp;lt;small&amp;gt;[mhostpc] mserver -D&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The environment variables on the REMOTE host should be:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] printenv | grep MIDAS&lt;br /&gt;
    MIDASSYS=/home/e777/packages/midas&lt;br /&gt;
    MIDAS_EXPT_NAME=e777&lt;br /&gt;
    MIDAS_SERVER_HOST=mhostpc.triumf.ca:1175&amp;lt;/span&amp;gt;&lt;br /&gt;
(a different port may be used - see above)&lt;br /&gt;
&lt;br /&gt;
=== Check access to ODB from Remote host ===&lt;br /&gt;
Run {{Utility|name=odbedit}} on the remote host to check access to ODB. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] odbedit&lt;br /&gt;
 [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
If it does not work correctly, check that &lt;br /&gt;
* MIDAS_SERVER_HOST is defined on REMOTE host with same port as [[mserver]]&lt;br /&gt;
* &amp;lt;span style=&amp;quot;color:darkcyan;font-style:italic&amp;quot;&amp;gt;mserver&amp;lt;/span&amp;gt; is running on MIDAS host with the correct port&lt;br /&gt;
* MIDAS_SERVER_HOST is NOT defined on MIDAS host&lt;br /&gt;
* remote access permission to REMOTE host has been granted as described above.&lt;br /&gt;
&lt;br /&gt;
=== Build the analyzer on Experiment Host ===&lt;br /&gt;
The analyzer will be built and run on the MIDAS &#039;&#039;experiment host&#039;&#039; machine.&lt;br /&gt;
Select an example from $MIDASSYS/examples/ (see [[#Frontend and Analyzer (localhost)]]) and copy it to $HOME/online on the MIDAS host machine. Since we are assuming a 64-bit MIDAS host and a 32-bit remote host, edit the example Makefile so only the analyzer will be built. &lt;br /&gt;
&lt;br /&gt;
=== Build the frontend (32bit) for Remote host ===&lt;br /&gt;
The frontend runs on a 32-bit remote host in this example. It therefore must either&lt;br /&gt;
* be built 32-bit on the 64-bit MIDAS host with the &amp;quot;-m32&amp;quot; flag &lt;br /&gt;
* or built on the REMOTE host&lt;br /&gt;
and in either case the [[#Build 32-bit MIDAS libraries|32-bit MIDAS libraries]] used for linking. &lt;br /&gt;
&lt;br /&gt;
To avoid confusion, create a different subdirectory for the frontend, e.g.&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] mkdir $HOME/online/fe_32&amp;lt;/span&amp;gt;&lt;br /&gt;
Copy the Makefile and frontend code from the same example to this directory.&lt;br /&gt;
Modify the Makefile as needed, and only build the frontend.  &lt;br /&gt;
&lt;br /&gt;
Once built, start the frontend in an xterm on the REMOTE host. &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;[rlxhost] $HOME/online/fe_32/frontend&amp;lt;/span&amp;gt;&lt;br /&gt;
Check that it connects successfully to the experiment and the Equipments appear on the [[Status Page]] as described under [[#Frontend and Analyzer (localhost)]].  The Equipment Status (Figure 2) should show that the Equipments are now running on the remote cpu, i.e. &amp;quot;SampleFrontend@rlxhost.triumf.ca&amp;quot; rather than &amp;quot;Sample Frontend@localhost&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Run the Analyzer on Experiment host ===&lt;br /&gt;
Start the analyzer in an xterm on the MIDAS &#039;&#039;experiment host&#039;&#039; &lt;br /&gt;
 &amp;lt;small&amp;gt;[johnfoo@mhostpc e777] $HOME/online/analyzer&amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Continue by starting a run and dumping the data as described under [[#Frontend and Analyzer (localhost)]].&lt;br /&gt;
&lt;br /&gt;
=== Create experiment startup script ===&lt;br /&gt;
It is useful to create a script that will automatically start all the required clients for the experiment. This is called a startup script (any name can be used). Create  {{Filepath|path=$HOME/online/bin/start_daq.sh}} on the &#039;&#039;experiment host&#039;&#039; as follows, (supply the [[mhttpd]] ports if default is not used) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 # start_daq.sh&lt;br /&gt;
 cd $HOME/online&lt;br /&gt;
 #&lt;br /&gt;
 switch (`hostname`)&lt;br /&gt;
   case $MIDAS_HOST*:    ## MIDAS_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;Good, we are on $MIDAS_HOST&amp;quot;&lt;br /&gt;
      breaksw&lt;br /&gt;
   case $REMOTE_HOST*:   ## REMOTE_HOST is assigned in .cshrc (.bashrc)&lt;br /&gt;
      echo &amp;quot;startup script should be executed on $MIDAS_HOST&amp;quot;&lt;br /&gt;
 endsw&lt;br /&gt;
 #&lt;br /&gt;
 odbedit -c clean&lt;br /&gt;
 #   start mhttpd on default port (Mongoose https version)&lt;br /&gt;
 mhttpd  -D   # you can optionally restrict access to localhost and/or other specified hosts - see [[mhttpd]]&lt;br /&gt;
 #   start mserver on default port (use argument -p to use a different port) &lt;br /&gt;
 mserver -D  # start mserver on default port (1175) or a different port using -p option - see [[mserver]]&lt;br /&gt;
             # the port must match that of MIDAS_SERVER_HOST in .cshrc (.bashrc) - see above&lt;br /&gt;
             # access must be specifically allowed - see [[#Grant Remote host access permission||above]]&lt;br /&gt;
 xterm -e ./analyzer &amp;amp;&lt;br /&gt;
 ## start frontend on remote host&lt;br /&gt;
 #ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp;&lt;br /&gt;
 mlogger -D&lt;br /&gt;
 #end file&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Note that command to start the frontend on the remote host is commented out. It can be uncommented once the start_frontend script is written and tested.&lt;br /&gt;
&lt;br /&gt;
Shut down any clients that are running already by running odbedit on the MIDAS &#039;&#039;experiment host&#039;&#039; and execute the new startup script   {{File|name=start_daq.sh}} (make it executable if desired)&lt;br /&gt;
 &amp;lt;small&amp;gt;&lt;br /&gt;
   [mhostpc] odbedit&lt;br /&gt;
   [local:e777:S]/&amp;gt;sh all&lt;br /&gt;
   [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
and check that {{Utility|name=odbedit}} still works on the &#039;&#039;REMOTE host&#039;&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:green; font-size:80%&amp;quot;&amp;gt;&lt;br /&gt;
    [rlxhost] odbedit &lt;br /&gt;
    [mhostpc.triumf.ca:1175:e777:Stopped]/&amp;gt;ls &amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may wish to modify the script to restart missing clients only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Create script to start frontend ===  &lt;br /&gt;
The startup file  {{File|name=start_daq.sh}}  invoked a script  {{File|name=start_frontend}} to start the remote frontend. This line was commented out (see [[#Create experiment startup script|above]]). Once the frontend is working, create a script to start the frontend (e.g. file {{Filepath|path=$HOME/online/bin/start_frontend}}).&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
 #!/bin/tcsh&lt;br /&gt;
 # Script to start frontend running on $REMOTE_HOST&lt;br /&gt;
 #&lt;br /&gt;
 # This script runs on the REMOTE HOST&lt;br /&gt;
 #&lt;br /&gt;
 echo &amp;quot;starting frontend for experiment $MIDAS_EXPT_NAME &amp;quot;&lt;br /&gt;
 xterm -geometry 150x50+800+0 -fg white -bg blue -title &amp;quot;Frontend&amp;quot; -e  &amp;quot;$HOME/online/fe_32/frontend&amp;quot; &amp;amp;&lt;br /&gt;
 echo &amp;quot;Frontend task has been started&amp;quot;&lt;br /&gt;
 exit&lt;br /&gt;
&amp;lt;/small&amp;gt;&lt;br /&gt;
Check that this script works by running it on the REMOTE host. If successful, &lt;br /&gt;
run the commented command in an xterm on the &#039;&#039;experiment host&#039;&#039;&lt;br /&gt;
    &amp;lt;small&amp;gt;[mhostpc] ssh $REMOTE_HOST $HOME/online/bin/start_frontend -O &amp;gt;&amp;amp; $HOME/online/bin/start_frontend.log  &amp;amp; &amp;lt;/small&amp;gt;&lt;br /&gt;
This command relies on password-less access set up with SSH keys (see [[#Experimental setup (Remote)]]).&lt;br /&gt;
If successful, uncomment line in {{File|name=start_daq.sh}}, and run the script to check that it can start the remote client(s) from the MIDAS &#039;&#039;experiment host&#039;&#039; (first shutting down all running clients) :&lt;br /&gt;
&amp;lt;small&amp;gt;&lt;br /&gt;
    [mhostpc] odbedit -c &amp;quot;sh all&amp;quot;&lt;br /&gt;
    [mhostpc] ./start_daq.sh &amp;lt;/small&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next [[#Customizing your experiment|customize your experiment]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Customizing your experiment ==&lt;br /&gt;
&lt;br /&gt;
Here are some of the more common options provided for users to customize their experiments according to their own preferences:&lt;br /&gt;
&lt;br /&gt;
; Write frontend(s) to read out and control your hardware&lt;br /&gt;
: Modify the example frontend and Makefile (from $MIDASSYS/examples/) you have already copied and built so it accesses your hardware. &lt;br /&gt;
&lt;br /&gt;
: The example Frontend.c is an example of [[Frontend user code]]. You can find documentation about the frontend structure under [[Frontend Application]], [[Frontend Operation]] and [[Frontend user code]]. You may need to set up some [[Event Notification (Hot-Link)|Hot-Links]] in the frontend. The MIDAS package includes device drivers for some of the more common hardware. See [[MIDAS Driver Library]] for more information.  &lt;br /&gt;
&lt;br /&gt;
; Modify analyzer(s) for your data &lt;br /&gt;
: Modify the example analyzer code as necessary to analyze the data from your frontends.&lt;br /&gt;
&lt;br /&gt;
; Slow Controls &lt;br /&gt;
: Control your slow-controls equipment with slow-control frontend(s) optionally using the [[#MIDAS Package Installation|MSCB]] system. &lt;br /&gt;
&lt;br /&gt;
; Data logger &lt;br /&gt;
: Set up the data logger [[mlogger]] to log data to a storage device. Many options are available - see [[Data Logger]], [[mlogger]] and [[/Logger ODB tree]] for instructions.&lt;br /&gt;
&lt;br /&gt;
; Allow programs to be restarted from the [[Programs Page]] &lt;br /&gt;
: See mhttpd [[Programs Page]] and [[/Programs ODB tree]]&lt;br /&gt;
&lt;br /&gt;
; Write scripts which run at start and end of run &lt;br /&gt;
: See [[/Programs ODB tree#Execute on start run]] and  [[/Programs ODB tree#Execute on stop run]]&lt;br /&gt;
&lt;br /&gt;
; Create a shutdown script &lt;br /&gt;
: Create a script similar to the startup script to shutdown the experiment&lt;br /&gt;
&lt;br /&gt;
; Lazy logger&lt;br /&gt;
: Set up the [[lazylogger]] for archiving data files for storage.&lt;br /&gt;
&lt;br /&gt;
; Create edit-on-start parameters &lt;br /&gt;
: See [[Edit-on-start Parameters]]&lt;br /&gt;
&lt;br /&gt;
; Set up the alarm system &lt;br /&gt;
: See [[Alarm System]] and [[Alarms Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up history system &lt;br /&gt;
: See [[History System]] and [[History Page]]&lt;br /&gt;
&lt;br /&gt;
; Set up the Electronic logbook (Elog) &lt;br /&gt;
: See [[Elog]] for details&lt;br /&gt;
&lt;br /&gt;
; Set up the Sequencer &lt;br /&gt;
: The [[Sequencer Page#Sequencer]] can be used to run a sequence of runs, changing parameters as needed.  &lt;br /&gt;
&lt;br /&gt;
; Write a webserver Custom page &lt;br /&gt;
: To better control and monitor your experiment, you may want to write a [[Custom Page]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Installation]]&lt;/div&gt;</summary>
		<author><name>Olchansk</name></author>
	</entry>
</feed>