Problems reading an ascii file

I am using Root 3.03/09, compiled for win32 (VC6). I cannot test my macro with a more recent version, I don’t have VC7.
I copied an example from the tutorial named basic.C, which reads an ascii file and puts the contents in an ntuple, and put it in my HOME directory. Here is the source:

//   example of macro to read data from an ascii file and
//   create a root file with an histogram and an ntuple.
#include <iostream.h>

   ifstream in;
// we assume a file basic.dat in the current directory
// this file has 3 columns of float data"basic.dat", ios::in);

   Float_t x,y,z;
   Int_t nlines = 0;
   TFile *f = new TFile("basic.root","RECREATE");
   TH1F *h1 = new TH1F("h1","x distribution",100,-4,4);
   TNtuple *ntuple = new TNtuple("ntuple","data from ascii file","x:y:z");

   while (1) {
      in >> x >> y >> z;
      if (!in.good()) break;
      if (nlines < 5) printf("x=%8f, y=%8f, z=%8f\n",x,y,z);
   printf(" found %d points\n",nlines);



The macro works fine, I get no error message, except that it finds no point (although the file contains data in the required format) and makes no output file named basic.root. Here is the output:

Any idea ?


Your given macro works fine with ROOT v3.10.02 on Linux, after adding the missing opening parenthesis at the beginning. Are you sure that you have read permissions set correctly on the file? What does
gSystem->AccessPathName(“basic.dat”, kReadPermission);
from within a ROOT session in that directory return? It should return zero
if the file is readable. Or, try inserting the lines
if( ! in.is_open() )
std::cerr << “unable to open basic.dat.\n”;
after“basic.dat”, ios::in);
If that does not work, I would suspect that there is something funny with the input file, e.g., was it created on a different platform?


I tried all this. Even creating a new file containing vectors in notepad won’t work. The fileopening works fine (he opens the file without error), but I don’t see my entrires.
Maybe this is some nasty Windows feature (I am new to windows) ?


Move to a more recent version, eg 3.10/02
ifstream was not supported in 3.09 under Windows.
3.10/02 should work also with VC++6