24 namespace ARICHTools {
37 std::array<uint8_t, 4>( {{
'A',
'B',
'C',
'D'}});
54 static auto isValidSector(
const uint8_t sector) noexcept ->
bool
68 ModuleID_t(
const int8_t sector =
'0',
const int channel = 0) noexcept
84 return ModuleID_t::isValidSector(this->
getSector()) &&
128 rStream <<
id.getSector() <<
static_cast<int>(
id.getChannel());
138 return m_ID == rOther.m_ID;
147 return m_ID != rOther.m_ID;
156 return m_ID < rOther.m_ID;
165 return m_ID <= rOther.m_ID;
174 return m_ID > rOther.m_ID;
183 return m_ID >= rOther.m_ID;
226 namespace PrivateHelperClasses {
243 inline auto isValidChar(
const unsigned char character)
const noexcept
246 return std::isdigit(character);
257 inline auto operator()(
const std::string& rToken)
const ->
int
259 return std::stoi(rToken);
275 inline auto isValidChar(
const unsigned char character)
const noexcept
278 return std::isdigit(character) || (
static_cast<unsigned char>(
'.') == character);
289 inline auto operator()(
const std::string& rToken)
const ->
double
291 return std::stod(rToken);
304 inline auto isValidChar(
const unsigned char character)
const noexcept
307 return std::isdigit(character) || ModuleID_t::isValidSector(character);
321 std::find_if(rToken.begin(), rToken.end(),
322 [](
const char c) { return !std::isspace(c); });
323 const auto end = std::find_if(begin, rToken.end(),
324 [](
const char c) { return std::isspace(c); });
326 if ((begin + 1 == end) || !std::all_of(begin, end, [
this](
const char c) {
327 return this->isValidChar(c);
329 throw std::invalid_argument(
"Invalid argiment for module cast, got: '" +
332 const auto chID = std::stoi(std::string(begin + 1, end));
336 throw std::out_of_range(
"Module ID out of range. got: '" + rToken +
"' !");
365 template <
typename T>
366 static inline auto convert(
const std::string& rLine,
const char delim =
' ')
371 if (!std::all_of(rLine.begin(), rLine.end(),
372 [&cast, delim](
const unsigned char c) {
373 return std::isdigit(c) || std::isspace(c) ||
374 (c == delim) || cast.isValidChar(c);
376 throw std::runtime_error(
"Detected invalid character in '" + rLine +
379 auto iss = std::istringstream(rLine);
380 auto retval = std::vector<T>();
381 auto token = std::string();
384 while (std::getline(iss, token, delim))
386 retval.emplace_back(cast(token));
387 }
catch (
const std::invalid_argument& rErr) {
388 throw std::runtime_error(
"Invalid token, got:'" + token +
"'! " +
390 }
catch (
const std::out_of_range& rErr) {
392 throw std::runtime_error(
"Conversion out of range, got: '" + token +
393 "'! " + rErr.what());
409 template <
typename T>
410 static inline auto parse(
const std::string& rLine,
const char delim =
' ')
413 auto out = std::stringstream();
414 auto iss = std::istringstream(rLine);
415 auto token = std::string();
417 if (!std::getline(iss, token, delim))
418 return std::string();
422 StringToVector::expand<T>(out, delim, token);
428 while (std::getline(iss, token, delim))
433 StringToVector::expand<T>(out, delim, token);
435 out << delim << token;
437 }
catch (
const std::invalid_argument& rErr) {
438 throw std::runtime_error(
"Invalid token, got:'" + token +
"'! " +
440 }
catch (
const std::out_of_range& rErr) {
442 throw std::runtime_error(
"Conversion out of range, got: '" + token +
443 "'! " + rErr.what());
458 template <
typename T>
459 static inline auto expand(std::ostream& rStream,
const char delim,
460 const std::string& rToken) -> std::ostream&
462 auto itPos = std::search(rToken.begin(), rToken.end(),
465 auto lhs = cast(std::string(rToken.begin(), itPos));
467 auto rhs = cast(std::string(itPos, rToken.end()));
470 throw std::runtime_error(
471 "Invalid expansion! lhs ist greater then rhs, got: '" + rToken +
475 for (++lhs; lhs <= rhs; ++lhs)
476 rStream << delim << lhs;
491 auto getDeadCutList(
const char chipID,
const std::string& line)
494 auto ids = StringToVector::convert<int>(line,
',');
495 for (
auto& rID : ids)
496 rID = ModuleID_t(chipID, rID).getNumbering();
512 std::string& remove_nondigit(std::string& s)
515 s.erase(remove_if(s.begin(), s.end(),
516 [](
const unsigned char& c) { return !std::isdigit(c); }),
528 std::string& remove_chars_if_not(std::string& s,
const std::string& allowed)
530 s.erase(remove_if(s.begin(), s.end(),
531 [&allowed](
const char& c) {
532 return allowed.find(c) == std::string::npos;
Abstract base class for different kinds of events.