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, August 2017 

2 

3""" 

4A FileHandler that specifies whether an event has been flagged ADVOK, 

5allowing information about it to be shared with EM follow up partners. 

6""" 

7 

8import json 

9from llama.filehandler import EventTriggeredFileHandler, JSONFile 

10from llama.files.lvc_gcn_xml import LvcGcnXml 

11from llama.files.lvalert_advok import LVAlertAdvok 

12 

13 

14@JSONFile.set_class_attributes 

15class Advok(EventTriggeredFileHandler, JSONFile): 

16 """ 

17 The existence of this file should be taken as an indication that the 

18 event has been marked as ADVOK. This may have occured either through the 

19 actual application of the ``ADVOK`` label to the event on GraceDB, or 

20 through the sending of a GCN notice for this event (which has happened even 

21 when ADVOK was not applied, as in G298048), or when a LLAMA operator 

22 chooses to manually mark the event as EM followup ready by creating this 

23 file. Once this file exists, dependent files will assume that the event is 

24 legitimate and will carry on with any communication efforts they are 

25 programmed to perform. 

26 

27 Should be created either simultaneously with a GCN 

28 notice or simultaneously with an LVAlert adding the ``ADVOK`` label to 

29 an event (these are the use cases at time of writing, anyway). 

30 """ 

31 

32 FILENAME = 'advok.json' 

33 

34 # allowed values of ``alert_type`` 

35 _alert_types = [ 

36 'lvalert', 

37 'gcn', 

38 'manual' 

39 ] 

40 

41 # pylint: disable=arguments-differ 

42 def _generate(self, alert_type, notice_time_iso): 

43 """Specify the alert type that notified us that this event was ADVOK 

44 (this also implicitly specifies which file contains the evidence that 

45 this tag is applied) as well as the time that the ADVOK notice 

46 being used was generated.""" 

47 if alert_type not in self._alert_types: 

48 fmt = 'alert_type must be in: {}\ninstead got:{}' 

49 raise ValueError(fmt.format(self._alert_types, alert_type)) 

50 dic = {'alert_type': alert_type, 'notice_time_iso': notice_time_iso} 

51 self._write_json(dic) 

52 

53 @property 

54 def time(self): 

55 """The time at which this became ADVOK.""" 

56 return self.read_json()['notice_time_iso'] 

57 

58 @property 

59 def alert_type(self): 

60 """A string describing the provenance of this trigger, i.e. what 

61 "alert" caused us to create this event (and with it, this 

62 ``SkymapInfo`` file).""" 

63 return self.read_json()['alert_type'] 

64 

65 @property 

66 def alert_file_handler(self): 

67 """Get the file handler which tells us that this event is ready for 

68 EM followup.""" 

69 alert_type = self.alert_type 

70 if alert_type.startswith('gcn'): 

71 return LvcGcnXml(self) 

72 if alert_type == 'lvalert': 

73 return LVAlertAdvok(self) 

74 # default case 

75 if alert_type in self._alert_types: 

76 return None 

77 raise ValueError('Invalid alert_type value: {}'.format(alert_type))