-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunDB.py
executable file
·80 lines (60 loc) · 2.33 KB
/
runDB.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pymongo
import os
def get_collection():
uri = 'mongodb://pax:%[email protected]:27017/run'
uri = uri % os.environ.get('MONGO_PASSWORD')
c = pymongo.MongoClient(uri,
replicaSet='runs',
readPreference='secondaryPreferred')
db = c['run']
collection = db['runs_new']
return collection
def get_did(run_id, detector='tpc'):
collection = get_collection()
if detector == 'tpc':
query = {"detector" : "tpc",
"number" : int(run_id)}
elif detector == 'muon_veto':
query = {"detector" : "muon_veto",
"name" : run_id}
cursor = collection.find(query, {"number" : True,
"name" : True,
"data" : True,
"_id" : False})
data = list(cursor)[0]['data']
did = None
for d in data:
if d['host'] == 'rucio-catalogue' and d['status'] == 'transferred':
did = d['location']
return did
def get_name(run_id, detector='tpc'):
if detector == 'muon_veto':
return run_id
else:
collection = get_collection()
cursor = collection.find({'detector' : 'tpc', 'number' : int(run_id)},
{'name' : 1})
return list(cursor)[0]['name']
def events_per_file(run_id, detector='tpc'):
collection = get_collection()
if detector == 'tpc':
query = {"detector" : "tpc", "number" : int(run_id)}
else:
query = {"detector" : "muon_veto", "name" : run_id}
ret = list(collection.find(query, {'reader' : 1}))[0]
if 'Zip' in ret['reader']['ini']['trigger_config_override']:
events_per_file = ret['reader']['ini']['trigger_config_override']['Zip']['events_per_file']
else:
events_per_file = 1000
return events_per_file
def runs_by_source(source, num_range=None):
collection = get_collection()
query = {'detector' : 'tpc',
'source.type' : source
}
if num_range:
query['$and'] = [{'number' : {'$gte' : num_range[0]}},
{'number' : {'$lte' : num_range[1]}}
]
ret = list(collection.find(query, {'number': 1}))
return [run['number'] for run in ret]