예제 #1
0
    def __init__(self,
                 username=None,
                 password=None,
                 mongo_url=None,
                 is_nt=True):
        """
        :param username: corrections DB username
            read the .xenon_config for the users "pymongo_user" has
            readonly permissions to the corrections DB
            the "CMT admin user" has r/w permission to corrections DB
            and read permission to runsDB
        :param password: DB password
        :param is_nt: bool if True we are looking at nT if False we are looking at 1T
        """

        mongo_kwargs = {
            'url': mongo_url,
            'user': username,
            'password': password,
            'database': 'corrections'
        }
        corrections_collection = utilix.rundb.xent_collection(**mongo_kwargs)

        # Do not delete the client!
        self.client = corrections_collection.database.client

        # Setup the interface
        self.interface = strax.CorrectionsInterface(
            self.client, database_name='corrections')

        self.is_nt = is_nt
        if self.is_nt:
            self.collection = self.client['xenonnt']['runs']
        else:
            self.collection = self.client['run']['runs_new']
예제 #2
0
def test_connect_to_db():
    """
    Test connection to db
    """
    corrections_collection = utilix.rundb.xent_collection(
        database='corrections')
    client = corrections_collection.database.client
    cmt = strax.CorrectionsInterface(client, database_name='corrections')
    df = cmt.read('global_xenonnt')
    mes = 'Return empty dataframe when reading DB. Please check'
    assert not df.empty, mes
예제 #3
0
    def __init__(self, username='******', password=None, is_nt=True):
        """
        :param username: corrections DB username
            nt_analysis user has read only permission to corrections DB
            cmt user has r/w permission to corrections DB and read permission to runsDB
        :param password: DB password
        :param is_nt: bool if True we are looking at nT if False we are looking at 1T
        """
        self.username = username
        self.is_nt = is_nt

        if password is not None:
            self.password = password
        elif self.username.endswith('analysis'):
            self.password = straxen.get_secret('rundb_password')
        else:
            raise ValueError(f'No password for {username}')

        # Get the mongo url
        runsdb_mongo_url = straxen.rundb.get_mongo_url(hostname=getfqdn())
        _, _url = runsdb_mongo_url.split('@')

        # Never use the admin authentication here.
        _url = _url.replace('/admin', '/xenonnt')

        self.interface = strax.CorrectionsInterface(
            host=f'mongodb://{_url}',
            username=self.username,
            password=self.password,
            database_name='corrections')

        # Use the same client as the CorrectionsInterface
        client = self.interface.client

        if self.is_nt:
            self.collection = client['xenonnt']['runs']
        else:
            self.collection = client['run']['runs_new']
예제 #4
0
def test_connect_to_db():
    """
    Test connection to db
    """
    if not straxen.utilix_is_configured():
        warn('Cannot do test becaus  ' 'no have access to the database.')
        return

    username = None
    password = None
    mongo_url = None
    is_nt = True
    mongo_kwargs = {
        'url': mongo_url,
        'user': username,
        'password': password,
        'database': 'corrections'
    }
    corrections_collection = utilix.rundb.xent_collection(**mongo_kwargs)
    client = corrections_collection.database.client
    cmt = strax.CorrectionsInterface(client, database_name='corrections')
    df = cmt.read('global')
    mes = 'Return empty dataframe when reading DB. Please check'
    assert not df.empty, mes
예제 #5
0
def corrections():
    dummy_client = pymongo.MongoClient()
    cmt = strax.CorrectionsInterface(client=dummy_client)
    return cmt