-
Notifications
You must be signed in to change notification settings - Fork 7
Select values
Dmitry Romanov edited this page Dec 11, 2017
·
16 revisions
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 ],
...]
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
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)
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])
# 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
- Select runs & get values (python)
Getting started & basic usage:
- Installation
- Select values tutorial (python)
- Query syntax
- Add data (python)
- CLI Basics
RCDB Explained:
- Connection
- DB and APIs structure
- SQL examples
- Creating condition types
- Adding condition values
- Saving files
- SQLAlchemy
- Logging
- Performance
Command line tools:
DAQ: