Commit 242f8087 authored by Erik Asbjørn Mikkelsen Jensen's avatar Erik Asbjørn Mikkelsen Jensen
Browse files

improved output of dataprinter

parent 25a167ce
......@@ -25,6 +25,8 @@
using namespace std;
vector<string> comps{"==", "!=", "<", ">", "<=", ">="};
void modify_and_print(string filename) {
ifstream ifs(filename.c_str());
string line;
......@@ -46,6 +48,13 @@ void modify_and_print(string filename) {
}
}
bool is_crit(string str) {
for (string q : comps) {
if (str.find(q) != string::npos) return true; // if string q is found in string str, str is a criterion
}
return false;
}
int main(int argc, char* argv[]) {
// Open the root-file, which is the first given argument, and access its tree with the name of the second given argument
TFile input(argv[1]);
......@@ -54,26 +63,20 @@ int main(int argc, char* argv[]) {
// Separate out all other arguments as either parameters to be printed or criteria on the parameters (comparison statements)
vector<string> args(argv + 3, argv + argc);
vector<string> comps{"==", "!=", "<", ">", "<=", ">="};
vector<string> argtypes;
string printvars = "";
string selection = "";
int flag; // flag = 0 means the string s in the loop below is a parameter to be printed, flag = 1 means it is a criterion
for (string s : args) {
flag = 0;
for (string q : comps) {
if (s.find(q) != string::npos) { // if string q is found in string s, s is a criterion -> flag = 1
flag = 1;
break;
}
}
if (flag == 0) {
if (!is_crit(s)) {
if (!printvars.empty()) printvars += ":"; // printvars = "var1:var2:var3:...:varN" when we are done
printvars += s;
argtypes.emplace_back("var");
} else {
if (!selection.empty()) selection += " && "; // selection = "sel1 && sel2 && sel3 && ... && selM" when we are done
selection += s;
argtypes.emplace_back("sel");
}
}
/*
......@@ -94,11 +97,22 @@ int main(int argc, char* argv[]) {
stdout = saved; // stdout back to normal
// Print a comment line showing the command which created the output
cout << "#";
for (int i = 0; i < argc; i++) {
cout << "###### Output created with the following command ######" << endl;
cout << "# ";
int i;
for (i = 0; i < 3; i++) {
cout << argv[i] << " ";
}
cout << "[criteria must be surrounded by \"'s, e.g. A <= 20 -> \"A <= 20\"]" << endl;
for (string s : argtypes) {
if (s.compare("var") == 0) {
cout << argv[i] << " ";
i++;
} else if (s.compare("sel") == 0) {
cout << "\"" << argv[i] << "\" ";
i++;
}
}
cout << endl;
// Print output in suitable format
modify_and_print(tmpf);
......
Supports Markdown
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