Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  01 Dec 2023, Pavel Murat, Forum, MIDAS state machine : how to get around w/o 'configured' state?  
    Reply  02 Dec 2023, Stefan Ritt, Forum, MIDAS state machine : how to get around w/o 'configured' state?  muegamma.msl
       Reply  02 Dec 2023, Pavel Murat, Forum, MIDAS state machine : how to get around w/o 'configured' state?  
Message ID: 2639     Entry time: 02 Dec 2023     In reply to: 2637     Reply to this: 2641
Author: Stefan Ritt 
Topic: Forum 
Subject: MIDAS state machine : how to get around w/o 'configured' state?  
> The MIDAS state machine doesn't seem to have a state in between 'initialized' and 
> 'running'.
> In a larger detectors with multiple subsystems, the DAQ systems often have one more state:
> after ending a previous run and before starting a new one from the 'stopped' state, 
> one needs to make sure that all subdetectors are ready, or 'configured' for the new run. 
> So theat calls for a 'configure' step during which the detector (all subsystems in 
> parallel, to save the time) transitions from 'initialized'/'stopped' to 'configured' state, 
> from which it transitions to the 'running' state.
> 
> If one of the subdetectors fails to get configured, it could be excluded from the run 
> configuration and another attempt to reconfigure the system could be made without 
> starting a new run. Or an attempt could be made to troubleshoot and configure the 
> failed subsytem individually , with the rest subsystems waiting in a 'configured' state.
> 
> How does the logic of configuring the detector for the new run is implemented in MIDAS? 
> - it is a fairly common operational procedure, so I'm sure there should be a way 
> of doing that.

We have a similar requirement in our MEG experiment. Configuring your subdetectors can
be quite complex and therefore it's almost impossible to define a 'configure' step in
the run transition system to accommodate all corner cases.

Instead of a new state, we do everything through the sequencer:

- To start a run, we start a special sequencer script. We have different scripts for
calibration runs, data runs, special runs.

- When the user starts the script, they are asked for certain parameters, like number
of events, number of runs to take, how to configure the subdetectors, which subdetectors
to read out etc.

- The script then configures the whole experiment by setting everything in the ODB for
each equipment.

- The frontends connected to their equipment get a hotlink from the ODB and start the
configuration of the trigger etc. based on the parameters from the ODB

- The progress of the configuration is indicated by the frontend by writing back the
progress (like 0...100) into the ODB

- The script now waits for the progress to reach 100. It shows the current progress
on the sequencer page, so you see exactly where we are.

- If we have several subdetectors, each of them can publish a progress, and the script
can wait for an AND of all progress, or exclude one if it fails etc. Any logic is
possible there.

- Once all progresses are at 100, the run is finally started.

- If the mechanics of configuration become more elaborate, one can 'hide' it in
sub-modules of the script.

This scheme allows us to configure very different run modes, we use it in MEG since
many years (about 0.5M runs) and it works very nice.

Attached is our main script to start a full data run. You don't have to understand
all details, but it can give you a glimpse of what it's possible with the sequencer.
The function "ApplySettings" is the one waiting for the configuration flag in the ODB
(we simply use a boolean flag there). The code is:

SUBROUTINE ApplySettings
  ODBSET "/Equipment/Trigger/Settings/Reload all", y, 1
  WAIT seconds, 2
  WAIT ODBValue, "/Equipment/Trigger/Variables/Config busy", ==, y
ENDSUBROUTINE

Best,
Stefan
Attachment 1: muegamma.msl  2 kB  | Hide | Hide all
COMMENT "MEG Run"
INCLUDE /home/meg/online/sequencer/lib/WDAQPMT
INCLUDE /home/meg/online/sequencer/lib/WDAQMPPC
INCLUDE /home/meg/online/sequencer/lib/WDAQTC
INCLUDE /home/meg/online/sequencer/lib/WDAQCDCH
INCLUDE /home/meg/online/sequencer/lib/WDAQSystem
INCLUDE /home/meg/online/sequencer/run23/setswzerosuppression
INCLUDE /home/meg/online/sequencer/run23/xec/subscripts/ledcontrol
INCLUDE /home/meg/online/sequencer/run23/cdch/dcmon

PARAM enableDCMON, "enable DCMON readout", true, false

# Run parameters
SET Nevent, 5000
SET Nrun, infinite

# LXe Thresholds
# QH: 43.5 MeV
SET QHEnergy, 43.5
# QL: 39 MeV
SET QLEnergy, 39
# QC: 90 MeV
SET VetoEnergy, 90

# Time Window
# Narrow +-8 ns
Set NarrowThreshold, 10
# Wide +-25 ns
Set WideThreshold, 32

# Time Offset 
Set TimeOffset, 8

#make sure "Physics" is set
ODBSET "/Experiment/Run Parameters/Physics", 1, 1

#reload all default settings
CALL ReloadAll
CALL ApplySettings

#Apply Zero Suppression
CALL SetZeroSuppression

CALL SetLEDAmpl, 0.7, 4

# Trigger setting
CALL DisableAllTriggers

# 12.5 Hz of MEG trigger (12.5 Hz)
CALL EnableTrigger, 0, 1, 0

# 0.14 Hz of MEG LowQ (31 Hz)
CALL EnableTrigger, 1, 217, 0

# 0.14 Hz of MEG WideAngle (57 Hz)
CALL EnableTrigger, 2, 401, 0

# 0.14 Hz of MEG WideTime (36 Hz)
CALL EnableTrigger, 3, 253, 0

# 0.42 Hz of QH (1600 Hz)
CALL EnableTrigger, 10, 3755, 0

# 0.14 Hz of QL (3850 Hz)
CALL EnableTrigger, 11, 27100, 0

# 0.3 Hz of Cosmics (168 Hz)
CALL EnableTrigger, 15, 560, 0

# 0.1 Hz of LEDs
CALL EnableTrigger, 13, 100, 21

# 0.42 Hz of TCTrack
CALL EnableTrigger, 20, 6000000, 9

# 1 Hz of TCSingle 
#CALL EnableTrigger, 21, 1800000, 12

# 0.5Hz of Pedestal
CALL EnableTrigger, 63, 100000, 0

CALL SetHighThreshold, $QHEnergy
CALL SetLowThreshold, $QLEnergy
CALL SetVetoThreshold, $VetoEnergy

ODBGET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/XecHighThreshold", QHThreshold
ODBGET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/XecLowThreshold", QLThreshold
ODBGET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/XecVetoThreshold", VetoThreshold
ODBSET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/TimeNarrowThreshold", $NarrowThreshold
ODBSET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/TimeWideThreshold", $WideThreshold
ODBSET "/Equipment/Trigger/Settings/WaveDAQ/TRG/MASTER/TcTimeOffset", $timeOffset

# Reload and wait for configuration
CALL ApplySettings

# Set "XXX Data" flags
CALL UpdateDataFlags

# Loop for runs
LOOP $Nrun

   # Set Run description
   CAT description, "MEG run. QH: " $QHThreshold, ", QL: " $QLThreshold, ", QC: " $VetoThreshold, ", TimeNarrow: ", $NarrowThreshold, ", TimeWide: ", $WideThreshold, ", Offset: ", $timeOffset
   ODBSET "/Experiment/Run Parameters/Run Description", $description, 1

   CALL dcmon, $enableDCMON

   TRANSITION start
   WAIT events, $Nevent
   TRANSITION stop

ENDLOOP

#reload settings
CALL ReloadAll
ELOG V3.1.4-2e1708b5