mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-13 07:47:13 +02:00
read write cluster file (#60)
* Read and write cluster files (save work) * add reading test * use define for examples env variable and fix ci * read and write cluster files (working) * fix cluster CI
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
|
||||
set(EXAMPLE_LIST "json_example;logger_example;numpy_read_example;multiport_example;raw_example;zmq_restream_example")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};mythen_example;numpy_write_example;zmq_receiver_example;zmq_sender_example;")
|
||||
set(EXAMPLE_LIST "${EXAMPLE_LIST};cluster_example")
|
||||
foreach(example ${EXAMPLE_LIST})
|
||||
add_executable(${example} ${example}.cpp)
|
||||
target_include_directories(${example} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_link_libraries(${example} PUBLIC aare PRIVATE aare_compiler_flags)
|
||||
endforeach()
|
||||
|
||||
|
53
examples/cluster_example.cpp
Normal file
53
examples/cluster_example.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include "aare/core/defs.hpp"
|
||||
#include "aare/file_io/ClusterFile.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;
|
||||
}
|
2
examples/include/aare/examples/defs.hpp
Normal file
2
examples/include/aare/examples/defs.hpp
Normal file
@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
#define AARE_ROOT_DIR "AARE_ROOT_DIR"
|
@ -1,10 +1,9 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
@ -18,7 +17,7 @@ void test(File &f, int frame_number) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR_VAR));
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR));
|
||||
std::filesystem::path const fpath(PROJECT_ROOT_DIR / "data" / "jungfrau" / "jungfrau_single_master_0.json");
|
||||
std::cout << fpath << '\n';
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
@ -11,7 +13,7 @@ int main() {
|
||||
|
||||
// writing to file
|
||||
std::ofstream textfile;
|
||||
textfile.open("Test.txt");
|
||||
textfile.open("/tmp/Test.txt");
|
||||
aare::logger::set_streams(textfile.rdbuf());
|
||||
aare::logger::info(LOCATION, "info printed to file");
|
||||
|
||||
@ -26,7 +28,7 @@ int main() {
|
||||
|
||||
// setting file output by path
|
||||
// user doesn't have to close file
|
||||
aare::logger::set_output_file("Test2.txt");
|
||||
aare::logger::set_output_file("/tmp/Test2.txt");
|
||||
aare::logger::info(LOCATION, "info printed to Test2.txt");
|
||||
return 0;
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
#include <iostream>
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
@ -19,7 +19,7 @@ void test(File &f, int frame_number) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR_VAR));
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR));
|
||||
std::filesystem::path const fpath(PROJECT_ROOT_DIR / "data" / "jungfrau" / "jungfrau_double_master_0.json");
|
||||
std::cout << fpath << '\n';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
#include <iostream>
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
@ -32,7 +32,7 @@ void test2(File &f, int frame_number) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR_VAR));
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR));
|
||||
if (PROJECT_ROOT_DIR.empty()) {
|
||||
throw std::runtime_error("environment variable PROJECT_ROOT_DIR is not set");
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
#include <iostream>
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
@ -18,7 +18,7 @@ void test(File &f, int frame_number) {
|
||||
|
||||
int main() {
|
||||
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR_VAR));
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR));
|
||||
std::filesystem::path const fpath(PROJECT_ROOT_DIR / "data" / "numpy" / "test_numpy_file.npy");
|
||||
std::cout << fpath << '\n';
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/core/Frame.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
#include <iostream>
|
||||
|
||||
using aare::File;
|
||||
using aare::FileConfig;
|
||||
|
@ -1,10 +1,9 @@
|
||||
// Your First C++ Program
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/file_io/File.hpp"
|
||||
#include "aare/utils/logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define AARE_ROOT_DIR_VAR "PROJECT_ROOT_DIR"
|
||||
|
||||
using aare::File;
|
||||
using aare::Frame;
|
||||
|
||||
@ -17,7 +16,7 @@ void test(File &f, int frame_number) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR_VAR));
|
||||
auto PROJECT_ROOT_DIR = std::filesystem::path(getenv(AARE_ROOT_DIR));
|
||||
if (PROJECT_ROOT_DIR.empty()) {
|
||||
throw std::runtime_error("environment variable PROJECT_ROOT_DIR is not set");
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/network_io/ZmqSocketReceiver.hpp"
|
||||
#include "aare/network_io/defs.hpp"
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "aare/core/Frame.hpp"
|
||||
#include "aare/examples/defs.hpp"
|
||||
#include "aare/network_io/ZmqHeader.hpp"
|
||||
#include "aare/network_io/ZmqSocketSender.hpp"
|
||||
#include "aare/network_io/defs.hpp"
|
||||
|
Reference in New Issue
Block a user