BNMR: Data Logging: Difference between revisions

From DaqWiki
Jump to navigation Jump to search
en>Suz
m (New page: {{Pagelinks}} == Links == <div style="column-count:3;-moz-column-count:3;-webkit-column-count:3"> * BNMR: mdarc * BNMR: mheader * BNMR: Camp Logging * BNMR: Epics Logging ...)
 
 
(15 intermediate revisions by 2 users not shown)
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>


== Data Logging ==
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 Logging in the {{bnmqr|join=and}} experiments is performed by
* the custom data archiver client [[BNMR: mdarc]] (for both run types),
* the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] (Type 1 only)
with input from [[BNMR: mheader]] (Type 1 only)  and data read from the CAMP and EPICS slow control systems (see [[BNMR: Camp Logging]] and[[BNMR: Epics Logging]].


The data are saved in MUD format which can be read the the analyzer program ''physica''. Data files are archived at the end of run to the MUSR archive area.  
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.


The {{bnmqr|join=and}} experiments also use the MUSR [[BNMR: Run numbering]] scheme. The data files are named according to the run number (see [[#Naming of saved files]].
Users analyze MUD files using:
* the [https://github.com/dfujim/mudpy mudpy] and [https://github.com/dfujim/bdata 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 <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
 
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.
 
== bnxr_logger.exe introduction ==
The <code>bnxr_logger.exe</code> program is responsible for collecting data and writing to MUD 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 contents of the ODB is also saved at end-of-run by [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger].
 
The program gets data from the following sources:
* [[#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
 
More details on each of these is presented further down this page.
 
== Saved data 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. [[BNMR: Run numbering|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
<pre>
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.
 
Using the same example as before, after the run the saved data directory would contain:
<pre>
-rw-r--r--    1 bnmr    bnmr        4399 Feb 26 12:10 040362.msr
</pre>
 
=== Archiving ===
 
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 ===
 
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]]
 
=== Cleaning up if end-of-run fails ===
 
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.
 
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)


The '''data is saved differently''' for Type 1 (I-MUSR) and Type 2 (TD-MUSR) [[BNMR: Experimental Modes|Experimental Modes]]:
Usage is:
<pre>
      logger_cleanup.exe
          [-r Run number]
                        Run number of run to be cleaned up and/or archived. Defaults to the most recent run.


=== Type 2 (TD-MUSR) runs ===
          [-h Hostname  ]
                      hostname is supplied only for a remote host


For Type 2 runs, the client [[BNMR: mdarc]] is required to save the data as it is saved directly into MUD format. Client [[BNMR: mheader] is inactive.
          [-e Experiment]
<span style="color:green;  font-style:italic; ">Mdarc</span> receives histograms and scaler data from the [[BNMR: frontend|frontend]] in the form of MIDAS banks.
                      experiment name (default is given by environment variable MIDAS_EXPT_NAME)
These MIDAS banks are not saved (c.f. Type 1), but the data they contain is converted to MUD format, and saved in ''.msr'' files. If [[BNMR: Camp Logging]] and/or [[BNMR: Epics Logging]] is enabled, data from CAMP and EPICS logged variables are read directly from CAMP and EPICS and also saved in the '''*.msr''' file in standard  MUD TD-musr format.
</pre>


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.
=== Resetting the run numbers ===


BNMR and BNQR reuse [[BNMR:_Run_numbering|run numbers]] each year (i.e. you need to specify both the year and run number to identify a dataset).


=== Type 1 (I-MUSR) runs ===
At the start of each year, you need to change where the data is being written to. This will automatically reset the run numbers to the new values for the year as well


In addition to  [[BNMR:mdarc]], the standard MIDAS logger [https://midas.triumf.ca/MidasWiki/index.php/Mlogger mlogger] and client [[BNMR:mheader] are also required for Type 1 runs.
<pre>
Scaler data from the [[BNMR: frontend|frontend]] is sent out in the form of MIDAS banks. These banks are named differently and have different content to those sent
cd /isdaq/data1/<expt>/dlog
for a Type 2 run. The client [[BNMR: mheader|mheader]] is also required for a Type 1 run. At begin and end-of-run, it 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 containing
mkdir <year>
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 from the  .mid file by the program {{Client|name=midbnmr}} after the end-of-run.
rm current
ln -s <year> current
# Use the web interface to toggle between real and test modes (without starting a run), and verify that the run numbers are 30000/40000 (for BNMR) and 30000/45000 (for BNQR).
</pre>


The standard Midas logger 
== bnxr_logger.exe details ==
[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 
<span style="color:green;  font-style:italic; ">mdarc</span>  also receives the data banks, and converts the data to MUD format (using [[#Description|midbnmr]]
routines), saving a ''.msr'' file. The data in this file is 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.


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.


== Naming of saved files ==
The program is built as part of the main build (<code>cd build; make install</code> from the bnmr repository).


The data are written into a saved file in the directory given by the ODB parameter
The general functions performed by the program are:
[[BNMR: Keys in /Equipment/FIFO_acq/mdarc ODB subtree#saved_data_directory|saved_data_directory]].
* 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.
Type 1 (I-Musr) runs result in two saved data files, a .mid and a .msr file. Type 2 (TD-Musr) runs result in only one saved file, the .msr  file (see above). Both run types also produce a .odb file, containing a copy of the MIDAS online data base (ODB). In the event of corruption of the ODB, it can be regenerated from this file.
* 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.


The name of the  files is dependent on the run number. 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
=== Histograms ===
[[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 filename 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.


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
See the [[BNMR:_Histograms_and_Scalers#Histograms|histograms and scalers]] page for more details.


lrwxrwxrwx    1 bnmr    bnmr          48      Feb 26 12:09 040362.msr -> /isdaq/data1/bnmr/dlog/current/040362.msr_v27
Settings are stored in the ODB at {{Odbpath|path=/MUD Logging/Histos/Settings}}.
-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
=== CAMP ===
-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
[[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]].
 
==== Independent variables ====
 
Other CAMP variables can be logged during a run too.
 
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.
 
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).
 
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>
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
</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>).
 
=== Run comments ===
 
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 allows the user to note any critical information about the run that should be stored in the file, not just in a separate logbook. The textarea 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}}.


And after the run had ended:
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}}.


-rw-r--r--    1 bnmr    bnmr        4399  Feb 26 12:10 040362.msr
MUD files have a section dedicated to storing run comments.
-rw-r--r--    1 bnmr    bnmr        19990 Feb 26 12:10 040362.odb


=== ODB variables ===


==== Independent variables ====


The number of intermediate versions of the run files kept during a run is controlled by the ODB parameter
ODB variables specifying the configuration of the run are stored as independent variables in the MUD file. The user does not specify directly which variables log for each mode; the decision is made by the [[BNMR:_RF_calculator|RF calculator]] program.
[[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.  


In particular, the variables to be saved are stored as ODB links in the {{Odbpath|path=/Equipment/RFCalculator/Computed/Mud links/PPG/PPG20}} directory (for mode 20; similar names for other modes). The definition of the links is in <code>mud_ind_var_links.py</code>, which is included by {{Client|name=rf_calculator_fe.py}}. This keeps all the mode-specific complexity in one place, and in a language that is more expressive. The C++ code in {{Client|name=bnxr_logger.exe}} simply has to iterate over all the links in the relevant directory.


In the case of a Type 1 run three files are saved, e.g.  
Note the following conversions between C++/ODB data types and MUD independent variables:
* Arrays/vectors are not supported (in principle we could store a histogram, but users have not requested that yet)
* Numbers are stored in the <code>mean</code> member of the MUD variable.
* Strings are stored in the <code>units</code> member of the MUD variable.
* Booleans are stored with 1/0 in the <code>mean</code> member and yes/no in the <code>units</code> member of the MUD variable.
* If the ODB link name contains parentheses, the string between the parenthesis is stored in the <code>units</code> member of the MUD variable (e.g. a link called <code>Frequency (Hz)</code> will end up with <code>Hz</code> as the units).
* If the ODB link name does not contain parentheses (e.g. <code>Frequency</code>), but there is another ODB key called <code>Frequency ((UNITS))</code>, the string in the latter key is stored as the <code>units</code> for the former. This is for backwards-compatibility with older files that were not consistent about whether MUD variables contain units in the <code>name</code>, or only in the <code>units</code>.


$ ls /isdaq/data1/bnqr/dlog/current/045238.* -lt
ODB settings are stored as "independent variables" in the MUD file, keyed by the ODB link name (of format like <code>PPG/PPG20/Enable RF</code> to be backwards-compatible with older files). To be clear, the name of the link itself is used, not the name of the target of the link.
-rw-r--r-- 1 bnqr users  123088 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.odb
-rw-r--r-- 1 bnqr users 2156308 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.mid
-rw-r--r-- 1 bnqr users  93341 Aug 18 11:00 /isdaq/data1/bnqr/dlog/current/045238.msr


See the [[BNMR:_Mode_changer|mode changer]] page for details about how the user may load settings from a MUD file to replicate a previous experimental configuration.


==== Run description ====


=== Archiving the data ===
Some ODB variables are also used to build the run description in the MUD file (along with any [[#Run_description|CAMP variables]] being used for the run description).
In both cases (Types 1(I-MUSR) and 2(TD-MUSR)), the final *.msr data file for '''real runs''' (see [[BNMR: Run numbering]]) is
automatically copied  by [[BNMR: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|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.
The variables used are:
* {{Odbpath|path=/Experiment/Edit on start/experiment number}} for the <code>exptNumber</code>
* {{Odbpath|path=/Experiment/Edit on start/experimenter}} for the <code>experimenter</code>
* {{Odbpath|path=/Experiment/Edit on start/run_title}} for the <code>run_title</code>
* {{Odbpath|path=/Experiment/Edit on start/sample}} for the <code>sample</code>
* {{Odbpath|path=/Experiment/Edit on start/orientation}} for the <code>orient</code>
* {{Odbpath|path=/Experiment/Name}} for the <code>area</code> and <code>apparatus</code>,
* {{Odbpath|path=/CurrentMode/Name}} for the <code>insert</code> (hijacking a field used by MUSR but not {{bnmqr|join=or}})
* {{Odbpath|path=/Runinfo/Start time binary}} for the <code>timeBegin</code>
* {{Odbpath|path=/Runinfo/Stop time binary}} for the <code>timeEnd</code>
* {{Odbpath|path=/MUD Logging/Run description/Settings/Manual field value}} if not reading from CAMP
* {{Odbpath|path=/MUD Logging/Run description/Settings/Manual temperature value}} if not reading from CAMP


See [[BNMR:_Edit-on-start_parameters|edit-on-start parameters]] for more details on those variables.


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

Latest revision as of 13:31, 2 October 2024

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)

Resetting the run numbers

BNMR and BNQR reuse run numbers each year (i.e. you need to specify both the year and run number to identify a dataset).

At the start of each year, you need to change where the data is being written to. This will automatically reset the run numbers to the new values for the year as well

cd /isdaq/data1/<expt>/dlog
mkdir <year>
rm current
ln -s <year> current
# Use the web interface to toggle between real and test modes (without starting a run), and verify that the run numbers are 30000/40000 (for BNMR) and 30000/45000 (for BNQR).

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

See the histograms and scalers page for more details.

Settings are stored in the ODB at /MUD Logging/Histos/Settings.

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 allows the user to note any critical information about the run that should be stored in the file, not just in a separate logbook. The textarea 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

Independent variables

ODB variables specifying the configuration of the run are stored as independent variables in the MUD file. The user does not specify directly which variables log for each mode; the decision is made by the RF calculator program.

In particular, the variables to be saved are stored as ODB links in the /Equipment/RFCalculator/Computed/Mud links/PPG/PPG20 directory (for mode 20; similar names for other modes). The definition of the links is in mud_ind_var_links.py, which is included by rf_calculator_fe.py. This keeps all the mode-specific complexity in one place, and in a language that is more expressive. The C++ code in bnxr_logger.exe simply has to iterate over all the links in the relevant directory.

Note the following conversions between C++/ODB data types and MUD independent variables:

  • Arrays/vectors are not supported (in principle we could store a histogram, but users have not requested that yet)
  • Numbers are stored in the mean member of the MUD variable.
  • Strings are stored in the units member of the MUD variable.
  • Booleans are stored with 1/0 in the mean member and yes/no in the units member of the MUD variable.
  • If the ODB link name contains parentheses, the string between the parenthesis is stored in the units member of the MUD variable (e.g. a link called Frequency (Hz) will end up with Hz as the units).
  • If the ODB link name does not contain parentheses (e.g. Frequency), but there is another ODB key called Frequency ((UNITS)), the string in the latter key is stored as the units for the former. This is for backwards-compatibility with older files that were not consistent about whether MUD variables contain units in the name, or only in the units.

ODB settings are stored as "independent variables" in the MUD file, keyed by the ODB link name (of format like PPG/PPG20/Enable RF to be backwards-compatible with older files). To be clear, the name of the link itself is used, not the name of the target of the link.

See the mode changer page for details about how the user may load settings from a MUD file to replicate a previous experimental configuration.

Run description

Some ODB variables are also used to build the run description in the MUD file (along with any CAMP variables being used for the run description).

The variables used are:

  • /Experiment/Edit on start/experiment number for the exptNumber
  • /Experiment/Edit on start/experimenter for the experimenter
  • /Experiment/Edit on start/run_title for the run_title
  • /Experiment/Edit on start/sample for the sample
  • /Experiment/Edit on start/orientation for the orient
  • /Experiment/Name for the area and apparatus,
  • /CurrentMode/Name for the insert (hijacking a field used by MUSR but not bnmr or bnqr)
  • /Runinfo/Start time binary for the timeBegin
  • /Runinfo/Stop time binary for the timeEnd
  • /MUD Logging/Run description/Settings/Manual field value if not reading from CAMP
  • /MUD Logging/Run description/Settings/Manual temperature value if not reading from CAMP

See edit-on-start parameters for more details on those variables.