Index: /trunk/magic/censorObjects/src/censorReadout.c
===================================================================
--- /trunk/magic/censorObjects/src/censorReadout.c	(revision 26951)
+++ /trunk/magic/censorObjects/src/censorReadout.c	(revision 26952)
@@ -19,5 +19,5 @@
     // if there is no mask file for this readout drop all sources
     if (badMaskFile) {
-      psMetadataRemoveKey (readout->analysis, "PSPHOT.SOURCES");
+      psMetadataRemoveKey (readout->analysis, "PSPHOT.DETECTIONS");
       return true;
     }
@@ -41,18 +41,20 @@
     }
 
-    // XXX why not do this? 
+    // XXX why not do this?
     pmReadout *readoutMask = pmFPAviewThisReadout (view, inMask->fpa);
     if (!readoutMask) {
         psError(CENSOR_ERR_CONFIG, true, "Can't find mask for this readout");
-	return false;
+        return false;
     }
 
     // select the raw objects for this readout, flag is they fall in a mask
-    psArray *inSources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
-    if (inSources == NULL) {
-        psError(CENSOR_ERR_CONFIG, true, "Can't find sources for this readout");
-	return false;
+    pmDetections *detections = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.DETECTIONS");
+    if (detections == NULL) {
+        psError(CENSOR_ERR_CONFIG, true, "Can't find detections for this readout");
+        return false;
     }
-		
+    psArray *inSources = detections->allSources;
+    psAssert (inSources, "missing sources?");
+
     // create a replacement output array:
     psArray *outSources = psArrayAllocEmpty(100);
@@ -60,32 +62,37 @@
     // only keep sources that do not match the specified mask bit
     for (int i = 0; i < inSources->n; i++) {
-	pmSource *source = inSources->data[i];
+        pmSource *source = inSources->data[i];
 
-	int xChip = source->peak->x;
-	int yChip = source->peak->y;
+        int xChip = source->peak->x;
+        int yChip = source->peak->y;
 
-	bool onChip = true;
-	onChip &= (xChip >= 0);
-	onChip &= (xChip < readoutMask->mask->numCols);
-	onChip &= (yChip >= 0);
-	onChip &= (yChip < readoutMask->mask->numRows);
+        bool onChip = true;
+        onChip &= (xChip >= 0);
+        onChip &= (xChip < readoutMask->mask->numCols);
+        onChip &= (yChip >= 0);
+        onChip &= (yChip < readoutMask->mask->numRows);
 
-	if (onChip) {
-	    psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip];
-	    if (value & streakMaskValue) {
-		// skip sources on streak masks
-		continue;
-	    }
-	}
-	psArrayAdd (outSources, 100, source);
+        if (onChip) {
+            psImageMaskType value = readoutMask->mask->data.PS_TYPE_IMAGE_MASK_DATA[yChip][xChip];
+            if (value & streakMaskValue) {
+                // skip sources on streak masks
+                continue;
+            }
+        }
+        psArrayAdd (outSources, 100, source);
     }
 
     psLogMsg ("censor", PS_LOG_INFO, "keeping %ld of %ld sources", outSources->n, inSources->n);
 
+    psFree (detections->allSources);
+    detections->allSources = outSources;
+
+#ifdef notdef
+    // XXX: this is not necessary (and incorrect) as we are re-using the pmDetections object that is in readout->analysis
     // remove the inSources and replace with the outSources
-    psMetadataRemoveKey (readout->analysis, "PSPHOT.SOURCES");
-    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY, "sources", outSources);
-    psFree (outSources);
-
+    psMetadataRemoveKey (readout->analysis, "PSPHOT.DETECTIONS");
+    psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY, "sources", detections);
+    psFree (detections);
+#endif
     return true;
 }
