KID |
KID, or KLOE Integrated Dataflow, is the main interface to the data handling system. Its main advantage is its ease of use; it allows the user to access one or more data sources by means of a one line URI (Uniform Resource Identifier).
The KID library is a generic interface to the KLOE data sources. The base library does not have any predefined access method and relies totally on the plug-ins.
[ | The URI paradigm | , | The C user interface | , | The FORTRAN user interface and the AC module | , | The plug-in interface | ] |
The KID library access the KLOE data sources my means of URIs. A URI is a one line text string, composed of a protocol, followed by the protocol specific data.
The KID library splits the given URI between the two parts; the protocol is used to identify the desired plug-in module, while the remaining part is sent untouched to the module functions. From this point on, all the calls to the KID library functions will be redirected to the corresponding functions of the plug-in module.
The end-user-oriented C interface of the KID library is quite similar to the ordinary file access library; the user has to open a data source, read-out the data until it has enough or it gets to the end, and finally it closes the data source. The KID library is a little bit more flexible since it have several open and read functions, but all-in-all the concept is the same. Most of the functions return an error code, with KID_IN_ERROR_OK meaning no error:
open functions
kid_in_open(URI,*handle)
The
classical open function. Given an URI, a handle is returned, if no
error occurred. This handle is then used for all successive calls
to the KID library.
kid_in_try_open(URI,*handle)
Similar
to the kind_in_open, but do not return an error if it cannot open
the source given in the URI. Instead, the returned handle is valid,
but marked as closed.
kid_in_reopen(handle)
This
function closes an existing handle and reopens it with the original
URI.
kid_in_switch(handle,URI)
Same
as kid_in_reopen, bur reopens the handle with a new URI.
readout functions
kid_in_get_dynamic(handle,*event_ptr,*event_size)
Return
an event in a newly allocated buffer; if the event is not
immediately available, KID_IN_ERROR_EMPTY is returned. While very
easy to use, it is a little bit inefficient due to massive use of
malloc. Moreover, the caller must free the given buffer.
kid_in_get_static(handle,event_ptr,*event_size/buffer_size)
Like
the previous one, but here is the user to be responsible to
preallocate a buffer big enough for the event it is about to get.
If the buffer is not big enough, KID_IN_ERROR_SIZE is returned
together with the event size.
kid_in_get_reference(handle,*event_ptr,*event_size)
Return
the pointer to the internal buffers where the event can be found;
if the event is not immediately available, KID_IN_ERROR_EMPTY is
returned. While very efficient, the returned buffer can
be overwritten at the next call to any KID function on the same
handler, and must be used with care!
kid_in_skip(handle,*nr_events)
Try
to skip the specified number of events and return the number of
really skipped ones.
kid_in_is_open(handle)
Check
if the handler is open. Returns a boolean value.
the close function
kid_in_close(handle)
Close
and invalidate the handle.
configuration functions
The KID library has
several configuration functions. They are not yet documented.
An example of use:
char *uri = "spydaq:ALL";
const int maxevents = 10000;
int err;
int buflen;
KID_IN_id kid_in_id;
err=kid_in_open(uri,&kid_in_id);
if (err!=KID_IN_ERROR_OK) return 1; /* error */
for(i=0; i<maxevents; i++)
{
int buflen;
const kevent *buffer;
do {
err = kid_in_get_dynamic(kid_in_id,&buffer,&buflen);
if (err==KID_IN_ERROR_EMPTY) sleep(1);
else break;
} while(1);
if (err==KID_IN_ERROR_CLOSED) break; /* no more events */
if (err!=KID_IN_ERROR_OK) {
printf("URL error at %i (%s)\n",i,ErrorGetMessage());
break;
}
/* use the buffer */
free(buffer);
}
kid_in_close(kid_in_id);
For more examples, see the function pages.
The end-user-oriented FORTRAN interface of the KID library has fewer functionalities than the C library, but on the other side, the available functions are more powerful. They are meant to be easy to use rather than extremely flexible:
open functions
kid_in_f_open(uri,uri_len,handle)
The
classical open function. Given an URI, a handle is returned, if no
error occurred. This handle is then used for all successive calls
to the KID library.
kid_in_f_open_extended(uri,uri_len,handle)
Like
the one above, but prepends “ybos:” to the URI, if no protocol
is found.
kid_in_f_reopen(handle)
This
function closes an existing handle and reopens it with the original
URI.
readout functions
kid_in_f_get_el(handle,buffer,len)
If
an event is available and the buffer given is big enough, an event
is returned in the buffer. If an event is not readily available,
KID_IN_ERROR_EMPTY is returned. If the buffer is not big enough,
KID_IN_ERROR_SIZE is returned together with the event size.
kid_in_f_get_retry(handle,buffer,len,nr_retires)
Like
the previous one, but retry up to nr_retries times (waiting
up to 10ms between retries) if an event is not yet ready. If
nr_retries<0, will wait forever if needed.
kid_in_f_get_timeout(handle,buffer,len,timeout_seconds)
Like
the previous one, will retry up to timeout_seconds seconds.
If timeout_seconds<0, will wait forever if needed.
kid_in_f_get_decoded_el(handle,buffer,len)
kid_in_f_get_decoded_retry(handle,buffer,len,nr_retires)
kid_in_f_get_decoded_timeout(handle,buffer,len,timeout_seconds)
Same
as the above ones, but unpacks the banks if needed.
the close function
kid_in_f_close(handle)
Close
and invalidate the handle.
configuration functions
Not documented yet.
The FORTRAN interface has been used to create an Analysis Control (AC) input module, named KIDIN. This input module allows to access the KLOE data using the input url AC command, in addition to the usual input file. Here are two examples of use:
input file “../data/myfile.ybos”
|
input url “spydaq:ALL”
|
To create a new module, the programmer is required to implement a module specific version of all the open, readout and close functions listed in the C user interface section. At this point, the functions must be registered to the KID library, together with the selected protocol string, using the kid_in_module_add function. From that point on, the KID library will redirect the calls to the registered functions every time the specified protocol is present in a URI.
While the basic KID library gives a good starting point, without some plug-in modules it is useless. Reallizing that, the KID package comes equipped with a rich set of read-to-use plug-in modules.
The standard modules can be divided in:
local file access
ybos
This module allows to access a locally
visible YBOS file.
local circular buffer access
spy
This module allows to access a local
circular buffer.
remote access
remote
This module allows to access a KID
resource on a remote machine.
data handling assisted file access
dbfile
This module allows to access a file
known to the data handling system. If needed, the required file is
automatically moved to a recall disk area.
dbraw
Like the previous one, but the request
is the where part of a query on the logger.raw_data table.
dbdatarec
Like the previous one, but the
request is the where part of a query on the logger.datarec_data
table.
dbmc
Like the previous one, but the request
is the where part of a query on the logger.mc_data table.
fastraw
fastdatarec
fastmc
Like the
previous three modules, but the query is limited to the files
already on a disk pool.
db
Like the previous ones, but a full query
is required.
DAQ specific module
spydaq
This module gets data from all the
DAQ farm nodes running the specified L3 filter.
glue modules
a dummy module
dummy
The dummy module never returns an
event. Can be used for test purposes.
For more details, see the module specific pages.
Since the standard modules are not part of the base KID library, the programmer must explicitly register them; this is accomplished by a call to the kid_in_stdmodules_init function.
Since the standard modules are not part of the base KID library, the programmer must explicitly register them; this is accomplished by a call to the kid_in_f_init function.
The AC input module KIDIN is already configured to register the standard modules, so it can be used as is.
Most of the time, both the basic KID library and the standard plug-in modules are needed, so only this scenario is presented.
Include files:
kid_in.h
kid_in_stdmodules.h
Compile time options:
-I${COMMONSRC} -I${KDATASRC}/inc -I${KIDSRC}/inc
Link time options:
${KID_IN_STDLIBS} -L${KIDBIN} -lkid -L${KDATABIN} -lkdata -L${COMMONBIN} -lCommon -lm
Link time options with pthreads:
${KID_IN_STDLIBS_PT} -L${KIDBIN} -lkid_pt -L${KDATABIN} -lkdata -L${COMMONBIN} -lCommon_pt -lm
Include files:
KIDF77INC:im_kidin.inc
Link time options:
${KIDF77LIBS} -L${COMMONBIN} -lCommon -lm
The following line must be put in the build_job uic:
Dictionary KIDF77INC:im_kidin.dict
The following option must be added to the link_ana opt file:
${KIDF77LIBS}
Send comment to Igor Sfiligoi.