85be21057a058a0bdb12caac2bae553376442f5a angie Mon Apr 15 10:56:28 2013 -0700 Refactoring to remove dependencies on annoGratorQuery from streamers,grators and formatters. Instead, provide basic assembly info and explicitly pass streamers(/grators) along with the rows that they produced into formatters. ref #6152 diff --git src/lib/annoFormatTab.c src/lib/annoFormatTab.c index 8d9518b..c4a2243 100644 --- src/lib/annoFormatTab.c +++ src/lib/annoFormatTab.c @@ -27,44 +27,43 @@ } struct annoColumn *col; int i; for (col = source->columns, i = 0; col != NULL; col = col->next, i++) { if (! col->included) continue; if (isFirst && i == 0) fputc('#', f); else fputc('\t', f); fputs(col->def->name, f); } } -static void aftInitialize(struct annoFormatter *vSelf, struct annoGratorQuery *query) +static void aftInitialize(struct annoFormatter *vSelf, struct annoStreamer *primary, + struct annoStreamer *integrators) /* Print header, regardless of whether we get any data after this. */ { -vSelf->query = query; struct annoFormatTab *self = (struct annoFormatTab *)vSelf; if (self->needHeader) { - struct annoStreamer *primary = query->primarySource; char *primaryHeader = primary->getHeader(primary); if (isNotEmpty(primaryHeader)) - printf("# Header from primary input:\n%s", primaryHeader); + fprintf(self->f, "# Header from primary input:\n%s", primaryHeader); printHeaderColumns(self->f, primary, TRUE); - struct annoStreamer *grator = (struct annoStreamer *)(query->integrators); - for (; grator != NULL; grator = grator->next) + struct annoStreamer *grator; + for (grator = integrators; grator != NULL; grator = grator->next) printHeaderColumns(self->f, grator, FALSE); fputc('\n', self->f); self->needHeader = FALSE; } } static double wigRowAvg(struct annoRow *row) /* Return the average value of floats in row->data. */ { float *vector = row->data; int len = row->end - row->start; double sum = 0.0; int i; for (i = 0; i < len; i++) sum += vector[i]; @@ -151,57 +150,54 @@ { if (! col->included) continue; if (!isFirst || i > 0) fputc('\t', f); if (words != NULL) fputs((words[i] ? words[i] : ""), f); } if (freeWhenDone) { freeMem(words[0]); freeMem(words); } } -static void aftFormatOne(struct annoFormatter *vSelf, struct annoRow *primaryRow, - struct slRef *gratorRowList) +static void aftFormatOne(struct annoFormatter *vSelf, struct annoStreamRows *primaryData, + struct annoStreamRows *gratorData, int gratorCount) /* Print out tab-separated columns that we have gathered in prior calls to aftCollect, * and start over fresh for the next line of output. */ { struct annoFormatTab *self = (struct annoFormatTab *)vSelf; -// How many rows did each grator give us, and what's the largest # of rows? +// Got one row from primary; what's the largest # of rows from any grator? int maxRows = 1; -int i; -struct slRef *grRef; -int numGrators = slCount(gratorRowList); -for (i = 0, grRef = gratorRowList; i < numGrators; i++, grRef = grRef->next) +int iG; +for (iG = 0; iG < gratorCount; iG++) { - int gratorRowCount = slCount(grRef->val); + int gratorRowCount = slCount(gratorData[iG].rowList); if (gratorRowCount > maxRows) maxRows = gratorRowCount; } // Print out enough rows to make sure that all grator rows are included. -struct annoStreamer *primarySource = vSelf->query->primarySource; -for (i = 0; i < maxRows; i++) +int iR; +for (iR = 0; iR < maxRows; iR++) { - printColumns(self->f, primarySource, primaryRow, TRUE); - struct annoStreamer *grator = (struct annoStreamer *)self->formatter.query->integrators; - for (grRef = gratorRowList; grRef != NULL; grRef = grRef->next, grator = grator->next) + printColumns(self->f, primaryData->streamer, primaryData->rowList, TRUE); + for (iG = 0; iG < gratorCount; iG++) { - struct annoRow *gratorRow = slElementFromIx(grRef->val, i); - printColumns(self->f, grator, gratorRow, FALSE); + struct annoRow *gratorRow = slElementFromIx(gratorData[iG].rowList, iR); + printColumns(self->f, gratorData[iG].streamer, gratorRow, FALSE); } fputc('\n', self->f); } } static void aftClose(struct annoFormatter **pVSelf) /* Close file handle, free self. */ { if (pVSelf == NULL) return; struct annoFormatTab *self = *(struct annoFormatTab **)pVSelf; freeMem(self->fileName); carefulClose(&(self->f)); annoFormatterFree(pVSelf); }