Esempio n. 1
0
def send_processing_request(instrument_id, run_id, user=None, destination=None, is_complete=False):
    """
        Send an AMQ message to the workflow manager to reprocess
        the run
        @param instrument_id: Instrument object
        @param run_id: DataRun object
    """
    if destination is None:
        destination = '/queue/POSTPROCESS.DATA_READY'

    # IPTS name
    try:
        ipts = run_id.ipts_id.expt_name.upper()
    except:
        ipts = str(run_id.ipts_id)

    # Verify that we have a file path.
    # If not, look up ICAT
    file_path = run_id.file
    if len(file_path) == 0:
        from report.icat_server_communication import get_run_info
        run_info = get_run_info(str(instrument_id), '', run_id.run_number)
        for _file in run_info['data_files']:
            if _file.endswith('_event.nxs') or _file.endswith('.nxs.h5'):
                file_path = _file
        # If we don't have the IPTS, fill it in too
        if len(ipts) == 0:
            ipts = run_info['proposal']

    # Sanity check
    if len(file_path) == 0 or len(ipts) == 0 or ipts is None:
        logging.error("No ICAT information for run %s: message not sent", run_id)
        raise RuntimeError("Run %s not found in ICAT" % str(run_id))
    # Build up dictionary
    data_dict = {'facility': 'SNS',
                 'instrument': str(instrument_id),
                 'ipts': ipts,
                 'run_number': run_id.run_number,
                 'data_file': file_path
                }
    if is_complete is True:
        data_dict['is_complete'] = 'true'
    if user is not None:
        data_dict['information'] = "Requested by %s" % user

    data = json.dumps(data_dict)
    reporting_app.view_util.send_activemq_message(destination, data)
    logging.info("Reduction requested: %s", str(data))
Esempio n. 2
0
def detail(request, instrument, run_id):
    """
        Run details
        @param instrument: instrument name
        @param run_id: run number, as string
    """
    # Get instrument
    instrument_id = get_object_or_404(Instrument, name=instrument.lower())
    run_object = get_object_or_404(DataRun, instrument_id=instrument_id, run_number=run_id)

    icat_info = get_run_info(instrument, str(run_object.ipts_id), run_id)

    # Breadcrumbs
    breadcrumbs = "<a href='%s'>home</a>" % reverse(settings.LANDING_VIEW)
    breadcrumbs += " &rsaquo; <a href='%s'>%s</a>" % (reverse('report:instrument_summary',
                                                              args=[instrument]), instrument)
    breadcrumbs += " &rsaquo; <a href='%s'>%s</a>" % (reverse('report:ipts_summary',
                                                              args=[instrument, run_object.ipts_id.expt_name]),
                                                      str(run_object.ipts_id).lower())
    breadcrumbs += " &rsaquo; run %s" % run_id
    if users.view_util.is_experiment_member(request, instrument_id, run_object.ipts_id) is False:
        template_values = {'instrument':instrument.upper(),
                           'run_object':run_object,
                           'helpline': settings.HELPLINE_EMAIL,
                           'breadcrumbs':breadcrumbs}
        template_values = users.view_util.fill_template_values(request, **template_values)
        template_values = dasmon.view_util.fill_template_values(request, **template_values)
        return render(request, 'report/private_data.html', template_values)

    # Check whether we need a re-reduce link
    reduce_url = None
    if view_util.needs_reduction(request, run_object):
        reduce_url = 'reduce'

    # Find status entries
    status_objects = RunStatus.objects.filter(run_id=run_object).order_by('created_on').reverse()

    # Look for an image of the reduction
    plot_template_dict = view_util.get_plot_template_dict(run_object, instrument, run_id)

    # Check whether this is the last known run for this instrument
    last_run_id = DataRun.objects.get_last_cached_run(instrument_id)
    if last_run_id == run_object:
        next_url = None
    else:
        try:
            DataRun.objects.get(instrument_id=instrument_id,
                                run_number=run_object.run_number + 1)
            next_url = reverse('report:detail', args=[instrument, run_object.run_number + 1])
        except:
            next_url = None

    # Get previous run
    try:
        DataRun.objects.get(instrument_id=instrument_id,
                            run_number=run_object.run_number - 1)
        prev_url = reverse('report:detail', args=[instrument, run_object.run_number - 1])
    except:
        prev_url = None

    template_values = {'instrument':instrument.upper(),
                       'run_object':run_object,
                       'status':status_objects,
                       'breadcrumbs':breadcrumbs,
                       'icat_info':icat_info,
                       'reduce_url':reduce_url,
                       'reduction_setup_url':reporting_app.view_util.reduction_setup_url(instrument),
                       'prev_url': prev_url,
                       'next_url': next_url,
                      }
    template_values.update(plot_template_dict)
    if icat_info == {}:
        template_values['user_alert'] = ["Could not communicate with ICAT: please notify ICAT support staff"]
    try:
        if 'data_files' not in icat_info or icat_info['data_files'] is None or len(icat_info['data_files'])==0:
            if view_util.is_acquisition_complete(run_object):
                template_values['no_icat_info'] = "There is no catalog information for this run yet."
            else:
                template_values['no_icat_info'] = "The final data file for this run is not yet available."

    except:
        logging.error("Could not determine whether we have ICAT info: %s", sys.exc_value)
        template_values['no_icat_info'] = "There is no catalog information for this run yet."
    template_values = users.view_util.fill_template_values(request, **template_values)
    template_values = dasmon.view_util.fill_template_values(request, **template_values)
    return render(request, 'report/detail.html', template_values)