95const uint32_t
field_bits[] = {0, 6, 0, 8, 14, 15, 8, 8, 10, 16, 2, 0, 14, 15, 16, 10, 26, 16, 8, 8, 16, 26, 8, 8,
rr,
rr,
rr,
rr,
rr, 14};
115int32_t
fgNPads[159] = {68, 68, 68, 68, 70, 70, 70, 72, 72, 72, 74, 74, 74, 76, 76, 76, 78, 78, 78, 80, 80, 80, 82, 82, 82, 84, 84, 84, 86, 86, 86, 88, 88, 88, 90, 90, 90, 92, 92, 92, 94, 94, 94, 96, 96, 96, 98, 98, 98, 100, 100, 100, 102,
116 102, 102, 104, 104, 104, 106, 106, 106, 108, 108, 74, 76, 76, 76, 76, 78, 78, 78, 80, 80, 80, 80, 82, 82, 82, 84, 84, 84, 86, 86, 86, 86, 88, 88, 88, 90, 90, 90, 90, 92, 92, 92, 94, 94, 94, 96, 96, 96, 96, 98, 98, 98, 100,
117 100, 100, 100, 102, 102, 102, 104, 104, 104, 106, 106, 106, 106, 108, 108, 108, 110, 110, 110, 110, 112, 112, 114, 114, 114, 116, 116, 118, 118, 120, 120, 122, 122, 122, 124, 124, 126, 126, 128, 128, 130, 130, 130, 132, 132, 134, 134, 136, 136, 138, 138, 138, 140};
119int32_t
fgNPadsMod[159] = {80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
120 104, 104, 104, 104, 104, 116, 116, 116, 116, 116, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104, 104,
121 104, 104, 104, 104, 104, 104, 104, 104, 104, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 128, 128, 128, 128, 128, 128, 128, 128, 128, 126, 126, 128, 128, 140, 140, 140, 140, 140, 134, 134, 140, 140, 140, 140, 140, 140};
239int32_t
main(
int argc,
char** argv)
244 printf(
"Cannot use truncate bits with differential qmax / qtot");
248 printf(
"Cannot use truncate bits with differential sigma");
252 if (!(fp = fopen(
file,
"rb"))) {
253 printf(
"Error opening file\n");
257 fseek(fp, 0, SEEK_END);
258 size_t nFileSize = ftell(fp);
259 fseek(fp, 0, SEEK_SET);
268 printf(
"Memory allocation error\n");
272 fprintf(stderr,
"Reading %d clusters...", (int32_t)
nClusters);
275 fprintf(stderr,
"Done\nSorting clusters...");
280 fprintf(stderr,
" (removing track ordering)...");
281 int32_t last_event = 0;
284 if (last_event !=
event) {
285 if (
i - 1 > starti) {
295 int32_t startrow = -1;
305 if (currow != startrow && startrow != -2) {
306 if (
i - 1 > starti) {
322 fprintf(stderr,
"Done\n");
327 double* probabilities[
nFields];
338 double rawtotalbytes = 0;
339 double entrototalbytes = 0;
340 for (int32_t isector = 0; isector < 36; isector++) {
341 for (int32_t ipatch = 0; ipatch < 6; ipatch++) {
343 printf(
"SECTOR %d ", isector);
346 printf(
"PATCH %d", ipatch);
355 memset(histograms[
i], 0,
sizeof(int64_t) * (1 <<
field_bits[
i]));
360 size_t nClustersUsed = 0;
362 int32_t lastRow = 0, lastPad = 0, lastTime = 0, lastSector = 0, lastResPad = 0, lastResTime = 0, lastQTot = 0, lastQMax = 0, lastSigmaPad = 0, lastSigmaTime = 0, lastTrack = -1, lastEvent = 0;
367 if (cluster.
pad >= 32768) {
368 printf(
"%d\n", cluster.
pad);
378 bool newTrack = lastTrack != cluster.
trackID;
379 uint32_t dSigmaPad, dSigmaTime;
381 if (cluster.
event != lastEvent) {
382 lastRow = lastPad = lastTime = lastSector = 0;
391 if (lastTrack != cluster.
trackID) {
392 lastSector = lastResPad = lastResTime = lastQTot = lastQMax = lastSigmaPad = lastSigmaTime = 0;
423 if (cluster.
row != lastRow) {
424 lastPad = lastTime = 0;
429 lastRow = cluster.
row;
441 if (cluster.
qtot < 0) {
482 lastEvent = cluster.
event;
486 printf(
"Event %u Track %d Sector %u Patch %u Row %u Pad %u Time %u sigmaPad %u sigmaTime %u qTot %u qMax %u Flag %u resPad %u resTime %u avgTot %u avgMax %u\n", cluster.
event, cluster.
trackID, cluster.
sector, cluster.
patch, cluster.
row, cluster.
pad, cluster.
time, cluster.
sigmaPad,
491 bool forceStore =
false;
532 histograms[
j][dSigmaPad]++;
536 histograms[
j][dSigmaTime]++;
547 histograms[myj][cluster.
vals[
ROW]]++;
556 histograms[
j][cluster.
vals[
j]]++;
561 histograms[
j][
val]++;
565 histograms[
j][
val]++;
569 histograms[
j][
val]++;
573 histograms[
j][
val]++;
577 myj = (myj - (80 - 11)) / 12;
583 histograms[
j][cluster.
pad]++;
592 printf(
"Clusters in block: %ld / %ld\n", nClustersUsed,
nClusters);
594 double log2 = log(2.);
602 double huffmanSize = 0;
608 probabilities[
i][
j] = (double)histograms[
i][
j] / (
double)counts[
i];
609 if (probabilities[
i][
j]) {
610 double I = -log(probabilities[
i][
j]) / log2;
611 double H = I * probabilities[
i][
j];
624 for (HuffCodeMap::const_iterator it = codes.begin(); it != codes.end(); it++) {
625 huffmanSize += it->second.size() * probabilities[
i][it->first];
628 entropies[
i] = entropy;
629 huffmanSizes[
i] = huffmanSize;
633 double entroTotal = 0., huffmanTotal = 0.;
661 entroTotal += entropies[
i] * counts[
i];
662 huffmanTotal += huffmanSizes[
i] * counts[
i];
670 if (counts[
i] == 0) {
673 printf(
"Field %2d/%16s (count %10ld / used %1d) rawBits %2d huffman %9.6f entropy %9.6f\n",
i,
field_names[
i], counts[
i], used[
i],
field_bits[
i], huffmanSizes[
i], entropies[
i]);
676 printf(
"Raw Bits: %d - Total Size %f MB Clusters %d\n", rawBits, (
double)rawBits * (
double)nClustersUsed / 8. / 1.e6, nClustersUsed);
677 printf(
"Huffman Bits: %f - Total Size %f MB\n", huffmanTotal / (
double)nClustersUsed, huffmanTotal / 8. / 1.e6);
678 printf(
"Entropy Bits: %f - Total Size %f MB\n", entroTotal / (
double)nClustersUsed, entroTotal / 8. / 1.e6);
679 printf(
"Maximum Compression Ratio: %f (Huffman %f)\n", (
double)rawBits * (
double)nClustersUsed / entroTotal, (
double)rawBits * (
double)nClustersUsed / huffmanTotal);
680 entrototalbytes += entroTotal;
681 rawtotalbytes += (double)rawBits * (
double)nClustersUsed;
696 printf(
"Total Compression: %f\n", rawtotalbytes / entrototalbytes);
704 delete[] histograms[
i];
705 delete[] probabilities[
i];