RE: Reading files from a root executable

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Fri, 18 Nov 2005 08:57:32 -0600


> Int_t n_run[10000000], n_ev[10000000];

Most likely this is the problem. You are trying to allocated 80Mb on the stack.
Use a TArray, and std::vector<int> or a new'ed array instead.

Cheers,
Philippe

-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch] On Behalf Of Luca Grandi
Sent: Thursday, November 17, 2005 12:18 PM To: roottalk_at_root.cern.ch
Subject: [ROOT] Reading files from a root executable

Hi I continue to get the following error

luca$ ./lifetime

in executing the executable called lifetime. Its source is as it follows and it is compiled to run outside root.

#include <iostream>
#include "TFile.h"
#include "stdio.h"
#include "stdarg.h"
#include <fstream>
#include "Riostream.h"

int main()
{

    Int_t nlines=0;

    Int_t n_run[10000000], n_ev[10000000];     ifstream FILE_ntp;
    FILE_ntp.open("run800.ntp");
    while (1){
    if (!FILE_ntp.good()) {break; printf("ERRORE\n");}

      FILE_ntp >> n_run[nlines];
      if (nlines<5) printf("%d\n",n_ev[nlines]);
      nlines++;
   }        

}

To create the executable I have used the makefile attached at the end of the mail: in the same directory I have the standard Makefile.Arch file. Compiling it under OSX gives me the output

c++ -O2 -pipe -Wall -W -Woverloaded-virtual -D_REENTRANT -Wno-long-double -I/sw/include/root -c lifetime.cxx
MACOSX_DEPLOYMENT_TARGET=10.4 c++ -O2 -bind_at_load lifetime.o

-L/sw/lib/root -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint
-lPostscript -lMatrix -lPhysics -L/usr/X11R6/lib -lfreetype -lpthread -lm
-ldl  -o lifetime

lifetime done
MACOSX_DEPLOYMENT_TARGET=10.4 c++ -dynamiclib -single_module -undefined dynamic_lookup -o
make: *** [all] Abort trap

WHAT IS the problem? I have written other small programs and I get the same error each time I Try to read a file (for example with scanf) while I have no problem to write on files. Note that they are working properly if executed as a script in root

Thanks
Luca

# Makefile for the ROOT test programs.
# This Makefile shows nicely how to compile and link applications
# using the ROOT libraries on all supported platforms.
#
# Copyright (c) 2000 Rene Brun and Fons Rademakers
#
# Author: Fons Rademakers, 29/2/2000

include Makefile.arch

#---------------------------------------------------------------------------

---

LIFETIMEO       = lifetime.$(ObjSuf)
LIFETIMES       = lifetime.$(SrcSuf)
LIFETIME       = lifetime$(ExeSuf)



OBJS          = $(LIFETIMEO)

PROGRAMS      = $(LIFETIME)


#---------------------------------------------------------------------------
--- .SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf) all: $(PROGRAMS) ifeq ($(PLATFORM),macosx)
# We need to make both the .dylib and the .so
$(LD) $(SOFLAGS) $(EVENTO) $(OutPutOpt) $(EVENTSO) $(LD) -bundle -undefined $(UNDEFOPT) $(LDFLAGS) $^ \ $(OutPutOpt) $(subst .$(DllSuf),.so,$@) endif @echo "$@ done" $(LIFETIME): $(LIFETIMEO) $(LD) $(LDFLAGS) $^ $(LIBS) $(OutPutOpt)$@ @echo "$@ done" clean: @rm -f $(OBJS) core .SUFFIXES: .$(SrcSuf)
###
.$(SrcSuf).$(ObjSuf): $(CXX) $(CXXFLAGS) -c $<
Received on Fri Nov 18 2005 - 15:59:32 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET