The Saxsdog Network

The network may consist of 3 different services. The “Saxsdog Server” does the image processing. The “Saxs Feeder” publishes new file events and the “Saxs Leash” controls an configures the server. The feeder is optional.

The SAXSNetwork configuration

The Saxsdog server and the Saxsleash have a common configuration file, which tells them how to connect with each other and which also includes a shared secret for authentication. If you want two computers to connect via the Saxsleash you need to have a copy of the file on each of them.

To create such a configuration, use the command:

$ saxsnetconf

It will ask for the Feeder URL and for the Saxsdog Server URL. Then it will generate a random secret and save the file in file in $Home/.saxdognetwork. You will have to copy the file to the other computers you need to allow to connect to your network. The secret must be the same on all of them.

[{
   "Server":"tcp://hostname:port",
   "Feeder":"tcp://hostname:port",
   "Secret":"Some large random string."
   "Name":"Pilatus1M"
}]

The authentication is done by hashing the request and the secret including a time stamp. The time stamp is checked if it lies within 900 seconds of the servers time.

The Saxsdog Server

The Saxdog Server is the program that is started on the processing computer (node). It may subscribe to a “new file” event service.

$ saxsdogserver --help
Usage: saxsdogserver [options] basedir

Options:
  -h, --help            show this help message and exit
  -p port, --port=port  Port to offer command service. Default is 7777.
  -t THREADS, --threads=THREADS
                        Number of concurrent processes.
  -f tcp://hostname:port, --feeder=tcp://hostname:port
                        Specify the URL of the new file event service (Saxsdog
                        Feeder)
  -w, --watch           Watch directory for changes, using file system events
                        recursively for all sub directories.
  -R RELPATH, --relpath=RELPATH
                        Specify output directory as relative path to image
                        file. Default: '../work'
  -o OUTDIR, --out=OUTDIR
                        Specify output directory
  -d, --daemon          Start server  as daemon

The Saxs Leash

_images/screenshot.png

The Leash Program is a GUI to load calibrations into the Saxdog Server and monitor the processing of the data. It provides a calibration editor, as mask preview and basic data import from saxsconverter.

The main window has 3 tab cards. The first is for setting up the server, the second to review the currently processed data and the third for basic statistics. The command to launch it is.

leash

Saxs Leash Commandline

The “Saxs Leash” command line client can issue the commands for the Saxsdog Server.

$ saxsleash --help
Usage: saxsleash close|abort|new|get|plot|plotdata|readdir|stat|listdir|putplotdata|fileslist|mergedata|getmergedata [options] [arguments]

Options:
  -h, --help            show this help message and exit
  -S tcp://HOSTNAME:PORT, --server=tcp://HOSTNAME:PORT
                        URL of "Saxsdog Server"
  -s N, --skip=N        plot: Skip first N points.
  -k N, --clip=N        plot: Clip last N points.
  -x TYPE, --xaxsistype=TYPE
                        plot: Select type of X axis scale, might be
                        [linear|log|symlog]
  -y TYPE, --yaxsistype=TYPE
                        plot: Select type of Y axis scale, might be
                        [linear|log|symlog]
  -N SERVERNO, --serverno=SERVERNO
                        select server from config list by index default:0

Most of the command line options are about the plot command, but in order to visualize the processed data, one has to send the commands to setup a calibration.

New

$ saxsleash new cal.json data/AAA_integ.msk data/

The new command loads a calibration and starts the queue to receive new files. It requires 3 arguments:

  1. Calibration file. as in The Dedector Calibration File,
  2. mask file,
  3. directory where the image files are or are going to be.

If there is a queue running, this command will abort the other one and replace it. One server can have only one queue at a time.

Plot

$ saxsleash plot

The plot command will grab the next image and show a plot of the result in a window. This command will be repeated until the user interrupts it with Ctrl-C.

Close

$ saxsleash close

Closes the queue. Which means, the server will process what is left in the queue but ignore all new files.

Abort

$ saxsleash abort

The abort command will close the queue and stop all data processing processes. It will only wait for each process to finish the picture they started before. The remaining pictures in the queue are ignored.

Stat

$ saxsleash stat

Return basic statistics data about the processes.

Read Dir

$ saxsleash readdir

This command will put all the images in the configured directory into the queue. This is useful to reprocess pictures.

List Directory

  $ saxsleash listdir Serverdirectory

Returns a list of files and directories on the server. Mostly used for the Leash GUI dialoges.

Files List

$ saxsleash fileslist

Returns a list of processed files.

Merge Data

$  saxsleash mergedata mergeconf.json

Sends command to merge data. Takes a merge configuration file as argument.

The Saxsdog Network Protocol

The Saxsdog Server

The saxdog server can watch for files ystem events for himself or subscribe to a zmq service, the Saxsdog Feeder, that publishes new file names. The server can process the new images according to one calibration. The server may only have one calibration at a time, it is not designed to be used by multiple users at the same time.

