Advanced Computing Platform for Theoretical Physics

Commit 556225b1 authored by Yu-Chen Ding's avatar Yu-Chen Ding
Browse files

distinguish match/exact

parent 8b48d7c6
......@@ -136,6 +136,8 @@ class CRDataset : public std::vector<std::shared_ptr<CRData>> {
public:
std::shared_ptr<CRData> find_exact(const std::string& quantity,
const std::string& exp) const;
std::shared_ptr<CRData> find_match(const std::string& quantity,
const std::string& exp) const;
};
class CRPlot {
......
......@@ -374,8 +374,7 @@ std::shared_ptr<CRData> CRDataset::find_exact(const std::string& quantity,
const std::string& exp) const {
std::shared_ptr<CRData> found = nullptr;
for (const auto& e : *this) {
if (_CRUTIL::is_substr_i(e->experiment, exp) &&
quantity == e->y_quantity) {
if (e->experiment == exp && quantity == e->y_quantity) {
if (found) {
throw std::runtime_error("ambiguous '" + quantity +
"' data found for '" + exp + "'");
......@@ -386,6 +385,28 @@ std::shared_ptr<CRData> CRDataset::find_exact(const std::string& quantity,
return found;
}
std::shared_ptr<CRData> CRDataset::find_match(const std::string& quantity,
const std::string& exp) const {
std::shared_ptr<CRData> found = nullptr;
size_t eff_len = -1;
for (const auto& e : *this) {
if (_CRUTIL::is_substr_i(e->experiment, exp) &&
quantity == e->y_quantity) {
size_t new_eff_len = e->experiment.find('(');
if (new_eff_len == std::string::npos) {
new_eff_len = e->experiment.size();
}
if (found && new_eff_len >= eff_len) {
// use minimum matched entry
continue;
}
found = e;
eff_len = new_eff_len;
}
}
return found;
}
CRData CRData::from_crd(const std::string& filename) {
_CRUTIL::StreamParser fp(filename);
std::ifstream ifs(filename);
......
......@@ -12,7 +12,7 @@ int main(int argc, char* argv[]) {
CRDataset ds;
ds.parse_file(argv[1]);
auto data = ds.find_exact("B/C", "AMS02");
auto data = ds.find_match("B/C", "AMS02");
plot.AddData(*data, {2, 20, 1});
// plot.AddCurve(argv[2], {3, 2, 2}, "fitted B/C");
......
......@@ -12,7 +12,7 @@ int main(int argc, char* argv[]) {
CRDataset ds;
ds.parse_file(argv[1]);
auto data = ds.find_exact("B/C", "AMS02");
auto data = ds.find_match("B/C", "AMS02");
plot.AddData(*data, {2, 20, 1}, "AMS02");
// plot.AddCurve(argv[2], {3, 2, 2}, "fitted B/C");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment