aare/examples/cluster_example.cpp
Bechir Braham 91a628cd6c
pedestal (#67)
* add config files for multimodule receiving

* read subfiles with unordered and missing frames

* save work debugging

* Revert "save work debugging"

This reverts commit e791992a05efd754f93a80c980d17397eb4b6045.

* Revert "read subfiles with unordered and missing frames"

This reverts commit 1177fd129d3690db92e9597ccda62598e5a44d41.

* throw when two frames have different frame numbers

* write single part RawFile (working beta)

* correct total number of frames in master file

* add new mythen file with syncd frames

* save work

* save work for receive multimodule
multimodule config results in too much packet loss. needs more debugging.

* setup Task Distributiosn/ parallelization programming model

* read frames with same frame number

* clang-tidy fixes, formatting, add tests

* added second receiver

* Synchronize between zmq streams and merge frames

* improve readability in loop

* fix failing tests

* add simple test for merge frames

* restructure files and use top-level header

* working pedestal + tests

* test_pedestal statistics

* QA test pedestal, fix clang-tidy errors

---------

Co-authored-by: Bechir <bechir.brahem420@gmail.com>
Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
2024-05-08 12:33:51 +02:00

54 lines
1.6 KiB
C++

#include "aare.hpp"
#include "aare/examples/defs.hpp"
#include <cassert>
#include <iostream>
using namespace aare;
int main() {
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv("AARE_ROOT_DIR"));
std::filesystem::path const fpath(PROJECT_ROOT_DIR / "data" / "clusters" / "single_frame_97_clustrers.clust");
// reading a file
aare::ClusterFile cf(fpath, "r");
std::cout << "file opened " << '\n';
std::cout << "n_clusters " << cf.count() << '\n';
std::cout << "frame_number " << cf.frame() << '\n';
std::cout << "file size: " << cf.count() << '\n';
cf.seek(0); // seek to the beginning of the file (this is the default behavior of the constructor)
auto cluster = cf.read(97);
std::cout << "read 10 clusters" << '\n';
int offset = 0;
int data_offset = 0;
for (auto c : cluster) {
assert(c.y == offset + 200);
for (int i = 0; i < 9; i++) {
assert(c.data[i] == data_offset + i);
}
offset++;
data_offset += 9;
}
// writing a file
std::filesystem::path const fpath_out("/tmp/cluster_example_file.clust");
aare::ClusterFile cf_out(fpath_out, "w", ClusterFileConfig(1, 44));
std::cout << "file opened for writing" << '\n';
std::vector<Cluster> clusters;
for (int i = 0; i < 1084; i++) {
Cluster c;
c.x = i;
c.y = i + 200;
for (int j = 0; j < 9; j++) {
c.data[j] = j;
}
clusters.push_back(c);
}
cf_out.write(clusters);
std::cout << "wrote 10 clusters" << '\n';
cf_out.update_header();
return 0;
}