This commit is contained in:
Erik Frojdh 2023-05-31 14:25:20 +02:00
parent 6013f94d01
commit b21ae3da2e
3 changed files with 106 additions and 73 deletions

View File

@ -33,3 +33,16 @@ conda develop install .
#or with pip #or with pip
pip install --editable . pip install --editable .
``` ```
## Cluster file specifications
```
[int32 frame_number][int32 n_clusters][clusters....]
// Cluster data type
typedef struct {
int16_t x;
int16_t y;
int32_t data[9];
} Cluster ;
```

View File

@ -2,7 +2,8 @@
int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) { int read_clusters(FILE *fp, int64_t n_clusters, Cluster *buf, int *n_left) {
#ifdef CR_VERBOSE #ifdef CR_VERBOSE
printf("Item size: %lu n_clusters: %lld, n_left: %d\n", sizeof(Cluster), n_clusters,*n_left); printf("Item size: %lu n_clusters: %lld, n_left: %d\n", sizeof(Cluster),
n_clusters, *n_left);
#endif #endif
int iframe = 0, nph = *n_left; int iframe = 0, nph = *n_left;
size_t n_read = 0, nph_read = 0, nn = *n_left, nr = 0; size_t n_read = 0, nph_read = 0, nn = *n_left, nr = 0;
@ -61,10 +62,14 @@ int analyze_clusters(int64_t n_clusters, Cluster* cin, ClusterAnalysis *cout){
for (int iy = 0; iy < 3; iy++) { for (int iy = 0; iy < 3; iy++) {
val = (cin + ic)->data[iy * 3 + ix]; val = (cin + ic)->data[iy * 3 + ix];
tot3 += val; tot3 += val;
if (ix<=1 && iy<=1) tot2[0]+=val; if (ix <= 1 && iy <= 1)
if (ix>=1 && iy<=1) tot2[1]+=val; tot2[0] += val;
if (ix<=1 && iy>=1) tot2[2]+=val; if (ix >= 1 && iy <= 1)
if (ix>=1 && iy>=1) tot2[3]+=val; tot2[1] += val;
if (ix <= 1 && iy >= 1)
tot2[2] += val;
if (ix >= 1 && iy >= 1)
tot2[3] += val;
} }
} }
t2max = tot2[0]; t2max = tot2[0];
@ -78,10 +83,8 @@ int analyze_clusters(int64_t n_clusters, Cluster* cin, ClusterAnalysis *cout){
(cout + ic)->c = c; (cout + ic)->c = c;
(cout + ic)->tot2 = t2max; (cout + ic)->tot2 = t2max;
(cout + ic)->tot3 = tot3; (cout + ic)->tot3 = tot3;
//printf("%d %d %d %d %d %d\n",ic,(cin+ic)->x, (cin+ic)->y, (cout+ic)->c, (cout+ic)->tot2, (cout+ic)->tot3); // printf("%d %d %d %d %d %d\n",ic,(cin+ic)->x, (cin+ic)->y,
// (cout+ic)->c, (cout+ic)->tot2, (cout+ic)->tot3);
} }
return n_clusters; return n_clusters;
} }

View File

@ -9,3 +9,20 @@ def test_references_on_read(data_path):
clusters = r.read(10) clusters = r.read(10)
assert sys.getrefcount(clusters) == 2 #Over counts by one due to call by reference assert sys.getrefcount(clusters) == 2 #Over counts by one due to call by reference
def test_size_on_read(data_path):
fname= (data_path/'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust').as_posix()
r = ClusterFileReader(fname)
for i in range(10):
clusters = r.read(10)
assert clusters.size == 10
def test_resize_on_read(data_path):
# File contains 481603 clusters, output should be resized to the correct size
fname= (data_path/'beam_En700eV_-40deg_300V_10us_d0_f0_100.clust').as_posix()
r = ClusterFileReader(fname)
max_clusters = 10000000 #400MB initial allocation
clusters = r.read(max_clusters)
assert clusters.size == 481603
assert sys.getrefcount(clusters) == 2