Exemplo n.º 1
0
def downloadDQLL(firstRun, lastRun):
    db = ratdb.RATDBConnector(
        server="postgres://[email protected]:5400/ratdb")

    tables = []
    for i in range(firstRun, lastRun + 1):
        table = db.fetch(obj_type="DQLL", run=i)
        if table:  #check the downloaded table is not empty
            print "Fetching DQLL table for run ", i, "\n"
            tables.append(table)
        else:
            print "DQLL Table for run ", i, " NOT found\n"

    return tables
Exemplo n.º 2
0
def is_table_in_ratdb(run_number, logfile, table_name):
    '''
    Check whether a table exists in ratdb.
    '''
    try:
        ratdbLink = ratdb.RATDBConnector('postgres://' +
                                         settings.RATDBWRITE_AUTH + '@' +
                                         settings.RATDB_SERVER + '/ratdb')
        table = ratdbLink.fetch(obj_type=table_name, run=run_number)
        return len(table)
    except:
        write_to_log(
            logfile, " Error: Request table: %s not in ratdb for run %i" %
            (table_name, run_number))
        return False
Exemplo n.º 3
0
def get_table(runnumber, tablename, db_address, db_host, db_username,
              db_password, db_name, db_port):
    """Function to retrieve a table from the postgresql ratdb database. 
    :param: The run number (string)
    :param: The table name (e.g. RUN, DQLL)
    :param: The address of the postgresql database (string)
    :param: The hostname for the postgresql database (string).
    :param: The read-mode username for the postgresql database (string).
    :param: The read-mode password for the postgresql database (string).
    :returns: True and the table for the specified run number if it exists
    """

    db_connector_address = db_address + "://" + db_username + ":" + db_password + "@" + db_host + ":" + str(
        db_port) + "/" + db_name

    try:
        db = ratdb.RATDBConnector(db_connector_address)

        result = db.fetch(obj_type=tablename, run=runnumber)

        if not len(result):

            table = "none"

            sys.stderr.write(
                "%s - get_table():ERROR:cannot find %s.ratb table\n" %
                (datetime.datetime.now().replace(microsecond=0), tablename))

        else:

            table = result[0]['data']

        return len(result) > 0, table

    except Exception as e:

        sys.stderr.write("%s - get_table():ERROR: %s\n" %
                         (datetime.datetime.now().replace(microsecond=0), e))
        sys.exit(1)
Exemplo n.º 4
0
def write_to_ratdb(filename, logfile):
    '''
    Pushes file to RATDB with the ratdb tool and 
    return whether it was successful
    '''
    attempt = 0
    ratdbLink = None
    in_ratdb = False
    while not in_ratdb and attempt < 5:
        try:
            ratdbLink = ratdb.RATDBConnector('postgres://' +
                                             settings.RATDBWRITE_AUTH + '@' +
                                             settings.RATDB_SERVER + '/ratdb')
            in_ratdb = len(ratdbLink.upload([filename]))
        except Exception, error:
            print("ratdb error %s \n" % str(error))
            write_to_log(
                logfile,
                'Could NOT upload to RATDB due to the error: %s. \n' % error)
            write_to_log(logfile, 'Will retry in 10s... .\n')
            attempt += 1
            if ratdbLink is not None:
                ratdbLink.close_ratdb_connection()
            time.sleep(10.)
import ROOT
from rat import ratdb
db = ratdb.RATDBConnector('postgres://[email protected]:5400/ratdb')
result = db.fetch(obj_type="TELLIE_RUN", run=102315)
trigger_delay = result[0]['data']['sub_run_info'][0]['trigger_delay']
fibre_delay = result[0]['data']['sub_run_info'][0]['fibre_delay']
print "Fibre delay %.1fns, trigger delay %dns" % (fibre_delay, trigger_delay)

ROOT.RAT.DB.Get().LoadDefaults()
fibre = "FT019A"
entry = ROOT.RAT.DB.Get().GetLink("FIBRE", fibre)
vector = ROOT.TVector3(entry.GetD("x"), entry.GetD("y"), entry.GetD("z"))
print "Position is ( %.1f | %.1f | %.1f )mm" % (vector.X(), vector.Y(),
                                                vector.Z())