### Editor 1 (proc)

return $.data[pixel];

### Editor 2 (main)

print("This output will go to the Console.\n"); // The four first values of pixel 1 var arr = [ $.data[1][0], $.data[1][1], $.data[1][2], $.data[1][3] ]; print("Pixel 1: [ "+arr+" ]\n"); // Get the maximum sample from each pixel var rc = [new Array(1440),new Array(1440)]; for (var p=0; p<$.event.numPix; p++) { var max = 0; var idx = 0; for (var s=5; s<$.event.numRoi-50; s++) { // spike suppression var h = ($.data[p][s]-$.data[p][s-1]) + ($.data[p][s]-$.data[p][s+1]); if ($.data[p][s]>max && h<20) { max = $.data[p][s]; idx = s; } } rc[0][p]=max; rc[1][p]=idx; } return rc;

### Runtime error

### Console

### Run info

### Debug

Run file: Evt: /--- Pix: CBPX: =

### Camera display

Min: Max: |  | Min: Max: |

Min: Max: | Show pixel marker | Min: Max:

### Waveform

Xmin: Xmax: | Ymin: Ymax:

### Additional controls

### Help

### How does it work?

When you submit a javascript to the server, it will be executed on a sandbox on the server. Before the event is loaded from a file and made available within the sandbox. Generally, the sandbox can easily be enhanced, e.g. with algorithms available in php. This can be done on request. After execution, the result returned by the script is then displayed in the camera display.

### Why Javascript?

Simply for security reasons. To avoid tranferring the event to the client's browser, the script must be executed on the server side. Also Python and PHP offer the possibility to execute scripts within a program, they do not have any security feature to avoid for exmple access to the local disk. The V8 Javascript engine however, is very limited in functionality and therefore ideally suited for a sandboxed and therefore safe excution on the server. Any other solution is welcome.

### Javascript hints!

Please note that in Javascript only basic data typed (number, etc) are copied in an assignment. In all other cases, only a reference is copied. For example, the following code snippet does not return 2 as you might expect but 7!

    var arr = [ 0, 1, 2, 3 ];
    var cpy = arr;
    cpy[2] = 7;
    print(arr[2]);

To avoid that, the global namespace implements a clone function. For exmaple, the following code snippet will return the expected output:

    var arr = [ 0, 1, 2, 3 ];
    var cpy = $.clone(arr);
    cpy[2] = 7;
    print(arr[2]);

### Javascript arrays

Note that javascript arrays have some very powerful member functions. For a description see for example here or search google for function like map or reduce.

### The global object $

The environment provides a global object (namesapce) called $ with the following members:

$.file.numEvents | Number of events in the file
$.file.runStart | MJD of run start minus 40587 (unix time in days)
$.file.runEnd | MJD of run end minus 40587 (unix time in days)
$.file.drsFile | If this is a DRS calibration file, the step id, otherwise -1
$.event | The event header information as obtained from the file
$.event.numRoi | Number of samples per pixel
$.event.numPix | Number of pixels
$.event.eventNumber | Event number
$.event.triggerNumber | Trigger number
$.event.triggerType | Trigger type
$.event.trigger | Decoded trigger information
$.event.unixTime[2] | Timestamp when the event arrived at the event builder
$.data[numPix][numRoi] | The event data
$.nroi | Shortcut to $.event.numRoi
$.npix | Shortcut to $.event.numPix
$.trigger | Shortcut to $.event.trigger
$.neighbors | Array of 1440 arrays each containing the corresponding neighbors

### Stack traces

Please note that due to some interna, the line numbers in the stack trace shown in case of runtime errors are by one line too high.

### Editor 1 (proc)

proc can return an array with numRoi entries or an array with up to four sub-arrays each of nRoi entries. They will be displayed in the graph. The chosel pixel is available as pixel. The most simple is to just return the selected pixel data unprocssed:

    return $.data[pixel];

### Editor 2 (main)

main should return extracted data per pixel. As proc it can return a single array or an array with up to four sub-arrays each with numPix entries. They are displayed in the camera displays. The function implemented as proc is accessible as proc(i) with i being available in proc as pixel. A very simple extractor could be to return just the sample at the trigger position

    var rc = [];
    for (var i=0; i<$.event.numPix; i++)
        rc[i] = $.data[i][60];
    return rc;

or taking the data pre-procesed by the code of the proc-function:

    var rc = [];
    for (var i=0; i<$.event.numPix; i++)
        rc[i] = proc(i)[60];
    return rc;

Note that the precise access to the result of proc might depend on what exactly is retruned by proc (an array, or an array with sub-arrays). Pixel which are not returned (`undefind` or `null`) are not displayed. This allows to show cleaned images as well or test image cleaning algorithms.

### What is the data?

The data are all data files found in disks in La Palma (to be precise: on daq's disks). The data is raw-data but with the most recent DRS calibration (only the 1024-cell offset calibration) applied, while the application is done in intergers, i.e. the fractional part of the calibration constant is removed. (This is basically what is written in our FITS files as part of the lossless compression process). No spike or jump removal is applied.

### The editor

Key bindings of the editor can be found at Codemirror. In addition the following binding are defined: Tab - Auto indent; F11 - Switch to fullscreen; Esc - In fullscreen mode to leave fullscreen; Ctrl-r - replace; Ctrl-y - Delete the line under the cursor; Ctrl-. (dot) - Fold code; Ctrl-Down (cursor down) - Autocomplete.

### How to change the file?

Start typing the date in the filename field. The available files will be filtered as you type. To select a file you need to select it fom the pull down.

### How to change the displayed pixel?

Enter the pixel number on the corresponding field or its hwardware address. As soon as you acknowledge your change (e.g. remove focus by clicking somewhere else) the pixel contents gets displayed.

### How to Save/Load a script?

To load a file choose a file fro your local hard drive via the file selection dialog. To save the contents of the editor, press Save.

### Submit

If you have changed the script and you want to run it on the current event press Submit. The Javascript will be executed for this event on the server.

### Pixel value

To display the value returned for a pixel just click on the pixel. The value will be displayed in the Pixel field. This will also display the corresponding waveform in the graph.

### Min/max values

Min and max values for the plot and the graph can be determined automatically or manully. To set the to a fixed value, enable the min and/or max field and enter the value of your choice. It will survive changing files, events or pixel.

### Why is loading the page so slow?

The total contents of the javascript libraries is about 1MB which all have to be treasferred to the browser. In addition the loading and processing of the event takes up to 1s so that the loading time of the page might be untypically slow. Once finished, the amaount of code to load can be decreased.

### How to unzoom the plot?

Double click on the plot.