BNMR: Shift Monitor: Difference between revisions
en>Suz mNo edit summary |
m (4 revisions imported) |
(No difference)
|
Revision as of 12:36, 25 April 2022
Links
Introduction
The BNMR shift monitor system consists of the perlscript monitor.pl in directory /home/bnmr/online/perl, 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 program monitor.pl 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 in shift files in the directory /isdaq/data1/bnmr/mon/<year>/.
Output from the perlscript is sent to a logfile.
How it works
The perlscript /home/bnmr/online/perl/monitor.pl is run on isdaq01 (i.e. the midas host for bnmr and bnqr experiments) as a cron job (except for testing). Its output is written to a log file. It is run only as user bnmr, which has permission to access the EPICS variables needed.
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 the bnqr ODB is done using odbedit, i.e.
for bnmr | odbedit -c 'ls "/Experiment/Edit on start/experiment number" ' |
for bnqr | odbedit -h isdaq01:1177 -e bnqr -c 'ls "/Experiment/Edit on start/experiment number" ' |
The perlscript
monitor.pl 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:
- bnmr in single channel mode, or
- bnqr in single channel mode,or
- both experiments (in dual channel mode)
- 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
Log files
The current log file is /isdaq/data1/bnmr/mon/monitor.log
When monitor.pl 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)).
Logrotate (see #Rotate log files) is used to rotate the log files on a daily basis. 7 days worth of logfiles are retained.
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 1
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
Example 2 Test Mode
In this example monitor.pl has been run in test mode (the * under "Testing" indicates test mode - see #How it works). In this case, the same experiment numbers have been used for testing monitor.pl on both bnmr and bnqr.
# Shift Monitor File first opened at Thu Jul 24 13:52:21 2014 # Threshold(uA) ExptNum BNMR(min) BNQR(min) Time line written Testing 10.000 00001508 0080 0036 Thu Jul 24 15:50:01 2014 * 10.000 00001412 0035 0021 Thu Jul 24 15:49:02 2014 *
Input Parameters
Input Parameter | Explanation | |
---|---|---|
1 | Proton Current Threshold (uA) | User selected value. If proton current is less than this value, program will exit without updating shift file. In Test Mode, set value to 0 to skip reading proton current from EPICS. |
2 | Suppress printing | Must be TRUE if running as a cron job |
3 | Test Mode | Set Test Mode TRUE for testing if EPICS switches are set to "off" |
4 | BNMR enabled | In Test Mode, set TRUE to enable BNMR regardless of EPICS switch |
5 | BNQR enabled | In Test Mode, set TRUE to enable BNQR regardless of EPICS switch |
6 | skip file | In Test Mode, set TRUE to prevent any update of shift files |
- NOTE
- If not running in Test Mode, only the first two parameters are required.
Running the program by hand
The perlscript monitor.pl can be run by hand to check its operation. However, each time it is run, a minute will be added to the current experiment(s) in the shift files. Therefore, it should not be run by hand during the beam period (i.e. when the cron job is running) unless in test mode with the input parameter) skip file set true, to prevent any update of shift files.
To run the program, as user bnmr, in an xterm type e.g.
/home/bnmr/vmic_online/perl/monitor.pl 15
Printing to the screen ( input parameter suppress printing) need not be set true when running by hand.
The program can also be run in test mode, e.g
/home/bnmr/vmic_online/perl/monitor.pl 5 0 1 0 1
This would enable the bnqr experiment regardless of the EPICS switches (see #Input Parameters). If the proton current is less than the threshold, in test mode the script continues after writing a message to the log file. The shift file would be updated.
or it can be run in test mode with input parameter) skip file set true, to prevent any update of shift files:
/home/bnmr/vmic_online/perl/monitor.pl 0 0 1 1 1 1
This would enable both experiments regardless of the EPICS switches. The proton current would not be read (see #Input Parameters), the shift files remain unchanged.
Running the cron job
As user bnmr, in an xterm type
$ crontab -l
to list the crontab file, or to edit it
$ crontab -e
The crontab file will be displayed as follows:
# MAILTO=Gerald Morris <gmorris@triumf.ca>,suz@triumf.ca SHELL=/bin/csh # cron parameters : # minute hour dayofmonth month dayofweek command # # Aug 31 2016 SD use logrotate # logrotate now cycles the logfiles monitor.log. # See /etc/logrotate.d/musrmidas # # monitor.pl parameters: proton_current(uA) noprint testing bnmr_running bnqr_running skip_file # # run like this for TESTING cron job when epics switches are not set correctly and proton I is zero: # #use the odb to change the experiment numbers under "/experiment/edit on start/" #* * * * * /home/bnmr/online/perl/monitor.pl 0 1 1 1 1 0 # # Note: emacs Cntrl X Cntrl C y to exit # # run like this normally (change "10" to required proton current threshold) : # Uncomment to turn on monitor # typical BL2A current is about 40 \mu A; set a threshold somewhat less. # * * * * * /home/bnmr/online/perl/monitor.pl 35 1
The example above shows
- the shift program monitor.pl being run as a cron job every minute (cron parameters all = *)
with parameters
- minimum proton current 35
- suppress printing TRUE
Printing must be suppressed when running as a cron job, otherwise the MAILTO recipient will get long email messages every minute. If the last line is commented out, the cron job will not be running the monitor program (see stopping the cron job).
Stopping the cron job
As user bnmr, in an xterm type
$ crontab -e
which will display the crontab file to be edited (see above). Comment out the last line that starts the perlscript, i.e.
## * * * * * /home/bnmr/vmic_online/perl/monitor.pl 35 1
and exit from the editor.
Rotate log files
The log files are rotated daily by logrotate. This is controlled by the file /etc/logrotate.d/musrmidas with the command
/data1/bnmr/log/*.log { rotate 4 monthly missingok nocreate notifempty
See also logrotate perlscript logfiles.