Unable to read from large ascii data file

Hello,
I’m trying to get a tree from an ASCII data file, which is of about 3 Gb.
But when I try

[code]int getdatatree(char *filename) {
FILE *input = fopen(filename, “r”);

if (input == NULL) return 1;

TFile *rootfile = new TFile("data.root", "RECREATE");

TTree *t = new TTree("data", "data read from file");

Int_t n;
Int_t m;
Double_t x;
Double_t y;
Double_t z;
Double_t w;

t->Branch("a", &n);
t->Branch("b", &m);
t->Branch("c", &x);
t->Branch("d", &y);
t->Branch("e", &z);
t->Branch("f", &w);


while (feof(input) == 0) {
	if (fscanf(input, "%d %d", &n, &m) != 2) break;
	
	if (fscanf(input, "%lf %lf %lf %lf", &x, &y, &z, &w) != 4) break;
	t->Fill();	
}
	
rootfile->Write();

fclose(input);
rootfile->Close();

return 0;

}
[/code]

I get 1 as return value, and obviously the tree is not filled.

Is there any solution?

Thanks,
Rene

And if it is not the case (e.g. if there is no solution to this which seems to be a file offset bits related issue), is there any way to automatically read multiple files with a same pattern?
I mean, in C I would do

[code]int main(int argc, char **argv) {
int i;

if (argc < 2) return 1;

for (i = 1; i < argc; i++) {
	/* read data from the file "argv[i]"
	   and then update the tree */
}

printf("%d files read\n", argc-1);

return 0;

}[/code]
calling this using

Hi,

[quote]I get 1 as return value, and obviously the tree is not filled. [/quote] so the line FILE *input = fopen(filename, "r"); fails. You may need to use fopen64 and/or use a 64b build.

Cheers,
Philippe.

I tried, but in the ROOT prompt I got

while if I compile the macro, after some seconds of computation I get a segmentation violation error.

This is the header I added:

[code]#include
#include <TObject.h>
#include <TString.h>
#include <TCut.h>
#include <TTimeStamp.h>
#include <TTree.h>
#include <TFile.h>
#include <TROOT.h>
#include <TBranch.h>
#include <TNamed.h>
#include <TChain.h>
#include <TMath.h>
#include <TGraphErrors.h>
#include <TMultiGraph.h>
#include <TLegend.h>
#include <TAxis.h>
#include <stdio.h>

extern FILE* fopen64(const char *filename, const char *type);
[/code]

(note the extern definition, otherwise neither ROOT nor gcc seem to recognize fopen64).

Uhm, how can I use a 64b build on my 32 bit SLC5 machine?

Thanks in advance.

Hi,

fopen64 is not available via CINT (and anyway you really will need to compile in order to process the 3Gb in a reasonable time).

You can’t :slight_smile:

[quote]while if I compile the macro, after some seconds of computation I get a segmentation violation error.
[/quote]What is the stack trace?

Cheers,
Philippe.