Transient Astronomy - Customizing the Event Filter

iFor background, you should at least skim-read the paper Transient Astronomy with ACP Scheduler (PDF) and focus on the Message Classification and Filtering section.

The role of the event filter is to look at incoming VOEvent messages and determine which ones should be acted upon by the observatory. If a VOEvent is of interest, the filter is responsible for the following tasks:

This information is passed back to the receiver by writing it to the filter program's standard out. For details see Return Data below.

tBefore writing your own event filter, it is strongly suggested that you familiarize yourself with the standard filter, a script called DefaultEventFilter.js. You really should understand it completely, including its usage of command line parameters and its return data under various circumstances. The filter logic is somewhat complex, but it offers a high level of flexibility. There's a limit to what can be written here; we've done the best we can in a practical amount of time.

Types of Programs

imageThe filter can be any type of Windows command line program, written in any language. This includes Windows Script programs which run under the Windows command line script host cscript.exe, plus Perl and Python scripts which have their own execution engines. If the filter is an executable program, it can be written in any language which provides a command line interface and which supports reading from "standard in" and writing to "standard out" and "standard error".

Data Flow

The validated VOEvent XML is piped into the script or program’s standard input and the result parameters (described above and detailed below) are expected to be written by the filter to its standard output. The receiver simply waits for the (external) filter program to exit before moving to the next phase of processing, constructing the observing request from RTML and optionally interrupting the scheduler for time-critical events.

If the incoming VOEvent message is digitally signed, the receiver will have already checked the signature. If the signature is valid, the signer's ID is passed on the command line to the filter program (see below). If the signature mode is set to "strict" and the signature check fails, the event is discarded before it reaches the filter. If the signature mode is set to "lenient" and the check fails, the signer ID passed to the filter is blank. This allows you (for example) to make a further requirement that all incoming messages must be signed if your filter requires a non-blank signer ID.

Programming Considerations

The VOEvent XML that is piped into the filter has already been validated by the receiver, therefore you can load it into an XML engine (e.g. MSXML) and work with either the Document Object Model (XMLDOM) or use XPath programming to traverse the document tree and extract the information you need to make your decision and construct your returned items. If you don't know XPath, you should probably get familiar with it, as this is the easiest and most efficient way to extract information from the VOEvent XML. The object is to reject events that are not of interest

Error Handling

If the filter program encounters an error and must exit unsuccessfully it is vital that it do both of the following:

  1. Write all error messages to its standard error, and
  2. Exit with error status. All programming languages provide a way for the program to specify an integer status value upon exiting. Typically, an error status is anything other than zero, which is the universal "success" status value.

You have control over your program's exit status value, and as you'll see below, the receiver will report the exit status value in its log and in a balloon popup if your program exits with any error status. Therefore, you can use the exit status value to help you isolate between sources of error within your program.

tipThe Windows Script Host (cscript.exe) automatically does these two things. If your script fails to compile or if there is a fatal run-time error, cscript.exe puts all error text on its standard error and exits with non-zero status. The exit status value isn't too useful, but the error text is usually very useful.

Command Line

imageThe command line passed to the filter contains several items. They are (in order of appearance on the command line):

  1. If (and only if) the executable is cscript.exe, //NoLogo. This prevents the Windows Script Host from writing its banner/logo to standard out (which would be seen as part of the filter's return data)
  2. The receiver's configured Command Line Arguments string
  3. img//ftypes:XXX,YYY... These are the three-letter filter type codes from the receiver's configured Active Event Types (see image to right). These codes are used by the filter to select the types of events that will be passed on for observation.
  4. //rxdata:C:\Program Files\... The path to the ReceiverData folder. This can be used if the filter wants to construct an RTML request template on the fly (templates must be in the ReceiverData folder), or for storing and retrieving any sort of asset that the filter might wish to save on disk. Note that the working directory for the filter program is also set to the ReceiverData folder, but some programmers don't like to depend on this for anything!
  5. //signer:xxxxxx If the message was digitally signed and the signature was successfully validated, this will be the ID of the signer. Otherwise this will be blank. Thus you cannot tell the difference between an unsigned message and one that was signed but which failed signature validation with the receiver set to the "lenient" validation mode. Per the current draft VOEvent Digital Signature paper, the Signer ID must match the Author IVORN in the VOEvent message. You should check this in the filter, the receiver does not do this!

tipThe Windows Script Host exposes the arguments in 3, 4, and 5 as "named arguments" in a separate collection. The rest of the arguments are separated into the "unnamed arguments" collection and are indexed according to their order on the command line. The //NoLogo argument is not passed to the script. Look at the DefaultEventFilter.js script and the Windows Script Host documentation (included in ACP's online help set) for more info.

Filter Type Codes