The Saxsdog Feeder

The “Saxsdog Feeder” service offers file events for subscription. It should not do any buffering or pre-selection, just send a new message when any new file was copied and is ready for processing. Also when a file is overwritten: Send a message. It should however, only send this event, when the file is completely written to the file system.

New file events are composed of the following message:

{
   "command":"new file",
   "argument":"/Path/to/file/"
}

The service must be a ZeroMQ zmq.PUP socket. This code is a simulation of the messages:

import zmq
import random
import sys
import time
import os
import json
from optparse import OptionParser

def startfeeder():
    """
    Simulator for new file anounciation service. For development and testing.
    """
    parser = OptionParser()
    usage = "usage: %prog [options]  "
    parser = OptionParser(usage)
    parser.add_option("-p", "--port", dest="port",
                      help="Port to offer file changes service", metavar="port",default="")
    parser.add_option("-d", "--dir", dest="dir",
                      help="Directory to monitor", metavar="dir",default=".")
    parser.add_option("-s", "--sdir", dest="sdir",
                      help="server dir, (prefix to filepaths)", metavar="dir",default=".")
    (options, args) = parser.parse_args(args=None, values=None)
    
    
    
    context = zmq.Context()
    socket = context.socket(zmq.PUB)
    if options.port=="":
        conf=json.load(open(os.path.expanduser("~"+os.sep+".saxsdognetwork"))) 
        port=conf['Feeder'].split(':')[-1]
    else:
        port=options.port
    print "conecting:","tcp://*:%s" % port
    socket.bind("tcp://*:%s" % port)
    
    fileslist=[]
    if len(args)>0 and options.dir==".":
        dirtosearch =args[0]
    else:
        dirtosearch =options.dir
    for path, subdirs, files in os.walk(dirtosearch):
                for name in files:
                    if name.endswith('tif'):
                        fileslist.append( os.path.join(path, name))
    messageobj={"command":"new file","argument":""}
    while True:
       for file in fileslist:
            print file
            messageobj['argument']=file
            message=json.dumps(messageobj)
            socket.send(message)
            time.sleep(7)
                        

if __name__ == '__main__':
    startfeeder()

    

The Saxsdog Leash

The Saxsdog Leash is a user-facing control interface. There, the user should enter new calibrations and specify the data directories connected to it. During the processing, it shows a graph of one of the current images.

It may send the following commands:

Close

Request:

{
  "command":"close queue",
  "time":1404979588.715198,
  "sign":"Signature generated for request"
}

Answer:

{
"result":"queue closed",
"data":{
   "stat": {
      "time interval": 0.8776118755340576,
      "queue length": 0,
      "frames per sec": 10.25510279760422,
       "images processed": 235, "pics": 9
      }
   }
}

Abort

Request:

{
   "command":"abort queue",
   "time":1404979588.715198,
   "sign":"Signature generated for request"
}

Answer:

{
   "result":"queue stopped emptied and closed",
   "data":{
      "stat": {
         "time interval": 0.8776118755340576,
         "queue length": 0,
         "frames per sec": 10.25510279760422,
         "images processed": 235,
         "pics": 9
      }
   }
}

New

Request:

{
   "command":"new queue",
   "argument":{
      "directory":["path","to","data"],
      "calibration":{},
      "maskbin":""
   },
"time":1404979588.715198,
"sign":"Signature generated for request"
}

Answer:

{ "result":"new queue",
  "data":{
         }

}

Plot

Request:

{  "command":"send plot",
   "time":1404979588.715198,
   "sign":"Signature generated for request"
}

Answer:

{
 "result":"plot data",
 "data":{
   "filename":"/name/.tiv" ,
   "stat": {
         "time interval": 0.8776118755340576,
         "queue length": 0,
         "frames per sec": 10.25510279760422,
         "images processed": 235,
         "pics": 9
         },
   "array":[[0],[0],[0]]
   }
}

Readdir

This puts all existing files in the queue directory into the queue again.

Request:

{
   "command":"readdir",
   "time":1404979588.715198,
   "sign":"Signature generated for request"

}

Answer:

{
   "result":"directory refilled queue",
   "data":{
      "stat": {
         "time interval": 0.8776118755340576,
         "queue length": 0,
         "frames per sec": 10.25510279760422,
         "images processed": 235, "pics": 9
      }
   }
}

Stat

Get basic processing statistics.

Request:

{  "command":"stat","argument":{},
   "time":1404979588.715198,
   "sign":"Signature generated for request"}

Answer:

{
"data": {
   "stat": {
      "time interval": 711.6886098384857,
      "queue length": 0,
      "frames per sec": 9.972057866165134,
      "images processed": 7332,
      "pics": 7097
      }
    },
"result": "stat"
}

Error

In case of error in the Saxsdog server it will return an error message:

{
"result":"Error",
"data":{"Error":"Error message"}
}