Using ifstream with root 5.34.26 on ubuntu 14.04

Hi,

my script crashes just as I try to use ifstream to read a file. This is the corresponding part of my script:


#include
#include
#include
#include <math.h>

#include “TAxis.h”
#include “TH2.h”
#include “TStyle.h”
#include “TCanvas.h”
#include “TNtupleD.h”
#include <stdio.h>
#include <stdlib.h>
#include <vector.h>

using namespace std;

TCanvas* rod(){

TFile *temp=new TFile(“rod.root”, “RECREATE”);

   char rubish[20];

   double values = 0.;

   cout << "start r = 1" << endl;

   ifstream file_h60_r1_lines("h60/Rod_h60_r1/output.txt");

   int lines_h60_r1 = 0;

   while (!file_h60_r1_lines.eof()) {
 if (lines_h60_r1==0) file_h60_r1_lines >> rubish >> rubish >> rubish >> rubish >> rubish >> rubish;
 else file_h60_r1_lines >> values >> values >> values >> values >> values >> values;
     lines_h60_r1++;
   }
          cout << "start r = 1_2" << endl;

and the output is:


adriana@adriana:~/Thorium/Rod$ root rod.C


  •                                     *
    
  •    W E L C O M E  to  R O O T       *
    
  •                                     *
    
  • Version 5.34/26 20 February 2015 *
  •                                     *
    
  • You are welcome to visit our Web site *
  •      [root.cern.ch](http://root.cern.ch)            *
    
  •                                     *
    

ROOT 5.34/26 (v5-34-26@v5-34-26, Feb 20 2015, 13:23:25 on linux)

CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing rod.C…
start r = 1

*** Break *** segmentation violation

===========================================================
There was a crash (#6 0xb71d37bb in SigHandler(ESignals) () from /home/adriana/root/lib/libCore.so).
This is the entire stack trace of all threads:

#0 0xb771f424 in __kernel_vsyscall ()
#1 0xb6d82313 in __waitpid_nocancel () at …/sysdeps/unix/syscall-template.S:81
#2 0xb6d0cdad in do_system (line=0x8e1f280 “/home/adriana/root/etc/gdb-backtrace.sh 23171 1>&2”) at …/sysdeps/posix/system.c:148
#3 0xb71cd8bb in TUnixSystem::Exec(char const*) () from /home/adriana/root/lib/libCore.so
#4 0xb71d15c2 in TUnixSystem::StackTrace() () from /home/adriana/root/lib/libCore.so
#5 0xb71d3687 in TUnixSystem::DispatchSignals(ESignals) () from /home/adriana/root/lib/libCore.so
#6 0xb71d37bb in SigHandler(ESignals) () from /home/adriana/root/lib/libCore.so
#7 0xb71cc792 in sighandler(int) () from /home/adriana/root/lib/libCore.so
#8 0xb7201b55 in textinput::TerminalConfigUnix::HandleSignal(int) () from /home/adriana/root/lib/libCore.so
#9 0xb7201ba4 in (anonymous namespace)::TerminalConfigUnix__handleSignal(int) () from /home/adriana/root/lib/libCore.so
#10
#11 __memcpy_ssse3_rep () at …/sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1243
#12 0xb6efa479 in std::basic_istream<char, std::char_traits >& std::operator>><char, std::char_traits >(std::basic_istream<char, std::char_traits >&, char*) () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#13 0xb68c6202 in G__G__stream__0_48(G__value*, char const*, G__param*, int) () from /home/adriana/root/lib/libCint.so
#14 0xb672b5c3 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) () from /home/adriana/root/lib/libCint.so
#15 0xb67dae2f in G__execute_call () from /home/adriana/root/lib/libCint.so
#16 0xb67db1fe in G__call_cppfunc () from /home/adriana/root/lib/libCint.so
#17 0xb67b69b8 in G__interpret_func () from /home/adriana/root/lib/libCint.so
#18 0xb67a566c in G__getfunction () from /home/adriana/root/lib/libCint.so
#19 0xb67fdd89 in G__overloadopr () from /home/adriana/root/lib/libCint.so
#20 0xb6800a9a in G__bstore () from /home/adriana/root/lib/libCint.so
#21 0xb678293d in G__getexpr () from /home/adriana/root/lib/libCint.so
#22 0xb6809ab1 in G__exec_statement () from /home/adriana/root/lib/libCint.so
#23 0xb6812f85 in G__exec_statement () from /home/adriana/root/lib/libCint.so
#24 0xb6818041 in G__exec_loop(char const*, char*, std::list<G__FastAllocString, std::allocator<G__FastAllocString> > const&) [clone .constprop.42] () from /home/adriana/root/lib/libCint.so
#25 0xb680fc3f in G__exec_statement () from /home/adriana/root/lib/libCint.so
#26 0xb67b7e59 in G__interpret_func () from /home/adriana/root/lib/libCint.so
#27 0xb67a566c in G__getfunction () from /home/adriana/root/lib/libCint.so
#28 0xb677c39e in G__getitem () from /home/adriana/root/lib/libCint.so
#29 0xb6781a6c in G__getexpr () from /home/adriana/root/lib/libCint.so
#30 0xb678da20 in G__calc_internal () from /home/adriana/root/lib/libCint.so
#31 0xb681efef in G__process_cmd () from /home/adriana/root/lib/libCint.so
#32 0xb7190cf5 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/adriana/root/lib/libCore.so
#33 0xb718c92b in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/adriana/root/lib/libCore.so
#34 0xb70e932f in TApplication::ExecuteFile(char const*, int*, bool) () from /home/adriana/root/lib/libCore.so
#35 0xb70e978c in TApplication::ProcessFile(char const*, int*, bool) () from /home/adriana/root/lib/libCore.so
#36 0xb70e86a1 in TApplication::ProcessLine(char const*, bool, int*) () from /home/adriana/root/lib/libCore.so
#37 0xb6fb3545 in TRint::Run(bool) () from /home/adriana/root/lib/libRint.so
#38 0x08048cc0 in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#11 __memcpy_ssse3_rep () at …/sysdeps/i386/i686/multiarch/memcpy-ssse3-rep.S:1243
#12 0xb6efa479 in std::basic_istream<char, std::char_traits >& std::operator>><char, std::char_traits >(std::basic_istream<char, std::char_traits >&, char*) () from /usr/lib/i386-linux-gnu/libstdc++.so.6

Root > Function rod() busy flag cleared

root [1]


I would be very grateful for any suggestions.

Thank you,

Cristian

Hi Cristian,

This is maybe not related, but you should add a test to make sure your file exists… Something like:

if (!file_h60_r1_lines) { cout << "sorry, the file \"h60/Rod_h60_r1/output.txt\" does't exists" << endl; return; }
And there are several tutorials in $(ROOTSYS)/tutorials using ifstream (graphics\earth.C, graphs\motorcycle.C, and basic.C). Do they also fail for you?

Cheers, Bertrand.

Hello,

Thank you for your reply. The root scripts in the tutorials are running fine. However I did check the existence of the input file before posting the question and it was there.

I have attached the relevant part of my script which I renamed test.C and the input ASCII file - if you could please try to run it. It runs perfectly fine on my MacOSX, but not on my Ubuintu 14.04. The ROOT version is 5.34.26.

Thank you,

Cristian
output.txt (1.86 KB)
test.C (926 Bytes)

char rubish[32];

Use something like: char rubish[200];instead of char rubish[20];
(sorry, I didn’t see that Wile replied in the same time…)

Oh dear,

I am really sorry about this :blush: It was running fine on my Mac though.

Thank you for looking into this,

Best regards,

Cristian