Browsing Calibration Metadata

Just to get an idea what's there, it can be useful to look at the contents of the calibration metadata database interactively. Here are some instructions.

Bring up mysql

Part of the MySQL distribution is a program mysql which allows you to issue standard sql queries. It's simplest to bring it up if you're logged on to the same machine which hosts the database, currently centaurusa.slac.stanford.edu. Once logged on, the mysql command will already be defined for you. Connect to the database like this:

$ mysql -u glastreader -p calib

You can also connect from any machine in the slac domain which has the MySQL client software installed, such as a SLAC public Linux machine. If you are logged on to such a machine and have checked out the package MYSQLEXT, you can gain access to the mysql command by sourcing the MYSQLEXT setup file. Then you can issue this command:

$ $MYSQLEXT_DIR/bin/mysql -u glastreader -h centaurusa.slac.stanford.edu -p calib

Note in this case you also have to specify the host, following the -h flag. By the way, -u is used to specify a username, here glastreader, and -p says you want to be prompted for password. Ask one of the initiated (e.g., me) what the password is. The calib on the end specifies that you will be working with that database. Typically (and in our case) a single MySQL server handles multiple databases.

Useful commands

The show tables and describe tablename commands are often a good way to start out:

mysql> show tables;
+-----------------+
| Tables_in_calib |
+-----------------+
| junk            |
| metadata_v0     |
| metadata_v1     |
+-----------------+
3 rows in set (0.00 sec)

mysql> describe metadata_v1;
+-------------+------------------------------------+------+-----+---------+----------------+
| Field       | Type                               | Null | Key | Default | Extra          |
+-------------+------------------------------------+------+-----+---------+----------------+
| ser_no      | mediumint(9)                       |      | PRI | NULL    | auto_increment |
| instrument  | varchar(16)                        |      |     |         |                |
| calib_type  | varchar(20)                        |      |     |         |                |
| data_fmt    | varchar(10)                        |      |     |         |                |
| data_size   | int(11)                            | YES  |     | NULL    |                |
| vstart      | datetime                           | YES  |     | NULL    |                |
| vend        | datetime                           | YES  |     | NULL    |                |
| enter_time  | timestamp(14)                      | YES  |     | NULL    |                |
| fmt_version | varchar(12)                        | YES  |     | NULL    |                |
| completion  | enum('OK','INC','ABORT')           | YES  | MUL | NULL    |                |
| proc_level  | enum('PROD','TEST','DEV','SUPSED') |      |     | TEST    |                |
| creator     | varchar(255)                       | YES  |     | NULL    |                |
| uid         | varchar(12)                        |      |     |         |                |
| data_ident  | varchar(255)                       |      |     |         |                |
| input_desc  | varchar(255)                       | YES  |     | NULL    |                |
| notes       | varchar(255)                       | YES  |     | NULL    |                |
+-------------+------------------------------------+------+-----+---------+----------------+
16 rows in set (0.00 sec)

Currently only the table metadata_v1 is of any interest. The describe command lists all the column names defined for the table. The glastreader user really does just have read access, which makes select about the only other interesting command. Here are some examples:

mysql> select ser_no, instrument, calib_type, vstart, vend from metadata_v1 where instrument="BFEM";
+--------+------------+--------------+---------------------+---------------------+
| ser_no | instrument | calib_type   | vstart              | vend                |
+--------+------------+--------------+---------------------+---------------------+
|      3 | BFEM       | TKR_Bad_Chan | 2000-10-31 00:00:00 | 2000-11-23 00:00:00 |
+--------+------------+--------------+---------------------+---------------------+
1 row in set (0.01 sec)

mysql> select ser_no, vstart, instrument from metadata_v1;
+--------+---------------------+------------+
| ser_no | vstart              | instrument |
+--------+---------------------+------------+
|      1 | 2000-10-31 00:00:00 | BTEM       |
|      2 | 2000-10-31 00:00:00 | BTEM       |
|      3 | 2000-10-31 00:00:00 | BFEM       |
|      4 | 2000-10-31 00:00:00 | BTEM       |
|      5 | 2001-10-31 00:00:00 | BTEM       |
|      6 | 2000-08-02 00:00:00 | EM         |
|      7 | 2000-08-02 00:00:00 | EM         |
+--------+---------------------+------------+
7 rows in set (0.00 sec)

mysql> select ser_no, vstart, instrument from metadata_v1 where vstart > "2000-9-1";
+--------+---------------------+------------+
| ser_no | vstart              | instrument |
+--------+---------------------+------------+
|      1 | 2000-10-31 00:00:00 | BTEM       |
|      2 | 2000-10-31 00:00:00 | BTEM       |
|      3 | 2000-10-31 00:00:00 | BFEM       |
|      4 | 2000-10-31 00:00:00 | BTEM       |
|      5 | 2001-10-31 00:00:00 | BTEM       |
+--------+---------------------+------------+
5 rows in set (0.01 sec)

You can run a script from the mysql command line with the source command:

mysql> source myfile.sql;
    ...
    [same output you would see if you executed the lines
     in the script interactively one by one]

Hints

Almost all commands you issue to mysql require a semi-colon (;) at the end, and it never hurts to include it. If you forget, mysql tries to tell you by prompting with -> rather than the normal mysql>.

mysql> show tables
    -> ;
+-----------------+
| Tables_in_calib |
+-----------------+
| junk            |
| metadata_v0     |
| metadata_v1     |
+-----------------+
3 rows in set (0.00 sec)

Similarly, it tells you if you forgot a matching single or double quote with prompts "> or '>, respectively.

mysql> select ser_no from metadata_v1 where vstart > "2000-9-1
    "> "
    -> ;
+--------+
| ser_no |
+--------+
|      1 |
|      2 |
|      3 |
|      4 |
|      5 |
+--------+
5 rows in set (0.01 sec)

For complete documentation on everything connected with MySQL, see the online manual, in particular chapter 6 for SQL command syntax.

Last modified: