Skip to content

Commit 1acd2d0

Browse files
committed
added HBF size stats
1 parent a3d98b2 commit 1acd2d0

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/readRaw.cxx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212
#include <lz4.h>
1313
#include <stdio.h>
1414
#include <string>
15+
#include <inttypes.h>
1516

1617
#include "DataBlock.h"
1718
#include "DataBlockContainer.h"
1819
#include "DataSet.h"
1920
#include "RdhUtils.h"
21+
#include "CounterStats.h"
2022

2123
//#define ERRLOG(args...) fprintf(stderr,args)
2224
#define ERRLOG(args...) fprintf(stdout, args)
@@ -40,6 +42,11 @@ int main(int argc, const char* argv[])
4042
bool dataBlockHeaderEnabled = false;
4143
bool checkContinuousTriggerOrder = false;
4244
bool isAutoPageSize = false; // flag set when no known page size in file
45+
bool dumpStats = false; // if set, statistics on HBF/TF size are reported at the end.
46+
CounterStats statsHBFsize;
47+
CounterStats statsTFsize;
48+
uint32_t linkLastOrbit[RdhMaxLinkId + 1] = {undefinedOrbit};
49+
uint32_t linkCurrentHBFSize[RdhMaxLinkId + 1] = {0};
4350

4451
uint32_t timeframePeriodOrbits = 0;
4552
uint32_t firstTimeframeHbOrbitBegin = 0;
@@ -62,6 +69,7 @@ int main(int argc, const char* argv[])
6269
" dumpDataBlockHeader=0|1 : dump the data block headers (internal readout headers).\n"
6370
" dumpData=(int) : dump the data pages. If -1, all bytes. Otherwise, the first bytes only, as specified.\n"
6471
" dumpDataInline=(int) : if set, each packet raw content is printed (hex dump style).\n"
72+
" dumpStats=(int) : if set, some statistics are printed on HBF/TF size.\n"
6573
" fileReadVerbose=(int) : if set, more information is printed when reading/decoding file.\n"
6674
" timeframePeriodOrbits=(int) : if set, TF id computed (and printed, when dump enabled) for each RDH. Typically, 128 or 256.\n"
6775
" \n",
@@ -114,6 +122,8 @@ int main(int argc, const char* argv[])
114122
checkContinuousTriggerOrder = std::stoi(value);
115123
} else if (key == "timeframePeriodOrbits") {
116124
timeframePeriodOrbits = (uint32_t) std::stoi(value);
125+
} else if (key == "dumpStats") {
126+
dumpStats = std::stoi(value);
117127
} else {
118128
ERRLOG("unknown option %s\n", key.c_str());
119129
}
@@ -124,6 +134,11 @@ int main(int argc, const char* argv[])
124134
return -1;
125135
}
126136

137+
if (dumpStats) {
138+
// need RDH to get HBF size
139+
validateRDH = 1;
140+
}
141+
127142
ERRLOG("Using data file %s\n", filePath.c_str());
128143
ERRLOG("dataBlockHeaderEnabled=%d dumpRDH=%d validateRDH=%d checkContinuousTriggerOrder=%d dumpDataBlockHeader=%d dumpData=%d dumpDataInline=%d fileReadVerbose=%d \n", (int)dataBlockHeaderEnabled, (int)dumpRDH, (int)validateRDH, (int)checkContinuousTriggerOrder, (int)dumpDataBlockHeader, dumpData, (int)dumpDataInline, (int)fileReadVerbose);
129144

@@ -169,6 +184,11 @@ int main(int argc, const char* argv[])
169184
const int maxBlockSize = 128 * 1024L * 1024L; // maximum memory allocated for page reading (or decompressing)
170185
bool checkOrbitContiguous = true; // if set, verify that they are no holes in orbit number
171186

187+
statsHBFsize.enableHistogram(131072,1,100000000,1); // good precision histogram 100k points to cover up to 100MB HBF size
188+
auto registerHBF = [&] (uint32_t size) {
189+
statsHBFsize.set(size);
190+
};
191+
172192
for (fileOffset = 0; fileOffset < (unsigned long)fileSize;) {
173193

174194
#define ERR_LOOP \
@@ -404,6 +424,21 @@ int main(int argc, const char* argv[])
404424
maxOrbit = h.getTriggerOrbit();
405425
}
406426

427+
unsigned int linkId = h.getLinkId();
428+
if (linkId <= RdhMaxLinkId) {
429+
uint32_t prevOrbit = linkLastOrbit[linkId];
430+
if (prevOrbit != h.getTriggerOrbit()) {
431+
if (prevOrbit != undefinedOrbit) {
432+
// previous HBF completed, register it
433+
registerHBF(linkCurrentHBFSize[linkId]);
434+
}
435+
// this is a new HBF
436+
linkCurrentHBFSize[linkId] = 0;
437+
linkLastOrbit[linkId] = h.getTriggerOrbit();
438+
}
439+
linkCurrentHBFSize[linkId] += h.getMemorySize();
440+
}
441+
407442
if (dumpDataInline) {
408443
long nBytes = h.getOffsetNextPacket();
409444
for (long ix = 0; ix < nBytes; ix++) {
@@ -461,6 +496,36 @@ int main(int argc, const char* argv[])
461496
ERRLOG("max orbit 0x%X\n", maxOrbit);
462497
}
463498

499+
if (dumpStats) {
500+
// register final HBF size
501+
int nLinksActive = 0;
502+
for (unsigned int i = 0; i< RdhMaxLinkId; i++) {
503+
if (linkLastOrbit[i] != undefinedOrbit) {
504+
// final HBF now completed, register it
505+
registerHBF(linkCurrentHBFSize[i]);
506+
nLinksActive++;
507+
}
508+
}
509+
510+
printf("HBF size (bytes): min=%" PRIu64 " max=%" PRIu64 " avg=%.0f stdev=%0.f links=%d nsamples=%d\n", statsHBFsize.getMinimum(), statsHBFsize.getMaximum(), statsHBFsize.getAverage(), statsHBFsize.getStdDev(), nLinksActive, (int)statsHBFsize.getCount());
511+
512+
printf("Distribution:\n");
513+
std::vector<double> x;
514+
std::vector<CounterValue> c;
515+
statsHBFsize.getHisto(x,c);
516+
for(unsigned int i=0;i<c.size();i++) {
517+
if (c[i]) {
518+
if (i==0) {
519+
printf("< %d\t%d\n",(int)x[i],(int)c[i]);
520+
} else if (i+1>=c.size()) {
521+
printf("> %d\t%d\n",(int)x[i],(int)c[i]);
522+
} else {
523+
printf("%d - %d\t%d\n",(int)x[i],(int)x[i+1],(int)c[i]);
524+
}
525+
}
526+
}
527+
}
528+
464529
// check file status
465530
if (feof(fp)) {
466531
ERRLOG("End of file\n");

0 commit comments

Comments
 (0)