Compare a column of an ASCII file with a known number to find matching points

Good afternoon,

thank you for reading and employ your time helping a beginner like me.
I have an ascii file with 4 columns comma separated: The first column is made of characters, the other three are double.

I am trying to open the file and then I need to compare a number (in my code called xpeak) with the second column of my file and as soon as xpeak = #of the 2 column, I need to print the entire row.

I don’t know if it is clearly explained, but to be more specific:
if xpeak=a number of the second column
print the string, double, double, double corresponding to that.

could anyone please give me some hint to do this? I know that I need a for loop, but I can’t figure out how to loop on a single column and then make me print the entire row. I am stuck and I don’t know how to go ahead with this.

thank you very much

ROOT Version: latest 6.
Platform: linux
Compiler: Not Provided

In ROOT, try something like:

  const char *filename = "MyAsciiFile.txt";
  TTree *t = new TTree("t", "t");
  // 4 columns (a string and 3 double values) comma separated
  t->ReadFile(filename, "c1/C:c2/D:c3/D:c4/D", ',');
  double xpeak = 100.0; // set the actual value here
  t->Scan("*", TString::Format("c2 == %25.17g", xpeak));

Hello Wile,
thank you for your support, it does compile, but I would also like to print the value of the 4 columns when found c2=xpeak. how can I do that?

thank you again for your help and time

Try: t->Scan("*");

it does work perfectly, thank you so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.