Skip to content

Commit

Permalink
IMPORTANT: (hardcoded) change in get_mongo_collection function (#107)
Browse files Browse the repository at this point in the history
* IMPORTANT: (hardcoded) change in get_mongo_collection function and implementation everywhere

* Forgot one file, changed it now

* I think we need this to make to make it pass the tests

* Update rundb.py

Co-authored-by: Serena Di Pede <[email protected]>
  • Loading branch information
mflierm and dipedeserena authored Jan 20, 2022
1 parent c9bb341 commit 4181b7e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion amstrax/auto_processing/amstraxer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def main(args):
testing_rd['start'] = datetime.datetime.now()
st = amstrax.contexts.context_for_daq_reader(st,
args.run_id,
run_doc=testing_rd)
run_doc=testing_rd,
detector=args.detector)

if args.from_scratch:
for q in st.storage:
Expand Down
2 changes: 1 addition & 1 deletion amstrax/auto_processing/auto_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_args():
context = args.context
detector = args.detector
target = args.target
runs_col = amstrax.get_mongo_collection()
runs_col = amstrax.get_mongo_collection(detector)

while 1:
# Update task list
Expand Down
2 changes: 1 addition & 1 deletion amstrax/auto_processing/copy_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def main(args):
# Initialize runsdatabase collection
runs_database = config['RunsDatabaseName']
runs_collection = config['RunsDatabaseCollection']
runsdb = amstrax.get_mongo_collection(
runsdb = amstrax.get_mongo_collection(detector,
database_name=runs_database,
database_col=runs_collection
)
Expand Down
3 changes: 2 additions & 1 deletion amstrax/auto_processing/process_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
# Do import later to get fast --help
import amstrax

run_collection = amstrax.get_mongo_collection()
detector = args.detector
run_collection = amstrax.get_mongo_collection(detector)
run_name = args.run_id
target = args.target
print(f'Start processing {run_name}: {target}')
Expand Down
5 changes: 3 additions & 2 deletions amstrax/contexts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
def xams(*args, **kwargs):
if '_detector' in kwargs:
raise ValueError('Don\'t specifify _detector!')
mongo_kwargs = dict(mongo_collname='runs_gas',
mongo_kwargs = dict(mongo_collname='runs_gas', #IF YOU CHANGE THIS, ALSO CHANGE IN GET_MONGO_COLLECTION (RUNSDB.PY)!
runid_field='number',
mongo_dbname='run',
)
Expand Down Expand Up @@ -175,6 +175,7 @@ def amstrax_run10_analysis(output_folder='./strax_data'):

def context_for_daq_reader(st: strax.Context,
run_id: str,
detector: str,
runs_col_kwargs: dict = None,
run_doc: dict = None,
check_exists=True,
Expand Down Expand Up @@ -204,7 +205,7 @@ def context_for_daq_reader(st: strax.Context,
if runs_col_kwargs is None:
runs_col_kwargs = {}
if run_doc is None:
run_col = ax.get_mongo_collection(**runs_col_kwargs)
run_col = ax.get_mongo_collection(detector)
run_doc = run_col.find_one({'number': int(run_id)})
daq_config = run_doc['daq_config']
live_dir = st.config['live_data_dir']
Expand Down
20 changes: 15 additions & 5 deletions amstrax/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,24 @@ def get_mongo_client(**link_kwargs):
return pymongo.MongoClient(f'mongodb://{user}:{password}@127.0.0.1:{local_port}/admin')


# @export
# def get_mongo_collection(database_name='run',
# database_col='runs_new',
# **link_kwargs,
# ):
# """Get the runs collection"""
# return get_mongo_client(**link_kwargs)[database_name][database_col]

@export
def get_mongo_collection(database_name='run',
database_col='runs_new',
def get_mongo_collection(detector,
**link_kwargs,
):
"""Get the runs collection"""
return get_mongo_client(**link_kwargs)[database_name][database_col]

if detector == 'xams':
return get_mongo_client(**link_kwargs)['run']['runs_gas']
elif detector == 'xamsl':
return get_mongo_client(**link_kwargs)['run']['runs_new']
else:
raise NameError(f'detector {detector} is not a valid detector name.')

@export
class RunDB(strax.StorageFrontend):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def setUp(self) -> None:
st = amstrax.contexts.context_for_daq_reader(
self.st,
run_id=self.run_id,
run_doc=self.rd)
run_doc=self.rd,
detector='xams')
self.st = st

@classmethod
Expand All @@ -61,7 +62,8 @@ def test_make(self):
amstrax.contexts.context_for_daq_reader(
self.st,
run_id=self.run_id,
run_doc=self.rd)
run_doc=self.rd,
detector='xams')

def get_metadata(self):
md = amstrax_files.get_file(self.run_doc_name)
Expand Down

0 comments on commit 4181b7e

Please sign in to comment.