Project

General

Profile

Pushing GR database to SAM

Accessing the SAM database

Only a few people are able to push tables to the database. Go to Service Now, click "request something," and ask for nova_sam_gr permissions for the sam_nova_prd and samtest databases.

Easy way to test your access is, in python, interactively:

import psycopg2, psycopg2.extras
psycopg2.connect("dbname=samtest host=cspgsdev.fnal.gov port=5432")
psycopg2.connect("dbname=sam_nova_prd host=sampgsdb01.fnal.gov port=5433")

As of 11/7/2019 the host and ports above are the correct ones for accessing each database.

If your connect commands are successful, you'll get output like:

>>> psycopg2.connect("dbname=sam_nova_prd host=sampgsdb01.fnal.gov port=5433")
<connection object at 0x7fec9b3a8e88; dsn: 'dbname=sam_nova_prd host=sampgsdb01.fnal.gov port=5433', closed: 0>

If they are unsuccessful, you'll get output like:

psycopg2.OperationalError: could not connect to server: Connection refused
    Is the server running on host "cspgsprd1.fnal.gov" (131.225.107.59) and accepting
    TCP/IP connections on port 5432?

If the connection is failing, you will need to ask the database admins (via a ticket) if the database has been moved to a new host etc. If this is the case you will also need to update the script, linked below.

Using the script

You run the script like:

python getGoodRuns4SAM.py -D fardet -T v6.1

where -D is either fardet or neardet, and -T is the tag of the Good Runs database that you want to push. The most recent tags should be here: List of Validated FD subruns

The script will write out a csv ("goodRuns4SAM.csv") and will also push the information in that csv to the database. (Hint: To check the csv that is pushed to the database for potential errors before pushing to the database, comment out the lines in the script with "curr" and "con" so that you don't connect to the SAM database at all, and just print out the csv.)

Making the definitions

samweb create-definition isgood_nd_prod5 "novagr_good true with novagr_tag v3.0" 
samweb create-definition isgood_fd_prod5 "novagr_good true and novagr_ngood_cont_diblock > 3 with novagr_tag v6.1" 
samweb create-definition isgood_prod5 "defname:isgood_nd_prod5 or defname:isgood_fd_prod5" 

Replace with the current production campaign number and ND and FD GR database tags as needed.

Resources

Tech note
Script to push to SAM DB