BNMR: Shift Monitor: Difference between revisions

From DaqWiki
Jump to navigation Jump to search
en>Suz
(New page: {{Pagelinks}} = Links = <div style="column-count:3;-moz-column-count:3;-webkit-column-count:3"> * BNMR * * Experimental Modes * [[BNMR: Getting Started|...)
 
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Pagelinks}}
{{Pagelinks}}


= Links =
== Introduction ==
<div style="column-count:3;-moz-column-count:3;-webkit-column-count:3">
The BNMR shift monitor system consists of the python program {{File|name=bnxr_common/beamtime_monitor.py}}, which is
* [[BNMR]]
run as a '''cron job''' during the beam period.  It run as user ''bnmr'', and accesses the required information from both the {{bnmqr|join=and}} ODBs.
*
 
* [[BNMR: Experimental Modes|Experimental Modes]]
The shift monitor keeps a running total of how much usable beam time (in minutes) each TRIUMF experimental group has had access to, while running as experiment {{bnmqr|join=or}} (or both).  It reads the proton current from EPICS once per minute.
* [[BNMR: Getting Started|Getting Started]]
The information is stored as text files in the directory  {{Filepath|path=/isdaq/data1/bnmr/mon/<year>/}}, alongside an Excel spreadsheet that summarises each campaign. The text files are updated every minute, and the Excel spreadsheet every 8 hours.
</div>
 
== beamtime_monitor.py ==
This script is responsible for reading the state of the beamlines and DAQ systems, and recording summaries in text files.
 
=== How it works ===
 
The script determines which TRIUMF experimental group is running by reading the '''experiment number''' from the ODB parameter {{Odbpath|path=/Experiment/Edit on start/experiment number}} on both experiments. Access to both ODBs uses Midas' python tools.
 
