libPromote Documentation


written by Joey Mukherjee -
Joey@swri.org

Table of contents

  1. Overview
  2. Getting Started
  3. Choosing between the C/C++ Interface
  4. The C interface
    1. pro_InitPromote
    2. pro_AddSource
    3. pro_NeedToPromote
    4. pro_PromoteAll
    5. pro_DemoteAll
    6. pro_FreePromote
  5. The C++ interface
    1. Constructor/Destructor
    2. SetBTime/SetETime
    3. AddSource
    4. BuildDBList
    5. PromoteList
    6. DemoteAllData
    7. SetXStatus
    8. SetAutoPromoteMeta
  6. Sample Code
    1. C Code
    2. C++ Code

Overview

Promotion of data is an easily added feature of SDDAS software and this library is the way to do it. It is by no means a necessary part of any SDDAS software.

Promotion of data refers to an application retrieving the data from a remote archive server so one may analyze your data without having to retrieve the data manually.

The advantages of doing it this way is that you only retrieve the data you need. If, for instance, one wishes to analyze a bit of UARS data from 1993, you do not need to request the entire dataset of UARS, only the hour in which you are interested.

Getting Started...

First, decide whether you wish to use the C or C++ interface. The C++ interface is more powerful (i.e. more things can be controlled) or the simpler C interface. Regardless of which interface you choose, you must link with libstdc++ if you are using gcc.

Furthermore, this library makes use of our typedefs so you will need to include SDDAS_types.h if you do not already. It will be automatically included when you include either libPromote.h or Promote.h.

Another thing to remember is you may only promote a single time range per Promote stucture whether you use the C or C++ interface. If you want to promote multiple time ranges, you must create multiple Promote * for C++ and multiple void * structures for the C interface.

Choosing between the C and C++ Interface

Each particular interface is geared toward a different type of user. If you are familiar with C++, the C++ interface should not be anymore complex than the C one. The C one; however, is a very simple interface meant to be used with a variety of programs/programmer levels. It involves only four routines which are easily utilized in any program. The C++ makes the programmer do a little more work, but allows one to have better control over what happens. For instance, with the C++ interface the automatic meta data promote may be turned on or off, as well as multiple interfaces to similar routines.

C Interface

The C interface to libPromote is very simple and is based on a data key and a time. To use the C interface, add an "#include "libPromote.h"" in your source file. The routines are as follows:

void *pro_InitPromote (SDDAS_INT, SDDAS_INT, SDDAS_LONG,
                       SDDAS_INT, SDDAS_INT, SDDAS_LONG,
                       SDDAS_BOOL);

The first six fields are the beginning and ending times. The sequence is as follows:

  1. beginning year,
  2. beginning day,
  3. beginning millisecond,
  4. ending year,
  5. ending day,
  6. ending millisecond

Finally, the last parameter enables an X status window to appear. Send a sTrue to enable this window, or sFalse to disable it.

The value returned is a pointer to a opaque structure. You may not do anything with this pointer except send it to one of the five following routines. This structure must be freed with pro_FreePromote after being called. .

void pro_AddSource (void *, SDDAS_ULONG);
The first parameter is the opaque data structure created by pro_InitPromote. The next parameter is the data key representing the source. This can be had in a number of ways. You can use either get_data_key (see IDFS Programmers Manual) or if you use either of our Source GUIs, they both return the data_key to you.

SDDAS_BOOL pro_NeedToPromote (void *);

This routine will determine whether or not you need to promote data based on the data source sent in and the time specified in the pro_InitPromote. It will return sTrue if you need to promote and sFalse if you do not.

SDDAS_BOOL pro_PromoteAll (void *);

This routine requires the pointer returned by pro_InitPromote as input and will simply promote all off-line data that you requested in the pro_InitPromote. It returns sTrue for success and sFalse for failure.

SDDAS_BOOL pro_DemoteAll (void *);

This routine requires the void pointer returned by pro_InitPromote as input and will simply demote (delete!) all on-line data that you requested in the pro_InitPromote. It returns sTrue for success and sFalse for failure.

For this routine to work, pro_PromoteAll had to be called previously. You may not call pro_DemoteAll without calling pro_PromoteAll first.

void pro_FreePromote (void *);
This simply frees the structure that was generated by pro_InitPromote. You may call this routine anytime after pro_InitPromote provided pro_InitPromote did not return a NULL. Once you call this routine, you may no longer call pro_PromoteAll or pro_DemoteAll.

C++ Interface

To use the C++ interface, add "#include "Promote.h"." This will initialize the Promote object. The more complex C++ interface is as follows:

    Promote ();
    virtual ~Promote ();
The usual constructor/destructor. These will initialize/free the data structure so the compiler will call these automatically.

