Skip to content

Select values

Dmitry Romanov edited this page Dec 11, 2017 · 16 revisions

TL; DR;

Fastest way to select values in 3 lines:

# import RCDB
from rcdb.provider import RCDBProvider

# connect to DB
db = RCDBProvider("mysql://[email protected]/rcdb")

# select values with query
table = db.select_values(['polarization_angle','beam_current'], "@is_production", run_min=30000, run_max=30050)

table will contain 3 columns run_number, polarization_angle, beam_current. Like:

[[30044,  -1.0,  UNKNOWN],
 [30045,  45.0,  PARA   ],
...] 

Select and filter

The fastest designed way to get values from RCDB is by using select_values function. The full example is here: $RCDB_HOME/python/example_select_values.py

The simplest usage is to put condition names and a run range:

from rcdb.provider import RCDBProvider

db = RCDBProvider("mysql://[email protected]/rcdb")

table = db.select_values(['polarization_angle','polarization_direction'], run_min=30000, run_max=30050)

# Print results
print(" run_number, polarization_angle, polarization_direction")
for row in table:
    print row[0], row[1], row[2]

output:

30044 -1.0 UNKNOWN
30045 45.0 PARA

Query

It is possible to put selection query as a second argument as in TL; DR; example:

table = db.select_values(['polarization_angle','beam_current'], "@is_production", run_min=30000, run_max=30050)

Exact runs

Instead of using run range one can specify exact run numbers using runs argument

table = db.select_values(['event_count'], "@is_production", runs=[30300,30298,30286])

All options

                                                                             # Default value | Descrition
                                                                             #---------------+------------------------------------
table = db. select_values(val_names=['event_count'],                         # []            | List of conditions names to select, empty by default
                          search_str="@is_production and event_count>1000",  # ""            | Search pattern.
                          run_min=30200,                                     # 0             | minimum run to search/select
                          run_max=30301,                                     # sys.maxsize   | maximum run to search/select
                          sort_desc=True,                                    # False         | if True result runs will by sorted descendant by run_number, ascendant if False
                          insert_run_number=True,                            # True          | If True the first column of the result will be a run number
                          runs=None)                                         # None          | a list of runs to search from. In this case run_min and run_max are not used

More info about select runs && get values