10#ifndef TRIAL_SELECTION_H
11#define TRIAL_SELECTION_H
30inline std::string
trim(
const std::string& s) {
31 const char* ws =
" \t\r\n";
32 size_t b = s.find_first_not_of(ws);
33 if (b == std::string::npos)
return "";
34 size_t e = s.find_last_not_of(ws);
35 return s.substr(b, e - b + 1);
43 std::vector<int> trials;
46 if (c ==
',' || c ==
' ' || c ==
'\t' || c ==
';') {
48 trials.push_back(std::stoi(token));
55 if (!token.empty()) trials.push_back(std::stoi(token));
64 std::ifstream in(path);
66 throw std::runtime_error(
"Cannot open trials file: " + path);
68 std::vector<int> trials;
70 while (std::getline(in, line)) {
71 std::string t =
trim(line);
72 if (t.empty() || t[0] ==
'#')
continue;
73 trials.push_back(std::stoi(t));
84 std::ifstream in(path);
86 throw std::runtime_error(
"Cannot open subject_trial CSV: " + path);
88 std::vector<SubjectTrial> rows;
90 bool header_skipped =
false;
91 while (std::getline(in, line)) {
92 std::string t =
trim(line);
93 if (t.empty() || t[0] ==
'#')
continue;
95 if (!header_skipped) {
96 header_skipped =
true;
99 lower.push_back(
static_cast<char>(std::tolower(
static_cast<unsigned char>(c))));
100 if (lower.rfind(
"subject", 0) == 0)
continue;
102 std::stringstream ss(t);
103 std::string subj, trial_str;
104 if (!std::getline(ss, subj,
','))
continue;
105 if (!std::getline(ss, trial_str,
',')) {
106 throw std::runtime_error(
"Malformed line in " + path +
": " + line);
121 const char* env = std::getenv(
"SLURM_ARRAY_TASK_ID");
122 if (!env || *env ==
'\0')
return -1;
123 return std::stoi(std::string(env));
DataSerializer - Abstract base class for format-agnostic DIC data I/O.
std::vector< int > parseTrialList(const std::string &spec)
Parse a comma/space-separated list of integer trial IDs.
std::string trim(const std::string &s)
Trim leading/trailing whitespace (spaces, tabs, CR, LF).
int slurmArrayTaskId()
Resolve SLURM_ARRAY_TASK_ID from the environment.
std::vector< int > readTrialsFile(const std::string &path)
Read a trials file: one trial ID per line.
std::vector< SubjectTrial > readSubjectTrialCsv(const std::string &path)
Read subject_trial.csv (header "subject,trial") into rows, skipping the header line and any blank/com...
A single (subject, trial) row, e.g.