IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 397


Ignore:
Timestamp:
Apr 7, 2004, 4:13:17 PM (22 years ago)
Author:
Paul Price
Message:

Small changes to psDlist explanation.
Added section in memory management about what psMyTypeAlloc
and psMyTypeFree should do. This is important to define because
of the metadata, but it probably needs some more thought.

File:
1 edited

Legend:

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

    r391 r397  
    1 %%% $Id: psLibSDRS.tex,v 1.32 2004-04-07 03:26:07 eugene Exp $
     1%%% $Id: psLibSDRS.tex,v 1.33 2004-04-08 02:13:17 price Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    487487
    488488\tbd{REF}.
     489
     490\subsubsection{Relation of Memory Management to Structures}
     491
     492In this document, we specify several C \code{struct}s.  It is expected
     493that instances of, for example, \code{struct psMyType} will be
     494constructed using \code{psMyTypeAlloc()} calls, and destructed using
     495\code{psMyTypeFree()} calls.  The allocator will allocate the required
     496memory with \code{psAlloc} and increment the appropriate
     497\code{refCounter}.  The destructor will decrement the appropriate
     498\code{refCounter} and free the memory with \code{psFree} \emph{if and
     499only if} the new value of the \code{refCounter} is zero.
     500
     501This allows the \code{psMyType} to be imported into the metadata
     502(\S\ref{sec:metadata}) without the user worrying about the details of
     503the memory allocation/deallocation.  For example:
     504
     505\begin{verbatim}
     506void psFooMetadata(psMetadata *md)
     507{
     508    psFoo *foo = psFooAlloc();
     509    (void) psMetaDataAppend(md, psMetaDataItemAlloc(PS_META_FOO,foo,"Comment","foo.bar"));
     510    (void) psFooFree(foo);
     511}
     512\end{verbatim}
     513
     514In the above case, \code{foo} is created, stuffed into the metadata,
     515and then the programmer follows the rule of ``for every \code{alloc},
     516there is an equal and opposite free'' before the function returns.
     517However, the metadata needs to carry around the \code{psFoo}, and so
     518it is important that \code{psFooFree} does not free the memory for
     519\code{foo}, but only decrements its \code{refCounter}.  Hence, at the
     520conclusion of the function, the memory pointed to by \code{foo} in the
     521course of the function remains allocated, and the corresponding
     522\code{refCounter} is 1 (specifically, the reference in the metadata).
    489523
    490524\subsection{Tracing and Logging}
     
    10161050\code{psDlist} may have changed.  The value of \code{where} specifies
    10171051if the specified data item should be placed on the front of the list
    1018 (\code{PS_DLIST_HEAD}), or at the end of the list
    1019 (\code{PS_DLIST_TAIL}).
     1052(\code{PS_DLIST_HEAD}), at the end of the list (\code{PS_DLIST_TAIL}),
     1053to add after (\code{PS_DLIST_NEXT}) or before (\code{PS_DLIST_PREV})
     1054the current element (specified by the iteration cursor), or an index
     1055that the new \code{data} should inhabit.
    10201056
    10211057A data item may be retrieved from the list with the function:
     
    23292365
    23302366\subsection{Metadata}
     2367\label{sec:metadata}
    23312368
    23322369\subsubsection{Conceptual Overview}
     
    23972434manipulation of the data should be reflected in the metadata where
    23982435appropriate.  This is always an issue of concern.  For example,
    2399 consider an image of dimensions \code{Nx, Ny}.  If a function extracts
    2400 a subraster, it must change the values of \code{Nx, Ny} to match the
     2436consider an image of dimensions \code{nX, nY}.  If a function extracts
     2437a subraster, it must change the values of \code{nX, nY} to match the
    24012438new dimensions.  What should it do to the corresponding metadata?
    24022439Clearly, it should change the corresponding value which defines
    2403 \code{Nx, Ny}.  However, it is not quite so simple: there may be other
     2440\code{nX, nY}.  However, it is not quite so simple: there may be other
    24042441metadata values which depend on those values.  These must also be
    24052442changed appropriately.  What if the metadata element points to a
     
    24142451image exposure time is a notorious example in astronomy.  Different
    24152452observatories use different header keywords (ie, metadata names) for
    2416 the same concept of the exposure time (EXPTIME, EXPOSURE, OPENTIME,
    2417 INTTIME, etc).  Any system which operates on these metadata needs to
    2418 address the issue of identifying these names.  This issue seems like an
    2419 argument for hardwiring metadata in the structure, but in fact it does
    2420 not present such a strong case.  If the metadata are hardwired, some
    2421 function will still have to know how to interpret the various names to
    2422 populate the structure.  The concept can still be localized with
    2423 generic metadata containers by including abstract metadata names
    2424 within the code which are tied to the various implementations-specific
    2425 metadata names. 
     2453the same concept of the exposure time (\code{EXPTIME},
     2454\code{EXPOSURE}, \code{OPENTIME}, \code{INTTIME}, etc).  Any system
     2455which operates on these metadata needs to address the issue of
     2456identifying these names.  This issue seems like an argument for
     2457hardwiring metadata in the structure, but in fact it does not present
     2458such a strong case.  If the metadata are hardwired, some function will
     2459still have to know how to interpret the various names to populate the
     2460structure.  The concept can still be localized with generic metadata
     2461containers by including abstract metadata names within the code which
     2462are tied to the various implementations-specific metadata names.
    24262463
    24272464\subsubsection{Metadata Representation}
     
    25102547\end{verbatim}
    25112548
    2512 The type \code{psMetaDataSet} is a container class for metadata. Note that there are
    2513 in fact \emph{two} representations of the metadata (each \code{psMetaDataItem} appears
    2514 on both).
    2515 
    2516 We are using the standard \PS{} doubly-linked list types
    2517 \code{psDlist} and \code{psHash}.  For example:
     2549The type \code{psMetaDataSet} is a container class for metadata. Note
     2550that there are in fact \emph{two} representations of the metadata
     2551(each \code{psMetaDataItem} appears on both).  The first
     2552representation employs a doubly-linked list that allows the order of
     2553the metadata to be preserved (e.g., if FITS headers are read in a
     2554particular order, they should be written in the same order).  The
     2555second representation employs a hash table which allows fast look-up
     2556given a specific metadata keyword.
     2557
     2558When we refer to ``metadata'' (especially in the case of images), we
     2559generally mean a \code{psMetaDataSet}:
     2560\begin{verbatim}
     2561typedef psMetaDataSet psMetadata;
     2562\end{verbatim}
     2563
     2564An example of the usage of the metadata APIs is as follows:
    25182565\begin{verbatim}
    25192566    for (int i = 0; i < 10; i += 5) {
     
    25742621\end{verbatim}
    25752622
    2576 It is an unfortunate fact that certain metadata keywords (such as \code{COMMENT} in a FITS header)
    2577 may be repeated with different values.  The \code{psMetaDataAppend} routine is required
    2578 to check that all metadata names are unique unless the type is qualified as \code{PS_META_NON_UNIQUE};
    2579 in this case a unique integer will be added to each name that you specify. In this case,
    2580 you may either delete individual element separately or as a complete set:
     2623It is an unfortunate fact that certain metadata keywords (such as
     2624\code{COMMENT} and \code{HISTORY} in a FITS header) may be repeated
     2625with different values.  The \code{psMetaDataAppend} routine is
     2626required to check that all metadata names are unique unless the type
     2627is qualified as \code{PS_META_NON_UNIQUE}; in this case a unique
     2628integer will be added to each name that you specify. In this case, you
     2629may either delete individual element separately or as a complete set:
    25812630\begin{verbatim}
    25822631psMetaDataItemFree(psMetaDataRemove(ms, "lang.hello.0"));
     
    25852634
    25862635\subsubsection{MetaData APIs}
     2636
     2637In this section, we explain the metadata APIs more fully.
     2638
     2639The 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
     2642support multiple types, the data being input must be a pointer, even
     2643if 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
     2645corresponding arguments following.
     2646
     2647Note that the destructor does not
    25872648
    25882649\begin{verbatim}
Note: See TracChangeset for help on using the changeset viewer.