Cint


This code works at CINT. 

But when I try to compile the program by a Makefile, it gives the error at the below.

[color=red]H_dec.cc: In function `int main()':
H_dec.cc:84: warning: converting to `int' from `float'
H_dec.cc:86: error: invalid types `TH1F*[72][float]' for array subscript
make: *** [H_dec] Error 1[/color]

How should I use TH1Farray class in a .cc file?

This code works at CINT.

But when I try to compile the program by a Makefile, it gives the error at the below.

[color=red]H_dec.cc: In function int main()': H_dec.cc:84: warning: converting toint’ from float' H_dec.cc:86: error: invalid typesTH1F*[72][float]’ for array subscript
make: *** [H_dec] Error 1[/color]

How should I use TH1Farray class in a .cc file?

Hi,

Try adding #include “TH1F.h”?

Philippe.

I tried it. It gives the same error. here is the include part of my code;

#include <TSystem.h>
#include “TH1F.h”
#include <TROOT.h>
#include <TRint.h>
#include <TFile.h>
#include <TTree.h>
#include <TEventList.h>
#include <TChain.h>
#include <TH1D.h>
//#include <TF1.h>
//#include <TH2.h>
#include “TVector2.h”
#include “TVector3.h”
#include “TLorentzVector.h”
#include <TCanvas.h>
#include <TMath.h>
#include <TProfile.h>
#include <TProfile2D.h>
#include “TClonesArray.h”
#include <TStyle.h>
#include “time.h”
#include
#include
#include
#include
#include <math.h>
#include
#include

[quote]H_dec.cc:84: warning: converting to int' fromfloat’
H_dec.cc:86: error: invalid types `TH1F*[72][float]’ for array subscript [/quote]humm … what is the content of the line 84 and 86? [It does not seem to what you mentioned in you first post].

Philippe.

I do lots of TH1F histos like this;

     52      TH1F *h[30][72];
     53      for (int ie=0; ie<=29; ie++ ){
     54       for (int ip=0; ip<=71; ip++ ){
     55       TString histoname = "eta";
     56       if (ie<=14) histoname += (ie-15);
     57       if (ie>14)  histoname += (ie-14);
     58       histoname += "phi";
     59       histoname += (ip+1);
     60       h[ie][ip] = new TH1F(histoname,"RecH0en--dep4-"+histoname,100,-10,50);

And I Fill all the TH1F histos by the loops at the below. It works when I use t.C and t.h system. but I want to do the same job by using C compiler.

     81    int nevent = chain.GetEntries();
     82         for (int i=0; i<nevent; i++ ) {
     83            chain.GetEvent(i);
     84              for (int cell=0; cell<ihohit;cell++) {
     85     //         int cell=0; 
     86              int eykgi = RecHOEta[cell]+14;
     87              if (RecHOEta[cell]<0) eykgi++;
     88              h[eykgi][RecHOPhi[cell]-1]->Fill(RecHOen[cell]);

[color=red]H_dec.cc:86: warning: converting to int' fromfloat’
H_dec.cc:88: error: invalid types `TH1F*[72][float]’ for array subscript
make: *** [H_dec] Error 1[/color]

[/code]

Hi,

The problem is that RecHOEta and RecHOPhi are (seemingly) declared as array of floats. If there are intended to be used as indices, you should declare them as array of ints or longs.

Cheers,
Philippe.

I changed like this;

     66 //float RecHOPhi[375];
     67 int RecHOPhi[375];
     68 //float RecHOEta[375];
     69 int RecHOEta[375];

It was compiled without an error. but when I run it I got;

*** Break *** segmentation violation
Using host libthread_db library “/lib64/tls/libthread_db.so.1”.
Attaching to program: /proc/9374/exe, process 9374
[Thread debugging using libthread_db enabled]
[New Thread 4131854816 (LWP 9374)]
0xffffe410 in __kernel_vsyscall ()
#1 0x00356f13 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2 0x003007b9 in do_system () from /lib/tls/libc.so.6
#3 0x0043398d in system () from /lib/tls/libpthread.so.0
#4 0xf7af1d4d in TUnixSystem::Exec ()
from /afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_2_1_9/external/slc4_ia32_gcc345/lib/libCore.so
#5 0xf7af83d0 in TUnixSystem::StackTrace ()
from /afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_2_1_9/external/slc4_ia32_gcc345/lib/libCore.so
#6 0xf7af4959 in TUnixSystem::DispatchSignals ()
from /afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_2_1_9/external/slc4_ia32_gcc345/lib/libCore.so
#7 0xf7af4a03 in SigHandler ()
from /afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_2_1_9/external/slc4_ia32_gcc345/lib/libCore.so
#8 0xf7af3aae in sighandler ()
from /afs/cern.ch/cms/sw/slc4_ia32_gcc345/cms/cmssw/CMSSW_2_1_9/external/slc4_ia32_gcc345/lib/libCore.so
#9
#10 0x0804a575 in main () at HO.cc:94

     94              h[eykgi][RecHOPhi[cell]-1]->Fill(RecHOen[cell]);

how could I declare them as array of ints or longs ?

Hi,

[quote]how could I declare them as array of ints or longs ?[/quote]You already did (and you picked the ‘int’ case).

The crash probably means that you reading past the end of the array (i.e.
ecHOPhi[cell]-1 is too big) and/or you did not initialize the element.

You can try to debug this by either running root.exe (or your executable) in a debugger (gdb) or try using valgrind (valgrind.org).

Cheers,
Philippe.