Elements of the NSCL acquisition system are named with Universal Resource Locators, or URIs. For the purposes of the NSCLDAQ, a URI is not really distinguishable from a URL (Universal Resource Locator). It has the form: protocol://host:port/path, or protocol://host:port
Is the means used to talk with a resource. For nscldaq this is most often tcp
Is the system that hosts the resource that is identified by the URI. The host can either be a dotted IP address, or the DNS name of a host on the network.
Identifies the resource within the host. This identification may differ depending on what the resource is. For a ring buffer, for example, the path is the name of the ring buffer.
Identifes the network port number used to contact the server that provides the resource to the network.
The URI library is a class that parses URI's and provides member functions that return the elements of a URI. Here's a trivial example of the URI library in use:
Example 51-1. Sample URI library program
#include <URL.h> #include <URIFormatException.h> #include <iostream> #include <stdlib.h> int main(int argc, char** argv) { if (argc != 2) { cerr << "Usage:\n"; cerr << " urltest URI\n"; exit(-1); } try { URL uri(argv[1]); cout << "Protocol: " << uri.getProto() << " host : " << uri.getHostName() << " path: " << uri.getPath() << " port: " << uri.getPort() << endl; } catch(CURIFormatException& error) { cerr << "URI was not valid: " << except.ReasonText() << endl; exit(-1); } exit(0); }
URL
constructor parses the
URI. If, however the URI is not valid syntax, or refers to
a host that does not exist, it will throw an
exception (CUIRFormatException
).
The construction and manipulation of the URI is therefore
wrapped in a try/catch
block.
CURIFormatException
reference page.
To incorporate the URI library into your source code, you must compile with an appropriate set of switches to allow the compiler to locat your header files, and the linker to locate the URL library both at link time and at load time. If the example program above is called urltest.cpp and if you have an environment variable DAQROOT that points to the top level directory of the NSCLDAQ install tree the command below will compile and link the program.