IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 404


Ignore:
Timestamp:
Apr 8, 2004, 1:22:10 PM (22 years ago)
Author:
Paul Price
Message:

Fleshed out metadata functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r397 r404  
    1 %%% $Id: psLibSDRS.tex,v 1.33 2004-04-08 02:13:17 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.34 2004-04-08 23:22:10 price Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    489489
    490490\subsubsection{Relation of Memory Management to Structures}
     491\label{sec:free}
    491492
    492493In this document, we specify several C \code{struct}s.  It is expected
     
    24772478    const int id;                       ///< unique ID for this item
    24782479    char *restrict name;                ///< Name of item
    2479     psMetaDataType type;                ///< type of this item
    2480     psMetaDataFlags flags;              ///< flags associated with this item
     2480    psMetadataType type;                ///< type of this item
     2481    psMetadataFlags flags;              ///< flags associated with this item
    24812482    const union {
    24822483        double d;                       ///< double value
     
    24862487    } val;                              ///< value of metadata
    24872488    char *comment;                      ///< optional comment ("", not NULL)
    2488     psDlist *restrict items;            ///< list of psMetaDataItems with the same name
    2489 } psMetaDataItem;
     2489    psDlist *restrict items;            ///< list of psMetadataItems with the same name
     2490} psMetadataItem;
    24902491\end{verbatim}
    24912492
     
    24932494shows that such tags are useful.
    24942495
    2495 The \code{psMetaDataType type} entry specifies the type of the data
     2496The \code{psMetadataType type} entry specifies the type of the data
    24962497being represented; the possibilities are listed in section \ref{metadataTypes}.
    24972498
     
    25002501
    25012502The possible types of metadata are identified by the enumerated type
    2502 \code{psMetaDataType} (see also table \ref{tabMetaDataTypes}); the initial defined values are:
     2503\code{psMetadataType} (see also table \ref{tabMetaDataTypes}); the initial defined values are:
    25032504\begin{verbatim}
    25042505/** Possible types of metadata. */
    25052506typedef enum {                          ///< type of val is:
    2506     PS_META_ITEM_SET = 0,               ///< NULL; metadata is in psMetaDataType.items
     2507    PS_META_ITEM_SET = 0,               ///< NULL; metadata is in psMetadataType.items
    25072508    PS_META_FLOAT,                      ///< float (.f)
    25082509    PS_META_INT,                        ///< int (.i)
     
    25142515    PS_META_UNKNOWN,                    ///< other (.v)
    25152516    PS_META_NTYPE                       ///< Number of types; must be last
    2516 } psMetaDataType;
     2517} psMetadataType;
    25172518\end{verbatim}
    25182519
     
    25422543/** A set of metadata */
    25432544typedef struct {
    2544     psDlist *restrict list;             ///< list of psMetaDataItem
     2545    psDlist *restrict list;             ///< list of psMetadataItem
    25452546    psHash *restrict table;             ///< hash table of the same metadata
    2546 } psMetaDataSet;
    2547 \end{verbatim}
    2548 
    2549 The type \code{psMetaDataSet} is a container class for metadata. Note
     2547} psMetadata;
     2548\end{verbatim}
     2549
     2550The type \code{psMetadata} is a container class for metadata. Note
    25502551that there are in fact \emph{two} representations of the metadata
    2551 (each \code{psMetaDataItem} appears on both).  The first
     2552(each \code{psMetadataItem} appears on both).  The first
    25522553representation employs a doubly-linked list that allows the order of
    25532554the metadata to be preserved (e.g., if FITS headers are read in a
     
    25572558
    25582559When we refer to ``metadata'' (especially in the case of images), we
    2559 generally mean a \code{psMetaDataSet}:
    2560 \begin{verbatim}
    2561 typedef psMetaDataSet psMetadata;
     2560generally mean a \code{psMetadata}:
     2561\begin{verbatim}
     2562typedef psMetadata psMetadata;
    25622563\end{verbatim}
    25632564
     
    25662567    for (int i = 0; i < 10; i += 5) {
    25672568        float sqrti = sqrt(i);
    2568         psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_INT, &i, NULL, "const.%d", i));
    2569         psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_FLOAT, &sqrti, "square root", "const.sqrt%d", i));
     2569        psMetadataAppend(ms, psMetadataItemAlloc(PS_META_INT, &i, NULL, "const.%d", i));
     2570        psMetadataAppend(ms, psMetadataItemAlloc(PS_META_FLOAT, &sqrti, "square root", "const.sqrt%d", i));
    25702571    }
    2571     psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_STR, "Bonjour", "French", "lang.hello"));
     2572    psMetadataAppend(ms, psMetadataItemAlloc(PS_META_STR, "Bonjour", "French", "lang.hello"));
    25722573    /*
    25732574     * Remove a key
    25742575     */
    2575     psMetaDataItemFree(psMetaDataRemove(ms, "lang.hello"));
     2576    psMetadataItemFree(psMetadataRemove(ms, "lang.hello"));
    25762577    /*
    25772578     * Print all metadata
    25782579     */
    25792580    fprintf(stdout, "------\n");
    2580     psMetaDataSetIterator(ms);
    2581     while ((meta = psMetaDataGetNext(ms, NULL)) != NULL) {
    2582         psMetaDataItemPrint(stdout, meta, "");
     2581    psMetadataSetIterator(ms);
     2582    while ((meta = psMetadataGetNext(ms, NULL)) != NULL) {
     2583        psMetadataItemPrint(stdout, meta, "");
    25832584    }
    25842585    /*
     
    25872588    fprintf(stdout, "------\n");
    25882589    fprintf(stdout, "Looking up by name:\n");
    2589     meta = psMetaDataLookup(ms, "const.5");
     2590    meta = psMetadataLookup(ms, "const.5");
    25902591    if (meta != NULL) {
    2591         psMetaDataItemPrint(stdout, meta, "");
     2592        psMetadataItemPrint(stdout, meta, "");
    25922593    }
    25932594\end{verbatim}
    25942595
    2595 \subsubsection{Naming convention for MetaData}
    2596 
    2597 The \code{psMetaDataItem} struct includes a name.  This name should be of
     2596\subsubsection{Naming convention for Metadata}
     2597
     2598The \code{psMetadataItem} struct includes a name.  This name should be of
    25982599the form \code{name1.name2.name3}$\cdots$, e.g.\hfil\break
    25992600\null\qquad\qquad\code{IPP.phase1.ota12.biassec}.
     
    26062607
    26072608\begin{verbatim}
    2608     psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
     2609    psMetadataAppend(ms, psMetadataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
    26092610                                           "Bonjour", "French", "lang.hello"));
    2610     psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
     2611    psMetadataAppend(ms, psMetadataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
    26112612                                           "Aloha", "Hawaiian", "lang.hello"));
    2612     psMetaDataAppend(ms, psMetaDataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
     2613    psMetadataAppend(ms, psMetadataItemAlloc(PS_META_STR | PS_META_NON_UNIQUE,
    26132614                                           "Good Morning", "English", "lang.hello"));
    26142615    /*
    26152616     * Print all metadata starting "lang"
    26162617     */
    2617     psMetaDataSetIterator(ms);
    2618     while ((meta = psMetaDataGetNext(ms, "lang")) != NULL) {
    2619         psMetaDataItemPrint(stdout, meta, "");
     2618    psMetadataSetIterator(ms);
     2619    while ((meta = psMetadataGetNext(ms, "lang")) != NULL) {
     2620        psMetadataItemPrint(stdout, meta, "");
    26202621    }
    26212622\end{verbatim}
     
    26232624It is an unfortunate fact that certain metadata keywords (such as
    26242625\code{COMMENT} and \code{HISTORY} in a FITS header) may be repeated
    2625 with different values.  The \code{psMetaDataAppend} routine is
     2626with different values.  The \code{psMetadataAppend} routine is
    26262627required to check that all metadata names are unique unless the type
    26272628is qualified as \code{PS_META_NON_UNIQUE}; in this case a unique
     
    26292630may either delete individual element separately or as a complete set:
    26302631\begin{verbatim}
    2631 psMetaDataItemFree(psMetaDataRemove(ms, "lang.hello.0"));
    2632 psMetaDataItemFree(psMetaDataRemove(ms, "lang.hello"));
    2633 \end{verbatim}
    2634 
    2635 \subsubsection{MetaData APIs}
     2632psMetadataItemFree(psMetadataRemove(ms, "lang.hello.0"));
     2633psMetadataItemFree(psMetadataRemove(ms, "lang.hello"));
     2634\end{verbatim}
     2635
     2636\subsubsection{Metadata APIs}
    26362637
    26372638In this section, we explain the metadata APIs more fully.
    26382639
    2639 The allocator for \code{psMetaDataItem} returns a full
    2640 \code{psMetaDataItem} ready for insertion into the
    2641 \code{psMetaDataSet}.  It is important to note that, in order to
     2640The allocator for \code{psMetadataItem} returns a full
     2641\code{psMetadataItem} ready for insertion into the
     2642\code{psMetadata}.  It is important to note that, in order to
    26422643support multiple types, the data being input must be a pointer, even
    26432644if it is a \code{float} or \code{int}, for example.  The name of the
    2644 \code{psMetaDataItem} takes a \code{sprintf} format string, with the
     2645\code{psMetadataItem} takes a \code{sprintf} format string, with the
    26452646corresponding arguments following.
    26462647
    2647 Note that the destructor does not
     2648Note that the destructor for \code{psMetadataItem} must call the
     2649appropriate destructor for the \code{val} (recall that it is the duty
     2650of the \code{psMyTypeFree}s to decrement the \code{refCounter} and
     2651free the memory if and only if the new value of the \code{refCounter}
     2652is zero --- see \S\ref{sec:free}).
    26482653
    26492654\begin{verbatim}
    26502655/** Constructor */
    2651 psMetaDataItem *psMetaDataItemAlloc(int typeFlags, ///< type of this piece of metadata + flags
     2656psMetadataItem *psMetadataItemAlloc(int typeFlags, ///< type of this piece of metadata + flags
    26522657                                    const void *val, ///< value of new item N.b. a pointer even if the item
    26532658                                                     ///< is of type e.g. int
     
    26592664
    26602665/** Destructor */
    2661 void psMetaDataItemFree(psMetaDataItem *ms ///< piece of metadata to destroy
    2662     );
     2666void psMetadataItemFree(psMetadataItem *ms ///< piece of metadata to destroy
     2667    );
     2668\end{verbatim}
     2669
     2670
     2671The constructor for the collection of metadata, \code{psMetadata},
     2672simply returns an empty metadata container (employing the constructors
     2673for the doubly-linked list and hash table).  The destructor needs to
     2674free each of the \code{psMetadataItem}s using
     2675\code{psMetadataItemFree}.
     2676
     2677\begin{verbatim}
    26632678/** Constructor */
    2664 psMetaDataSet *psMetaDataSetAlloc(void);   ///< make a new set of metadata
     2679psMetadata *psMetadataAlloc(void);   ///< make a new set of metadata
    26652680
    26662681/** Destructor */
    2667 void psMetaDataSetFree(psMetaDataSet *ms ///< destroy a set of metadata
    2668     );
    2669 
    2670 /**** Utilities **********************************************************************/
    2671 
    2672 /// Add entry to the end of the metadata set
    2673 psMetaDataItem *psMetaDataAppend(psMetaDataSet *restrict ms, ///< Metadata set to add to
    2674                                  psMetaDataItem *restrict item ///< Metatdata to add
    2675     );
    2676 
    2677 /// delete entry from the metadata set
    2678 psMetaDataItem *psMetaDataRemove(psMetaDataSet *restrict ms, ///< Metadata set to delete from
     2682void psMetadataFree(psMetadata *md ///< destroy a set of metadata
     2683    );
     2684\end{verbatim}
     2685
     2686
     2687Items may be added to the metadata in one of two ways --- firstly, an
     2688item may be added by appending a \code{psMetadataItem} which has
     2689already been created; and secondly by directly providing the data to
     2690be appended.  In both cases, the \code{psMetadataItem} that is
     2691appended to the metadata is returned.
     2692
     2693\begin{verbatim}
     2694/// Add item to the end of the metadata
     2695psMetadataItem *psMetadataAppendItem(psMetadata *restrict md, ///< metadata to add to
     2696                                     psMetadataItem *restrict item ///< Metatdata to add
     2697    );
     2698
     2699/// Add item to the end of the metadata.  Combines psMetadataItemAlloc and psMetadataAppendItem
     2700psMetadataItem *psMetadataAppend(psMetadata *restrict md, ///< Metadata to add to
     2701                                 int typeFlags ///< type of this piece of metadata + flags
     2702                                 const void *val, ///< value of new item N.b. a pointer even if the item
     2703                                                  ///< is of type e.g. int
     2704                                 const char *comment, ///< comment associated with item
     2705                                 const char *name, ///< name of new item of metadata (may be in sprintf
     2706                                                   ///< format)
     2707                                 ...    ///< possible arguments for name format
     2708    );
     2709\end{verbatim}
     2710
     2711Items may be removed from the metadata by specifying a key.  If the
     2712key matches a metadata item, the item is removed from the metadata and
     2713returned; otherwise, \code{NULL} is returned.  If the key is not
     2714unique, then \emph{all} items corresponding to the key are removed,
     2715and the \tbd{first} item is returned.
     2716
     2717\begin{verbatim}
     2718/// delete entry from the metadata
     2719psMetadataItem *psMetadataRemove(psMetadata *restrict md, ///< metadata to delete from
    26792720                                 const char *restrict key ///< Key to delete
    26802721    );
    2681 
     2722\end{verbatim}
     2723
     2724The metadata may be iterated over by (re-)setting the iterator for the
     2725appropriate \code{psMetadata}, and getting the next item.
     2726\code{psMetadataGetNext} has the ability to match the beginning of a
     2727key, e.g., if the user only wants to iterate through
     2728\code{IPP.machines.sky} and doesn't want to bother with
     2729\code{IPP.machines.detector}.
     2730
     2731\begin{verbatim}
    26822732/// reset the iterator to the start of the list
    2683 void psMetaDataSetIterator(psMetaDataSet *ms ///< Metadata set to set iterator for
     2733void psMetadataSetIterator(psMetadata *md ///< metadata to set iterator for
    26842734    );
    26852735
    26862736/// get the next entry in the sequence
    2687 psMetaDataItem *psMetaDataGetNext(psMetaDataSet *restrict ms, ///< Metadata set to get from
     2737psMetadataItem *psMetadataGetNext(psMetadata *restrict md, ///< metadata to get from
    26882738                                  const char *restrict match ///< Match this
    26892739    );
    2690 
     2740\end{verbatim}
     2741
     2742Items may be found within the metadata by providing a key.  In the
     2743event that the key is non-unique, the first item is returned.
     2744
     2745\begin{verbatim}
    26912746/// find the metadata with the specified key
    2692 psMetaDataItem *psMetaDataLookup(const psMetaDataSet *restrict ms, ///< Metadata set to look up
     2747psMetadataItem *psMetadataLookup(const psMetadata *restrict md, ///< metadata to look up
    26932748                                 const char *restrict key ///< Key to find
    26942749    );
    2695 
     2750\end{verbatim}
     2751
     2752Metadata items may be printed to an open file descriptor, optionally
     2753pre-pending a specified string.
     2754
     2755\begin{verbatim}
    26962756/// print metadata item to the specified stream
    2697 void psMetaDataItemPrint(FILE *fd,              ///< file descriptor to write to
    2698                          const psMetaDataItem *restrict ms, ///< item of metadata to print
     2757void psMetadataItemPrint(FILE *fd,              ///< file descriptor to write to
     2758                         const psMetadataItem *restrict md, ///< item of metadata to print
    26992759                         const char *prefix        ///< print this at the beginning of each line
    27002760    );
     
    30533113    psDlist *objects;                   ///< objects derived from cell
    30543114    psImage *overscan;                  ///< bias region (subimage) of cell
    3055     psMetaDataSet *md;                  ///< Readout-level metadata
     3115    psMetadata *md;                  ///< Readout-level metadata
    30563116} psReadout;
    30573117\end{verbatim}   
     
    30813141                                        ///< image, objects and overscan.
    30823142    struct psReadout *readouts;         ///< Readouts from the cell
    3083     psMetaDataSet *md;                  ///< Cell-level metadata
     3143    psMetadata *md;                  ///< Cell-level metadata
    30843144
    30853145    psCoordXform *cellToChip;           ///< Transformations from cell coordinates to chip coordinates
     
    31113171    psCell *cells;                      ///< Cells in the Chip
    31123172
    3113     psMetaDataSet *md;                  ///< Chip-level metadata
     3173    psMetadata *md;                  ///< Chip-level metadata
    31143174    psCoordXform *chipToFPA;            ///< Transformations from chip coordinates to FPA coordinates
    31153175    psCoordXform *FPAtoChip;            ///< Transformations from FPA coordinates to chip
     
    31473207    psChip *chips;                      ///< Chips in the Focal Plane Array
    31483208
    3149     psMetaDataSet *md;                  ///< FPA-level metadata
     3209    psMetadata *md;                  ///< FPA-level metadata
    31503210    psDistortion *TPtoFP;               ///< Transformation term from
    31513211    psDistortion *FPtoTP;               ///< Transformation term from
Note: See TracChangeset for help on using the changeset viewer.