Frame Library (Fr)
User's Manual
VIR-MAN-LAP-5400-103
Version 6.20
March 15, 2006


Summary:

Introduction
A quick tour of the Library: The examples
The Frame Utilities: FrCopy, FrDump and FrCheck
Reference Part
 
Library control FrAdcData FrSimData
Frame Handling FrDetector FrSimEvent
Input File: FrFileI FrEvent FrStatData
Output File: FrFileO FrHistory FrSummary
File checksum FrMsg FrTable
Error Handling FrProcData FrVect
FrSerData FrFilter
The Matlab interface
The ROOT interface
The Octave interface
The Python interface
The Frame Library Installation
Library Changes

Introduction

The C structures used by The Frame Library


A quick tour of the Library: the examples

Many examples are provided with the frame library in the directory src. They have been designed to test the various parts of the library and are good starting points for a new program. The Files are:


The Frame Utilities: FrCopy, FrDump and FrCheck

To copy a (set of) frame(s): FrCopy

To dump frames: FrDump

To check a  frame file: FrCheck


Reference Part

 
Library control FrAdcData FrSimEvent
Frame Handling FrDetector FrStatData
Input File: FrFileI FrHistory FrSummary
Output File: FrFileO FrMsg FrTable
File checksum FrProcData FrEvent
Error Handling FrSerData FrVect
FrSimData

Library control

The Frame library do not need any initialization. However, you can change some of the default parameters using the following function or you can access to some information.

FrLibIni

FrLibSetLvl

FrLibVersion

FrLibVersionF

Frame Handling

 
FrameCompress, FrameMerge FrameReshape
FrameCopy, FrameRead, FrameTagXXX,
FrameDump, FrameReadN, FrameUntagXXX,
FrameDumpToBuf FrameReadRecycle FrameWrite
FrameExpand, FrameReadT FrameWriteToBuf
FrameFree, FrameReadTAdc, FrameRemoveUntaggedData
FrameFindVect FrameReadFromBuf Back to summary

FrameCompress

FrameCopy

FrameDump

FrameDumpToBuf

FrameExpand

FrameFree

FrameGetAdcSize

FrameFindXXX

FrameFindXXX

FrameMerge

FrameNew

FrameRead

FrameReadN

FrameReadTAdc, FrameReadTProc, FrameReadTSer, FrameReadTSim

FrameReadFromBuf

