Cannot run a root macro with user-defined class

Dear Rooters

I tried to convert my analysis code to a Root macro. The problem is that my code includes a class I defined and implemented in separate files. When I run “root .x .cc”, the error message is

Processing Z-Adjustment_alphaRoot.cc…
In file included from input_line_9:1:
/Ramiel/My Document/Work/KMUTT Work/LI/Z-Adjustment/RootMacro/Z-Adjustment_alphaRoot.cc:37:6: error: expected ‘;’ after top level declarator
int Z-Adjustment_alphaRoot()
^
;

What could be the problem?

ps I tried to search the forum for similar problems and could not find any.
My Root version is 6.04.
I am running on Mac OS X 10.8.5

Please help,
Kachanon
StudentMark.cc (1.25 KB)
StudentMark.h (908 Bytes)
Z-Adjustment_alphaRoot.cc (12.8 KB)

Hi,

the first thing would be to avoid invalid function names, like the ones containing “-”, e.g. “Z-Adjustment_alphaRoot” should be “Z_Adjustment_alphaRoot”.
Then what you can do is the following from the root prompt:

root[0] .L StudentMark.cc+
root[1] .x  Z_Adjustment_alphaRoot.cc

I attached the modified files because of the name change mentioned above and some missing include guards.

Cheers,
Danilo
StudentMark.h (964 Bytes)
Z_Adjustment_alphaRoot.cc (12.8 KB)
StudentMark.cc (1.25 KB)

Hi,

Thank you very much for your help. I followed your suggestion and it produced an error I do not understand. The error message is:

root [0] .L StudentMark.cc+
Info in TMacOSXSystem::ACLiC: creating shared library /Ramiel/My Document/Work/KMUTT Work/LI/Z-Adjustment/RootMacro/./StudentMark_cc.so
clang: warning: unknown warning option ‘-Wheader-guard’; did you mean ‘-Wheader-hygiene’?
warning: unknown warning option ‘-Wheader-guard’; did you mean
’-Wheader-hygiene’? [-Wunknown-warning-option]
1 warning generated.
root [1] .x Z_Adjustment_alphaRoot.cc
root.exe(1077,0x7fff7a554180) malloc: *** mmap(size=140377062785024) failed (error code=12)
*** error: can’t allocate region
*** set a breakpoint in malloc_error_break to debug
libc++abi.dylib: terminate called throwing an exception

Cheers,
Kachanon

Hi Kachanon,

this looks weird:I cannot reproduce the issue.
How did you install root (from sources, binaries)? What version of OSx you are running on?
Did you modify the studentMark.cc file and if yes, could you repost it?

Cheers,
Danilo

Hi,

I installed Root using command “tar -xzf root_v6.04.02.macosx64-10.8-clang51.tar.gz” o the binary-version file I downloaded from root.cern.ch/content/release-60402 .

In my .bash_profile, I have
export ROOTSYS=$HOME/root
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LUBRARY_PATH:ROOTSYS/lib

My OS X version is 10.8.5 .

I didn’t modify any files you give me. I attach the three C++ files and also the input txt file just in case.

Cheers,
Kachanon
Data.txt (7.63 KB)
StudentMark.cc (1.23 KB)
StudentMark.h (933 Bytes)
Z_Adjustment_alphaRoot.cc (12.9 KB)

Hi,

After running “.L StudentMark.cc+” and .x the macro again, it seems to work. Unfortunately, it doesn’t like my end-of-file checking. Somehow, it returns segmentation violation after it meet the end of the file. I am working on this issue. If I manage to fix it, I will let you know. If you have any suggestions, please give them to me.

Regards,
Kachanon

Hi,

After deleting the blank line at the end of the input file, everything works properly. Problem’s solved!

Thanks a lot for the help,
Kachanon Nirunpong