109 std::ifstream infile;
110 infile.open(filename, std::ios::in);
111 if (!infile.is_open())
113 msg->MSG_ERROR(
"config file ", filename,
" does not exist");
119 auto md5sum =
Exec(TString(
"md5sum " + filename).Data());
120 std::regex md5_regex(
"([0-9a-f]{32})");
121 auto match = std::sregex_iterator(md5sum.begin(), md5sum.end(), md5_regex);
125 msg->MSG_ERROR(
"input file ", filename,
" has already been read");
133 while (std::getline(infile,
line))
136 auto commentstart =
line.find(
"#");
137 if (commentstart != std::string::npos)
139 line.erase(commentstart,
line.size());
144 std::regex word_regex(
"([^\\s]+)");
145 auto words_begin = std::sregex_iterator(
line.begin(),
line.end(), word_regex);
146 auto words_end = std::sregex_iterator();
147 std::vector<std::string> matched_words;
148 for (
auto i = words_begin; i != words_end; ++i)
150 matched_words.push_back((*i).str());
153 if (matched_words.size() >= 2)
155 if (matched_words[0] ==
"include")
157 for (uint32_t i = 1; i < matched_words.size(); i++)
164 if (matched_words.size() >= 3)
166 std::string type = matched_words[0];
167 std::string name = matched_words[1];
171 std::istringstream record(matched_words[2]);
174 BookParFile<int>(name, temp_int);
176 else if (type ==
"intvec")
178 std::vector<int> temp_intvec;
179 for (uint32_t i = 2; i < matched_words.size(); i++)
181 std::istringstream record(matched_words[i]);
184 temp_intvec.push_back(temp_int);
186 BookParFile<std::vector<int>>(name, temp_intvec);
188 else if (type ==
"double")
190 std::istringstream record(matched_words[2]);
192 record >> temp_double;
193 BookParFile<double>(name, temp_double);
195 else if (type ==
"doublevec")
197 std::vector<double> temp_doublevec;
198 for (uint64_t i = 2; i < matched_words.size(); i++)
200 std::istringstream record(matched_words[i]);
202 record >> temp_double;
203 temp_doublevec.push_back(temp_double);
205 BookParFile<std::vector<double>>(name, temp_doublevec);
207 else if (type ==
"long")
209 std::istringstream record(matched_words[2]);
212 BookParFile<long>(name, temp_long);
214 else if (type ==
"longvec")
216 std::vector<long> temp_longvec;
217 for (uint64_t i = 2; i < matched_words.size(); i++)
219 std::istringstream record(matched_words[i]);
222 temp_longvec.push_back(temp_long);
224 BookParFile<std::vector<long>>(name, temp_longvec);
226 else if (type ==
"bool")
228 std::istringstream record(matched_words[2]);
231 BookParFile<bool>(name, temp_bool);
233 else if (type ==
"boolvec")
235 std::vector<bool> temp_boolvec;
236 for (uint64_t i = 2; i < matched_words.size(); i++)
238 std::istringstream record(matched_words[i]);
241 temp_boolvec.push_back(temp_bool);
243 BookParFile<std::vector<bool>>(name, temp_boolvec);
245 else if (type ==
"string")
247 std::istringstream record(matched_words[2]);
249 record >> temp_string;
250 BookParFile<TString>(name, temp_string);
252 else if (type ==
"stringvec")
254 std::vector<TString> temp_stringvec;
255 for (uint64_t i = 2; i < matched_words.size(); i++)
257 std::istringstream record(matched_words[i]);
259 record >> temp_string;
260 temp_stringvec.push_back(temp_string);
262 BookParFile<std::vector<TString>>(name, temp_stringvec);
266 MSGUser()->MSG_WARNING(
"parameter ", name,
" type ", type,
" is not allowed");