24 namespace ARICHTools {
37 std::array<uint8_t, 4>( {{
'A',
'B',
'C',
'D'}});
73 ModuleID_t(
const int8_t sector =
'0',
const int channel = 0) noexcept
133 rStream <<
id.getSector() <<
static_cast<int>(
id.getChannel());
143 return m_ID == rOther.m_ID;
152 return m_ID != rOther.m_ID;
161 return m_ID < rOther.m_ID;
170 return m_ID <= rOther.m_ID;
179 return m_ID > rOther.m_ID;
188 return m_ID >= rOther.m_ID;
231 namespace PrivateHelperClasses {
248 inline auto isValidChar(
const unsigned char character)
const noexcept
251 return std::isdigit(character);
262 inline auto operator()(
const std::string& rToken)
const ->
int
264 return std::stoi(rToken);
280 inline auto isValidChar(
const unsigned char character)
const noexcept
283 return std::isdigit(character) || (
static_cast<unsigned char>(
'.') == character);
294 inline auto operator()(
const std::string& rToken)
const ->
double
296 return std::stod(rToken);
309 inline auto isValidChar(
const unsigned char character)
const noexcept
326 std::find_if(rToken.begin(), rToken.end(),
327 [](
const char c) { return !std::isspace(c); });
328 const auto end = std::find_if(begin, rToken.end(),
329 [](
const char c) { return std::isspace(c); });
331 if ((begin + 1 == end) || !std::all_of(begin, end, [
this](
const char c) {
332 return this->isValidChar(c);
334 throw std::invalid_argument(
"Invalid argiment for module cast, got: '" +
337 const auto chID = std::stoi(std::string(begin + 1, end));
341 throw std::out_of_range(
"Module ID out of range. got: '" + rToken +
"' !");
370 template <
typename T>
371 static inline auto convert(
const std::string& rLine,
const char delim =
' ')
376 if (!std::all_of(rLine.begin(), rLine.end(),
377 [&cast, delim](
const unsigned char c) {
378 return std::isdigit(c) || std::isspace(c) ||
379 (c == delim) || cast.isValidChar(c);
381 throw std::runtime_error(
"Detected invalid character in '" + rLine +
384 auto iss = std::istringstream(rLine);
385 auto retval = std::vector<T>();
386 auto token = std::string();
389 while (std::getline(iss, token, delim))
391 retval.emplace_back(cast(token));
392 }
catch (
const std::invalid_argument& rErr) {
393 throw std::runtime_error(
"Invalid token, got:'" + token +
"'! " +
395 }
catch (
const std::out_of_range& rErr) {
397 throw std::runtime_error(
"Conversion out of range, got: '" + token +
398 "'! " + rErr.what());
414 template <
typename T>
415 static inline auto parse(
const std::string& rLine,
const char delim =
' ')
418 auto out = std::stringstream();
419 auto iss = std::istringstream(rLine);
420 auto token = std::string();
422 if (!std::getline(iss, token, delim))
423 return std::string();
427 StringToVector::expand<T>(out, delim, token);
433 while (std::getline(iss, token, delim))
438 StringToVector::expand<T>(out, delim, token);
440 out << delim << token;
442 }
catch (
const std::invalid_argument& rErr) {
443 throw std::runtime_error(
"Invalid token, got:'" + token +
"'! " +
445 }
catch (
const std::out_of_range& rErr) {
447 throw std::runtime_error(
"Conversion out of range, got: '" + token +
448 "'! " + rErr.what());
463 template <
typename T>
464 static inline auto expand(std::ostream& rStream,
const char delim,
465 const std::string& rToken) -> std::ostream&
467 auto itPos = std::search(rToken.begin(), rToken.end(),
470 auto lhs = cast(std::string(rToken.begin(), itPos));
472 auto rhs = cast(std::string(itPos, rToken.end()));
475 throw std::runtime_error(
476 "Invalid expansion! lhs ist greater then rhs, got: '" + rToken +
480 for (++lhs; lhs <= rhs; ++lhs)
481 rStream << delim << lhs;
496 auto getDeadCutList(
const char chipID,
const std::string& line)
499 auto ids = StringToVector::convert<int>(line,
',');
500 for (
auto& rID : ids)
501 rID = ModuleID_t(chipID, rID).getNumbering();
517 std::string& remove_nondigit(std::string& s)
520 s.erase(remove_if(s.begin(), s.end(),
521 [](
const unsigned char& c) { return !std::isdigit(c); }),
533 std::string& remove_chars_if_not(std::string& s,
const std::string& allowed)
535 s.erase(remove_if(s.begin(), s.end(),
536 [&allowed](
const char& c) {
537 return allowed.find(c) == std::string::npos;
Abstract base class for different kinds of events.