The program reads the proton current from EPICS (via <code>caget "CCS2ISAC:BL2ACURRENT"</code>).
<ul>
<li> If it is below the threshold value (supplied as the first  [[#Input Parameter|input parameter]] to {{File|name=monitor.pl}}),  it exits.</li>
<li> Otherwise it reads from the EPICS switches which experiment(s) is/are enabled:
<ul>  
<li>{{bnmr}} in [[BNMR Dual Channel Mode#Single Channel Mode|single channel mode]], '''or'''
<li>{{bnqr}} in single channel mode,'''or'''
<li> '''both''' experiments (in [[BNMR Dual Channel Mode|dual channel mode]])</li>
</li>
</ul>
<li> It reads the [[#How it works|experiment number]] from the enabled experiment(s).  The experiment number must be valid (0 < expt_num < 9999), otherwise no beam time will be allocated and an error will be reported </li>
<li> The program determines the name of the shift file by date and by 12-hour shift (AM/PM).</li>
<li> If no file of that filename exists, it is created and a line written for each different experiment number, and each running experiment assigned 1 minute of running time.  </li>
<li> If {{bnmqr|join=and}} are '''both''' running with the '''same''' experiment number, only one line will be created with {{bnmqr|join=and}} experiments each given 1 minute accumulated time. </li>
<li> If there is an existing file, the program looks for a line with the experiment number. If it finds one, the accumulated time is incremented for the appropriate experiment.  All other lines are copied and an updated file is written. If no line exists for this experiment number, a new line will be written.</li>
<li> If '''test mode''' is enabled (see [[#Input Parameters]]) an entry to the shift file written in test mode will be followed by an asterisk (see [[#Shift files]]) -- unless parameter ''skip file'' is true</li>
</ul>
 
=== Debug files ===
The current log file is {{Filepath|path=/isdaq/data1/bnmr/mon/monitor.log}}
 
When  the program is running as a cron job,  the output of the program can only be found in the log file, since printing informational messages to the screen must be suppressed (any messages printed are sent as email (see MAILTO in crontab)). 
 
Note : the shift files are never rotated or deleted unless by the user.
 
=== Shift files ===
Shift files are located in the directory  {{Filepath|path=/isdaq/data1/bnmr/mon/<year>/}}  and filenames are of the form
{{File|name=24Jul2014_AM.txt, 24Jul2014_PM.txt}}.  The AM shift starts at 8.30am, the PM shift at 8:30pm.


The format of the shift files is shown in the following examples:


== Introduction ==
==== Example ====
The BNMR shift monitor system consists of two perlscripts
This example shows one experimenter group (expt number 1604) has run on  {{bnmr}} and two (1539,1419) on  {{bnqr}} during an 8-hour shift.
<pre>
# Shift Monitor File first opened at Sun Jun 12 20:30:01 2016
# Threshold(uA)  ExptNum        BNMR(min)    BNQR(min)  Time line written        Testing
  35.000        00001604      0643        0000      Mon Jun 13 08:28:01 2016   
  35.000        00001539      0000        0536      Mon Jun 13 06:32:01 2016   
  35.000        00001419      0000        0117      Mon Jun 13 08:29:01 2016   
</pre>
 
=== Arguments ===
<pre>
usage: beamtime_monitor.py [-h] --min-current MIN_CURRENT [--dry-run]
                          [--skip-bnmr] [--skip-bnqr]
                          [--skip-expt-name-check] [--verbose]
                          [--verbose-to-logfile]


*   <span style="color:navy ; font-style:italic; "> monitor.pl</span>
optional arguments:
*    <span style="color:navy ; font-style:italic; ">cycle_monitor_logfiles.pl</span>
  -h, --help            show this help message and exit
  --min-current MIN_CURRENT
                        Minimum beam current to count as being active
  --dry-run            Don't write to log file, just print to screen
  --skip-bnmr          Don't calculate BNMR beamtime
  --skip-bnqr          Don't calculate BNQR beamtime
  --skip-expt-name-check
                        Don't check that we're connecting to a midas expt
                        called 'bnmr'
   --verbose            Print more output to screen
  --verbose-to-logfile  Record more output to monitor.log
</pre>


both of which are normally run as cron jobs,  and a shell-script  {{File|name=check_exptnum}}.
== beamtime_to_excel.py ==


The Shift Monitor program  {{File|name=monitor.pl}} keeps a running total of how much usable beam time  (in minutes) each experiment number has had access to, while running as experiment {{bnmqr|join=or}} (or both).  It reads the proton current from EPICS once per minute.
This script is responsible for reading the shift files generated by <code>beamtime_monitor.py</code> summarizing them in an Excel spreadsheet. The format of the spreadsheet matches one that was manually updated by Gerald in the past.
The information is stored in shift files in the directory  {{Filepath|path=/isdaq/data1/bnmr/mon/<year>/}}. This is also the location of the log files used to store messages.  
== How it works ==


The perlscript  {{Filepath|path=/home/bnmr/vmic_online/perl/monitor.pl}}  is run  on isdaq01 (i.e. the host for  {{bnmqr|join=and}} experiments)  as a cron job  (except for testing).  Its output is written to a log file. It is run as user {{bnmr}},  which has permission to access the EPICS variables needed, and, of course, its own odb.
=== Arguments ===


Access to the {{bnqr}} odb has to be done via ssh. A script {{Filepath|path=/home/bnqr/vmic_online/bnqr/bin/check_exptnum}} is run to read {{bnqr}}'s experiment number using  {{Utility|name=odb -c}} , and a ssh-key for access.
<pre>
usage: Summarize beamtime monitor files into a single excel spreadsheet
      [-h] [--source-dir SOURCE_DIR] [--output-file OUTPUT_FILE]
      [--schedule-info SCHEDULE_INFO] [--isotope-info ISOTOPE_INFO]
      [--fake-data] [--start-date START_DATE] [--end-date END_DATE] [--quiet]


The perlscript {{File|name=monitor.pl}} reads the proton current from EPICS (via ''caget "CCS2ISAC:BL2ACURRENT"'').
optional arguments:
* If it is below the threshold value (supplied as the first  input parameter to {{File|name=monitor.pl}} )  it exits.
  -h, --help            show this help message and exit
* Otherwise it reads from the EPICS switches whether {{bnmr}}, {{bnqr}} or both experiments (i.e. dual channel mode) are enabled.  
  --source-dir SOURCE_DIR
** If {{bnmqr|join=or}} or both experiments are enabled, it reads the experiment numbers from both  {{bnmqr|join=and}}. The experiment number must be > 0. Otherwise it exits.
                        Defaults to /data1/bnmr/mon/<current_year>
* The program determines the name of the shift file by date and by 12-hour shift (AM/PM).
  --output-file OUTPUT_FILE
* If no file of that filename exists, it is created and a line written for each different experiment number, and each running experiment assigned 1 minute of running time.
                        Defaults to <source_dir>/beamtime.xlsx
* If bnmr and bnqr are both running (dual channel mode) with the same experiment number, only one line will be created with bnmr and bnqr both given 1 minute accumulated time).
  --schedule-info SCHEDULE_INFO
* If there is an existing file, the program looks for a line with the experiment number. If it finds one, the accumulated time is incremented for the appropriate experiment.  All other lines are copied and an updated file is written. If no line exists for this experiment number, it will be created.
                        Text to describe the date range / schedule. Defaults
                        to date range shown.
  --isotope-info ISOTOPE_INFO
                        Text to describe the isotope(s) used. Defaults to
                        empty string.
  --fake-data          Skip reading real beamtime files, and use fake data
                        for testing.
  --start-date START_DATE
                        Format dd/mm/yyyy. Limit to only showing shifts
                        on/after this date.
  --end-date END_DATE  Format dd/mm/yyyy. Limit to only showing shifts
                        on/before this date.
  --quiet              Supress stdout output (e.g. if running in cron)
</pre>
[[Category:BNMR]]

Latest revision as of 14:13, 28 April 2022

Introduction

The BNMR shift monitor system consists of the python program bnxr_common/beamtime_monitor.py, which is run as a cron job during the beam period. It run as user bnmr, and accesses the required information from both the bnmr and bnqr ODBs.

The shift monitor keeps a running total of how much usable beam time (in minutes) each TRIUMF experimental group has had access to, while running as experiment bnmr or bnqr (or both). It reads the proton current from EPICS once per minute. The information is stored as text files in the directory /isdaq/data1/bnmr/mon/<year>/, alongside an Excel spreadsheet that summarises each campaign. The text files are updated every minute, and the Excel spreadsheet every 8 hours.

beamtime_monitor.py

This script is responsible for reading the state of the beamlines and DAQ systems, and recording summaries in text files.

How it works

The script determines which TRIUMF experimental group is running by reading the experiment number from the ODB parameter /Experiment/Edit on start/experiment number on both experiments. Access to both ODBs uses Midas' python tools.

The program reads the proton current from EPICS (via caget "CCS2ISAC:BL2ACURRENT").

  • If it is below the threshold value (supplied as the first input parameter to monitor.pl), it exits.
  • Otherwise it reads from the EPICS switches which experiment(s) is/are enabled:
  • It reads the experiment number from the enabled experiment(s). The experiment number must be valid (0 < expt_num < 9999), otherwise no beam time will be allocated and an error will be reported
  • The program determines the name of the shift file by date and by 12-hour shift (AM/PM).
  • If no file of that filename exists, it is created and a line written for each different experiment number, and each running experiment assigned 1 minute of running time.
  • If bnmr and bnqr are both running with the same experiment number, only one line will be created with bnmr and bnqr experiments each given 1 minute accumulated time.
  • If there is an existing file, the program looks for a line with the experiment number. If it finds one, the accumulated time is incremented for the appropriate experiment. All other lines are copied and an updated file is written. If no line exists for this experiment number, a new line will be written.
  • If test mode is enabled (see #Input Parameters) an entry to the shift file written in test mode will be followed by an asterisk (see #Shift files) -- unless parameter skip file is true

Debug files

The current log file is /isdaq/data1/bnmr/mon/monitor.log

When the program is running as a cron job, the output of the program can only be found in the log file, since printing informational messages to the screen must be suppressed (any messages printed are sent as email (see MAILTO in crontab)).

Note : the shift files are never rotated or deleted unless by the user.

Shift files

Shift files are located in the directory /isdaq/data1/bnmr/mon/<year>/ and filenames are of the form

24Jul2014_AM.txt, 24Jul2014_PM.txt. The AM shift starts at 8.30am, the PM shift at 8:30pm.

The format of the shift files is shown in the following examples:

Example

This example shows one experimenter group (expt number 1604) has run on bnmr and two (1539,1419) on bnqr during an 8-hour shift.

# Shift Monitor File first opened at Sun Jun 12 20:30:01 2016
# Threshold(uA)   ExptNum        BNMR(min)    BNQR(min)  Time line written        Testing
   35.000         00001604       0643         0000       Mon Jun 13 08:28:01 2016    
   35.000         00001539       0000         0536       Mon Jun 13 06:32:01 2016    
   35.000         00001419       0000         0117       Mon Jun 13 08:29:01 2016    

Arguments

usage: beamtime_monitor.py [-h] --min-current MIN_CURRENT [--dry-run]
                           [--skip-bnmr] [--skip-bnqr]
                           [--skip-expt-name-check] [--verbose]
                           [--verbose-to-logfile]

optional arguments:
  -h, --help            show this help message and exit
  --min-current MIN_CURRENT
                        Minimum beam current to count as being active
  --dry-run             Don't write to log file, just print to screen
  --skip-bnmr           Don't calculate BNMR beamtime
  --skip-bnqr           Don't calculate BNQR beamtime
  --skip-expt-name-check
                        Don't check that we're connecting to a midas expt
                        called 'bnmr'
  --verbose             Print more output to screen
  --verbose-to-logfile  Record more output to monitor.log

beamtime_to_excel.py

This script is responsible for reading the shift files generated by beamtime_monitor.py summarizing them in an Excel spreadsheet. The format of the spreadsheet matches one that was manually updated by Gerald in the past.

Arguments

usage: Summarize beamtime monitor files into a single excel spreadsheet
       [-h] [--source-dir SOURCE_DIR] [--output-file OUTPUT_FILE]
       [--schedule-info SCHEDULE_INFO] [--isotope-info ISOTOPE_INFO]
       [--fake-data] [--start-date START_DATE] [--end-date END_DATE] [--quiet]

optional arguments:
  -h, --help            show this help message and exit
  --source-dir SOURCE_DIR
                        Defaults to /data1/bnmr/mon/<current_year>
  --output-file OUTPUT_FILE
                        Defaults to <source_dir>/beamtime.xlsx
  --schedule-info SCHEDULE_INFO
                        Text to describe the date range / schedule. Defaults
                        to date range shown.
  --isotope-info ISOTOPE_INFO
                        Text to describe the isotope(s) used. Defaults to
                        empty string.
  --fake-data           Skip reading real beamtime files, and use fake data
                        for testing.
  --start-date START_DATE
                        Format dd/mm/yyyy. Limit to only showing shifts
                        on/after this date.
  --end-date END_DATE   Format dd/mm/yyyy. Limit to only showing shifts
                        on/before this date.
  --quiet               Supress stdout output (e.g. if running in cron)