IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 7, 2007, 2:31:50 PM (19 years ago)
Author:
Paul Price
Message:

Adding automatically-generated skycell pseudo-cameras, constructed from the user-defined cameras. This gives a couple of benefits: (1) skycells inherit the recipes of their original camera; (2) skycells use the same FILERULES as their original camera.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r13669 r13704  
    9393}
    9494
    95 // define a pmFPAfile, bind to the optional fpa if supplied
    96 pmFPAfile *pmFPAfileDefineOutput(const pmConfig *config, pmFPA *fpa, const char *name)
    97 {
    98     PS_ASSERT_PTR_NON_NULL(config, NULL);
    99     PS_ASSERT_PTR_NON_NULL(config->files, NULL);
    100     PS_ASSERT_PTR_NON_NULL(config->camera, NULL);
    101     PS_ASSERT_STRING_NON_EMPTY(name, NULL);
    102 
     95// Define an output pmFPAfile
     96static pmFPAfile *fpaFileDefineOutput(const pmConfig *config, // Configuration
     97                                      pmFPA *fpa, // Optional FPA to bind
     98                                      const char *name, // Name of file rule
     99                                      const char *cameraName, // Name of camera configuration to use
     100                                      const char *formatName // Name of camera format to use
     101    )
     102{
    103103    bool status;
    104104
    105105    // select the FILERULES from the camera config
    106     psMetadata *filerules = psMetadataLookupPtr (&status, config->camera, "FILERULES");
     106    psMetadata *filerules = psMetadataLookupPtr(&status, config->camera, "FILERULES");
    107107    if (filerules == NULL) {
    108108        psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!");
     
    112112    // select the name from the FILERULES
    113113    // check for alias name (type == STR, name is aliased name)
    114     const char *realname = psMetadataLookupStr (&status, filerules, name);
     114    const char *realname = psMetadataLookupStr(&status, filerules, name);
    115115    if (!realname || strlen(realname) == 0) {
    116116        realname = name;
     
    123123    }
    124124
    125     pmFPAfile *file = pmFPAfileAlloc ();
     125    pmFPAfile *file = pmFPAfileAlloc();
    126126
    127127    // save the name of this pmFPAfile
    128     file->name = psStringCopy (name);
    129 
    130     file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));
    131 
    132     const char *type = psMetadataLookupStr (&status, data, "FILE.TYPE");
     128    file->name = psStringCopy(name);
     129
     130    file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, data, "FILENAME.RULE"));
     131
     132    const char *type = psMetadataLookupStr(&status, data, "FILE.TYPE");
    133133    file->type = pmFPAfileTypeFromString(type);
    134134    if (file->type == PM_FPA_FILE_NONE) {
     
    153153    }
    154154
    155     psMetadata *camera;                 // Camera to use
    156     if (fpa && fpa->camera) {
    157         camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file
     155    // Use the camera we were told to, the camera of the provided FPA, or default to the default camera
     156    psMetadata *camera;                 // Camera configuration
     157    if (!cameraName || strlen(cameraName) == 0) {
     158        if (fpa && fpa->camera) {
     159            camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file
     160        } else {
     161            camera = config->camera;
     162        }
    158163    } else {
    159         camera = config->camera;
     164        bool mdok;                      // Status of MD lookup
     165        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Known cameras
     166        if (!mdok || !cameras) {
     167            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     168            return NULL;
     169        }
     170        camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest
     171        if (!mdok || !camera) {
     172            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
     173                    "camera configuration %s in site configuration.\n", cameraName);
     174            return NULL;
     175        }
     176
     177        if (fpa && fpa->camera && fpa->camera != camera) {
     178            psAbort("Camera of bound FPA is not the requested camera --- there is an inconsistency!");
     179        }
    160180    }
    161181    file->camera = psMemIncrRefCounter(camera);
    162182
    163     // select the format list from the selected camera
    164     const char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT");
    165     if (!formatName || strcmp(formatName, "NONE") == 0) {
    166         // Try to get by with the default
    167         formatName = config->formatName;
     183    // Use the format we were told to, the format specified in the file rule, or default to the default format
     184    if (!formatName || strlen(formatName) == 0) {
     185        // select the format list from the selected camera
     186        formatName = psMetadataLookupStr(&status, data, "FILE.FORMAT");
     187        if (!formatName || strcmp(formatName, "NONE") == 0) {
     188            // Try to get by with the default
     189            formatName = config->formatName;
     190        }
    168191    }
    169192    psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats
     
    177200    file->format = psMemIncrRefCounter(format);
    178201
    179     file->fpa = psMemIncrRefCounter(fpa);
     202    if (fpa) {
     203        file->fpa = psMemIncrRefCounter(fpa);
     204    } else {
     205        file->fpa = pmFPAConstruct(file->camera);
     206    }
    180207
    181208    file->fileLevel = pmFPAPHULevel(format);
     
    219246}
    220247
     248// define a pmFPAfile, bind to the optional fpa if supplied
     249pmFPAfile *pmFPAfileDefineOutput(const pmConfig *config, pmFPA *fpa, const char *name)
     250{
     251    PS_ASSERT_PTR_NON_NULL(config, NULL);
     252    PS_ASSERT_PTR_NON_NULL(config->files, NULL);
     253    PS_ASSERT_PTR_NON_NULL(config->camera, NULL);
     254    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     255
     256    return fpaFileDefineOutput(config, fpa, name, NULL, NULL);
     257}
    221258
    222259// search for argname on the config->argument list
     
    245282    psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname);
    246283    if (!status) {
    247         if (success) *success = true;
     284        if (success) *success = true;
    248285        return NULL;
    249286    }
     
    415452    if (!status) {
    416453        // this is not an error: this just means no matching argument was supplied
    417         if (success) *success = true;
     454        if (success) *success = true;
    418455        return NULL;
    419456    }
     
    545582    if (!status) {
    546583        psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname);
    547         if (success) *success = true;
     584        if (success) *success = true;
    548585        return NULL;
    549586    }
     
    679716        // don't free the file here: it is left on config->files
    680717        // to be used optionally by pmFPAfileDefineFromDetDB (or others)
    681         if (success) *success = true;
     718        if (success) *success = true;
    682719        return NULL;
    683720    }
     
    908945}
    909946
     947pmFPAfile *pmFPAfileDefineSkycell(const pmConfig *config, pmFPA *fpa, const char *filename)
     948{
     949    PS_ASSERT_PTR_NON_NULL(config, NULL);
     950    PS_ASSERT_STRING_NON_EMPTY(filename, NULL);
     951    PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL);
     952    PS_ASSERT_STRING_NON_EMPTY(config->formatName, NULL);
     953
     954    pmFPAfile *file;                    // The new file
     955
     956    if (config->cameraName[0] == '_' &&
     957        strcmp(config->cameraName + strlen(config->cameraName) - 8, "-SKYCELL") == 0) {
     958        // The input camera is already a skycell
     959        file = fpaFileDefineOutput(config, fpa, filename, config->cameraName, "SKYCELL");
     960    } else {
     961        // Find the correct camera configuration
     962        psString cameraName = NULL;         // Name of the new (automatically-generated) camera configuration
     963        psStringAppend(&cameraName, "_%s-SKYCELL", config->cameraName);
     964
     965        file = fpaFileDefineOutput(config, fpa, filename, cameraName, "SKYCELL");
     966        psFree(cameraName);
     967    }
     968
     969    // Ensure everything is written out at the appropriate level
     970    file->fileLevel = PM_FPA_LEVEL_FPA;
     971    file->dataLevel = PM_FPA_LEVEL_FPA;
     972    file->freeLevel = PM_FPA_LEVEL_FPA;
     973
     974    return file;
     975}
     976
    910977pmFPAfile *pmFPAfileDefineChipMosaic(const pmConfig *config, pmFPA *src, const char *filename)
    911978{
     
    916983    PS_ASSERT_STRING_NON_EMPTY(config->formatName, NULL);
    917984
     985    pmFPAfile *file;                    // The new file
    918986    if (config->cameraName[0] == '_' &&
    919987        strcmp(config->cameraName + strlen(config->cameraName) - 5, "-CHIP") == 0) {
    920988        // The input camera has already been mosaicked to this level
    921         pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename);
    922         psFree (file->camera);
    923         psFree (file->format);
    924         psFree (file->fpa);
    925         file->camera = psMemIncrRefCounter(config->camera);
    926         file->format = psMemIncrRefCounter(config->format);
    927         file->fpa = pmFPAConstruct(file->camera);
    928         return file;
    929     }
    930 
    931     // Find the correct camera configuration
    932     bool mdok;                          // Status of MD lookup
    933     psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations
    934     if (!mdok || !cameras) {
    935         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
    936         return NULL;
    937     }
    938     psString name = NULL;               // Name of the new (automatically-generated) camera configuration
    939     psStringAppend(&name, "_%s-CHIP", config->cameraName);
    940     psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest
    941     if (!mdok || !camera) {
    942         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
    943                 "camera configuration %s in site configuration.\n", name);
    944         psFree(name);
    945         return NULL;
    946     }
    947     psFree(name);
    948 
    949     // Need to look up the format of the same name, but under the mosaic camera
    950     psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS
    951     if (!mdok || !formats) {
    952         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n",
    953                 config->cameraName);
    954         return NULL;
    955     }
    956     psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format
    957     if (!mdok || !format) {
    958         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n",
    959                 config->formatName, config->cameraName);
    960         return NULL;
    961     }
    962 
    963     pmFPA *fpa = pmFPAConstruct(camera);
    964     if (!fpa) {
    965         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n");
    966         return NULL;
    967     }
    968     pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename);
    969     if (!file) {
    970         psErrorStackPrint(stderr, "file %s not defined\n", filename);
    971         return NULL;
    972     }
     989        file = fpaFileDefineOutput(config, NULL, filename, config->cameraName, config->formatName);
     990    } else {
     991        psString cameraName = NULL;         // Name of the new (automatically-generated) camera configuration
     992        psStringAppend(&cameraName, "_%s-CHIP", config->cameraName);
     993
     994        // Find the correct camera configuration
     995        file = fpaFileDefineOutput(config, NULL, filename, cameraName, config->formatName);
     996        psFree(cameraName);
     997    }
     998
    973999    file->src = src; // inherit output elements from this source pmFPA
     1000
    9741001    file->mosaicLevel = PM_FPA_LEVEL_CHIP; // don't do any I/O on this at a lower level
    975 
    976     psFree (file->format);
    977     file->format = psMemIncrRefCounter(format);
    978 
    979     psFree(fpa);
    9801002
    9811003    return file;
     
    9891011    PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL);
    9901012
     1013    pmFPAfile *file;                    // The new file
    9911014    if (config->cameraName[0] == '_' &&
    9921015            strcmp(config->cameraName + strlen(config->cameraName) - 4 , "-FPA") == 0) {
    9931016        // The input camera has already been mosaicked to this level
    994         pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename);
    995         psFree (file->camera);
    996         psFree (file->format);
    997         psFree (file->fpa);
    998         file->camera = psMemIncrRefCounter(config->camera);
    999         file->format = psMemIncrRefCounter(config->format);
    1000         file->fpa = pmFPAConstruct(file->camera);
    1001         return file;
    1002     }
    1003 
    1004     // Find the correct camera configuration
    1005     bool mdok;                          // Status of MD lookup
    1006     psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations
    1007     if (!mdok || !cameras) {
    1008         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
    1009         return NULL;
    1010     }
    1011     psString original;                  // Name of the original camera configuration
    1012     psString name = NULL;               // Name of the new (automatically-generated) camera configuration
    1013     if (config->cameraName[0] == '_' &&
     1017        file = fpaFileDefineOutput(config, NULL, filename, config->cameraName, config->formatName);
     1018    } else {
     1019
     1020        psString original;                  // Name of the original camera configuration
     1021        if (config->cameraName[0] == '_' &&
    10141022            strcmp(config->cameraName + strlen(config->cameraName) - 5 , "-CHIP") == 0) {
    1015         // It's a chip mosaic; we need to get the original name
    1016         original = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6);
    1017     } else {
    1018         original = psMemIncrRefCounter(config->cameraName);
    1019     }
    1020     psStringAppend(&name, "_%s-FPA", original);
    1021     psFree(original);
    1022     psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest
    1023     if (!mdok || !camera) {
    1024         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "
    1025                 "camera configuration %s in site configuration.\n", name);
    1026         psFree(name);
    1027         return NULL;
    1028     }
    1029     psFree(name);
    1030 
    1031     // Need to look up the format of the same name, but under the mosaic camera
    1032     psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS
    1033     if (!mdok || !formats) {
    1034         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n",
    1035                 config->cameraName);
    1036         return NULL;
    1037     }
    1038     psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format
    1039     if (!mdok || !format) {
    1040         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n",
    1041                 config->formatName, config->cameraName);
    1042         return NULL;
    1043     }
    1044 
    1045     pmFPA *fpa = pmFPAConstruct(camera);
    1046     if (!fpa) {
    1047         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n");
    1048         return NULL;
    1049     }
    1050     pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename);
    1051     if (!file) {
    1052         psErrorStackPrint(stderr, "file %s not defined\n", filename);
    1053         return NULL;
    1054     }
     1023            // It's a chip mosaic; we need to get the original name
     1024            original = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6);
     1025        } else {
     1026            original = psMemIncrRefCounter(config->cameraName);
     1027        }
     1028        psString cameraName = NULL;
     1029        psStringAppend(&cameraName, "_%s-FPA", original);
     1030
     1031        file = fpaFileDefineOutput(config, NULL, filename, cameraName, config->formatName);
     1032        psFree(cameraName);
     1033    }
     1034
    10551035    file->src = src; // inherit output elements from this source pmFPA
     1036
    10561037    file->mosaicLevel = PM_FPA_LEVEL_FPA; // don't do any I/O on this at a lower level
    1057     psFree (file->format);
    1058     file->format = psMemIncrRefCounter(format);
    1059 
    1060     psFree(fpa);
    10611038
    10621039    return file;
Note: See TracChangeset for help on using the changeset viewer.