BNMR: Data Logging: Difference between revisions

From DaqWiki
Jump to navigation Jump to search
m (Bsmith moved page DaqWiki:BNMR: Data Logging to BNMR: Data Logging without leaving a redirect)
No edit summary
Line 1: Line 1:
{{Pagelinks}}
{{Pagelinks}}


== Links ==
== MUD files ==
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
{{bnmqr|join=and}} do not save their data as Midas files, but use [http://musr.ca/mud/mud_fmt.html MUD files] instead (<code>.msr</code> extension).
* [[BNMR: mdarc]]
* [[BNMR: mheader]]
* [[BNMR: Camp Logging]]
* [[BNMR: Epics Logging]]
* [[BNMR: Getting Started|Getting Started]]
* [[BNMR#Nomenclature|Nomenclature]]
</div>


Therefore we only use the Midas [https://daq00.triumf.ca/MidasWiki/index.php/Mlogger mlogger] for recording [https://daq00.triumf.ca/MidasWiki/index.php/History_System history] data, not the regular event data.


== Data Format ==
The key feature to note is that '''MUD files are not event-based'''. One can save statistics and histograms, but not complex per-event data. Histograms may be used to a single number per event (the X-axis is event number) or the total counts over an entire run (the X-axis is time-of-flight in ns, for example). Data saved as statistics can include the mean/min/max/std.dev. and more information.
For both  [[BNMR#Environment|run types]], the frontend sends the data in the form of MIDAS data banks. The data banks are processed and  [[#Saved data files|saved]] as ''*.msr'' files in [http://musr.ca/mud/mud_fmt.html MUD] format. These files
are then analyzed by the MUSR/BNMR analyzer program ''physica'', and can be dumped/examined by the mud utility program ''mud_util''.  


For Type 1 (I-Musr) runs only, the incoming MIDAS data banks are '''also''' saved in a ''.mid'' file in
Users analyze MUD files using:
[https://midas.triumf.ca/MidasWiki/index.php/Event_Structure MIDAS format]. Both the saved ''*.mid'' file and the incoming data banks can be dumped using the
* the [https://github.com/dfujim/mudpy mudpy] and [https://github.com/dfujim/bdata bdata] python packages (with some GUIs built on top of them)
MIDAS utility program [https://midas.triumf.ca/MidasWiki/index.php/Mdump mdump]].
* the MUSR/BNMR analyzer program ''physica''
* the MUD utility program ''mud_util''


A couple of python utilities based on <code>bdata</code> are provided in the bnmr repository, which may be useful when adding new features to the data logger:
* <code>bnxr_common/tests/dump_mud_file.py</code> dumps the content of a MUD file to screen
* <code>bnxr_common/tests/diff_mud_files.py</code> compares the content of 2 MUD files


== Data Logging ==
DAQ experts may enable dumping of Midas banks to a Midas file for debugging purposes. The banks written will come from the [[BNMR:_frontend frontend]] program only, and will not contain any EPICS variables, CAMP variables, or any manipulation of histograms performed in the <code>bnxr_logger.exe</code> program.
Data Logging in the  {{bnmqr|join=and}} experiments is performed by
 
* the custom data archiver client [[BNMR: mdarc|mdarc]] (for both [[BNMR#Environment|run types]]),
== bnxr_logger.exe introduction ==
* the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] (Type 1 only)
The <code>bnxr_logger.exe</code> program is responsible for collecting data and writing to MUD files.
The {{bnmqr|join=and}} experiments use the MUSR-style [[BNMR: Run numbering|Run Numbering]] scheme. The data files are named according to the run number (see [[#Saved data files]]).
   
   
Most of the parameters controlling the data logging are found in the [[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree|mdarc ODB subtree]] at {{Odbpath|path=/Equipment/FIFO_acq/mdarc}}. Note that this area is also accessed by other clients (i.e. [[BNMR rf_config|rf_config]] and [[BNMR: mheader|mheader]]).  
Most of the parameters controlling the data logging are found in the ODB at {{Odbpath|path=/MUD Logging}}. Most settings are configured manually, though some are set/computed by the [[BNMR:_RF_calculator|RF calculator]] program and the beginning of each run.  


The '''data are saved differently''' for Type 1 (I-MUSR) and Type 2 (TD-MUSR) as explained below.
The program gets data from the following sources:
For both run types, the contents of the ODB is also saved at the end of every run by [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] in an ASCII file. In the event of corruption of the ODB, it can be regenerated from this file
* [[#Histograms|Histograms]] - read from midas banks sent by the [[BNMR: frontend|frontend]]
* [[#CAMP|Camp]] - read directly from CAMP
* [[#EPICS|EPICS]] - read directly from EPICS
* [[#ODB_variables|ODB variables]] - read directly from the ODB
* [[#Run_Comments|Run comments]] - read from a text file that is edited via a web interface


[[BNMR: Run numbering|Real]] data files are also [[#Archiving the data|archived]] in the MUSR Data Archive at the end of run.  
More details on each of these is presented further down this page.


== Saved data files ==


=== Type 1 (I-MUSR) runs ===
The {{bnmqr|join=and}} experiments use the MUSR-style [[BNMR: Run numbering|Run Numbering]] scheme. The data files are named according to the run number. [[BNMR: Run numbering|Real]] data files are archived in the MUSR Data Archive at the end of the run.


In addition to  [[BNMR: mdarc|mdarc]], the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] and client [[BNMR: mheader|mheader]] are also required to save Type 1 data.
During a run, several versions of the .msr (or MUD) data file are retained with a version number appended (in case of any problems with the most recent saved data). A symlink to the most recent version is updated during the run, so analysis programs do not have to concern themselves with the versioning information.


Scaler data from the [[BNMR: frontend|frontend]] are sent out in the form of MIDAS banks. These banks are named differently and have different content to those sent
For example, for BNMR run 40362, while the run is in progress, the saved data directory would contain files such as
for a Type 2 run. They contain the scaler data for each PPG cycle. At begin and end-of-run, {{Client|name=mheader}} sends an extra bank into the data stream, containing the header information required to write the MUD file. If CAMP and/or EPICS logging is enabled, CAMP and EPICS header banks are also sent by {{Client|name=mheader}}. These contain
<pre>
the names of the EPICS and CAMP variables that are to be logged. These banks must be received at begin-of-run, or the data cannot be converted to MUD format during the run. However, the data can still be converted to MUD format by the program {{Client|name=midbnmr}} after the end-of-run. During the run, {{Client|name=mheader}} periodically sends banks containing the values of the CAMP and EPICS logged variables.
lrwxrwxrwx    1 bnmr    bnmr          48  Feb 26 12:09 040362.msr -> /isdaq/data1/bnmr/dlog/current/040362.msr_v27
-rw-r--r--    1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v27
-rw-r--r--    1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v26
-rw-r--r--    1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v25
-rw-r--r--    1 bnmr    bnmr        4403  Feb 26 12:08 040362.msr_v24
</pre>
 
At end-of-run, normally all earlier versions are purged and the final data file is renamed without the appended version number, and the file archived to the MUSR Data Archive. These steps can be suppressed by setting {{Odbpath|path=/MUD Logging/Global/Settings/Purge and archive at end of run}} to false, for example if the user decides it would be better to keep the version 26 of a file instead of the most recent version 27.


The standard Midas logger 
Using the same example as before, after the run the saved data directory would contain:
[https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] saves all the data banks in standard MIDAS format, i.e. into a ''*.mid'' file. The client 
<pre>
<span style="color:green;  font-style:italic; ">mdarc</span>  also receives the data banks, and converts the data to MUD format (using [[#Description|midbnmr]]
-rw-r--r--   1 bnmr    bnmr        4399 Feb 26 12:10 040362.msr
routines), saving an ''.msr'' file. The data in this file are saved in standard MUSR I-musr format. Thus two data files are saved for each Type 1 run, a MIDAS-format (''.mid'') file and a MUD-format (''.msr'') file.
</pre>


=== Type 2 (TD-MUSR) runs ===
=== Archiving ===


For Type 2 runs, the client [[BNMR: frontend|frontend]] sends out data in the form of MIDAS banks (named differently from the Type 1 data banks). These banks contain the histograms accumulated and stored in the frontend. [[BNMR: mdarc|mdarc]] receives these banks, and saves the histogram data directly in MUD format. Client [[BNMR: mheader|mheader]] is inactive. If [[BNMR: Camp Logging|CAMP logging]] and/or [[BNMR: Epics Logging|EPICS Logging]] is enabled, data from CAMP and EPICS logged variables are read directly from the CAMP and EPICS slow control system, and also saved in the ''*.msr'' file in standard  MUD TD-musr format.  In this case, no intermediate ''*.mid'' file is produced.  The frequency of saving the data is controlled by the ODB key [[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#save_interval(sec)|save_interval(sec)]]. A new version of the data file is saved each time. At the end-of-run, the versions are purged and the final data file is archived.
The ODB keys {{Odbpath|path=Archiver task}} and {{Odbpath|path=Archiver dir}} in {{Odbpath|path=/MUD Logging/Global/Settings}} determine where files for "real" runs get copied to after a run is complete. This is normally just an <code>scp</code> to a directory on <code>cmms.triumf.ca</code>.


=== Nuking a run ===


== Saved data files ==
If the user decides that a run is irredeemable, they may choose to "nuke" the run and start again. This involves deleting ALL the files that have been written, pretending that the run never happened. The same run number will then be used for the next run. Users appreciate this feature as it allows analysis to occur on contiguous ranges of run numbers.
 
Indicating that a run should be nuked is done with the {{Odbpath|path=/MUD Logging/Global/Settings/Nuke this run}} flag in the ODB, which is generally achieved by the user clicking the "Nuke ⚠️" button on the [[BNMR: Custom Status page|Status page]]


The data are written by [[BNMR: mdarc|mdarc]] and the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] to the same directory
=== Cleaning up if end-of-run fails ===
(currently  {{Filepath|path=/isdaq/data1/bn[mq]r/dlog/current}} where {{Filepath|path=current}} is a soft-link to the current year). By using a soft-link, the path in the ODB does not need to be updated each year.


The same path  ({{Filepath|path=/isdaq/data1/bn[mq]r/dlog/current}}) is entered both in the ODB parameter
The {{Client|name=logger_cleanup.exe}} program can be used if {{Client|name=bnxr_logger.exe}} crashes during a run and fails to perform the standard cleanup/archive duties at the end of a run.
[[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#saved_data_directory|saved_data_directory]] used by {{Client|name=mdarc}} and in the ODB parameter  {{Odbpath|path=/logger/data dir}} used by the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger]. When  the
[[BNMR: Run numbering|Run Number]] is assigned, the perlscript
[[BNMR: Perlscripts#get_next_run_number.pl|get_next_run_number.pl]] checks that these two keys point to the same directory.


;The saved data files are named by their run number (see [[BNMR: Run numbering|Run Numbering]]) and their [[#Data Format]].
It effectively just runs the same code as the main MUD logger runs at the end of the run, but allows the user to specify any run number in the past if they wish.


Type 1 (I-Musr) runs result in two saved data files, a ''.mid'' and an ''.msr'' file (see [[#Data Format]]).  Type 2 (TD-Musr) runs result in only one saved data file, the ''.msr'' file (see above).  In addition, both run types also produce an ''.odb'' file at the end-of-run, containing a copy of the MIDAS online data base (ODB). The ''.odb''  files also named by the current run number.
It will:
* Delete any temporary files that are no longer needed
* Archive the final file if this was a "real" run (not a "test" run)


=== Type 1 data files ===
Usage is:
In the case of a Type 1 run, three files are saved, e.g.
<pre>
<pre>
$ ls /isdaq/data1/bnqr/dlog/current/045238.* -lt
      logger_cleanup.exe
-rw-r--r-- 1 bnqr users  123088 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.odb
          [-r Run number]
-rw-r--r-- 1 bnqr users 2156308 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.mid
                        Run number of run to be cleaned up and/or archived. Defaults to the most recent run.
-rw-r--r-- 1 bnqr users  93341 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.msr
 
          [-h Hostname  ]
                      hostname is supplied only for a remote host
 
          [-e Experiment]
                      experiment name (default is given by environment variable MIDAS_EXPT_NAME)
</pre>
</pre>


=== Type 2 data files ===
== bnxr_logger.exe details ==
For Type 2 runs, several versions of the .msr (or MUD) data file are retained with a version number appended (in case of any problems with the most recent saved data). At end-of-run,  normally all earlier versions are purged and the final data fileis renamed without the appended version number, then copied to an archive according to ODB parameter
 
[[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#archived_data_directory|archived_data_directory]]. The version numbers of the intermediate files are hidden from analysis programs by the use of a softlink, so that these programs always get the latest data.  The final data file name is used  as the soft-link name to refer to the latest data file. So during the run this filename is actually a soft-link to the latest version.
The code for the MUD logger is found in the bnmr repository at <code>bnxr_common/logging</code>. {{bnmqr|join=and}} are very similar, so the executable is almost identical for both (just an <code>#ifdef</code> for the default ODB settings to use). The main configuration is all done through ODB keys.
 
The program is built as part of the main build (<code>cd build; make install</code> from the bnmr repository).
 
The general functions performed by the program are:
* Read data sent by the [[BNMR: frontend|frontend]] and process it. This includes both the data from the scalers as well as metadata like the current cycle number.
* Read data from EPICS and CAMP, either periodically or each time we get data from the [[BNMR: frontend|frontend]].
* Write data to a MUD file periodically during the run.
 
=== Histograms ===
 
TODO
 
=== CAMP ===
 
[[BNMR:_CAMP|CAMP]] data is logged in two separate sections of the MUD file - in the run description and as independent variables. The {{Client|name=bnxr_logger.exe}} program connects directly to the CAMP server and reads the values from there.
 
==== Run description ====
 
The MUD run description section has entries for the magnetic field strength and temperature of the sample. This data can be exposed to users when searching for data files taken previously.
 
ODB settings in {{Odbpath|path=/MUD Logging/Run description/Settings}} specify whether to read the magnetic field and/or temperature from CAMP, and if so, which instrument to read from. CAMP can automatically compute the standard deviation of variables throughout a run, and the user can choose to record this value in the file too.
 
Only a single number gets written to the run description for each variable - the average value throughout the run.
 
;NOTE : Automatic CAMP variables to be logged must be set ''loggable'' in the CAMP CUI - see [[#Set CAMP variable loggable]].


For example, for BNMR run 40362 (running Type 2 (TD-MUSR) ),   while the run is in progress, the saved data directory would contain files such as
==== Independent variables ====
<pre>
 
lrwxrwxrwx    1 bnmr    bnmr          48      Feb 26 12:09 040362.msr -> /isdaq/data1/bnmr/dlog/current/040362.msr_v27
Other CAMP variables can be logged during a run too.
-rw-r--r--   1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v27
 
-rw-r--r--   1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v26
ODB settings in {{Odbpath|path=/MUD Logging/Camp/Settings}} define whether CAMP variables should be written as histograms of readings or just average values. The general configuration is to log a per-cycle histograms for T1 (TI) modes and just average values for T2 (TD) modes.
-rw-r--r--   1 bnmr    bnmr        4403  Feb 26 12:09 040362.msr_v25
 
-rw-r--r--   1 bnmr    bnmr        4403  Feb 26 12:08 040362.msr_v24
The user does not list each individual CAMP variable to be logged in the ODB, but instead lists which "categories" of variables should be included in the MUD file (e.g. <code>log_mdarc</code>). The mapping between CAMP variable and "category" is done via CAMP itself (see next section).
</pre>
 
And after the run had ended:
This CAMP data is stored as "independent variables" in the MUD file, keyed by the CAMP path (of format like <code>/Magnet/mag_field</code>).
 
==== Set CAMP variable loggable ====
 
All CAMP variables to be logged must be set loggable in the [[BNMR:_CAMP#CAMP User Interface|CAMP user interface]]. This includes the parameters to be used in the run description.
 
The loggable categories are shown in Table 1.
 
{| border="1" width=50% style="border-collapse:collapse; color:black; background-color:silver; text-align:center"
|+ Table 1 : CAMP logging for Type 1 and Type 2 runs
! rowspan="2" style="background-color:silver; text-align:left"|Set logging !!colspan=2 style="text-align:center"| Variable Logged for
|- style="text-align:center;background-color:silver;font-weight:bold;"
! style="text-align:center;" | Type1 (I-MUSR)!! style="text-align:center; "| Type2 (TD-MUSR)
|- style="background-color:springgreen;text-align:center"
| style="text-align:left"| log_mdarc
| Y
| Y
|- style="background-color:yellow;"
| style="text-align:left"| log_mdarc_td || rowspan="2"  style="background-color:silver;text-align:center"| N || rowspan="2"| Y
|- style="background-color:yellow;"
| style="text-align:left"| log_td_musr
|- style="background-color:skyblue;"
| style="text-align:left"|log_mdarc_ti || rowspan=2 | Y || rowspan=2  style="background-color:silver;text-align:center"| N
|- style="background-color:lightblue;"
| style="text-align:left"|log_i_musr
|-
|}
 
==== Checking which variables will be logged ====
 
The "Logging" custom webpage includes a feature that allows the user to see which CAMP variables will be logged given the current ODB and CAMP settings. This is implemented using the midas JRPC system to talk to the <code>bnxr_logger.exe</code> program, which returns the list of variables.
 
==== CAMP error file ====
CAMP keeps a log file for errors. This can be found in {{File|name=camp_srv.log}} at path {{Filepath|path=/home/musrdaq/musr/camp/[''camphost'']/log/}} where ''camphost'' is ''bnmrvw'' for  {{bnmr}} or ''polvw ''for  {{bnqr}}. Error counts can also be found on the CAMP CUI
under R.Errors and W.Errors in [[#CAMP User Interface|Figure 1]] above.
 
e.g.
<pre>
<pre>
-rw-r--r--    1 bnmr    bnmr        4399  Feb 26 12:10 040362.msr
tail -f ~musrdaq/musr/camp/bnmrvw/log/camp_srv.log
-rw-r--r--    1 bnmr    bnmr        19990 Feb 26 12:10 040362.odb
[JUN 26 17:46:41:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts
[JUN 26 17:46:43:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts
[JUN 26 17:46:45:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts
</pre>
</pre>


=== EPICS ===
See [[BNMR: EPICS|the EPICS page]] for an overview of EPICS in {{bnmqr|join=and}}.
Users directly specify which EPICS variables should be logged in {{Odbpath|path=/MUD Logging/Epics/Settings}} (or by using the relevant bit of the [[BNMR: Custom Logging page|Custom Logging page]]). The {{Client|name=bnxr_logger.exe}} program connects directly to EPICS and reads the values itself.
The code allows for deciding whether to store a histogram of readings throughout the run or just summary statistics. In general, a histogram is written for TI runs, where the scaler data is being store in a per-cycle style; the histograms for the EPICS data and scaler data will be the same length, with one entry per PPG cycle. To avoid overloading the EPICS server, we can read from it periodically rather than every time a new PPG cycle starts. Each time we read a value, we will apply it to all the cycles that happened since we last read.
EPICS data is stored as "independent variables" in the MUD file, keyed by the PV name (of format like <code>ILE2:BIAS15:RDVOL</code>).


The number of intermediate versions of the run files kept during a run is controlled by the ODB parameter
=== Run comments ===
[[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#num_versions_before_purge|num_versions_before_purge]]. The action of renaming the files to a final saved version and archiving can be suppressed by the ODB parameter [[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#endrun_purge_and_archive|endrun_purge_and_archive]]. This may be useful if the data in the latest saved file is bad for some reason. After the run is ended, the user can delete the bad data file by hand.
Running the client [[BNMR: cleanup|cleanup]] will then purge, rename and archive the final data file.


When a run is in progress, the user is presented with a <code>textarea</code> element on the [[BNMR: Custom Status page|status page]]. This is hooked up to the {{Client|name=run_comment_editor.py}} program using Midas JRPC. The python program just writes a text file on disk in the directory specified by {{Odbpath|path=/Logger/Data dir}}. Other settings for the python program are in {{Odbpath|path=/Equipment/RunComments/Settings}}.


When it is time for the {{Client|name=bnxr_logger.exe}} program to write a new MUD file, it just reads the file that was written by the python program. There are a couple of extra settings in {{Odbpath|path=/MUD Logging/TextFileComments/Settings}}.


== Archiving the data ==
MUD files have a section dedicated to storing run comments.
For both [[BNMR#Environment|run types]]), the final ''*.msr'' data file for '''real runs''' (see [[BNMR: Run numbering|run numbering]]) is
automatically copied  by [[BNMR: mdarc|mdarc]] to the archive directory, given by ODB parameter
[[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#archived_data_directory|archived_data_directory]].
Currently, this directory is {{Filepath|path=musrarc@cmms:dlog}}. SSH keys have been set up so that the copy can be performed without need of a password.


Should a file not be archived for some reason at end-of-run, the client [[BNMR: cleanup|cleanup]] will archive any files missing from the MUSR data archive.
=== ODB variables ===


TODO


[[Category:BNMR]] [[Category:Logging]]
[[Category:BNMR]] [[Category:Logging]]

Revision as of 18:03, 26 April 2022

MUD files

bnmr and bnqr do not save their data as Midas files, but use MUD files instead (.msr extension).

Therefore we only use the Midas mlogger for recording history data, not the regular event data.

The key feature to note is that MUD files are not event-based. One can save statistics and histograms, but not complex per-event data. Histograms may be used to a single number per event (the X-axis is event number) or the total counts over an entire run (the X-axis is time-of-flight in ns, for example). Data saved as statistics can include the mean/min/max/std.dev. and more information.

Users analyze MUD files using:

  • the mudpy and bdata python packages (with some GUIs built on top of them)
  • the MUSR/BNMR analyzer program physica
  • the MUD utility program mud_util

A couple of python utilities based on bdata are provided in the bnmr repository, which may be useful when adding new features to the data logger:

  • bnxr_common/tests/dump_mud_file.py dumps the content of a MUD file to screen
  • bnxr_common/tests/diff_mud_files.py compares the content of 2 MUD files

DAQ experts may enable dumping of Midas banks to a Midas file for debugging purposes. The banks written will come from the BNMR:_frontend frontend program only, and will not contain any EPICS variables, CAMP variables, or any manipulation of histograms performed in the bnxr_logger.exe program.

bnxr_logger.exe introduction

The bnxr_logger.exe program is responsible for collecting data and writing to MUD files.

Most of the parameters controlling the data logging are found in the ODB at /MUD Logging. Most settings are configured manually, though some are set/computed by the RF calculator program and the beginning of each run.

The program gets data from the following sources:

More details on each of these is presented further down this page.

Saved data files

The bnmr and bnqr experiments use the MUSR-style Run Numbering scheme. The data files are named according to the run number. Real data files are archived in the MUSR Data Archive at the end of the run.

During a run, several versions of the .msr (or MUD) data file are retained with a version number appended (in case of any problems with the most recent saved data). A symlink to the most recent version is updated during the run, so analysis programs do not have to concern themselves with the versioning information.

For example, for BNMR run 40362, while the run is in progress, the saved data directory would contain files such as

lrwxrwxrwx    1 bnmr     bnmr           48   Feb 26 12:09 040362.msr -> /isdaq/data1/bnmr/dlog/current/040362.msr_v27
-rw-r--r--    1 bnmr     bnmr         4403   Feb 26 12:09 040362.msr_v27
-rw-r--r--    1 bnmr     bnmr         4403   Feb 26 12:09 040362.msr_v26
-rw-r--r--    1 bnmr     bnmr         4403   Feb 26 12:09 040362.msr_v25
-rw-r--r--    1 bnmr     bnmr         4403   Feb 26 12:08 040362.msr_v24

At end-of-run, normally all earlier versions are purged and the final data file is renamed without the appended version number, and the file archived to the MUSR Data Archive. These steps can be suppressed by setting /MUD Logging/Global/Settings/Purge and archive at end of run to false, for example if the user decides it would be better to keep the version 26 of a file instead of the most recent version 27.

Using the same example as before, after the run the saved data directory would contain:

-rw-r--r--    1 bnmr     bnmr         4399 Feb 26 12:10 040362.msr

Archiving

The ODB keys Archiver task and Archiver dir in /MUD Logging/Global/Settings determine where files for "real" runs get copied to after a run is complete. This is normally just an scp to a directory on cmms.triumf.ca.

Nuking a run

If the user decides that a run is irredeemable, they may choose to "nuke" the run and start again. This involves deleting ALL the files that have been written, pretending that the run never happened. The same run number will then be used for the next run. Users appreciate this feature as it allows analysis to occur on contiguous ranges of run numbers.

Indicating that a run should be nuked is done with the /MUD Logging/Global/Settings/Nuke this run flag in the ODB, which is generally achieved by the user clicking the "Nuke ⚠️" button on the Status page

Cleaning up if end-of-run fails

The logger_cleanup.exe program can be used if bnxr_logger.exe crashes during a run and fails to perform the standard cleanup/archive duties at the end of a run.

It effectively just runs the same code as the main MUD logger runs at the end of the run, but allows the user to specify any run number in the past if they wish.

It will:

  • Delete any temporary files that are no longer needed
  • Archive the final file if this was a "real" run (not a "test" run)

Usage is:

      logger_cleanup.exe
           [-r Run number]
                        Run number of run to be cleaned up and/or archived. Defaults to the most recent run.

           [-h Hostname  ]
                      hostname is supplied only for a remote host

           [-e Experiment]
                       experiment name (default is given by environment variable MIDAS_EXPT_NAME)

bnxr_logger.exe details

The code for the MUD logger is found in the bnmr repository at bnxr_common/logging. bnmr and bnqr are very similar, so the executable is almost identical for both (just an #ifdef for the default ODB settings to use). The main configuration is all done through ODB keys.

The program is built as part of the main build (cd build; make install from the bnmr repository).

The general functions performed by the program are:

  • Read data sent by the frontend and process it. This includes both the data from the scalers as well as metadata like the current cycle number.
  • Read data from EPICS and CAMP, either periodically or each time we get data from the frontend.
  • Write data to a MUD file periodically during the run.

Histograms

TODO

CAMP

CAMP data is logged in two separate sections of the MUD file - in the run description and as independent variables. The bnxr_logger.exe program connects directly to the CAMP server and reads the values from there.

Run description

The MUD run description section has entries for the magnetic field strength and temperature of the sample. This data can be exposed to users when searching for data files taken previously.

ODB settings in /MUD Logging/Run description/Settings specify whether to read the magnetic field and/or temperature from CAMP, and if so, which instrument to read from. CAMP can automatically compute the standard deviation of variables throughout a run, and the user can choose to record this value in the file too.

Only a single number gets written to the run description for each variable - the average value throughout the run.

NOTE
Automatic CAMP variables to be logged must be set loggable in the CAMP CUI - see #Set CAMP variable loggable.

Independent variables

Other CAMP variables can be logged during a run too.

ODB settings in /MUD Logging/Camp/Settings define whether CAMP variables should be written as histograms of readings or just average values. The general configuration is to log a per-cycle histograms for T1 (TI) modes and just average values for T2 (TD) modes.

The user does not list each individual CAMP variable to be logged in the ODB, but instead lists which "categories" of variables should be included in the MUD file (e.g. log_mdarc). The mapping between CAMP variable and "category" is done via CAMP itself (see next section).

This CAMP data is stored as "independent variables" in the MUD file, keyed by the CAMP path (of format like /Magnet/mag_field).

Set CAMP variable loggable

All CAMP variables to be logged must be set loggable in the CAMP user interface. This includes the parameters to be used in the run description.

The loggable categories are shown in Table 1.

Table 1 : CAMP logging for Type 1 and Type 2 runs
Set logging Variable Logged for
Type1 (I-MUSR) Type2 (TD-MUSR)
log_mdarc Y Y
log_mdarc_td N Y
log_td_musr
log_mdarc_ti Y N
log_i_musr

Checking which variables will be logged

The "Logging" custom webpage includes a feature that allows the user to see which CAMP variables will be logged given the current ODB and CAMP settings. This is implemented using the midas JRPC system to talk to the bnxr_logger.exe program, which returns the list of variables.

CAMP error file

CAMP keeps a log file for errors. This can be found in camp_srv.log at path /home/musrdaq/musr/camp/[camphost]/log/ where camphost is bnmrvw for bnmr or polvw for bnqr. Error counts can also be found on the CAMP CUI under R.Errors and W.Errors in Figure 1 above.

e.g.

 tail -f ~musrdaq/musr/camp/bnmrvw/log/camp_srv.log
[JUN 26 17:46:41:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts
[JUN 26 17:46:43:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts
[JUN 26 17:46:45:2018] camp_srv: instrument 'biasV' not online in insIfWriteVerify /biasV | failed 2 attempts

EPICS

See the EPICS page for an overview of EPICS in bnmr and bnqr.

Users directly specify which EPICS variables should be logged in /MUD Logging/Epics/Settings (or by using the relevant bit of the Custom Logging page). The bnxr_logger.exe program connects directly to EPICS and reads the values itself.

The code allows for deciding whether to store a histogram of readings throughout the run or just summary statistics. In general, a histogram is written for TI runs, where the scaler data is being store in a per-cycle style; the histograms for the EPICS data and scaler data will be the same length, with one entry per PPG cycle. To avoid overloading the EPICS server, we can read from it periodically rather than every time a new PPG cycle starts. Each time we read a value, we will apply it to all the cycles that happened since we last read.

EPICS data is stored as "independent variables" in the MUD file, keyed by the PV name (of format like ILE2:BIAS15:RDVOL).

Run comments

When a run is in progress, the user is presented with a textarea element on the status page. This is hooked up to the run_comment_editor.py program using Midas JRPC. The python program just writes a text file on disk in the directory specified by /Logger/Data dir. Other settings for the python program are in /Equipment/RunComments/Settings.

When it is time for the bnxr_logger.exe program to write a new MUD file, it just reads the file that was written by the python program. There are a couple of extra settings in /MUD Logging/TextFileComments/Settings.

MUD files have a section dedicated to storing run comments.

ODB variables

TODO