36 std::stringstream ss(word);
37 std::stringstream output;
44 return stoi(output.str());
60 size_t &data_begin_offset,
61 size_t &data_end_offset,
65 std::vector<std::string> ¶ms_names)
67 size_t text_begin_offset;
68 size_t text_end_offset;
71 constexpr int off = 7;
73 handle.ignore(off,
' ');
76 handle >> text_begin_offset >> text_end_offset;
78 handle.seekg(text_begin_offset);
81 char delim = handle.get();
86 while (
size_t(handle.tellg()) < text_end_offset + 1) {
87 std::getline(handle, word, delim);
89 if (word ==
"$BEGINDATA") {
90 std::getline(handle, word, delim);
91 data_begin_offset =
static_cast<size_t>(stoul(word));
95 if (word ==
"$BYTEORD") {
96 std::getline(handle, word, delim);
97 is_be = word ==
"4,3,2,1";
101 if (word ==
"$ENDDATA") {
102 std::getline(handle, word, delim);
103 data_end_offset =
static_cast<size_t>(stoul(word));
107 if (std::regex_match(word, std::regex(
"\\$P[0-9]+N"))) {
110 std::getline(handle, word, delim);
113 if (params_names.size() <
id)
114 params_names.resize(
id,
"");
115 params_names[
id - 1] = word;
120 if (word ==
"$PAR") {
121 std::getline(handle, word, delim);
122 params_count =
static_cast<size_t>(stoul(word));
126 if (word ==
"$TOT") {
127 std::getline(handle, word, delim);
128 events_count =
static_cast<size_t>(stoul(word));
147 size_t data_begin_offset,
148 size_t data_end_offset,
150 size_t &events_count,
152 std::vector<float> &out_data)
155 auto diff = data_end_offset - data_begin_offset;
156 if (diff < params_count * events_count *
sizeof(
float))
157 events_count = diff / params_count /
sizeof(float);
159 out_data.resize(params_count * events_count);
161 handle.seekg(data_begin_offset);
162 handle.read(
reinterpret_cast<char *
>(out_data.data()),
163 params_count * events_count *
sizeof(float));
167 out_data.begin(), out_data.end(), out_data.begin(), [](
float n) {
168 uint8_t *tmp = reinterpret_cast<uint8_t *>(&n);
170 uint32_t w2 = *(tmp + 1);
171 uint32_t w3 = *(tmp + 2);
172 uint32_t w4 = *(tmp + 3);
173 uint32_t res = w4 << 0 | w3 << 8 | w2 << 16 | w1 << 24;
174 return *reinterpret_cast<float *>(&res);
178 out_data.begin(), out_data.end(), out_data.begin(), [](
float n) {
179 uint8_t *tmp = reinterpret_cast<uint8_t *>(&n);
181 uint32_t w2 = *(tmp + 1);
182 uint32_t w3 = *(tmp + 2);
183 uint32_t w4 = *(tmp + 3);
184 uint32_t res = w1 << 0 | w2 << 8 | w3 << 16 | w4 << 24;
185 return *reinterpret_cast<float *>(&res);
192 std::ifstream handle(filename, std::ios::in | std::ios::binary);
194 throw std::domain_error(
"Can not open file");
196 size_t data_begin_offset = 0;
197 size_t data_end_offset = 0;
201 handle, data_begin_offset, data_end_offset, dm.
d, dm.
n, is_be, dm.
names);
203 handle, data_begin_offset, data_end_offset, dm.
d, dm.
n, is_be, dm.
data);
static size_t parse_id(const std::string &word)
Helper function for parsing ID from string.
static void parse_info(std::ifstream &handle, size_t &data_begin_offset, size_t &data_end_offset, size_t ¶ms_count, size_t &events_count, bool &is_be, std::vector< std::string > ¶ms_names)
Parses info from FCS header.
static void parse_data(std::ifstream &handle, size_t data_begin_offset, size_t data_end_offset, size_t params_count, size_t &events_count, bool is_be, std::vector< float > &out_data)
Parses actual data from the FCS file.
void parse_FCS(const std::string &filename, DataModel &dm)
Parses FCS file and fills DataModel data.
Storage of data from loaded input file.
std::vector< std::string > names
Names of the dimensions.
std::vector< float > data
One-dimensional array storing d-dimensional input data in row-major order.