Skip to content

Query syntax

Dmitry Romanov edited this page Aug 16, 2016 · 7 revisions

Queries allow to select runs using simple 'python if syntax'. Condition names and aliases are used as variables. Queries are implemented in web GUI, python API and CLI .

Example. Query to get production runs with beam current around 100 uA and 'BCAL' in run_config ( here 'BCAL' is a detector / subsystem in HallD and run_config is a name of a configuration file):

General/web site query:

@is_production   and   80 < beam_current < 120   and   'BCAL' in run_config

The result of the query on HallD website

Queries syntax are the same across API-s (which supports queries at all)

python:

runs = db.select_runs("@is_production and 80 < beam_current < 120 and 'BCAL' in run_config")

CLI:

>>rcdb sel "@is_production and 80 < beam_current < 120 and 'BCAL' in run_config"

Syntax

Queries use python 'if' syntax. The full python documentation is here.

Concise version is:

  • <, <=, ==, !=, =>, > to compare values (same as in C++)

  • or, and, not for logic operators (||, &&, ! in C++)

  • in operator is to check a value or a subarray is present in the array, (arrays or lists in python can be given in square braces []):

    5 in radiator_id
    radiator_id in [5, 6, 12]
  • strings must be enclosed in ' - single braces. ==, != operators can be used to compare two strings, in operator works for substrings and letters:

    run_config == 'FCAL_BCAL_PS_m7.conf'
    'hd_all' in run_type

Aliases

One may notice @is_production in the query example above. @ means 'alias' - predefined set of conditions. For example for HallD @is_production alias is given as:

run_type in ['hd_all.tsg', 'hd_all.tsg_ps', 'hd_all.bcal_fcal_st.tsg'] and
beam_current > 2 and
event_count > 500000 and
solenoid_current > 100 and
collimator_diameter != 'Blocking'