| 1 |
|
|---|
| 2 | The idea of the psMetadata structure is to enable two competing needs
|
|---|
| 3 | of the metadata system. The purpose of the psHash in psMetadata
|
|---|
| 4 | is to allow quick access to the string-based keys. The purpose of the
|
|---|
| 5 | psList in psMetadata is to maintain a specific order of key/value
|
|---|
| 6 | pairs. Partly, this is conceived to allows the psMetadata structure
|
|---|
| 7 | to carry the data from a FITS header in such a way that the act of
|
|---|
| 8 | reading in and writing out a single FITS header does not change the
|
|---|
| 9 | header.
|
|---|
| 10 |
|
|---|
| 11 | Some background explanation of FITS headers may help clarify this (and
|
|---|
| 12 | may help with the issues in bug #120). A FITS header is an ASCII
|
|---|
| 13 | segment which preceeds each data segment in a FITS file. The FITS
|
|---|
| 14 | header components have a required sequence for some keywords, and a
|
|---|
| 15 | set of rules governing the format. An example of a few lines are:
|
|---|
| 16 |
|
|---|
| 17 | SIMPLE = T / file does conform to FITS standard
|
|---|
| 18 | BLANK = -32768 / Value used for NULL pixels
|
|---|
| 19 | DATE-OBS= '2004-06-16' / Observation start date (yyyy-mm-dd)
|
|---|
| 20 | COMMENT ---------------- DATA BLOCK ---------------------------------
|
|---|
| 21 | COMMENT --------------- PARAMETERS FOR SUPRIME_CAM ------------------
|
|---|
| 22 | EXPTIME = 1.05 / exposure time for image
|
|---|
| 23 | COMMENT ---------------- FOO ----------------------------------------
|
|---|
| 24 |
|
|---|
| 25 | the keys in FITS headers are always <= 8 upper-case characters, and
|
|---|
| 26 | are usually followed by the = sign (the exception are the comment type
|
|---|
| 27 | of keys, which have somewhat different rules in general). The key is
|
|---|
| 28 | followed (after the =) by the value, followed in turn by an optional
|
|---|
| 29 | comment, separated by ' / '. The data values may be integers, floats,
|
|---|
| 30 | strings, and booleans (I note that we don't have boolean types in the
|
|---|
| 31 | psMetadataType enum, do we?). Keep in mind that the CFITSIO tools
|
|---|
| 32 | provide the mechanisms to read in the FITS header blocks correctly
|
|---|
| 33 | from a file and to extract the key/value/comments with correct
|
|---|
| 34 | interpretation of the formats.
|
|---|
| 35 |
|
|---|
| 36 | If we require the ability to reconstruct the original order of the
|
|---|
| 37 | metadata items in a FITS header (and we do require this), then I don't
|
|---|
| 38 | think we can drop the psList.
|
|---|
| 39 |
|
|---|
| 40 | However, in looking at the needs, it seems like we may not have
|
|---|
| 41 | defined the interaction between the hash and the ITEM_SET list quite
|
|---|
| 42 | right. For the hash, I claim we want only one entry per hash key.
|
|---|
| 43 | Unique items are no problem, the bucket.data just points to the
|
|---|
| 44 | corresponding psMetadataItem entry (and both have the same value for
|
|---|
| 45 | 'key'). For the non-unique entries, we can't have multiple hash
|
|---|
| 46 | entries with the same name. Also, we don't care about getting to a
|
|---|
| 47 | specific non-unique entry fast by the hash. Instead, there should be
|
|---|
| 48 | a single hash entry for each non-unique key which points at a
|
|---|
| 49 | psMetadataItem container with a type of 'ITEM_SET'. the list in this
|
|---|
| 50 | set would then point at the collection of all non-unique entries. On
|
|---|
| 51 | the other side, the psList entries should each point at the individual
|
|---|
| 52 | psMetadataItem entries, whether unique or not. I have drawn a picture
|
|---|
| 53 | to illustrate this. (attached).
|
|---|
| 54 |
|
|---|
| 55 | If I want add a psMetadataItem, I should do the following things:
|
|---|
| 56 |
|
|---|
| 57 | look for the key in the psHash.
|
|---|
| 58 |
|
|---|
| 59 | if it exists, does it point to an entry with type = ITEM_SET?
|
|---|
| 60 |
|
|---|
| 61 | If YES, I can add it to the end of that psList (ie, being a little
|
|---|
| 62 | sloppy, metadata->hash->bucket->data->items) as well as to the end
|
|---|
| 63 | of the psMetadata list (metadata->list).
|
|---|
| 64 |
|
|---|
| 65 | If NO, this is an error (attempt to repeat a UNIQUE entry).
|
|---|
| 66 |
|
|---|
| 67 | if such an entry does not exist, add it to metadata->hash and
|
|---|
| 68 | metadata->list.
|
|---|
| 69 |
|
|---|
| 70 | (note that this still allows me to add a psMetadataItem of type
|
|---|
| 71 | ITEM_SET which should have a NULL data value. Also note that if it
|
|---|
| 72 | should be an error to attempt to add a psMetadataItem of type
|
|---|
| 73 | ITEM_SET which already exists).
|
|---|
| 74 |
|
|---|
| 75 | To delete a unique entry by index, I can get to it from
|
|---|
| 76 | metadata->list, which gets me a unique psMetadataItem, delete the
|
|---|
| 77 | entry from the list, and then also delete the entry with that name
|
|---|
| 78 | from the metadata->hash.
|
|---|
| 79 |
|
|---|
| 80 | To delete a unique entry by name is also trivial: I get to it from the
|
|---|
| 81 | metadata->hash, then I need to find the entry in metadata->list with
|
|---|
| 82 | the same ID (not fast, requires looping over almost all entries). To
|
|---|
| 83 | delete a n
|
|---|
| 84 |
|
|---|
| 85 | To delete a non-unique entry, the SDRS says you delete all non-unique
|
|---|
| 86 | entries (not sure I agree with this!). To do this by index, I would
|
|---|
| 87 | get to the item from metadata->list. Then I would get the entry point
|
|---|
| 88 | from metadata->hash with the same name and delete everything in that
|
|---|
| 89 | container.
|
|---|
| 90 |
|
|---|
| 91 | To delete a non-unique entry by name, you need to get to the
|
|---|
| 92 | containing entry, then loop over the metadata->list and delete all
|
|---|
| 93 | entries by their ID, then delete the container in metadata->hash.
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|