Difference between revisions of "G2pmysql"

From Hall A Wiki
Jump to: navigation, search
(Modifications made to RunInfo Tables after Run Period)
(C++/Root (and now Python) Mysql Library)
 
(74 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is just a page to help me collect useful mysql commands for now and document my work. It'll be more user friendly in the future.
+
Below is a description of the g2p mysql database. It will be continuously updated with new features as they're requested and as I think of them. So if you think of something you would like the database to do, just let me know.
 +
 
 
-Ryan
 
-Ryan
 
 
What's been done so far:
 
#Backed up DB - 6/4/12
 
##/adaqfs/home/adaq/g2p/g2pbackup.sql
 
## I also have a copy of this file on my own computer
 
#Updated Target Encoder Position for both L/R HRS - 6/4/12
 
## /adaqfs/home/a-onl/scripts/mysql/FixTargetPosition_g2p(R).pl accesses end of run files and updates the DB
 
## /adaqfs/home/a-onl/scripts/mysql/Target.sh loops through however many runs you want to using FixTargetPosition_g2p(R).pl
 
# Updated Target Number for both L/R HRS - 6/7/12
 
## Updated FixTargetPosition_g2p.pl to do this
 
## Fixed a bug so perl script now correctly finds negative encoder values
 
# Renamed Target.sh to mysql_g2p.sh 6/12/12
 
# Updated HWP Status using FixHWP_g2p(R).pl 6/12/12
 
# Updated PS Status using FixPS_g2p(R).pl 6/12/12
 
# Create a script to parse EPICS files from run period epics.pl 6/13/12
 
## Located on ifarm /w/halla-1/g2p/ryan/mysql
 
## EPICS files located at w/halla-1/g2p/epics
 
## Currently set up to loop through all the lines of EPICS file and compute the average of an EPICS variable between a start and stop time. This will eventually be tied to run times!
 
# Epics variables and descriptions can be found here https://hallaweb.jlab.org/wiki/index.php/G2p_epics
 
 
Things to check for/To Do List:
 
# <strike>HWP Status. Because the entry is filled at the start of run, what to make sure that it updated before a new run was started. </strike>
 
# <strike>Target Encoder Position. Again the entry is filled from the start of run so you want to check with the end of run and make sure this updated correctly. Most problems occur around dilution runs. </strike>
 
# <strike>Prescale factor. Up until a certain point there was a bug in the code so that the DB scripts only recorded the first digit of the prescale factor. So a PS of 10 would only record as a PS of 1. This was eventually fixed but the runs need to be checked. </strike>
 
# Based off of Encoder position should be able to correct Target Type and Target Number in beam. Encoder positions are in ().
 
## Decided to only update the Target Number because this was determined via EPICS so it is definitely not right. The Target Type could be useful because it was shift worker controlled, so if the Target Encoder was not reporting to EPICS correctly the Target Type may be correct. I stress 'may' because you have to trust the shift worker.
 
##Carbon - (10,000 , 15,000) 6 (at some point Carbon target became thicker but not sure when this should be checked)
 
##Carbon Hole - (41,000 ,  45,000) 2
 
## CH2 - ( 37,000 , 41,000 ) 3
 
## NH3 (Top/Bottom determined by Target Number) - ( 28,000 , 35,000)  4 (45,000 , 51,000) 1
 
## Dummy - (20,000 , 25,000) 5
 
## Home - < 1000 7
 
## If 999 or 0 Target Encoder is not reporting to EPICS - Record Target Number as 0
 
## Important Notes on Target Variable Epics reporting: Going through the HALOG I don't see Target Encoder Variables accurately reporting until Runs 3220/22305 on 3/16/12. See http://hallaweb.jlab.org/halog/log/html/1203_archive/120316153201.html
 
# For analysis table, create column for Target Material Type and get info from here https://hallaweb.jlab.org/wiki/index.php/Target_Material_Summary
 
# <strike>List of EPICS variables and what they actually correspond to </strike>
 
# Should base my mysql stuff off of this: https://userweb.jlab.org/~singhj/runsummary/
 
 
  
 
List of good mysql tutorial websites.
 
List of good mysql tutorial websites.
Line 46: Line 8:
 
  http://www.dreamincode.net/forums/topic/42301-beginners-guide-to-creating-simple-mysql-tables/
 
  http://www.dreamincode.net/forums/topic/42301-beginners-guide-to-creating-simple-mysql-tables/
  
Using the MYSQL DB (as hosted on adaql10):
+
Installing a MYSQL Server on your own machine
  Currently you can only connect to the DB from an adaq machine.
+
http://dev.mysql.com/doc/refman/5.0/en/macosx-installation.html
  To connect: [adaq@adaql5 ~]$ mysql -h adaql10 -u g2p -p    (email me or ask me for the password! Alexandre knows it too and maybe Vince)
+
  http://dev.mysql.com/doc/refman/5.0/en/windows-installation.html
 +
  http://dev.mysql.com/doc/refman/5.0/en/linux-installation-rpm.html
 +
Note: Default ROOT password for mysql user is blank
  
 +
== Web Interface ==
  
 +
The g2p database can be accessed through the web at the following [https://hallaweb.jlab.org/experiment/g2p/mysql/ link].
  
== g2p mysql Table Descriptions ==
+
The web interface allows you to search the g2p mysql database through your web browser and also output your search results to a CSV file. The search form parses the AnaInfo tables and displays selected fields to the browser. The download CSV file contains ALL the fields. Also selecting an individual run from the search results will display information on all the fields of that run in a new tab/window from both the AnaInfo and RunInfo tables.
  
There are two main categories of tables in the g2p mysql database. The first category includes tables that were filled with data online. The fields were filled either at the start or end of run with a snapshot of the EPICS information associated with the table variable or with summary information from the end of run script. Some of this information was provided by the shift worker so one should be careful with these tables. These tables are the RunInfo Tables and there is one for each DAQ arm (Left, Right, Third).
+
<b>1/30/13</b>
 +
There is now an interace to update the database through the web. I won't be making this information public for obvious reasons (even though the page is password protected!), so if you need access to it, email Ryan @ rbziel@jlab.org and we can work something out. Currently, this interface is limited to updating the RunQuality and ExpertComment flags for runs on both HRS.
  
==== RunInfo Tables ====
+
== C++/Root (and now Python) Mysql Library ==
  
Inside the g2p database are the following tables:
+
There is a C++/root library for the g2p mysql database. The library interfaces root with the mysql database, and by including the library/header file in root scripts the user gains the ability to access run information. This will be particularly useful for normalization variables (e.g. deadtime, prescale, etc.) in cross-section analysis. These variables only need be calculated once for each run because once they're in the database they don't need to be calculated again - only called. A description of the library function calls can be found [https://hallaweb.jlab.org/wiki/index.php/G2p_mysql_lib here].
 +
 
 +
As of 5/27/14 there is also a python library. Located at /w/halla-sfs62/g2p/ryan/mysql_root/Python/g2p_mysql_lib.py. The function calls are the same as the C++ library.
 +
 
 +
== Useful Files & Notes==
 +
 
 +
g2p mysql [https://userweb.jlab.org/~rbziel/mysql_BKUP/ DB backups]
 +
*Backup_List gives some information on the backups
 +
 
 +
Script used to initially [https://userweb.jlab.org/~rbziel/mysql_files/epics_db_example.pl fill] AnaInfo table from this [https://userweb.jlab.org/~rbziel/mysql_files/epics_csv.csv csv] file.
 +
*Thanks to Chao for providing the EPICS information
 +
 
 +
Run start and stop times can be found  [https://userweb.jlab.org/~rbziel/mysql_files/time.dat here] and the perl script used to edit the mysql db is [https://userweb.jlab.org/~rbziel/mysql_files/epics_time.pl this]
 +
*Thanks to Chao for providing these times
 +
*The times are in UNIX and I can't off the top of my head remember what the different columns are.
 +
 
 +
Trigger Efficiency and Deadtime calculations were made using the following scripts: On ifarm 'w/halla-sfs62/g2p/ryan/TEff/' has all the relevant files
 +
 
 +
Epics variables and descriptions can be found here https://hallaweb.jlab.org/wiki/index.php/G2p_epics
 +
 
 +
Target Variable Epics reporting: Going through the HALOG I don't see Target Encoder Variables accurately reporting until Runs 3220/22305 on 3/16/12. See http://hallaweb.jlab.org/halog/log/html/1203_archive/120316153201.html
 +
 
 +
== Connecting to the Database==
 +
 
 +
The database is hosted on the Jlab mysql server, jmysql, which is accessible from ifarm. Below I'll describe how to connect to the database and give a brief how-to on how to navigate the database. I recommend using google or one of the above mysql tutorials to learn how to do things that I haven't discussed below. For now I'm only giving access to the read-only account. This could change in the future if I can limit what fields the read/write account can edit.
 +
 
 +
<b> Connecting to the DB </b>
 +
Type the following command to connect from ifarm. You can either type the password immediately after "-p" with no space or leave it blank and then it will prompt you to enter the password.
 +
ifarm1102> mysql -h jmysql -u g2pro -p[password]
 +
 
 +
After successfully connecting you will be greeted with a mysql prompt. From here you can show and select the available databases. We are using the g2p database.
 +
mysql> show Databases;
 +
+--------------------+
 +
| Database          |
 +
+--------------------+
 +
| information_schema |
 +
| g2p                |
 +
| test              |
 +
+--------------------+
 +
3 rows in set (0.00 sec)
 +
 
 +
mysql> use g2p;
 +
 
 +
<b> Navigating the DB </b>
 +
Currently there are 5 tables in the database. The tables are described in another section, below. Also, you can see the contents of each table using the describe command.
 
  mysql> show Tables;
 
  mysql> show Tables;
 
  +---------------+
 
  +---------------+
 
  | Tables_in_g2p |
 
  | Tables_in_g2p |
 
  +---------------+
 
  +---------------+
 +
| AnaInfoL      |
 +
| AnaInfoR      |
 
  | RunInfoL      |  
 
  | RunInfoL      |  
 
  | RunInfoR      |  
 
  | RunInfoR      |  
 
  | RunInfoT      |  
 
  | RunInfoT      |  
 
  +---------------+
 
  +---------------+
  3 rows in set (0.00 sec)
+
  5 rows in set (0.00 sec)
  
Table Descriptions:
+
To sort and select data from the tables use the select command, which has the following syntax:
 +
mysql> select Field,Field,Field...etc from Table where Field >/</= value OR/AND Field >/</= value ...etc;
  
  mysql> describe RunInfoL;
+
For example to display SeptaStatus, Q1p, RunStartTime and RunStopTime information from the AnaInfoL table for run 3400 type the following:
  +--------------------+------------+------+-----+-------------------+-------+
+
  mysql> select SeptaStatus,Q1p,RunStartTime,RunStopTime from AnaInfoL where RunNumber = 3400;
  | Field              | Type      | Null | Key | Default          | Extra |
+
  +-------------+---------+---------------------+---------------------+
  +--------------------+------------+------+-----+-------------------+-------+
+
  | SeptaStatus | Q1p    | RunStartTime        | RunStopTime        |
  | RunNumber          | int(11)    | NO  | PRI | 0                |      | Start of Run
+
  +-------------+---------+---------------------+---------------------+
| RunStartTime      | datetime  | YES  |    | NULL              |      | Start of Run
+
  |          1 | 2.25094 | 2012-03-28 15:05:49 | 2012-03-28 15:16:49 |  
| EntryTime          | timestamp  | NO  |    | CURRENT_TIMESTAMP |      |
+
  +-------------+---------+---------------------+---------------------+
| RunTime            | float      | YES  |    | NULL              |      | End of Run
+
  1 row in set (0.00 sec)
| TargetPosition    | float      | YES  |    | NULL              |      | Start of Run
+
| TargetPolarization | float      | YES  |    | NULL              |      | Start of Run
+
| TargetField        | float      | YES  |    | NULL              |      | Start of Run
+
| LeftMomentum      | float      | YES  |    | NULL              |      | Start of Run
+
| LeftAngle          | float      | YES  |    | NULL              |      | Start of Run
+
| LeftSeptum        | float      | YES  |    | NULL              |      | Start of Run
+
| Energy            | float      | YES  |    | NULL              |      | Start of Run
+
| Current            | float      | YES  |    | NULL              |      | Start of Run
+
| Events            | int(11)    | YES  |    | NULL              |      | End of Run
+
| Deadtime           | float      | YES  |    | NULL              |      | End of Run
+
| BCM_Current        | float      | YES  |    | NULL              |      | End of Run
+
| u1_Charge          | float      | YES  |    | NULL              |      | End of Run
+
| d1_Charge          | float      | YES  |    | NULL              |      | End of Run
+
| HalfWavePlate      | longtext  | YES  |    | NULL              |      | Start of Run
+
| RunType            | longtext  | YES  |    | NULL              |      | End of Run (shift worker controlled!)
+
| TargetType        | longtext  | YES  |    | NULL              |      | End of Run (shift worker controlled!)
+
| sw_comment        | longtext  | YES  |    | NULL              |      | End of Run (shift worker controlled!)
+
| GoodRun            | tinyint(1) | YES  |     | NULL              |      |
+
| T3prescaled        | int(11)    | YES  |    | NULL              |      | End of Run
+
| T3real            | int(11)    | YES  |    | NULL              |      | End of Run
+
| T4prescaled        | int(11)    | YES  |    | NULL              |      | End of Run
+
| T4real            | int(11)    | YES  |    | NULL              |      | End of Run
+
| T7prescaled        | int(11)    | YES  |    | NULL              |      | End of Run
+
| T7real            | int(11)    | YES  |    | NULL              |      | End of Run
+
| T8prescaled        | int(11)    | YES  |    | NULL              |      | End of Run
+
| T8real            | int(11)    | YES  |    | NULL              |      | End of Run
+
| NMRArea            | float      | YES  |    | NULL              |      | Start of Run
+
| muFreq            | float      | YES  |    | NULL              |      | Start of Run
+
| T3realRate        | float      | YES  |    | NULL              |      | End of Run
+
| T4realRate        | float      | YES  |    | NULL              |      | End of Run
+
| T3preRate          | float      | YES  |    | NULL              |      | End of Run
+
| T4preRate          | float      | YES  |    | NULL              |      | End of Run
+
| ps3                | float      | YES  |    | NULL              |      | End of Run
+
| ps4                | float      | YES  |    | NULL              |      | End of Run
+
| ps7                | float      | YES  |    | NULL              |      | End of Run
+
| ps8                | float      | YES  |    | NULL              |      | End of Run
+
| FastRasterIx      | float      | YES  |    | NULL              |      | Start of Run
+
| FastRasterIy      | float      | YES  |    | NULL              |      | Start of Run
+
| SlowRasterIy      | float      | YES  |    | NULL              |      | Start of Run
+
| SlowRasterIx      | float      | YES  |    | NULL              |      | Start of Run
+
| TargetEncoder      | float      | YES  |    | NULL              |      | Start of Run
+
| SeptaStatus        | int(11)    | YES  |    | NULL              |      |
+
| RunStatus          | int(11)    | YES  |    | NULL              |      |  
+
  +--------------------+------------+------+-----+-------------------+-------+
+
  47 rows in set (0.01 sec)
+
  
 +
<b> Exiting the database </b>
 +
Exiting the database is easy! Just type exit when you're done.
  
mysql> describe RunInfoR;
+
== g2p mysql Table Descriptions ==
+--------------------+------------+------+-----+-------------------+-------+
+
| Field              | Type      | Null | Key | Default          | Extra |
+
+--------------------+------------+------+-----+-------------------+-------+
+
| RunNumber          | int(11)    | NO  | PRI | 0                |      |
+
| RunStartTime      | datetime  | YES  |    | NULL              |      |
+
| EntryTime          | timestamp  | NO  |    | CURRENT_TIMESTAMP |      |
+
| RunTime            | float      | YES  |    | NULL              |      |
+
| TargetPosition    | float      | YES  |    | NULL              |      |
+
| TargetPolarization | float      | YES  |    | NULL              |      |
+
| TargetField        | float      | YES  |    | NULL              |      |
+
| RightMomentum      | float      | YES  |    | NULL              |      |
+
| RightAngle        | float      | YES  |    | NULL              |      |
+
| RightSeptum        | float      | YES  |    | NULL              |      |
+
| Energy            | float      | YES  |    | NULL              |      |
+
| Current            | float      | YES  |    | NULL              |      |
+
| Events            | int(11)    | YES  |    | NULL              |      |
+
| Deadtime          | float      | YES  |    | NULL              |      |
+
| BCM_Current        | float      | YES  |    | NULL              |      |
+
| u1_Charge          | float      | YES  |    | NULL              |      |
+
| d1_Charge          | float      | YES  |    | NULL              |      |
+
| HalfWavePlate      | longtext  | YES  |    | NULL              |      |
+
| RunType            | longtext  | YES  |    | NULL              |      |
+
| TargetType        | longtext  | YES  |    | NULL              |      |
+
| sw_comment        | longtext  | YES  |    | NULL              |      |
+
| GoodRun            | tinyint(1) | YES  |    | NULL              |      |
+
| T1prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T1real            | int(11)    | YES  |    | NULL              |      |
+
| T2prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T2real            | int(11)    | YES  |    | NULL              |      |
+
| T7prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T7real            | int(11)    | YES  |    | NULL              |      |
+
| T8prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T8real            | int(11)    | YES  |    | NULL              |      |
+
| NMRArea            | float      | YES  |    | NULL              |      |
+
| muFreq            | float      | YES  |    | NULL              |      |
+
| T1realRate        | float      | YES  |    | NULL              |      |
+
| T2realRate        | float      | YES  |    | NULL              |      |
+
| T1preRate          | float      | YES  |    | NULL              |      |
+
| T2preRate          | float      | YES  |    | NULL              |      |
+
| ps1                | float      | YES  |    | NULL              |      |
+
| ps2                | float      | YES  |    | NULL              |      |
+
| ps7                | float      | YES  |    | NULL              |      |
+
| ps8                | float      | YES  |    | NULL              |      |
+
| SlowRasterIx      | float      | YES  |    | NULL              |      |
+
| SlowRasterIy      | float      | YES  |    | NULL              |      |
+
| FastRasterIy      | float      | YES  |    | NULL              |      |
+
| FastRasterIx      | float      | YES  |    | NULL              |      |
+
| TargetEncoder      | float      | YES  |    | NULL              |      |
+
| SeptaStatus        | int(11)    | YES  |    | NULL              |      |
+
| RunStatus          | int(11)    | YES  |    | NULL              |      |
+
+--------------------+------------+------+-----+-------------------+-------+
+
47 rows in set (0.00 sec)
+
  
mysql> describe RunInfoT;
+
There are two main categories of tables in the g2p mysql database. The first category includes tables that were filled with data online. The fields were filled either at the start or end of run with a snapshot of the EPICS information associated with the table variable or with summary information from the end of run script. Some of this information was provided by the shift worker so one should be careful with these tables. These tables are the RunInfo Tables and there is one for each DAQ arm (Left, Right, Third). As of 8/13/2012 these tables will no longer be updated!
+--------------------+------------+------+-----+-------------------+-------+
+
| Field              | Type      | Null | Key | Default          | Extra |
+
+--------------------+------------+------+-----+-------------------+-------+
+
| RunNumber          | int(11)   | NO  | PRI | 0                |      |
+
| RunStartTime      | datetime  | YES  |    | NULL              |      |
+
| EntryTime          | timestamp  | NO  |    | CURRENT_TIMESTAMP |      |
+
| RunTime            | float      | YES  |    | NULL              |      |
+
| LeftMomentum      | float      | YES  |    | NULL              |      |
+
| RightMomentum      | float      | YES  |    | NULL              |      |
+
| Energy            | float      | YES  |    | NULL              |      |
+
| Current            | float      | YES  |    | NULL              |      |
+
| Events            | int(11)    | YES  |    | NULL              |      |
+
| Deadtime          | float      | YES  |    | NULL              |      |
+
| BCM_Current        | float      | YES  |    | NULL              |      |
+
| u1_Charge          | float      | YES  |    | NULL              |      |
+
| d1_Charge          | float      | YES  |    | NULL              |      |
+
| HalfWavePlate      | longtext  | YES  |    | NULL              |      |
+
| RunType            | longtext  | YES  |    | NULL              |      |
+
| TargetType        | longtext  | YES  |    | NULL              |      |
+
| sw_comment        | longtext  | YES  |    | NULL              |      |
+
| GoodRun            | tinyint(1) | YES  |    | NULL              |      |
+
| T1prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T1real            | int(11)    | YES  |    | NULL              |      |
+
| T8prescaled        | int(11)    | YES  |    | NULL              |      |
+
| T8real            | int(11)    | YES  |    | NULL              |      |
+
| T1realRate        | float      | YES  |    | NULL              |      |
+
| T1preRate          | float      | YES  |    | NULL              |      |
+
| ps1                | int(11)    | YES  |    | NULL              |      |
+
| TargetPolarization | float      | YES  |    | NULL              |      |
+
| TargetPosition    | float      | YES  |    | NULL              |      |
+
| TargetField        | float      | YES  |    | NULL              |      |
+
| NMRArea            | float      | YES  |    | NULL              |      |
+
| muFreq            | float      | YES  |    | NULL              |      |
+
| TargetEncoder      | float      | YES  |    | NULL              |      |
+
+--------------------+------------+------+-----+-------------------+-------+
+
31 rows in set (0.00 sec)
+
  
===== Modifications made to RunInfo Tables after Run Period =====
+
The second category of tables are AnaInfo, analysis tables. The data in these tables is either filled from the EPICS information from the accumulated data files or via a student "expert". In this regard, these tables should be used be used for the analysis. They will be continually updated with more data fields as needed in the analysis process and errors will be corrected as they are discovered.
  
After the run period, a few minor issues were corrected with the RunInfo tables. The changes are listed below. It's listed as a snapshot of what I was working on during the period right after the end of the experiment, so it might not read very well. My apologies.
+
The AnaInfo were created from the RunInfo tables. This means that all the runs that exist in RunInfo exist in AnaInfo.
  
#Backed up DB - 6/4/12
+
====RunInfo Tables====
##/adaqfs/home/adaq/g2p/g2pbackup.sql - This is a backup of the original DB prior to any modifications
+
## I also have a copy of this file on my own computer
+
#Updated Target Encoder Position for both L/R HRS - 6/4/12
+
## /adaqfs/home/a-onl/scripts/mysql/FixTargetPosition_g2p(R).pl accesses end of run files and updates the DB
+
## /adaqfs/home/a-onl/scripts/mysql/Target.sh loops through however many runs you want to using FixTargetPosition_g2p(R).pl
+
# Updated Target Number for both L/R HRS - 6/7/12
+
## Updated FixTargetPosition_g2p.pl to do this
+
## Fixed a bug so perl script now correctly finds negative encoder values
+
# Renamed Target.sh to mysql_g2p.sh 6/12/12
+
# Updated HWP Status using FixHWP_g2p(R).pl 6/12/12
+
# Updated PS Status using FixPS_g2p(R).pl 6/12/12
+
# Create a script to parse EPICS files from run period epics.pl 6/13/12
+
## Located on ifarm /w/halla-1/g2p/ryan/mysql
+
## EPICS files located at w/halla-1/g2p/epics
+
## Currently set up to loop through all the lines of EPICS file and compute the average of an EPICS variable between a start and stop time. This will eventually be tied to run times!
+
# Epics variables and descriptions can be found here https://hallaweb.jlab.org/wiki/index.php/G2p_epics
+
  
Things to check for/To Do List:
+
[https://hallaweb.jlab.org/wiki/index.php/G2p_RunInfo RunInfo Tables]
# <strike>HWP Status. Because the entry is filled at the start of run, what to make sure that it updated before a new run was started. </strike>
+
# <strike>Target Encoder Position. Again the entry is filled from the start of run so you want to check with the end of run and make sure this updated correctly. Most problems occur around dilution runs. </strike>
+
# <strike>Prescale factor. Up until a certain point there was a bug in the code so that the DB scripts only recorded the first digit of the prescale factor. So a PS of 10 would only record as a PS of 1. This was eventually fixed but the runs need to be checked. </strike>
+
# Based off of Encoder position should be able to correct Target Type and Target Number in beam. Encoder positions are in ().
+
## Decided to only update the Target Number because this was determined via EPICS so it is definitely not right. The Target Type could be useful because it was shift worker controlled, so if the Target Encoder was not reporting to EPICS correctly the Target Type may be correct. I stress 'may' because you have to trust the shift worker.
+
##Carbon - (10,000 , 15,000) 6 (at some point Carbon target became thicker but not sure when this should be checked)
+
##Carbon Hole - (41,000 ,  45,000) 2
+
## CH2 - ( 37,000 , 41,000 ) 3
+
## NH3 (Top/Bottom determined by Target Number) - ( 28,000 , 35,000)  4 (45,000 , 51,000) 1
+
## Dummy - (20,000 , 25,000) 5
+
## Home - < 1000 7
+
## If 999 or 0 Target Encoder is not reporting to EPICS - Record Target Number as 0
+
## Important Notes on Target Variable Epics reporting: Going through the HALOG I don't see Target Encoder Variables accurately reporting until Runs 3220/22305 on 3/16/12. See http://hallaweb.jlab.org/halog/log/html/1203_archive/120316153201.html
+
# For analysis table, create column for Target Material Type and get info from here https://hallaweb.jlab.org/wiki/index.php/Target_Material_Summary
+
# <strike>List of EPICS variables and what they actually correspond to </strike>
+
# Should base my mysql stuff off of this: https://userweb.jlab.org/~singhj/runsummary/
+
  
 +
====AnaInfo Tables====
  
 +
[https://hallaweb.jlab.org/wiki/index.php/G2p_AnaInfo AnaInfo Tables]
  
== Misc. MYSQL Commands and Hints ==
+
== Feature Implementation==
  
====Installing a MYSQL Server on your own machine====
+
Because this a wiki, everyone should be able to edit it. In that regard, if there are features you would like to see implemented in the DB please list them below. This also includes additional tables or additional fields in existing tables. Thanks!
http://dev.mysql.com/doc/refman/5.0/en/macosx-installation.html
+
 
http://dev.mysql.com/doc/refman/5.0/en/windows-installation.html
+
* [https://hallaweb.jlab.org/wiki/index.php/G2p_AnaInfo#Additions_to_the_AnaInfo_Tables AnaInfo Table Additions]
http://dev.mysql.com/doc/refman/5.0/en/linux-installation-rpm.html
+
* C++ library/analysis code interface
Note: Default ROOT password for mysql user is blank
+
** Basic code exists now. It will be updated as needed
 +
* ?
 +
 
 +
== Misc. MYSQL Commands and Hints ==
  
 +
Below are some specific MYSQL commands so I don't have to look them up every time I want to use them.
  
 
====Checking Database size====
 
====Checking Database size====

Latest revision as of 14:15, 27 May 2014

Below is a description of the g2p mysql database. It will be continuously updated with new features as they're requested and as I think of them. So if you think of something you would like the database to do, just let me know.

-Ryan

List of good mysql tutorial websites.

http://www.tutorialspoint.com/mysql/index.htm
http://www.tizag.com/mysqlTutorial/
http://www.dreamincode.net/forums/topic/42301-beginners-guide-to-creating-simple-mysql-tables/

Installing a MYSQL Server on your own machine

http://dev.mysql.com/doc/refman/5.0/en/macosx-installation.html
http://dev.mysql.com/doc/refman/5.0/en/windows-installation.html
http://dev.mysql.com/doc/refman/5.0/en/linux-installation-rpm.html
Note: Default ROOT password for mysql user is blank

Web Interface

The g2p database can be accessed through the web at the following link.

The web interface allows you to search the g2p mysql database through your web browser and also output your search results to a CSV file. The search form parses the AnaInfo tables and displays selected fields to the browser. The download CSV file contains ALL the fields. Also selecting an individual run from the search results will display information on all the fields of that run in a new tab/window from both the AnaInfo and RunInfo tables.

1/30/13 There is now an interace to update the database through the web. I won't be making this information public for obvious reasons (even though the page is password protected!), so if you need access to it, email Ryan @ rbziel@jlab.org and we can work something out. Currently, this interface is limited to updating the RunQuality and ExpertComment flags for runs on both HRS.

C++/Root (and now Python) Mysql Library

There is a C++/root library for the g2p mysql database. The library interfaces root with the mysql database, and by including the library/header file in root scripts the user gains the ability to access run information. This will be particularly useful for normalization variables (e.g. deadtime, prescale, etc.) in cross-section analysis. These variables only need be calculated once for each run because once they're in the database they don't need to be calculated again - only called. A description of the library function calls can be found here.

As of 5/27/14 there is also a python library. Located at /w/halla-sfs62/g2p/ryan/mysql_root/Python/g2p_mysql_lib.py. The function calls are the same as the C++ library.

Useful Files & Notes

g2p mysql DB backups

  • Backup_List gives some information on the backups

Script used to initially fill AnaInfo table from this csv file.

  • Thanks to Chao for providing the EPICS information

Run start and stop times can be found here and the perl script used to edit the mysql db is this

  • Thanks to Chao for providing these times
  • The times are in UNIX and I can't off the top of my head remember what the different columns are.

Trigger Efficiency and Deadtime calculations were made using the following scripts: On ifarm 'w/halla-sfs62/g2p/ryan/TEff/' has all the relevant files

Epics variables and descriptions can be found here https://hallaweb.jlab.org/wiki/index.php/G2p_epics

Target Variable Epics reporting: Going through the HALOG I don't see Target Encoder Variables accurately reporting until Runs 3220/22305 on 3/16/12. See http://hallaweb.jlab.org/halog/log/html/1203_archive/120316153201.html

Connecting to the Database

The database is hosted on the Jlab mysql server, jmysql, which is accessible from ifarm. Below I'll describe how to connect to the database and give a brief how-to on how to navigate the database. I recommend using google or one of the above mysql tutorials to learn how to do things that I haven't discussed below. For now I'm only giving access to the read-only account. This could change in the future if I can limit what fields the read/write account can edit.

Connecting to the DB Type the following command to connect from ifarm. You can either type the password immediately after "-p" with no space or leave it blank and then it will prompt you to enter the password.

ifarm1102> mysql -h jmysql -u g2pro -p[password]

After successfully connecting you will be greeted with a mysql prompt. From here you can show and select the available databases. We are using the g2p database.

mysql> show Databases;
+--------------------+
| Database           |
+--------------------+
| information_schema | 
| g2p                | 
| test               | 
+--------------------+
3 rows in set (0.00 sec)
mysql> use g2p;

Navigating the DB Currently there are 5 tables in the database. The tables are described in another section, below. Also, you can see the contents of each table using the describe command.

mysql> show Tables;
+---------------+
| Tables_in_g2p |
+---------------+
| AnaInfoL      | 
| AnaInfoR      | 
| RunInfoL      | 
| RunInfoR      | 
| RunInfoT      | 
+---------------+
5 rows in set (0.00 sec)

To sort and select data from the tables use the select command, which has the following syntax:

mysql> select Field,Field,Field...etc from Table where Field >/</= value OR/AND Field >/</= value ...etc;

For example to display SeptaStatus, Q1p, RunStartTime and RunStopTime information from the AnaInfoL table for run 3400 type the following:

mysql> select SeptaStatus,Q1p,RunStartTime,RunStopTime from AnaInfoL where RunNumber = 3400;
+-------------+---------+---------------------+---------------------+
| SeptaStatus | Q1p     | RunStartTime        | RunStopTime         |
+-------------+---------+---------------------+---------------------+
|           1 | 2.25094 | 2012-03-28 15:05:49 | 2012-03-28 15:16:49 | 
+-------------+---------+---------------------+---------------------+
1 row in set (0.00 sec)

Exiting the database Exiting the database is easy! Just type exit when you're done.

g2p mysql Table Descriptions

There are two main categories of tables in the g2p mysql database. The first category includes tables that were filled with data online. The fields were filled either at the start or end of run with a snapshot of the EPICS information associated with the table variable or with summary information from the end of run script. Some of this information was provided by the shift worker so one should be careful with these tables. These tables are the RunInfo Tables and there is one for each DAQ arm (Left, Right, Third). As of 8/13/2012 these tables will no longer be updated!

The second category of tables are AnaInfo, analysis tables. The data in these tables is either filled from the EPICS information from the accumulated data files or via a student "expert". In this regard, these tables should be used be used for the analysis. They will be continually updated with more data fields as needed in the analysis process and errors will be corrected as they are discovered.

The AnaInfo were created from the RunInfo tables. This means that all the runs that exist in RunInfo exist in AnaInfo.

RunInfo Tables

RunInfo Tables

AnaInfo Tables

AnaInfo Tables

Feature Implementation

Because this a wiki, everyone should be able to edit it. In that regard, if there are features you would like to see implemented in the DB please list them below. This also includes additional tables or additional fields in existing tables. Thanks!

  • AnaInfo Table Additions
  • C++ library/analysis code interface
    • Basic code exists now. It will be updated as needed
  •  ?

Misc. MYSQL Commands and Hints

Below are some specific MYSQL commands so I don't have to look them up every time I want to use them.

Checking Database size

   SELECT SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024),2)) "Size in MB" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "g2p";
  +------------+
    | Size in MB |
  +------------+
    |       3.34 | 
  +------------+
  1 row in set (0.11 sec)

Dumping and Restoring the DB

backup: # mysqldump -h adaql10 -u g2p -p[password] [database_name] > dumpfilename.sql
restore:# mysql -h adaq10 -u g2p -p[password] [database_name] < dumpfilename.sql