-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertRun.py
50 lines (42 loc) · 1.35 KB
/
insertRun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from pprint import pprint
from airtable import Airtable
import pandas as pd
base_key = 'appQ2YoOIQFBKKIpG'
tables = ['RUNS','Crystals']
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--id',dest='runid')
parser.add_argument('--type',dest='runtype')
parser.add_argument('--xtal',dest='xtal')
parser.add_argument('--tag',dest='runtag')
args = parser.parse_args()
runID=args.runid
runType=args.runtype
runXtal=args.xtal
runTag=args.runtag
runTypes = ['SOURCE','PED','LED']
runTypeOK=False
for t in runTypes:
if t==runType:
runTypeOK=True
break
if not runTypeOK:
print('Unknown RunType %s'%runType)
exit(-1)
airtables={}
for t in tables:
airtables[t] = Airtable(base_key, t, api_key=os.environ['AIRTABLE_KEY'])
#print(airtable)
records=airtables['RUNS'].search('RunID',runID)
if (len(records)>0):
print('Error: RUN already inserted')
exit(-1)
if (runType=='SOURCE'):
records = airtables['Crystals'].search('ID', runXtal)
if (len(records)!=1):
print('Error in querying associated crystal')
exit(-1)
airtables['RUNS'].insert({'RunID': runID, 'Type':runType, 'Crystal':[records[0]['id']],'Processing status':'DAQ STARTED','TAG':runTag,'SetupID':1})
else:
airtables['RUNS'].insert({'RunID': runID, 'Type':runType,'Processing status':'DAQ STARTED','TAG':runTag,'SetupID':1})