Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# (c) Stefan Countryman, 2019 

2 

3""" 

4Tools related to the interactive status/results website maintained for the 

5current LLAMA run. 

6""" 

7 

8from pathlib import Path 

9from llama.classes import optional_env_var 

10from llama.utils import OUTPUT_DIR 

11from llama.serve.gui.domain import LLAMA_DOMAIN 

12 

13DEFAULT_LLAMA_GUI_PORT = '80' 

14# remember that this is a string representing a default env var 

15DEFAULT_FILE_PREVIEWS_STR = ( 

16 'CoincSummaryI3LvcPdf,' 

17 'CoincScatterI3LvcPng,' 

18 'CoincScatterI3LvcPdf,' 

19 'LvcSkymapFits,' 

20 'SkymapInfo,' 

21 'LvcDistancesJson,' 

22 'PAstro,' 

23) 

24# remember that this is a string representing a default env var 

25DEFAULT_FULL_WIDTH_FILE_PREVIEWS_STR = ( 

26 'LVCGraceDbEventData,' 

27 'IceCubeNeutrinoList,' 

28 'CoincSignificanceI3Lvc,' 

29 'CoincSignificanceSubthresholdI3Lvc,' 

30 'LvcGcnXml,' 

31) 

32LLAMA_GUI_PORT = optional_env_var( 

33 ['LLAMA_GUI_PORT'], 

34 """Specify the port on which ``llama serve gui`` is running.""", 

35 [DEFAULT_LLAMA_GUI_PORT], 

36)[0] 

37LLAMA_REL_URL_HOME = '' 

38LLAMA_GUI_HOME = f'http://{LLAMA_DOMAIN}:{LLAMA_GUI_PORT}/{LLAMA_REL_URL_HOME}' 

39LLAMA_GUI_USERNAME, LLAMA_GUI_PASSWORD = optional_env_var( 

40 ['LLAMA_GUI_USERNAME', 'LLAMA_GUI_PASSWORD'], 

41 """Specify a username and password that should be used to log in to ``llama 

42 serve gui`` through a web browser using basic HTTP auth.""", 

43) 

44FILE_PREVIEWS_STR, FULL_WIDTH_FILE_PREVIEWS_STR = optional_env_var( 

45 ['FILE_PREVIEWS', 'FULL_WIDTH_FILE_PREVIEWS'], 

46 """Specify a comma-separated list of FileHandler classes from the 

47 llama.pipeline.Pipeline in use that should have file previews on event 

48 pages. `FILE_PREVIEWS` will take up less than the full width of the page on 

49 desktop and `FULL_WIDTH_FILE_PREVIEWS` will take up the full width. If 

50 none are specified, defaults will be used.""", 

51 [DEFAULT_FILE_PREVIEWS_STR, DEFAULT_FULL_WIDTH_FILE_PREVIEWS_STR], 

52) 

53FILE_PREVIEWS = FILE_PREVIEWS_STR.strip(',').split(',') 

54FULL_WIDTH_FILE_PREVIEWS = FULL_WIDTH_FILE_PREVIEWS_STR.strip(',').split(',') 

55 

56 

57def gui_url(obj, linktype=None): 

58 """ 

59 Get a URL to the LLAMA GUI webpage running on this server. Use this to 

60 generate links to LLAMA ``Run``, ``Event``, and ``FileHandler`` webpages. 

61 

62 Parameters 

63 ---------- 

64 obj : object 

65 A LLAMA object. If this is has a ``rundir`` attribute, try to find the 

66 run name that LLAMA GUI uses. If it also has an ``eventid`` attribute, 

67 include that in the returned URL. If it also has a ``FILENAME`` 

68 attribute, include that as well. 

69 linktype : str, optional 

70 Optionally manually specify the output type as ``'run'``, ``'event'``, 

71 or ``'filehandler'``. Use this if you want to e.g. get a link to the 

72 webpage for an ``Event`` when providing a ``FileHandler``. Will not 

73 work if ``obj`` does not contain the data required to construct the 

74 requested ``linktype`` (e.g. ``linktype='filehandler'`` will fail if 

75 ``obj`` is a ``Run``). 

76 

77 Returns 

78 ------- 

79 url : str 

80 A URL linking to the LLAMA summary web page for the provided object. 

81 

82 Raises 

83 ------ 

84 ValueError 

85 If the ``rundir`` for the provided object is not in a directory served 

86 by ``llama serve gui``, if ``obj`` has no ``rundir`` attribute, or if 

87 the requested ``linktype`` cannot be constructed from ``obj``. 

88 """ 

89 if linktype not in ['run', 'event', 'filehandler', None]: 

90 raise ValueError(f"Unrecognized `linktype`: {linktype}") 

91 if not hasattr(obj, 'rundir'): 

92 raise ValueError(f'{obj} has no `rundir` attribute, cannot get url') 

93 if linktype in ['event', 'filehandler'] and not hasattr(obj, 'eventid'): 

94 raise ValueError(f'{obj} has no `eventid` attribute required by ' 

95 f'linktype="{linktype}"') 

96 if linktype == 'filehandler' and not hasattr(obj, 'FILENAME'): 

97 raise ValueError(f'{obj} has no `FILENAME` attribute required by ' 

98 'linktype="filehandler"') 

99 relpath = Path(obj.rundir).relative_to(OUTPUT_DIR) 

100 if linktype != 'run': 

101 relpath /= getattr(obj, 'eventid', '') 

102 relpath = str(relpath) + '/' 

103 if linktype in [None, 'filehandler'] and hasattr(obj, 'eventid'): 

104 relpath += getattr(obj, 'FILENAME', '') 

105 return LLAMA_GUI_HOME + relpath