Leafxxx->GetValue() return 0 when called into c code

Hi,

i’m tring to prepare an interface for FORTRAN an so i need to be able to read leaves.

I don’t understand why in the following code doesn’t give me back a value for “GetValue(##)” but always 0.
My leaf inherits from TLeafElement, the variable tree has been setted before as a general variable so it’s not null, also because all other GetNdata(), GetType(), etc… give me back correct values


double getleafdata_(int *Nentry, int *index, char leafName, int leafName_len){
leaf = (TLeaf
)tree->GetLeaf(leafName);
double tempD;

if(tree != 0) tree->GetEntry((Int_t)*Nentry);
if (leaf->InheritsFrom(“TLeafElement”)){
TLeafElement tle = (TLeafElement)tree->GetLeaf(leafName);
tempD = (double)tle->GetValue(*index);
printf(“%d”, tempD);
}

printf(“leafNAme------>%s \n”, leafName);
printf(“Nentry------>%d \n”, *Nentry);
printf(“index------->%d \n”, *index);
printf(“Ndata------->%d \n”, leaf->GetNdata());
printf(“value------->%s \n”, leaf->GetValue(*index)); <-----this one get null in return
leaf->PrintValue(1); <---- this one print the correct value on stdout

i made the same command through the root prompt

leaf = (TLeaf*)tree->GetLeaf(“somename”);
leaf->GetValue(somevalue)

and it work… some hints?

This is odd that you had to add [i](double)[/i]
Did you check the value of *index compare to GetNdata()?

Philippe.

This is odd that you had to add i[/i]
Did you check the value of *index compare to GetNdata()?

Philippe.

yes index and Nentry are in the correct ranges…

printf(“leafName------>%s \n”, leafName);
printf(“Nentry------>%d \n”, *Nentry);
printf(“index------->%d \n”, *index);
printf(“Ndata------->%d \n”, leaf->GetNdata());
printf(“value------->%u \n”, leaf->GetValue(*index));
leaf->PrintValue(*index);

the output is

leafName------>Records.TM_RECORD_OBT
Nentry------>0
index------->1
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

as you can see GetValue is still zero…

Cheers,
Maurizio

[quote]index------->1
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

as you can see GetValue is still zero… [/quote]
And this is normal. The ranger of the data is from 0 to Ndata exclusive.
I.e. You have to transform fortran index (1 to Ndata inclusive) to C index (0 to Ndata exclusive).

Cheers,
Philippe.

but it can’t be because i tried also to set by hands the value in the C code and these are the
results

leafName------>Records.TM_RECORD_OBT
Nentry------>0
index------->0
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

leafName------>Records.TM_RECORD_OBT
Nentry------>1
index------->0
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

leafName------>Records.TM_RECORD_OBT
Nentry------>1
index------->1
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

leafName------>Records.TM_RECORD_OBT
Nentry------>0
index------->1
Ndata------->1
value------->0
Records.TM_RECORD_OBT = 9243

other idea?

Hi,

I would need to look at the root file. Please let me know where to find it.

Cheers,
Philippe

Hi,

this is the file you asked for.

Thanks,
Maurizio
Run0001.Tmtc.Event.root (10.2 KB)

Hi,

This is quite odd :frowning:
I am unable to reproduce any problem.
In addition the code execute by PrintValue and GetValue is extremely similar (i.e. I don’t see the difference in you case).
Are you using a MakeClass generated skeleton?
Can you send me a tar file I can use to reproduce your problem?

Cheers,
Philippe.

Hi,

here is code with also a compiled version of the code just execute the “edai” file (transl. of “c’mon!”)

really thanks! :slight_smile:

Maurizio
interface.tar.gz (29 KB)

Hi,

Which platform is it compiled for?
How can I recompile it?
How can I run it?

Philippe

Hi,

well… it’s all in the file called “compile”

isn’t it?

cheers
Maurizio

The file named ‘compile’ appears (to me) as a binary file. I can read its content with a text editor and can not execute it either.

Cheers,
Philippe.

you are right…i don’t know why it is in such a shape… tomorrow i’ll take a look it it … it have not to be in that way…

have a good night

Cheers :slight_smile:

Maurizio

Well…
you has been so nice that i couldn’t leave you without what you asked for so…
here a new tar file with correct “compile” file

Cheers
Maurizio
interface.tar.gz (129 KB)

Hi,

The index has to be a C++ index AND you have properly use the value.
Your code reads:

this interpretes the argument to print a unsigned int. Since the argument is a double, it does not work right.
Once I use:

And set index to 0, and change the return value getleafdata to

I get the ouput below (which seems correct).

Cheers,
Philippe.

bash-2.05a$ ./edai
Hello, world.
Warning in TClass::TClass: no dictionary for class pamela::AlgorithmInfo is available
Warning in TClass::TClass: no dictionary for class pamela::RunInfo is available
Warning in TClass::TClass: no dictionary for class pamela::SubPacket is available
Warning in TClass::TClass: no dictionary for class pamela::TmtcEvent is available
Warning in TClass::TClass: no dictionary for class pamela::TmtcRecord is available
Records 3.
Event
fUniqueID
fBits
Tmtc_crc_ok
Records
Records.fUniqueID
Records.fBits
Records.TM_RECORD_OBT
Records.TM_DEA_ANA[16]
Records.TM_TH_ANA[16]
Records.TM_BIL_DIAG_ACQ[8]
Records.TM_CC_DIAG_ACQ[32]
Records.TM_DBL_ACQ[8]
Records.TM_DS_16_ACQ[2]
Records.TM_RECORD_CRC
Records.tmtc_crc_tot_ok
Records.TM_DEA_ANA_P[16]
Records.TM_TH_ANA_P[16]
leafName------>Records.TM_RECORD_OBT
Nentry------>0
index------->0
Ndata------->1
value------->9243.000000
Records.TM_RECORD_OBT = 9243
Records.TM_RECORD_OBT
0 0 9243