Ejemplo n.º 1
0
def main():

    # Parse command line
    parser = argparse.ArgumentParser(description='Manage the DAQ')
    parser.add_argument('--config',
                        type=str,
                        help='Path to your configuration file',
                        default='config.ini')
    parser.add_argument(
        '--log',
        type=str,
        help='Logging level',
        default='DEBUG',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'])
    args = parser.parse_args()
    config = configparser.ConfigParser()
    config.read(args.config)
    logger = logging.getLogger('main')
    logger.addHandler(LogHandler())
    logger.setLevel(getattr(logging, args.log))
    # Declare database object
    MongoConnector = MongoConnect(config, logger)

    # Declare a 'brain' object. This will cache info about the DAQ state in order to
    # solve the want/have decisions. The deciding functions also go here. It needs a
    # mongo connector because it has to pull options files
    DAQControl = DAQController(config, MongoConnector, logger)
    sleep_period = int(config['DEFAULT']['PollFrequency'])
    sh = SignalHandler()

    while (sh.event.is_set() == False):
        # Get most recent check-in from all connected hosts
        print('Getting update')
        if MongoConnector.GetUpdate():
            continue
        latest_status = MongoConnector.latest_status

        # Get most recent goal state from database. Users will update this from the website.
        print('Getting goal state')
        goal_state = MongoConnector.GetWantedState()
        if goal_state is None:
            continue

        # Print an update
        for detector in latest_status.keys():
            logger.debug(
                "Detector %s should be %sACTIVE and is %s" %
                (detector, '' if goal_state[detector]['active'] == 'true' else
                 'IN', latest_status[detector]['status'].name))

        # Decision time. Are we actually in our goal state? If not what should we do?
        DAQControl.SolveProblem(latest_status, goal_state)

        # Time to report back
        MongoConnector.UpdateAggregateStatus()

        sh.event.wait(sleep_period)
    MongoConnector.Quit()
    return
Ejemplo n.º 2
0
def main():

    # Parse command line
    parser = argparse.ArgumentParser(description='Manage the DAQ')
    parser.add_argument('--config',
                        type=str,
                        help='Path to your configuration file',
                        default='config.ini')
    parser.add_argument(
        '--log',
        type=str,
        help='Logging level',
        default='DEBUG',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'])
    parser.add_argument('--test', action='store_true', help='Are you testing?')
    args = parser.parse_args()
    config = configparser.ConfigParser()
    config.read(args.config)
    config = config['DEFAULT' if not args.test else "TESTING"]
    daq_config = json.loads(config['MasterDAQConfig'])
    control_mc = daqnt.get_client('daq')
    runs_mc = daqnt.get_client('runs')
    logger = daqnt.get_daq_logger(config['LogName'],
                                  level=args.log,
                                  mc=control_mc)
    crate_config = json.loads(config['CrateConfig'])

    # Declare necessary classes
    sh = daqnt.SignalHandler()
    SlackBot = daqnt.DaqntBot(os.environ['SLACK_KEY'])
    Hypervisor = daqnt.Hypervisor(control_mc[config['ControlDatabaseName']],
                                  logger,
                                  daq_config['tpc'],
                                  crate_config,
                                  sh=sh,
                                  testing=args.test,
                                  slackbot=SlackBot)
    MongoConnector = MongoConnect(config, daq_config, logger, control_mc,
                                  runs_mc, Hypervisor, args.test)
    DAQControl = DAQController(config, daq_config, MongoConnector, logger,
                               Hypervisor)
    # connect the triangle
    Hypervisor.mongo_connect = MongoConnector
    Hypervisor.daq_controller = DAQControl

    sleep_period = int(config['PollFrequency'])

    logger.info('Dispatcher starting up')

    while sh.event.is_set() == False:
        sh.event.wait(sleep_period)
        # Get most recent goal state from database. Users will update this from the website.
        if (goal_state := MongoConnector.get_wanted_state()) is None:
            continue
        # Get the Super-Detector configuration
        current_config = MongoConnector.get_super_detector()
        # Get most recent check-in from all connected hosts
        if (latest_status :=
                MongoConnector.get_update(current_config)) is None:
            continue
Ejemplo n.º 3
0
def main(config, control_mc, logger, daq_config, vme_config, SlackBot, runs_mc, args):
    sh = daqnt.SignalHandler()

    # Declare necessary classes
    hv = Hypervisor(
        control_mc[config['ControlDatabaseName']],
        logger,
        daq_config,
        vme_config,
        control_inputs=config['ControlKeys'].split(),
        testing=args.test,
        slackbot=SlackBot,
    )
    mc = MongoConnect(config, daq_config, logger, control_mc, runs_mc, hv, args.test)
    dc = DAQController(config, daq_config, mc, logger, hv)

    # connect the triangle
    hv.mongo_connect = mc
    hv.daq_controller = dc

    sleep_period = int(config['PollFrequency'])

    try:
        commit = subprocess.run('git log -n 1 --pretty=oneline'.split(),
                                capture_output=True
                                ).stdout.decode().split(' ')[0]
    except Exception as e:
        logger.debug(f'Couldn\'t get commit hash: {type(e)}, {e}')
        commit = 'unknown'
    logger.info(f'Dispatcher starting on commit: {commit}')

    while sh.event.is_set() == False:
        sh.event.wait(sleep_period)
        # Get most recent goal state from database. Users will update this from the website.
        if (goal_state := mc.get_wanted_state()) is None:
            continue
        # Get the Super-Detector configuration
        current_config = mc.get_super_detector()
        # Get most recent check-in from all connected hosts
        if (latest_status := mc.get_update(current_config)) is None:
            continue
Ejemplo n.º 4
0
cfile = args.config
if cfile is None:
    cfile = 'config.ini'
config.read(cfile)

# Declare database object
MongoConnector = MongoConnect(config)
state_codes = [
    "IDLE", "ARMING", "ARMED", "RUNNING", "ERROR", "TIMEOUT", "UNDECIDED"
]
pending_commands = []

# Declare a 'brain' object. This will cache info about the DAQ state in order to
# solve the want/have decisions. The deciding functions also go here. It needs a
# mongo connector because it has to pull options files
DAQControl = DAQController(config, MongoConnector)

while (1):

    # Get most recent check-in from all connected hosts
    MongoConnector.GetUpdate()
    latest_status = MongoConnector.latest_status

    # Get most recent goal state from database. Users will update this from the website.
    goal_state = MongoConnector.GetWantedState()

    # Decision time. Are we actually in our goal state? If not what should we do?
    DAQControl.SolveProblem(latest_status, goal_state)
    MongoConnector.ProcessCommands()

    # Time to report back
Ejemplo n.º 5
0
def main():

    # Parse command line
    parser = argparse.ArgumentParser(description='Manage the DAQ')
    parser.add_argument('--config',
                        type=str,
                        help='Path to your configuration file',
                        default='config.ini')
    parser.add_argument(
        '--log',
        type=str,
        help='Logging level',
        default='DEBUG',
        choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'])
    parser.add_argument('--test', action='store_true', help='Are you testing?')
    args = parser.parse_args()
    config = configparser.ConfigParser()
    config.read(args.config)
    config = config['DEFAULT' if not args.test else "TESTING"]
    config['MasterDAQConfig'] = json.loads(config['MasterDAQConfig'])
    control_uri = config['ControlDatabaseURI'] % os.environ['MONGO_PASSWORD']
    control_mc = pymongo.MongoClient(control_uri)
    runs_uri = config['RunsDatabaseURI'] % os.environ['RUNS_MONGO_PASSWORD']
    runs_mc = pymongo.MongoClient(runs_uri)
    logger = daqnt.get_daq_logger(config['LogName'],
                                  level=args.log,
                                  mc=control_mc)

    # Declare necessary classes
    sh = SignalHandler()
    Hypervisor = daqnt.Hypervisor(control_mc[config['ControlDatabaseName']],
                                  logger, sh)
    MongoConnector = MongoConnect(config, logger, control_mc, runs_mc,
                                  Hypervisor, args.test)
    DAQControl = DAQController(config, MongoConnector, logger, Hypervisor)

    sleep_period = int(config['PollFrequency'])

    logger.info('Dispatcher starting up')

    while (sh.event.is_set() == False):
        sh.event.wait(sleep_period)
        # Get most recent check-in from all connected hosts
        if MongoConnector.get_update():
            continue
        latest_status = MongoConnector.latest_status

        # Get most recent goal state from database. Users will update this from the website.
        if (goal_state := MongoConnector.get_wanted_state()) is None:
            continue

        # Print an update
        for detector in latest_status.keys():
            state = 'ACTIVE' if goal_state[detector][
                'active'] == 'true' else 'INACTIVE'
            msg = (f'The {detector} should be {state} and is '
                   f'{latest_status[detector]["status"].name}')
            if latest_status[detector]['number'] != -1:
                msg += f' ({latest_status[detector]["number"]})'
            logger.debug(msg)

        # Decision time. Are we actually in our goal state? If not what should we do?
        DAQControl.solve_problem(latest_status, goal_state)

        # Time to report back
        MongoConnector.update_aggregate_status()