There are multiple ways to set the time depending on your needs and the data that you have available to you. The SetBTime is for the beginning time and the SetETime is for the ending time.

    void SetBTime (SDDAS_INT, SDDAS_INT, SDDAS_LONG);  
    void SetETime (SDDAS_INT, SDDAS_INT, SDDAS_LONG);  

This first way requires the year, the day, and the millisecond of the day for data access.

    void SetBTime (SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_LONG = 0);
    void SetETime (SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_INT, SDDAS_LONG = 0);
The second way requires the year, day, hour, minute, second, and millisecond of the day for the data you wish to access. You are encouraged to make use of this routine rather than making the computation yourself. The last parameter is for millisecond and is an optional parameter. If you do not specify a millisecond to use, zero will be used.

Note: You need call only one set of routines (or you may mix/match them although this is not recommended).

    void AddSource (SDDAS_ULONG);
    void AddSource (char *, char *, char *, char *, char *);

There are two ways of specifying a source(s) using AddSource. Either send in the data key, or send in the string names (i.e. "UARS", "UARS-1", "PEM", "HEPS", "HPSA"). Also, this routine is "adding" sources to a list so you may add as many sources to this list as you like by calling this routine multiple times with different data keys or string names.

    SDDAS_INT BuildDBList (int, StatusType, int = 1000);

BuildDBList is the routine needed to build a list of items to promote. You must call this routine after setting the time and the sources. The first parameter is one of the following flags or a combination of the following created by OR'ing their values together:

The second parameter is one of the following flags and refers to what "state" of data to build a list :

The third parameter is optional and specifies the maximum number of entries to promote. The default is 1000 which is a pretty sizable number. Anything more than that and you might find a better way to get the data; however, this parameter can be changed.

Return Values:

    SDDAS_BOOL PromoteList ();

PromoteList will promote the list generated by BuildDBList; thus, it must be called after all the previous routines have been called. It will promote all the off-line data that was generated by the BuildDBList call. PromoteList will return a sTrue on success and an sFalse on failure.

    SDDAS_BOOL DemoteAllData (SDDAS_BOOL);

After the data has been promoted and you have finished using it, you may demote (delete!) all the data which has been promoted. PromoteList will return a sTrue on success and a sFalse on failure.

The parameter on the DemoteAllData signifies whether the data that is to be demoted is to be deleted regardless of whether or not the data was promoted. The default is sFalse which means the data will only be deleted if it was previously promoted. Sending an sTrue means delete the data regardless. This can be dangerous so be careful!

The following routines are all completely optional and need to be called only if necessary.

    void SetXStatus (XStatusType);

SetXStatus can turn on or off the X promotion status window. The default is OFF. Send SetXStatus either ON or OFF as input.

    void SetAutoPromoteMeta (SDDAS_BOOL);

SetAutoPromoteMeta will make the promote automatically promote some meta data if it does not exist. The default is to promote the meta data. Send SetAutoPromoteMeta either sTrue to promote the meta data or sFalse to not promote it.

Sample Code

This code demonstrates promoting some data for UARS HPSA data from 1991.

C Code


#include 
#include "libbase_idfs.h"
#include "libPromote.h"

int main (int argc, char *argv[])
{

    SDDAS_ULONG data_key1, data_key2;
    void *promo_struct;

    CfgInit ();              /* Initialize the database */

/* Determine our data keys */

    get_data_key ("UARS", "UARS-1", "PEM", "HEPS", "HPSA", &data_key1);
    get_data_key ("UARS", "UARS-1", "PEM", "VMAG", "VMMA", &data_key2);

/* Initialize our promotion structure */

    promo_struct = pro_InitPromote (1993, 191, 28800,
                                    1993, 191, 50400,
                                    sFalse);

/* Add our sources */

    pro_AddSource (promo_struct, data_key1);
    pro_AddSource (promo_struct, data_key2);

/* Promote the data if necessary */

    if (pro_NeedToPromote (promo_struct) == sTrue) {
        pro_PromoteAll (promo_struct);

/* do something with data in here */

        pro_DemoteAll (promo_struct);
    }

/* Free our promotion structure */

    pro_FreePromote (promo_struct);

/* Free the database info */

    CfgTerm ();
    exit (0);
}

C++ Code


#include "Promote.h"

int main ()
{
    Promote *P;

    CfgInit ();                 // Initialize CFG files
    P = new Promote ();
    P->SetXStatus (ON);         // default is off

    P->AddSource ("UARS", "UARS-1", "PEM", "HEPS", "HPSA");
    P->SetBTime (1993, 191, 8, 0, 0);
    P->SetETime (1993, 191, 14, 0, 0);

    if (P->BuildDBList (_I_FILE_ | _HD_FILE_ | _P_FILE_, OFFLINE) > 0) {
        P->PromoteList ();

// do something with data

        P->DemoteAllData ();
        delete P;
    }
    CfgTerm ();
    exit (0);
}