Exemplo n.º 1
0
 def decorated(*args, **kwargs):
     try:
         return func(*args, **kwargs)
     except Exception as e:
         bvlogging.get_logger().warn(traceback.format_exc())
         return {
             'status': 'ERROR',
             'message': e.message
         }
Exemplo n.º 2
0
def get_brilcalc_bxlumi(args={}):
    '''
    input:
        args: {
            'runnum': int,
            'lsnum': int,
            'normtag': str textbox or dropdown select,
            'type':  str or None,
            'without_correction': boolean,
            'unit': str
    }

    output: {
        'status':'OK'|'ERROR',
        'data'?: {
            'fillnum': int,
            'runnum': int,
            'lsnum': int,
            'tssec': int,
            'delivered': float[],
            'recorded': float[]
        },
        'message'?: str
    }
    '''
    cmd = _get_total_lumi_command_template()
    cmd.append('--xing')
    cmd.extend(_parse_run_ls_args(args))
    if args.get('without_correction', False):
        cmd.append('--without-correction')

    unit = '/ub'
    if 'unit' in args and args['unit']:
        unit = args['unit']
    cmd.extend(['-u', unit])

    if 'type' in args and args['type']:
        cmd.extend(['--type', args['type']])

    if 'normtag' in args and args['normtag']:
        cmd.extend(_parse_normtag(args['normtag']))

    bvlogging.get_logger().debug(cmd)
    try:
        r = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        if e.returncode != 0:
            out = re.sub('File ".*?"', '<FILE>', e.output)
            return {'status': 'ERROR', 'message': out}

    return {
        'status': 'OK',
        'data': _parse_brilcalc_bx_output(r)
    }
Exemplo n.º 3
0
import docopt
import webbrowser
import yaml
import cherrypy as cp
import brilview
from cherrypy.process import plugins
from brilview import brilview_flask_app, bvlogging, bvconfig

BRILVIEW_PYTHONPATH = (os.path.dirname(sys.executable) +
                       '/../lib/python2.7/site-packages/')
# ignore other PYTHONPATH
sys.path.insert(0, BRILVIEW_PYTHONPATH)

THISPATH = os.path.abspath(os.path.dirname(__file__))

log = bvlogging.get_logger()


def run_in_cp_tree(app, after_start=None):

    cpconfig = {'engine.autoreload.on': False}
    if hasattr(bvconfig, 'host') and bvconfig.host is not None:
        cpconfig['server.socket_host'] = bvconfig.host
    if hasattr(bvconfig, 'port') and bvconfig.port is not None:
        cpconfig['server.socket_port'] = bvconfig.port
    if hasattr(bvconfig, 'log_to_screen'):
        cpconfig['log.screen'] = bvconfig.log_to_screen
    if hasattr(bvconfig, 'log_file') and bvconfig.log_file is not None:
        cpconfig['log.error_file'] = bvconfig.log_file

    cp.config.update(cpconfig)
Exemplo n.º 4
0
def get_brilcalc_lumi(args={}):
    '''
    input:
      args: {
          begin: str '^\d\d/\d\d/\d\d \d\d:\d\d:\d\d$|^\d{6}$|^\d{4}$'
          end: str '^\d\d/\d\d/\d\d \d\d:\d\d:\d\d$|^\d{6}$|^\d{4}$'
          unit: str
          beamstatus: str ('stable beams' | 'squeeze' | 'flat top' | 'adjust')
          normtag: str textbox or dropdown select
          datatag: str
          hltpath:  str //'^HLT_[\w\*\?\[\]\!]+$' reject wildcard patterns ??
          type:  str or None
          selectjson: jsonstr
          byls: boolean
          without_correction: boolean
          pileup: boolean
          minbiasxsec: float
      }
    output: {
        'status':'OK'|'ERROR',
        'data'?: {
            'fillnum': [],
            'runnum': [],
            'tssec': [],
            'delivered': [],
            'recorded':[],
            'lsnum':[],
            'hltpathid':[],
            'hltpathid2name':{id:name},
            'hltpathname2id':{name:id},
            'pileup': []
        },
        'message'?: str
    }

    '''
    cmd = _get_total_lumi_command_template()
    cmd.extend(_parse_time_range_args(args))

    byls = False
    if args.get('byls', False):
        cmd.append('--byls')
        byls = True
    if args.get('without_correction', False):
        cmd.append('--without-correction')

    unit = '/ub'
    if 'unit' in args and args['unit']:
        unit = args['unit']
    cmd.extend(['-u', unit])

    if 'type' in args and args['type']:
        cmd.extend(['--type', args['type']])

    if 'normtag' in args and args['normtag']:
        normtag = args['normtag']
        if normtag == '':
            return {'status': 'ERROR', 'message': 'Empty normtag'}
        normtag_file = _make_normtag_filepath(normtag)
        if normtag_file is not None and os.path.isfile(normtag_file):
            normtag = normtag_file
        cmd.extend(['--normtag', normtag])

    if 'beamstatus' in args and args['beamstatus']:
        cmd.extend(['-b', args['beamstatus'].upper()])

    pileup = False
    if 'pileup' in args and args['pileup']:
        if not byls:
            raise ValueError('Pileup option must go with "byls"')
        pileup = True
        if 'minbiasxsec' in args:
            cmd.extend(['--minBiasXsec', str(args['minbiasxsec'])])

    hltpath = None
    if 'hltpath' in args and args['hltpath']:
        cmd.extend(['--hltpath', args['hltpath']])
        hltpath = args['hltpath']

    bvlogging.get_logger().debug(cmd)
    try:
        r = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        r = r.decode('utf-8')
    except subprocess.CalledProcessError as e:
        if e.returncode != 0:
            out = re.sub('File ".*?"', '<FILE>', e.output)
            return {'status': 'ERROR', 'message': out}

    return {
        'status': 'OK',
        'data': _parse_brilcalc_output(r, byls, pileup, hltpath)
    }