Frame Library (Fr)
User's Manual
VIR-MAN-LAP-5400-103
Version 4.53
May 2, 2002


Summary:

Introduction
A quick tour of the Library: The examples
The Frame Utilities: FrCopy, FrDump and FrCheck
Reference Part
 
Library control FrAdcData FrSimEvent
Frame Handling FrDetector FrStatData
Input File: FrFileI FrHistory FrSummary
Output File: FrFileO FrMsg FrTable
File checksum FrProcData FrTrigData
Error Handling FrSerData FrVect
FrSimData
The Matlab interface
The ROOT interface
The Octave 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 FrTrigData
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


Frame Handling

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

FrameCompress

FrameCopy

FrameDump

FrameDumpToBuf

FrameExpand

FrameFree

FrameGetV

FrameMerge

FrameNew

FrameRead

FrameReadN

FrameReadRecycle

FrameReadT

FrameReadTAdc, FrameReadTProc, FrameReadTSer, FrameReadTSim

FrameReadTChnl

FrameReadFromBuf

FrameReshapeNew, Add, End

  • Remark: The copy utility is a convenient way to change the frame size.
  • Example: See the file exampleReshape.c
  • FrameTagXXX with XXX=Adc, Ser, Sim, Sum, Proc, Trig

    void    FrameTag     (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    FrameTagSum  (FrameH *frame, char *tag);
    void    FrameTagTrig (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 function. It performed a 'global tag'
  • Remarks:
  • FrameUntagXXX with XXX=Adc, Ser, Sim, Sum, Proc, Trig

    FrameWrite

    FrameWriteToBuf


    FrAdcData:  ADC's data manipulation

    FrAdcDataDecimate FrAdcDataDump FrAdcDataFind FrAdcDataFree FrAdcDataGetV FrAdcDataNew and FrAdcDataNewF

    See Also

    FrAdcDataReadT


    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.

  • Input File: FrFileI

    FrFileIDump

    FrFileIEnd: close a input file

    FrFileIGetV:

    FrFileIGetVAdc, FrFileIGetSim, FrFileIGetProc:

    FrFileINew:

    FrFileINewFd

    FrFileIRewind

    FrFileITStart,  FrFileITEnd


    Output File: FrFileO

    FrFileOEnd:

    FrFileONewXXX

    FrFileOSetMsg


    File Checksum


    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

  • These functions have the same meaning as for the FrAdcData structure:
  • Constructor: FrProcData *FrProcDataNew (FrameH *frame, char *name, double sampleRate, int nData, int nBits);
  • Dump:  void FrProcDataDump (FrProcData *procData, FILE *fp, int debugLvl);
  • Destructor: void FrProcDataFree (FrProcData *procData);
  • Find it in a frame: FrProcData *FrProcDataFind (FrameH *frame, char *name)
  • Find the associated vector in a Frame: FrVect *FrProcDataGetV (FrameH *frameH, char *name);
  • File random access (FrProcData and vector): FrProcData *FrProcDataReadT (FrFile *iFile, char *name, double gtime)
  • File random access (associated vector for one or more frame): FrVect *FrFileGetVProc (FrFile *iFile, char *name, double tStart, double length)

  • FrSerData


    FrSimData

  • These functions have the same meaning as for the AdcData structure:
  • Constructor: FrSimData *FrSimDataNew (FrameH *frame, char *name, double sampleRate, int nData, int nBits);
  • Dump:  void FrSimDataDump (FrSimData *simData, FILE *fp, int debugLvl);
  • Destructor: void FrSimDataFree (FrSimData *simData);
  • Find it in a frame: FrSimData *FrSimDataFind (FrameH *frame, char *name)
  • Find the associated vector in a Frame: FrVect *FrSimDataGetV (FrameH *frameH, 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

  • Unless specified, these functions have the same meaning as for the AdcData structure:
  • Constructor: FrSimEvent *FrSimEventNew (FrameH *frameH,  char *name, char *comment, char *inputs, unsigned int GTimeS, unsigned int GTimeN,  float timeBefore, float timeAfter, float amplitude); It is advised to put extra event parameters in the string "comment" as a sequence of names and values.
  • Dump:  void FrSimEventDump (FrSimEvent *simEvent, FILE *fp, int debugLvl);
  • Destructor: void FrSimEventFree (FrSimEvent *simEvent);
  • Find it in a frame: FrSimEvent *FrSimEventFind (FrameH *frame, char *name, FrSimEvent *last). Since there could be more than one FrSimEvent with the same name in one single frame, the "last' parameters is used to make the selection. This function will return the next FrSimEvent structure following the last structure in the linked list and matching the "name". If last = NULL, the function returns the first found structure.
  • File random access (FrSimEvent and vector):  FrSimEvent *FrSimEventReadT (FrFile *iFile, char *name, double tStart,  double length); This function perform a random read access on the file *iFile. It returns all (as a link list) FrSimEvent structure which have a time between tStart and tStart+length. It returns also the associated vector (if any) but not the associated tables. The string name could contain several names and wild card. The function returns a pointer to the first FrSimEvent structure of the linked list or NULL in case of error (frame not in file, not Table Of Content, malloc failed).

  • 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

  • This function add a static data bloc.

  • void        FrStatDataAdd (FrDetector *detector, FrStatData *sData);

    FrStatDataFind

    FrStatDataFree

    FrStatDataNew

    FrStatDataTouch


    FrSummary

  • Unless specified, these functions have the same meaning as for the AdcData structure:
  • Constructor: FrSummary *FrSummaryNew (FrameH *frame, char *name, char *comment, char *test, FrVect *moments, FrTable *table);
  • Dump:  void FrSummaryDump (FrSummary *summary, FILE *fp, int debugLvl);
  • Destructor: void FrSummaryFree (FrSummary *summary);
  • Find it in a frame: FrSummary *FrSummaryFind (FrameH *frame, char *name).
  • File random access (FrSimEvent and vector):  FrSummary *FrSummaryReadT (FrFile *iFile, char *name, double tStart,  double length); This function perform a random read access on the file *iFile. It returns all (as a link list) FrSummary structure which have a time between tStart and tStart+length. It returns also the associated vector (if any) but not the associated tables. The string name could contain several names and wild card. The function returns a pointer to the first FrSummary structure of the linked list or NULL in case of error (frame not in file, not Table Of Content, malloc failed).

  • FrTable


    FrTrigData


    FrVect: Vectors handling

    FrVectNew

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

    FrVectNewTS

  • This function creates a one dimension time serie vector. Like for an FrAdcData, the vector type is set according the number of  bit (integer for positive values, float or double for negative value)
  • Syntax: FrVect *FrVectNewTS (char *name,  double sampleRate, int nData, int nBits)
  • The parameters (provided by the user) are:
  • FrVectNew1D

    FrVectFree

    FrVectCopy

    FrVectDump

    FrVectDecimate

    FrVectCompress

    FrVectExpand

    FrVectFillX

    FrVectFindQ

    FrVectIsValid

    FrVectMinMax


    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:
     
    /*----------------------------------------------- FrErrorDefHandler---*/
    void FrErrorDefHandler(level,lastMessage)
    int level;
    char *lastMessage;
    /*--------------------------------------------------------------------*/
    /* default handler for the FrameLib error. */
    /* input parameters: */
    /* lastMessage: the string which contain the last generated message */
    /* level: 2 = warning, */
    /* 3 = fatal error: requested action could not be completed*/
    /*--------------------------------------------------------------------*/
    {
    if(FrDebugLvl > 0)
    {fprintf(FrFOut,"%s",lastMessage);
    fprintf(stderr,"%s",lastMessage);}
    return;}
    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

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

    To uncompress it you should type:

    gunzip v4rXX.tar.gz
    tar xvf v4rXX.tar

    Then you could either

    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.

    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

      The first operation to set the MEX-file is to compile it. This is done using the script mymex (just type ./mymex from the matlab directory).

    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 will be 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.


    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 system, 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:


    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 root/ 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.
    For any question about the Octave interface, please contact  Eric Chassande-Mottin (ecm@obs-nice.fr)


    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)

  • Code cleaning in the FrCopy and FrDump utilities.
  • Fix a bug in FrAdcDataNew when creating ADC?s with floating point values.
  • Add a protection for bad arguments in FrAdcDataFind and FrSerDataFind in
  •     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)

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

    From Version 4.01 to Version 4.02 (May 21, 2000)

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

    From Version 4.02 to Version 4.03 (June 2, 2000)

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

    From Version 4.03 to Version 4.10 (October 11, 2000)

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

    From Version 4.10 to Version 4.11 (October 23, 2000)

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

    From Version 4.11 to Version 4.20 (December 7, 2000)

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

    From Version 4.20 to Version 4.21 (December 8, 2000)

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

    From Version 4.21 to Version 4.22 (December 12, 2000)

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

    From Version 4.22 to Version 4.23 (Jan 16, 2001)

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

    From Version 4.23 to Version 4.30 (Feb. 08, 2001)

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

    From Version 4.30 to Version 4.31 (Feb. 27, 2001)

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

    From Version 4.31 to Version 4.40 (July  11, 2001)

    Thanks to Isidoro Ferrante, Martin Hewitson,  Julien Ramonet, Andrei Sazonov, Peter Shawhan, Didier Verkindt and Andrea Vicere for finding and reporting bugs. All files written with version 3.40 and higher can be read with version 4.40

    From Version 4.40 to Version 4.41 (July  31, 2001)

    Thanks to Sam Finn, Frederique Marion and Peter Shawhan for finding and reporting problems and bugs. All files written with version 3.40 and higher can be read with version 4.41

    From Version 4.41 to Version 4.42 (Sept 19, 2001)

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

    From Version 4.42 to Version 4.43 (Oct 15, 2001)

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

     From Version 4.43 to Version 4.44 (Nov 14, 2001)

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

    From Version 4.44 to Version 4.50 (March 13, 2002)

    Thanks to Damir Buskulic, Eric Chassande-Mottin, Ed Daw, Martin Hewitson, Frederique Marion  Alain Masserot, Peter Shawhan and Didier Verkindt for suggestions, finding and reporting problems and bugs. All files written with version 3.40 and higher can be read with version 4.50

    From Version 4.50 to Version 4.51 (March 18, 2002)

    Thanks to Andrei Sazonov,  Peter Shawhan and Didier Verkindt for suggestions, finding and reporting problems and bugs.

    From Version 4.51 to Version 4.52 (March 20, 2002)

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

    From Version 4.52 to Version 4.53 (May 2, 2002)

    Thanks to Damir Buskulic, Jean-Marie Teuler and Didier Verkindt for suggestions, finding and reporting problems and bugs. All files written with version 3.40 and higher can be read with version 4.50