The receiver has a configuration item Active Event Types in which is a list of three-letter codes (SWF, TOC, CRT, US1, US2). These codes are used by the filter to determine which types of events will be accepted for observing. It is the filter's responsibility to recognize these codes. The receiver has no knowledge of the codes themselves, it simply passes the list of active codes to the filter via the //ftypes: command line argument. Look at the standard event filter DefaultEventFilter.js for an example of filter code usage.

Besides telling the filter which types of events to pass on along for observation, the filter code can be used to select an RTML observing request template which the receiver used to construct the observing request for the event. The template name can contain the filter type code, making maintenance easier. This is not required, however.

Return Data

Depending on the decision made by the filter, it must return data to the receiver on its standard out. The return data is a single string consisting of up to four parts separated by the vertical bar (|) character. The parts, are, in order:

  1. The target name which is used in constructing the Observing Plan to be submitted to the scheduler
  2. A message string which is logged and may appear in a popup balloon
  3. The name of an RTML observing request template to be used in constructing the Observing plan to be submitted to the scheduler.
  4. An optional flag that indicates to the scheduler that the observation to be made is of a time-critical nature

Target Name

The target name should be something that makes type of event recognizable i the list of plans in the scheduler. For example, you might extract the "Trigger ID" from a Swift GRB alert message and form a target name of "Swift trigger #nnnn".

tThe target name must be unique, so use something from the event that is unique to that particular event.

tIf the target name is empty, it indicates that the VOEvent was rejected by the filter.

Message String

This is what gets shown in the receiver's log and in a balloon popup message (when the filter exits). If the filter accepts the event, resulting observations being queued, the receiver will pop a balloon message announcing the observations, so in that case the message should be empty. For other conditions, such as a message that was received but discarded for some reason, you can announce it with a balloon popup.

The message string can optionally specify an icon for the balloon popup. To do this, start the message with a tilde character (~) followed by a single lower case letter per the table below

Code Meaning
i Information
w Warning
e Error
n None

For example, "~iThis is a test" would result in a balloon containing "This is a test" with an Information icon. Omitting the icon code prefix is the same as including "~n".

RTML Template Name

This is the file name of an RTML observing request template to be used by the receiver to construct the observing request for the event. If no extension is given, it is assumed to be .rtml. Typically, different types of events require different observing strategies, so the receiver provides a way for the filter to pick an appropriate observing strategy by picking the RTML template to be used. Once it knows which template to use, the receiver does some substitutions before importing the final RTML into the schedule database as the new request. This is described in detail in Customizing Observing Strategies.

iFor advanced applications, the filter can construct the RTML observing request on the spot, using the data in the VOEvent to determine the observing strategy (images, filters, exposures, etc.) beyond the simple template substitutions made as described at the end of Customizing Observing Strategies.

Time-Critical Flag

If the filter returns a target name, indicating that it has accepted the event for observations, this final part of the return string can indicate that the observations are of a time-critical nature. If this is the case, the final part of the string must be exactly timecrit (not case sensitive). Anything else will be ignored and will be logged as an unknown option from the filter.

Examples

A Swift alert we're interested in, using the SWFObsRequest.rtml template

Swift Trigger #12345||SWFObsRequest|timecrit

An event we rejected:

|~iA Catalina test message was received and discarded||

Program Invocation

The receiver's configuration settings provide for the path to the executable and command line arguments to be passed to the program (see diagram on the right). The receiver will invoke the filter program as follows:

  1. Look in the Scheduler's ReceiverData folder for the executable. The configured Executable path is appended to the path to the ReceiverData folder to form the entire path. Thus, a configured path of bin\foo.exe will result in the receiver looking in ReceiverData\bin\foo.exe. Normally, you would simply put your pre-patcher executable into the Receiver data and put the executable's file name into the configuration Executable path.
  2. If it doesn't find the program in step 1, it then looks in your Windows\System32 for the executable. This is provided only for script filters which use the Windows Script host cscript.exe (which is located in Windows\system32). Do not put your filter executable in Windows\system32!
  3. Construct a command line for the program per the section Command Line above.
  4. Set the working directory for the pre-patcher to the ReceiverData folder.
  5. The program is started as a separate process with the constructed command line, initially in the suspended state.
  6. The validated VOEvent XML is connected to the filter program's standard input.
  7. The filter program's standard output and standard error are connected back to the receiver.
  8. The receiver un-suspends (resumes) the filter program, allowing it to run to completion.
  9. The receiver waits for the filter program to exit.
  10. Upon exit, the filter program's "exit status" is tested for success. If the filter program exited with error status, the receiver logs the error and pops a balloon alert "**Filter task exited with error status nnn: xxxxxxx", where xxxxx is any text that comes in from the receiver's standard error. In any case, whatever is on standard out is passed back to the receiver as a result.