-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
49da039
commit b8a4498
Showing
8 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "aare/FileInterface.hpp" | ||
#include "aare/file_utils.hpp" | ||
#include "aare/Frame.hpp" | ||
|
||
#include <filesystem> | ||
|
||
namespace aare{ | ||
|
||
class CtbRawFile{ | ||
FileNameComponents m_fnc{}; | ||
public: | ||
CtbRawFile(const std::filesystem::path &fname); | ||
|
||
|
||
|
||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#pragma once | ||
#include "aare/defs.hpp" | ||
#include <filesystem> | ||
#include <fmt/format.h> | ||
#include <fstream> | ||
|
||
#include <nlohmann/json.hpp> | ||
using json = nlohmann::json; | ||
|
||
namespace aare { | ||
bool is_master_file(const std::filesystem::path &fpath); | ||
|
||
|
||
struct FileNameComponents { | ||
std::filesystem::path base_path{}; | ||
std::string base_name{}; | ||
std::string ext{}; | ||
int findex{}; | ||
bool valid{false}; // TODO! how do we do error handling? | ||
|
||
std::filesystem::path master_fname() const { | ||
return base_path / | ||
fmt::format("{}_master_{}{}", base_name, findex, ext); | ||
} | ||
|
||
std::filesystem::path data_fname(size_t mod_id, size_t file_id) { | ||
return base_path / fmt::format("{}_d{}_f{}_{}.raw", base_name, file_id, | ||
mod_id, findex); | ||
} | ||
}; | ||
|
||
FileNameComponents parse_fname(const std::filesystem::path &fname); | ||
|
||
class MasterFile { | ||
FileNameComponents m_fnc; | ||
std::string m_version; | ||
DetectorType m_type; | ||
TimingMode m_timing_mode; | ||
size_t m_total_frames; | ||
size_t m_subfile_rows; | ||
size_t m_subfile_cols; | ||
size_t m_bitdepth; | ||
size_t m_analog_samples; | ||
size_t m_digital_samples; | ||
size_t m_max_frames_per_file; | ||
uint32_t m_adc_mask; | ||
public: | ||
MasterFile(const std::filesystem::path &fpath) { | ||
m_fnc = parse_fname(fpath); | ||
|
||
|
||
|
||
std::ifstream ifs(fpath); | ||
json j; | ||
ifs >> j; | ||
double v = j["Version"]; | ||
m_version = fmt::format("{:.1f}", v); | ||
|
||
m_type = StringTo<DetectorType>(j["Detector// Type"].get<std::string>()); | ||
m_timing_mode = | ||
StringTo<TimingMode>(j["Timing Mode"].get<std::string>()); | ||
m_total_frames = j["Frames in File"]; | ||
m_subfile_rows = j["Pixels"]["y"]; | ||
m_subfile_cols = j["Pixels"]["x"]; | ||
m_max_frames_per_file = j["Max Frames Per File"]; | ||
try { | ||
m_bitdepth = j.at("Dynamic Range"); | ||
} catch (const json::out_of_range &e) { | ||
m_bitdepth = 16; | ||
} | ||
|
||
try { | ||
m_analog_samples = j.at("Analog Samples"); | ||
}catch (const json::out_of_range &e) { | ||
m_analog_samples = 0; | ||
} | ||
try{ | ||
std::string adc_mask = j.at("ADC Mask"); | ||
m_adc_mask = std::stoul(adc_mask, nullptr, 16); | ||
}catch (const json::out_of_range &e) { | ||
m_adc_mask = 0; | ||
} | ||
|
||
try { | ||
m_digital_samples = j.at("Digital Samples"); | ||
}catch (const json::out_of_range &e) { | ||
m_digital_samples = 0; | ||
} | ||
|
||
//Update detector type for Moench | ||
//TODO! How does this work with old .raw master files? | ||
if (m_type == DetectorType::Moench && m_analog_samples == 0 && | ||
m_subfile_rows == 400) { | ||
m_type = DetectorType::Moench03; | ||
}else if (m_type == DetectorType::Moench && m_subfile_rows == 400 && | ||
m_analog_samples == 5000) { | ||
m_type = DetectorType::Moench03_old; | ||
} | ||
|
||
// //Here we know we have a ChipTestBoard file update the geometry? | ||
// //TODO! Carry on information about digtial, and transceivers | ||
// if (m_type == DetectorType::ChipTestBoard) { | ||
// subfile_rows = 1; | ||
// subfile_cols = m_analog_samples*__builtin_popcount(m_adc_mask); | ||
// } | ||
|
||
// // only Eiger had quad | ||
// if (m_type == DetectorType::Eiger) { | ||
// quad = (j["Quad"] == 1); | ||
// } | ||
|
||
// m_geometry = {j["Geometry"]["y"], j["Geometry"]["x"]}; | ||
} | ||
|
||
}; | ||
|
||
|
||
|
||
} // namespace aare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "aare/CtbRawFile.hpp" | ||
|
||
|
||
|
||
namespace aare{ | ||
|
||
CtbRawFile::CtbRawFile(const std::filesystem::path &fname){ | ||
|
||
if(!std::filesystem::exists(fname)){ | ||
throw std::runtime_error(LOCATION + "File does not exist"); | ||
} | ||
|
||
m_fnc = parse_fname(fname); | ||
if(!m_fnc.valid){ | ||
throw std::runtime_error(LOCATION + "Could not parse master file name"); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} // namespace aare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "aare/file_utils.hpp" | ||
|
||
namespace aare { | ||
|
||
|
||
|
||
bool is_master_file(const std::filesystem::path &fpath) { | ||
std::string const stem = fpath.stem().string(); | ||
return stem.find("_master_") != std::string::npos; | ||
} | ||
|
||
FileNameComponents parse_fname(const std::filesystem::path &fname) { | ||
FileNameComponents fnc; | ||
fnc.base_path = fname.parent_path(); | ||
fnc.base_name = fname.stem(); | ||
fnc.ext = fname.extension(); | ||
try { | ||
auto pos = fnc.base_name.rfind('_'); | ||
fnc.findex = std::stoi(fnc.base_name.substr(pos + 1)); | ||
} catch (const std::invalid_argument &e) { | ||
fnc.valid = false; | ||
} | ||
auto pos = fnc.base_name.find("_master_"); | ||
if (pos != std::string::npos) { | ||
fnc.base_name.erase(pos); | ||
}else{ | ||
fnc.valid = false; | ||
} | ||
fnc.valid = true; | ||
return fnc; | ||
} | ||
|
||
} // namespace aare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "aare/file_utils.hpp" | ||
|
||
#include <catch2/catch_test_macros.hpp> | ||
|
||
using namespace aare; | ||
|
||
TEST_CASE("Use filename to determine if it is a master file") { | ||
|
||
REQUIRE(is_master_file("test_master_1.json")); | ||
} | ||
|
||
TEST_CASE("Parse a master file fname"){ | ||
auto fnc = parse_fname("test_master_1.json"); | ||
REQUIRE(fnc.base_name == "test"); | ||
REQUIRE(fnc.ext == ".json"); | ||
REQUIRE(fnc.findex == 1); | ||
|
||
REQUIRE(fnc.master_fname() == "test_master_1.json"); | ||
REQUIRE(fnc.data_fname(1, 2) == "test_d2_f1_1.raw"); | ||
} |