/// Read the source slit sizes from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readSourceSlitSize(const std::string &line) { boost::regex re_key("wheel", boost::regex::icase); if (boost::regex_search(line, re_key)) { boost::regex re_sig("([1-8]) wheel[ ]*([1-3])[ \\t]*=[ \\t]*(\\w+)"); boost::smatch posVec; if (boost::regex_search(line, posVec, re_sig)) { if (posVec.size() == 4) { std::string num_str = posVec[1]; int slit_number = 0; Poco::NumberParser::tryParse(num_str, slit_number); slit_number--; num_str = posVec[2]; int wheel_number = 0; Poco::NumberParser::tryParse(num_str, wheel_number); wheel_number--; num_str = posVec[3]; boost::regex re_size("\\w*?([0-9]+)mm"); int slit_size = 0; if (boost::regex_search(num_str, posVec, re_size)) { if (posVec.size() == 2) { num_str = posVec[1]; Poco::NumberParser::tryParse(num_str, slit_size); } } m_slit_positions[wheel_number][slit_number] = slit_size; } } } }
/// Read rectangular masks from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readRectangularMasks(const std::string& line) { // Looking for rectangular mask // Rectangular mask = 7, 0; 7, 255 Poco::RegularExpression re_key("rectangular mask", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression re_key_alt("elliptical mask", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression::Match match; if (re_key.match(line, 0, match) || re_key_alt.match(line, 0, match)) { Poco::RegularExpression re_sig("=[ ]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)[ ]*[ ;,][ ]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)"); if (re_sig.match(line, 0, match)) { Poco::RegularExpression::MatchVec posVec; re_sig.match(line, 0, posVec); if (posVec.size()==5) { for (int i=0; i<4; i++) { std::string num_str = line.substr(posVec[i+1].offset, posVec[i+1].length); m_mask_as_string = m_mask_as_string + " " + num_str; } m_mask_as_string += ","; } } } }
/// Read the moderator position from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readModeratorPosition(const std::string &line) { boost::regex re_key("sample location", boost::regex::icase); if (boost::regex_search(line, re_key)) { boost::regex re_sig("=[ ]*([0-9]+)"); boost::smatch posVec; if (boost::regex_search(line, posVec, re_sig)) { if (posVec.size() == 2) { std::string num_str = posVec[1]; Poco::NumberParser::tryParseFloat(num_str, m_moderator_position); m_moderator_position = -m_moderator_position / 1000.0; } } } }
/// Read the beam center from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readBeamCenter(const std::string &line) { boost::regex re_key("spectrum center", boost::regex::icase); if (boost::regex_search(line, re_key)) { boost::regex re_sig("=[ ]*([0-9]+.[0-9]*)[ ]*[ ,][ ]*([0-9]+.[0-9]+)"); boost::smatch posVec; if (boost::regex_search(line, posVec, re_sig)) { if (posVec.size() == 3) { std::string num_str = posVec[1]; Poco::NumberParser::tryParseFloat(num_str, m_center_x); num_str = posVec[2]; Poco::NumberParser::tryParseFloat(num_str, m_center_y); } } } }
/// Read the TOF cuts from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readTOFcuts(const std::string &line) { boost::regex re_key("tof edge discard", boost::regex::icase); if (boost::regex_search(line, re_key)) { boost::regex re_sig("=[ ]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)"); boost::smatch posVec; if (boost::regex_search(line, posVec, re_sig)) { if (posVec.size() == 3) { std::string num_str = posVec[1]; Poco::NumberParser::tryParseFloat(num_str, m_low_TOF_cut); num_str = posVec[2]; Poco::NumberParser::tryParseFloat(num_str, m_high_TOF_cut); } } } }
/// Read the moderator position from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readModeratorPosition(const std::string& line) { Poco::RegularExpression re_key("sample location", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression::Match match; if (re_key.match(line, 0, match)) { Poco::RegularExpression re_sig("=[ ]*([0-9]+)"); if (re_sig.match(line, 0, match)) { Poco::RegularExpression::MatchVec posVec; re_sig.match(line, 0, posVec); if (posVec.size()==2) { std::string num_str = line.substr(posVec[1].offset, posVec[1].length); Poco::NumberParser::tryParseFloat(num_str, m_moderator_position); m_moderator_position = -m_moderator_position/1000.0; } } } }
/// Read rectangular masks from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readRectangularMasks(const std::string &line) { // Looking for rectangular mask // Rectangular mask = 7, 0; 7, 255 boost::regex re_key("rectangular mask", boost::regex::icase); boost::regex re_key_alt("elliptical mask", boost::regex::icase); if (boost::regex_search(line, re_key) || boost::regex_search(line, re_key_alt)) { boost::regex re_sig("=[ ]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)[ ]*[ ;,][ " "]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)"); boost::smatch posVec; if (boost::regex_search(line, posVec, re_sig)) { if (posVec.size() == 5) { for (int i = 0; i < 4; i++) { std::string num_str = posVec[i + 1]; m_mask_as_string = m_mask_as_string + " " + num_str; } m_mask_as_string += ","; } } } }
/// Read the beam center from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readBeamCenter(const std::string& line) { Poco::RegularExpression re_key("spectrum center", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression::Match match; if (re_key.match(line, 0, match)) { Poco::RegularExpression re_sig("=[ ]*([0-9]+.[0-9]*)[ ]*[ ,][ ]*([0-9]+.[0-9]+)"); if (re_sig.match(line, 0, match)) { Poco::RegularExpression::MatchVec posVec; re_sig.match(line, 0, posVec); if (posVec.size()==3) { std::string num_str = line.substr(posVec[1].offset, posVec[1].length); Poco::NumberParser::tryParseFloat(num_str, m_center_x); num_str = line.substr(posVec[2].offset, posVec[2].length); Poco::NumberParser::tryParseFloat(num_str, m_center_y); } } } }
/// Read the TOF cuts from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readTOFcuts(const std::string& line) { Poco::RegularExpression re_key("tof edge discard", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression::Match match; if (re_key.match(line, 0, match)) { Poco::RegularExpression re_sig("=[ ]*([0-9]+)[ ]*[ ,][ ]*([0-9]+)"); if (re_sig.match(line, 0, match)) { Poco::RegularExpression::MatchVec posVec; re_sig.match(line, 0, posVec); if (posVec.size()==3) { std::string num_str = line.substr(posVec[1].offset, posVec[1].length); Poco::NumberParser::tryParseFloat(num_str, m_low_TOF_cut); num_str = line.substr(posVec[2].offset, posVec[2].length); Poco::NumberParser::tryParseFloat(num_str, m_high_TOF_cut); } } } }
/// Read the source slit sizes from a config file string /// @param line :: line (string) from the config file void EQSANSLoad::readSourceSlitSize(const std::string& line) { Poco::RegularExpression re_key("wheel", Poco::RegularExpression::RE_CASELESS); Poco::RegularExpression::Match match; if (re_key.match(line, 0, match)) { Poco::RegularExpression re_sig("([1-8]) wheel[ ]*([1-3])[ \\t]*=[ \\t]*(\\w+)"); if (re_sig.match(line, 0, match)) { Poco::RegularExpression::MatchVec posVec; re_sig.match(line, 0, posVec); if (posVec.size()==2) { std::string num_str = line.substr(posVec[1].offset, posVec[1].length); int slit_number = 0; Poco::NumberParser::tryParse(num_str, slit_number); slit_number--; num_str = line.substr(posVec[2].offset, posVec[2].length); int wheel_number = 0; Poco::NumberParser::tryParse(num_str, wheel_number); wheel_number--; num_str = line.substr(posVec[3].offset, posVec[3].length); Poco::RegularExpression re_size("\\w*?([0-9]+)mm"); int slit_size = 0; re_size.match(num_str, 0, posVec); if (posVec.size()==2) { num_str = line.substr(posVec[1].offset, posVec[1].length); Poco::NumberParser::tryParse(num_str, slit_size); } m_slit_positions[wheel_number][slit_number] = slit_size; } } } }