mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-19 18:47:13 +02:00
added simple decoding of scan parameters
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
#include "aare/RawFile.hpp"
|
||||
#include "aare/PixelMap.hpp"
|
||||
#include "aare/defs.hpp"
|
||||
#include "aare/json.hpp"
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "aare/RawMasterFile.hpp"
|
||||
|
||||
#include <sstream>
|
||||
namespace aare {
|
||||
|
||||
RawFileNameComponents::RawFileNameComponents(
|
||||
@ -51,6 +51,32 @@ const std::string &RawFileNameComponents::base_name() const {
|
||||
const std::string &RawFileNameComponents::ext() const { return m_ext; }
|
||||
int RawFileNameComponents::file_index() const { return m_file_index; }
|
||||
|
||||
// "[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]"
|
||||
ScanParameters::ScanParameters(const std::string& par){
|
||||
std::istringstream iss(par.substr(1, par.size()-2));
|
||||
std::string line;
|
||||
while(std::getline(iss, line)){
|
||||
if(line == "enabled"){
|
||||
m_enabled = true;
|
||||
}else if(line.find("dac") != std::string::npos){
|
||||
m_dac = line.substr(4);
|
||||
}else if(line.find("start") != std::string::npos){
|
||||
m_start = std::stoi(line.substr(6));
|
||||
}else if(line.find("stop") != std::string::npos){
|
||||
m_stop = std::stoi(line.substr(5));
|
||||
}else if(line.find("step") != std::string::npos){
|
||||
m_step = std::stoi(line.substr(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ScanParameters::start() const { return m_start; }
|
||||
int ScanParameters::stop() const { return m_stop; }
|
||||
int ScanParameters::step() const { return m_step; }
|
||||
const std::string &ScanParameters::dac() const { return m_dac; }
|
||||
bool ScanParameters::enabled() const { return m_enabled; }
|
||||
|
||||
|
||||
RawMasterFile::RawMasterFile(const std::filesystem::path &fpath)
|
||||
: m_fnc(fpath) {
|
||||
if (!std::filesystem::exists(fpath)) {
|
||||
@ -113,6 +139,10 @@ std::optional<size_t> RawMasterFile::transceiver_samples() const {
|
||||
return m_transceiver_samples;
|
||||
}
|
||||
|
||||
ScanParameters RawMasterFile::scan_parameters() const {
|
||||
return m_scan_parameters;
|
||||
}
|
||||
|
||||
void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
std::ifstream ifs(fpath);
|
||||
json j;
|
||||
@ -203,6 +233,13 @@ void RawMasterFile::parse_json(const std::filesystem::path &fpath) {
|
||||
// keep the optional empty
|
||||
}
|
||||
|
||||
try{
|
||||
std::string scan_parameters = j.at("Scan Parameters");
|
||||
m_scan_parameters = ScanParameters(scan_parameters);
|
||||
}catch (const json::out_of_range &e) {
|
||||
// not a scan
|
||||
}
|
||||
|
||||
// Update detector type for Moench
|
||||
// TODO! How does this work with old .raw master files?
|
||||
#ifdef AARE_VERBOSE
|
||||
|
@ -38,6 +38,26 @@ TEST_CASE("Master file name does not fit pattern"){
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("Parse scan parameters"){
|
||||
ScanParameters s("[enabled\ndac dac 4\nstart 500\nstop 2200\nstep 5\nsettleTime 100us\n]");
|
||||
REQUIRE(s.enabled());
|
||||
REQUIRE(s.dac() == "dac 4");
|
||||
REQUIRE(s.start() == 500);
|
||||
REQUIRE(s.stop() == 2200);
|
||||
REQUIRE(s.step() == 5);
|
||||
}
|
||||
|
||||
TEST_CASE("A disabled scan"){
|
||||
ScanParameters s("[disabled]");
|
||||
REQUIRE_FALSE(s.enabled());
|
||||
REQUIRE(s.dac() == "");
|
||||
REQUIRE(s.start() == 0);
|
||||
REQUIRE(s.stop() == 0);
|
||||
REQUIRE(s.step() == 0);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Parse a master file in .json format"){
|
||||
auto fpath = test_data_path() / "jungfrau" / "jungfrau_single_master_0.json";
|
||||
REQUIRE(std::filesystem::exists(fpath));
|
||||
|
Reference in New Issue
Block a user