-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeasDB.py
More file actions
42 lines (35 loc) · 1.58 KB
/
measDB.py
File metadata and controls
42 lines (35 loc) · 1.58 KB
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
import json
import os
class MeasDB():
def __init__(self, dbFile):
self.dbFile=dbFile
print('Opening '+dbFile)
if (os.path.isfile(dbFile)):
self.db=json.load(open(dbFile))
print('Loaded MeasDB from '+dbFile)
else:
self.db=dict()
def getDB(self):
return self.db
def getXtals(self):
return sorted(self.db.keys())
def getMeas(self,xtal):
return [ '%s:%s,'%(str(r['tag']),str(r['runs'])) for r in self.db[xtal]['runs']]
def insertMeas(self,crys,prod,geo,xtalid,runs,refRuns,ledRuns,tag):
if crys in self.db.keys():
if (tag in [ r['tag'] for r in self.db[crys]['runs'] ]):
print('ERROR. Tag %s already present'%tag)
else:
self.db[crys]['runs'].append({'tag':tag,'runs':runs, 'refRuns':refRuns,'ledRuns':ledRuns})
print('Tag %s for crystal %s inserted correctly. Total runs for this xtal %d'%(tag,crys,len(self.db[crys]['runs'])))
else:
self.db[crys]={ 'type':'xtal','producer':prod,'geometry':geo,'id':xtalid,'runs':[ {'tag':tag,'runs':runs, 'refRuns':refRuns,'ledRuns':ledRuns} ] }
print('Tag %s for crystal %s inserted correctly. Total runs for this xtal %d'%(tag,crys,len(self.db[crys]['runs'])))
def save(self,fOut=''):
if (fOut!=''):
self.dbFile=fOut
if(len(self.db)==0):
return
with open(self.dbFile, 'w') as file:
file.write(json.dumps(self.db, indent=4, sort_keys=True))
print('Saved measDB into '+self.dbFile)