FrameReshapeNew, Add, End

  • Remark: The copy utility is a convenient way to change the frame size.
  • Example: See the file exampleReshape.c

    FrameSetPrefix

  • FrameTagXXX with XXX=Adc, Event, Proc, Ser, Sim, SimEvt, Stat, Sum

    void    FrameTag     (FrameH *frame, char *tag);
    void    FrameTagEvent(FrameH *frame, char *tag);
    void    FrameTagAdc  (FrameH *frame, char *tag);
    void    FrameTagProc (FrameH *frame, char *tag);
    void    FrameTagSer  (FrameH *frame, char *tag);
    void    FrameTagSim  (FrameH *frame, char *tag);
    void    FrameTagSimEvt(FrameH *frame, char *tag);
    void    FrameTagStat (FrameH *frame, char *tag);
    void    FrameTagSum  (FrameH *frame, char *tag);
    void FrameTagAdc(myframe, "Lr* SaDb2")
    will keep from the frame myframe the SaDb2 ADC and all ADC with a name starting with Lr.
  • The function FrameTag call all the other functions. It performed a 'global tag'
  • Remarks:
  • FrameUntagXXX with XXX=Adc, Event, Proc, Ser, Sim, SimEvt, Stat, Sum

    FrameRemoveUntaggedXXX with XXX=Adc, Event, Proc, Ser, Sim, SimEvt, Stat, Sum

    FrameWrite

    FrameWriteToBuf


    FrAdcData:  ADC's data manipulation

    FrAdcDataDecimate FrAdcDataDump FrAdcDataFind FrAdcDataFree

    FrAdcDataGetSize

    FrAdcDataNew and FrAdcDataNewF FrAdcDataReadT FrAdcDataSetDataValid, ..SetFShift, ...SetTOffset


    FrDetector

  • void        FrDetectorDump (FrDetector *detector, FILE *fp, int debugLvl); Dump a detector structure.
  • FrDetector *FrDetectorNew (char *name); Allocate a detector structure
  • void        FrDetectorFree (FrDetector *detector); Free a detector structure and associated data.

  • FrEvent


    Input File: FrFileI

    FrFileIDump

    FrFileIEnd: close a input file

    FrFileIGetVect, ...GetV, ...VectF, ...VectFN, ...VectD, ...VectDN:

    FrFileIGetXXXNames:

    FrFileIGetFrameInfo:

    FrFileIGetChannelList:

    FrFileIGetEventInfo and SimEventInfo:

    FrFileINew:

    FrFileINewFd

    FrFileIRewind

    FrFileISetTime

    FrFileITFirstEvt,  FrFileITLastEvt

    FrFileITStart,  FrFileITEnd

    FrFileITNextFrame


    Output File: FrFileO

    FrFileOEnd:

    FrFileONewXXX

    FrFileOPutV

    FrFileOSetMsg


    File Checksum


    FrFilter


    FrHistory

    The best way to add an history record is to used the FrFileONewH function which will set the default history record produced at each FrameWrite to the one you want. However, the FrHIstory records could be manipulated using the following functions.

    FrHistoryAdd

    FrHistoryFree


    FrMsg


    FrProcData


    FrSerData


    FrSimData

    FrSimData *simData, FILE *fp, int debugLvl);
  • Destructor: void FrSimDataFree (FrSimData *simData);
  • Find it in a frame: FrSimData *FrSimDataFind (FrameH *frame, char *name)
  • File random access (FrSimData and vector): FrSimData *FrSimDataReadT (FrFile *iFile, char *name, double gtime)
  • File random access (associated vector for one or more frame): FrVect *FrFileGetVSim (FrFile *iFile, char *name, double tStart, double length)


    FrSimEvent


    FrStatData

    A static data is a structure which may stay for more than one frame. It is written on tape only once. These data stay as long as they are valid compare to the frame time boundary, or as long there is not a new bloc of data with the same name but with an highest version number. In the case of long frames there could be several static data with the same name if they have different starting times which cover the frame duration.

    FrStatDataAdd

    FrStatDataDump

    FrStatDataFind

    FrStatDataFree

    FrStatDataFreeOne

    FrStatDataNew

    FrStatDataReadT

    FrStatDataTouch


    FrSummary


    FrTable


    FrVect: Vectors handling

    FrVectNew

                    vect = FrVectNew (FR_VECT_2S,2,512,15., "microns",512,15., "microns");

    FrVectNewTS

    FrVectNew1D

    FrVectFree

    FrVectCompress

    FrVectCopy

    FrVectCopyToF, FrVectCopyToD, FrVectCopyToI, FrVectCopyToS

    FrVectDump

    FrVectDecimate

    FrVectDecimateMin, FrVectDecimateMax

    FrVectExpand

    FrVectExtend

    FrVectFillX

    FrVectFindQ

    FrVectGetIndex

    FrVectGetTotSize

    FrVectGetValueI

    FrVectGetValueGPS

    FrVectGetValueX

    FrVectHtoC

    FrVectIsValid

    FrVectLoad

    FrVectMean

    FrVectMinMax

    FrVectRMS

    FrVectResample

    FrVectSave

    FrVectSetName

    FrVectSetUnitX

    FrVectSetUnitY

    FrVectToAudio

    FrVectZoomIn

    FrVectZoomInI

    FrVectZoomOut


    Frame Library Error Handling
    Several errors may occurs during the code execution. A typical one is the failure of the memory allocation. In this case, the functions return NULL. But when the error occurs, a default handler is called. This handler is the following:
      If the debug level (dbglvl) set by the call to FrLibIni has a value > 0 this handler print debug information on stderr and on the debug output file. This handler could be changed by the user at the initialization by calling the function:
    void FrErrorSetHandler (void (*handler) (int, char *));
    At any time the user can get the history of the errors (recorded in one string) by using the function:

    char *FrError (0," ","get history");


    The Frame Library Installation

    Copyright and Licensing Agreement:

    This is a reprint of the copyright and licensing agrement of the Frame Library:
     

    Installing the library and associated tools

    A compressed (gzip) tar file is available at http://wwwlapp.in2p3.fr/virgo/FrameL.

    To uncompress it you should type:

        tar xvf vXrYY.tar.gz

    Then use the simple scripts:

    If you run on a non standard system, you may want to change the low level I/O function calls. By default the Unix function call are used. To use the standard C FILE library you should compile the code using the option -DFRIOCFILE. To do more specific changes to the I/O you just need to change the FrIO.c file which group all those function call.

    To use a user defined compression code (compression = 255) the functions FrVectUComp and FrVectUExpand should be provided by the user and the library should be compiled with the option -DFR_USER_COMPRESSION.

    To use long long types you can compile the library with the -D FR_LONG_LONG option.

    For any questions about this software, please contact Benoit Mours (mours@lapp.in2p3.fr) or Didier Verkindt (verkindt@lapp.in2p3.fr).

    Computer requirement for The Frame Library

    The Frame software requests that the computer is at least a 32 bits computer. The Frame software writes the data in their original size and format. When reading the data on a different hardware, the frame library performed the byte swapping if needed (big-endian versus little-endian). It also expends or truncates the INT_8 variables if one machine has only 32 bits integer. The floating point variables are assumed to be always in IEEE format. The frame software (and installation scripts) has been tested on the following platforms: The Frame Library is ANSI-C code with POSIX compliance.

    Test procedure

    Once the library and the example have been installed, you can test it by running these examples. The prefix example has been replace by Fr. So to run the exampleFull, go in your machine sub directory and run FrFull. The first obvious thing to check is that the example run completely without crashing. Then some of the examples run in loop (like FrMark, FrMultiR, FrMultiW). They more designed to search for memory leak and it would be a good idea to check that the program size stay constant. Most of these tests created an frame file called test.dat. Each time this file is created, it is a good idea to run the utility FrDump with debug 1 and 2 and 3 on these file to check that the file content looks right. The suggested test sequence is:


    The Matlab interface

    Introduction

    Matlab is a popular numeric computation and visualization Software. Since the Frame library is a plain C software, the connection between frame files and Matlab is easy to set. In the FrameLib package there is a matlab directory which contains: The purpose of this interface is to provide a direct path to extract data from a frame.

    Matlab interface setting installation

    Using frextract:

    The frextract function could be called with the following arguments:

    Using frgetvect:

    The frgetvect function perform a random access in the frame file using the table of content (which of course need to be present). This function is much faster than frextract when working with large file. This function could be called with the following arguments:

    Using other Frame tools with Matlab:

    Do not forget also than you can run any Frame Utility program from Matlab by using the shell escape command ! For instance:

    ! FrDump -i ../data/test.dat

    will call the program FrDump with the argument ran.dat.

    Remark: if you call frgetvect and an exception is thrown (mexErrMsgIdAndTxt, etc), it is supposed to print its error message and dump you back to the commandline, but instead, it aborts, exiting matlab completely. To fix that, add "-fexceptions" to the build options in mgr/makegcc.


    The ROOT interface

    Introduction

    ROOT is a powerful interactive environment developed at CERN (http://root.cern.ch). Among its various tools, It provide a very nice interactive C/C++ interpreter and detailed histograms capability. In the root directory of the Frame Library you will find a few scripts and macro to use the frames in the ROOT environment.

    Frame library installation for ROOT

    Assuming that you have already installed ROOT on your computer, you need first to build a special shared library. To do that, just adapt the build script to your system. You need at least to change the path to the ROOT directory and you may need to change some of the compilation flags... Once this is done, you need to update the PATH and  LD_LIBRARY_PATH to include the FrameLib binary directory (named by your system). Then if you start root from the Fr root sub directory, it will execute the FrLogon.C which load everything you need.

    Using the Frame Library in ROOT

    Once ROOT is properly started, any Frame Library function is available as a ROOT command. Then 2 ROOT macro have been provided to build histograms out of the FrAdcData and the frame vector (FrVect). Just look at the three macro example to see what you can do. The FrVect vectors play a key role in these interactive analysis and more complex programs have been developed to provide direct interface to FFT and signal processing. See the Frv package (see http://wwwlapp.in2p3.fr/virgo/FrameL) and the Vega package (http://wwwlapp.in2p3.fr/virgo/vega). The test.dat file used by the exampleAscii.C and exampleAdc.C macros could be generated by running the FrFull example.

    ROOT macros availabe:


    The Octave interface

    Introduction

    GNU Octave www.octave.org is a high-level language, primarily intended for numerical computations. The interface frame to octave contains two routines [loadadc, loadproc] for loading ADC and PROC data from a given frame file into the Octave context.  It has great similarities with the interface to Matlab previously described.
     

    How it works?

    Here is a description of what input variables should be provided to the loading interface and what output variables are available to the user:

    LOADADC: Download an ADC signal in the Octave workspace from a given frame file.
    Usage: [adc,fs,valid,t0,timegps,unit,slope,bias]  = loadadc (fileName,[adcName[,nFrames[,first]]])
    Input parameters:

    Output parameters:


    LOADPROC: Download an PROC signal in the Octave workspace from a given frame file.
    Usage: [proc,fs,t0,timegps]  = loadproc (fileName,[procName[,nFrames[,first]]])
    Input parameters:

    Output parameters: SAVEADC: Write an ADC signal from the Octave workspace to a given frame file.
    Usage: status=saveadc(fileName,signalName,data[,fs,[t0]])
    Input parameters: Output parameters:


    SAVEPROC: Write an PROC signal from the Octave workspace to a given frame file.
    Usage: status=saveproc(fileName,signalName,data[,fs,[t0]])
    Input parameters:

    Output parameters:


    Note that this description is also available online, by typing ``help loadadc'' or ``help loadproc'' at the octave prompt.

    Test and getting started

    A test script plotframe.m is also part of the package. It uses the test framefile [test.dat] in the directory /data of the Frame Lib distribution. The script produces a plot of the first 1024 data points of the ADC signal 'Adc0', computes and plots its spectrum. This may be used as a start for learning how the interface works.


    The Python interface

    Purpose:

    This is the equivalent of the Matlab frgetvect interface.

    Remarks:

    This is still at prototype level. One difference from the Matlab version is that it always returns all 7 outputs. Also, there are no error checking at all, and rather than throwing exceptions, it will just segfault for the most part.

    Prerequisites:

    Instructions to build and test it:

    For any question about the Python interface, please contact  Nick Fotopoulos (nvf at mit.edu).


    Library Changes

    From Version 2.37 to Version 3.10

        Files written with version 2.37 can be read by version 3.10.

    From Version 3.10 to Version 3.20

    From Version 3.20 to Version 3.30

    From Version 3.30 to Version 3.40

        All files written with version 2.37 and higher can be read by version 3.40.

    From Version 3.40 to Version 3.42

        All files written with version 2.37 and higher can be read by version 3.42.

    From Version 3.42 to Version 3.50

    All files written with version 2.37 and higher can be read by version 3.50.

    From Version 3.50 to Version 3.60 (March 22, 1998)

        All files written with version 2.37 and higher can be read by version 3.60.

    From Version 3.60 to Version 3.70 (Sep 16, 1998)

        All files written with version 2.37 and higher can be read by version 3.70.

    From Version 3.70 to Version 3.71 (October 6, 1998)

        All files written with version 2.37 and higher can be read by version 3.71.

    From Version 3.71 to Version 3.72 (October 9, 1998)

        All files written with version 2.37 and higher can be read by version 3.72.

    From Version 3.72 to Version 3.73 (November 11, 1998)

        All files written with version 2.37 and higher can be read by version 3.73.

    From Version 3.73 to Version 3.74 (April 2, 1999)

        All files written with version 2.37 and higher can be read by version 3.74.

    From Version 3.73 to Version 3.75 (April 29, 1999)

        All files written with version 2.37 and higher can be read by version 3.75.

    From Version 3.75 to Version 3.80 (May 17, 1999)

        All files written with version 2.37 and higher can be read by version 3.80.

    From Version 3.80 to Version 3.81 (June 4, 1999)

        All files written with version 2.37 and higher can be read by version 3.81.

    From Version 3.81 to Version 3.82 (June 9, 1999)

    From Version 3.82 to Version 3.83 (June 15, 1999)

        All files written with version 2.37 and higher can be read by version 3.83.

    From Version 3.83 to Version 3.84 (August 23, 1999)

        All files written with version 2.37 and higher can be read by version 3r84.

    From Version 3.84 to Version 3.85 (September 11, 1999)

        All files written with version 2.37 and higher can be read by version 3r85.

    From Version 3.85 to Version 4.00 (May 1, 2000)

        All files written with version 3.40 and higher can be read with version 4.00

    From Version 4.00 to Version 4.01 (May 15, 2000)

    Most files written with version 3.40 and higher can be read with version 6.20