From 4181b7ef036a67cd0e55642a35f84ea34f425105 Mon Sep 17 00:00:00 2001 From: Maricke Flierman <53177596+mflierm@users.noreply.github.com> Date: Thu, 20 Jan 2022 08:54:54 +0100 Subject: [PATCH] IMPORTANT: (hardcoded) change in get_mongo_collection function (#107) * 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 <48323986+dipedeserena@users.noreply.github.com> --- amstrax/auto_processing/amstraxer.py | 3 ++- amstrax/auto_processing/auto_processing.py | 2 +- amstrax/auto_processing/copy_live.py | 2 +- amstrax/auto_processing/process_run.py | 3 ++- amstrax/contexts.py | 5 +++-- amstrax/rundb.py | 20 +++++++++++++++----- tests/test_basics.py | 6 ++++-- 7 files changed, 28 insertions(+), 13 deletions(-) diff --git a/amstrax/auto_processing/amstraxer.py b/amstrax/auto_processing/amstraxer.py index d3e77e57..097ccccf 100644 --- a/amstrax/auto_processing/amstraxer.py +++ b/amstrax/auto_processing/amstraxer.py @@ -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: diff --git a/amstrax/auto_processing/auto_processing.py b/amstrax/auto_processing/auto_processing.py index 330050d9..0488a20b 100644 --- a/amstrax/auto_processing/auto_processing.py +++ b/amstrax/auto_processing/auto_processing.py @@ -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 diff --git a/amstrax/auto_processing/copy_live.py b/amstrax/auto_processing/copy_live.py index 2a14eccd..b5ca222d 100644 --- a/amstrax/auto_processing/copy_live.py +++ b/amstrax/auto_processing/copy_live.py @@ -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 ) diff --git a/amstrax/auto_processing/process_run.py b/amstrax/auto_processing/process_run.py index 487af87a..d4e2c95d 100644 --- a/amstrax/auto_processing/process_run.py +++ b/amstrax/auto_processing/process_run.py @@ -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}') diff --git a/amstrax/contexts.py b/amstrax/contexts.py index 780b5f4c..5e6b29cc 100644 --- a/amstrax/contexts.py +++ b/amstrax/contexts.py @@ -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', ) @@ -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, @@ -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'] diff --git a/amstrax/rundb.py b/amstrax/rundb.py index 5883083b..cf7da9fb 100644 --- a/amstrax/rundb.py +++ b/amstrax/rundb.py @@ -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): diff --git a/tests/test_basics.py b/tests/test_basics.py index 91c2d370..52d51a82 100644 --- a/tests/test_basics.py +++ b/tests/test_basics.py @@ -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 @@ -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)