Run States and Transitions: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
(The midas documentation has moved to https://midas.triumf.ca/docs/)
Tag: Replaced
 
Line 1: Line 1:
{{Pagelinks}}
The midas documentation has moved. See [https://midas.triumf.ca/docs/develop/features/core_system/runs/#run-states-and-transitions Run states and transitions] in Runs: overview and [https://midas.triumf.ca/docs/develop/features/core_system/runs/programming/ Runs: programming] for the new documentation about run states and transitions.
 
==Introduction ==
Three Run States define the states of the MIDAS DAQ system:
 
; Stopped, Paused, Running
 
In order to change from one state to another, MIDAS provides four basic transition functions :
 
; TR_START, TR_PAUSE, TR_RESUME, TR_STOP
 
 
[[File:Transition.gif|center|frame|Representation of run states and associated transitions]]
 
== MIDAS State and Transition Codes ==
MIDAS provides three State Codes (defined in [[midas.h]]) for the three run states (Stopped, Paused and Running).
 
The run states and their values are:
 
* STATE_STOPPED 1
* STATE_PAUSED 2
* STATE_RUNNING 3
 
The current State of an experiment is available under the [[/Runinfo ODB tree]].
 
The Transition Codes (also defined in [[midas.h]] for the four Transitions are:
 
*    TR_START  1
*    TR_STOP  2
*    TR_PAUSE  4
*    TR_RESUME 8
 
While a transition is in progress, these Transition Codes will be found under the [[/Runinfo ODB tree]] for an experiment.
 
== Run Transition Priority ==
 
During these transition periods, any MIDAS client registered to receive notification of such a transition will be able to perform dedicated tasks in either synchronized or asynchronized mode, within the overall run control of the experiment.
 
In order to provide more flexibility to the transition sequence of all the MIDAS clients connected to a given experiment, each transition function has a transition sequence number attached to it. This transition sequence is used to establish within a given transition the order of the invocation of the MIDAS clients (from the lowest sequence number to the highest). By this means, MIDAS provides the user with full control of the sequencing of any MIDAS client.
 
Click on the links to see an example of how the transition priority operates at [[start of run]] and at [[end of run]].
 
 
== Registering for a run transition ==
 
Any MIDAS client can register to receive notification for a run transition. This notification is done by registering to the system for a given transition ( [[cm_register_transition()]] ) by specifying the transition type and the sequencing number (1 to 1000).
The following example show registering to the TR_START transition with a sequencing number of 450 and to a TR_STOP transition with a sequencing number of 650.
 
  INT main()
  {
    ...
  cm_register_transition(TR_START, tr_prestart,450);
  cm_register_transition(TR_STOP, tr_poststop,650);
    ...
  }
  <br>
  // callback
  INT tr_prestart(INT run_number, char *error)
  {
        // code to perform actions prior to frontend starting
        return (status);
  }
  <br>
  // callback
  INT tr_poststop(INT run_number, char *error)
  {
        // code to perform actions after frontend has stopped
        return (status);
  }
 
On a TR_START transition, tr_prestart will run after the logger and event builder, but before the Frontend (see Default Transition Sequence Numbers).
On a TR_STOP transition, tr_poststop will run after the frontend, but before the logger and event builder.
 
 
 
== Multiple Registration to a Transition ==
Multiple registration to a given transition can be requested. This last option allows (for example) two callback functions to be invoked before and after a given transition , such as the start of the logger.
 
my_application.c
<br>
  // Callback
  INT before_logger(INT run_number, char *error)
  {
    printf("Initialize ... before the logger gets the Start Transition");
    ...
    return CM_SUCCESS;
  }
<br>
  // Callback
  INT after_logger(INT run_number, char *error)
  {
    printf("Log initial info to file... after logger gets the Start Transition");
    ...
    return CM_SUCCESS;
  }
<br>
  INT main()
  {
    ...
    cm_register_transition(TR_START, before_logger, 100);
    cm_register_transition(TR_START, after_logger, 300);
    ...
  }
 
 
 
== Default Transition Sequence Numbers ==
 
By default the following sequence numbers are used:
 
<table style="text-align: left; width: 50%;" border="1" cellpadding="2"
cellspacing="2">
 
<tr>
<td colspan="1" rowspan="2"> <b>Client</b> <br>
</td>
<td colspan="4" rowspan="1" style=" text-align: center;">
<b>Default Transition Sequence Number</b><br>
</td>
</tr>
<tr>
<td>TR_START<br>
</td>
<td>TR_PAUSE<br>
</td>
<td>TR_RESUME<br>
</td>
<td>TR_STOP<br>
</td>
</tr>
<tr>
<td>Frontend<br>
</td>
<td>500<br>
</td>
<td>500<br>
</td>
<td>500<br>
</td>
<td>500<br>
</td>
</tr>
<tr>
<td>Analyzer<br>
</td>
<td>500</td>
<td>500</td>
<td>500</td>
<td>500</td>
</tr>
<tr>
<td>Logger<br>
</td>
<td>200<br>
</td>
<td>500</td>
<td>500</td>
<td>800<br>
</td>
</tr>
<tr>
<td>EventBuilder <br>
</td>
<td>300<br>
</td>
<td>500</td>
<td>500</td>
<td>700<br>
</td>
</tr>
</table>
 
 
== Review the Client Transition Sequence Numbers in the ODB ==
 
The [[/System ODB tree]] contains information specific to each "MIDAS client" currently connected to the experiment. The sequence number appears in the ODB under the  [[/System ODB tree #/System/Clients subtree|/System/Clients subtree]].
 
=== Change the Client Sequence Number ===
The [[/System ODB tree #/System/Clients subtree|/System/Clients subtree]] reflects the system at a given time. If a permanent change of a client sequence number is required, the MIDAS system call ''cm_set_transition_sequence()'' can be used.
 
== Deferred Transitions ==
 
Any [[#Introduction|transition]] may be deferred until some condition is satisfied. This is usually set up in a frontend (see [https://midas.triumf.ca/MidasWiki/index.php/Frontend_user_code#Deferred_Transition setup Deferred Transition] for further information).
 
[[Category:Transition]]

Latest revision as of 22:01, 30 October 2026

The midas documentation has moved. See Run states and transitions in Runs: overview and Runs: programming for the new documentation about run states and transitions.