Adding std::vector<MyClass> to TBranch

I am trying to make a tree with branches that hold an object of type TDepthSlice (my own class). This class contains a std::vector of another class that I have constructed (TVoxel). When trying to push_back my TVoxel-object I get segmanetation violation error. However, if I make the change from std::vector to std::vector push_back works. I would be grateful if someone could tell I do wrong.

Best Regards,
Karin
TVoxel.h (581 Bytes)
TDepthSlice.h (167 Bytes)

1 Like

its always better to stay within ROOT #includes
why not switch to TClonesArray

Hi Karin,

using stl is just fine :slight_smile: You’ll need to add the ClassDef statements, and you need a #pragma link C++ class vector+; in your Linkdef.h. See e.g. attached files (which also fix some other problems). Call .L TVoxel.h+ .L TDepthSlice.h+ .L runTest.C+ runTest()

Axel.
karin_voxel.tar.gz (1.35 KB)

1 Like

Hello Axel!
Thank you for answering so quickly and so thoroughly! Unfortunately I run into problem when I try to follow what you did. I started root and tried .L TVoxel.h+ (with the files that you send me) and I got the following:

Microsoft Windows XP [Version 5.1.2600]
© Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\ked>cd Desktop

C:\Documents and Settings\ked\Desktop>cd karin

C:\Documents and Settings\ked\Desktop\karin>root -l
root [0] .L TVoxel.h+
Info in TWinNTSystem::ACLiC: creating shared library C:\Documents and Settings\ked\Desktop\karin\TVoxel_h.dll
Error: rootcint: The input list file C:\Documents.in does not exist
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
’cl’ is not recognized as an internal or external command,
operable program or batch file.
root [1]

Do you understand what this means?

I also wonder about this .h+. What does it mean? What is the difference between running .L TVoxel.h and .L TVoxel.h+?

Best Regards,
Karin

Hi Karin.

[quote=“karineklund”]C:\Documents and Settings\ked\Desktop\karin>root -l
root [0] .L TVoxel.h+
Info in TWinNTSystem::ACLiC: creating shared library C:\Documents and Settings\ked\Desktop\karin\TVoxel_h.dll
Error: rootcint: The input list file C:\Documents.in does not exist[/quote]
ROOT has a problem compiling stuff in directories which contain a space (as in “Documents and Settings”). We need to fix that - but for now you’ll have to put it into a directory not containign spaces, e.g. C:\rootfiles.

.L file.C (or .h) loads the file into Cint as a macro, i.e. Cint interprets it line by line, (more or less) as if you’d have entered the whole macro at the prompt. .L file.C+ (or .h+) compiles the code into a dynamic library (.so on unix, .dll on windows), and loads that. This gives better error messages as the compiler complains about errors, not Cint, and it improves the execution speed. So I’d always compile my code, loading it with file.C+ (or .h+). You can read more on that in the Users Guide; look for “Aclic”.

Cheers, Axel.

Hello Axel!
I have been busy woth other things for a while, but now I am back on my TDepthSlice-Object project. I moved the folder “karin” to under c: but I still get an error when I do .L TVoxel.h+

C:\karin>root -l
root [0] .L TVoxel.h+
Info in TWinNTSystem::ACLiC: creating shared library :\karin\TVoxel_h.dll
Error: rootcint: environment variable ROOTSYS not defined
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
’cl’ is not recognized as an internal or external command,
operable program or batch file.

The difference is that it now complaines about ROOTSYS not being defined, what is this?

/Karin

Hi Karin,

you have to define ROOTSYS (see the root install web page). And you have to ahve your compiler in your path.

I assume you have MS Visual Studio .NET 2003? Run the “Visual Studio Command Prompt” from the “Visual Studio Tools” subfolder in the Start menu, then “set ROOTSYS=C:\wherever\your\root\is” (you can also define that in Start->Control Panel->System, tab Advanced, button “Environment variables”, such that all programs you start after defining it know what ROOTSYS is), start root, and .L TVoxel.h.

Axel.

Hello again Axel!

I am sorry, but I am confused and I don’t understand. I added the ROOTSYS in enviroment variables (C:\root since this is where I have root, but should it not be root\bin or lib or something?). But what is the compiler I use with .L? I have gcc and it seems to be working. Good enough? Well something is still wrong.

Should I write .h or .h+? If I write .h+ I get:

[quote]root [0] .L TVoxel.h+
Info in TWinNTSystem::ACLiC: creating shared library C:\karin\TVoxel_h.dll
’cl’ is not recognized as an internal or external command,
operable program or batch file.
Internal error: G__copytotmpfile() 2
FILE:C:\DOCUME~1\ked\LOCALS~1\Temp/\s244.rootcint.h LINE:0
Error: cannot open file "C:\DOCUME~1\ked\LOCALS~1\Temp/\s244.rootcint.h" FILE: LINE:0
!!!Removing C:\karin\sh8
.cxx C:\karin\sh8
.h !!!
Error: rootcint: failed to open C:\karin\sh8_.cxx in ReplaceBundleInDict()
‘cl’ is not recognized as an internal or external command,
operable program or batch file.
Error in : Compilation failed![/quote]

If I write .h it does not complain until I get to actually running testRun(), and then it says:

[quote]root [0] .L TVoxel.h
root [1] .L TDepthSlice.h
root [2] .L runTest.C
root [3] runTest()
Error in TBranchElement::GetDataMemberOffset: obsolete call with (TVoxel,fUniqueID)

Error in TBranchElement::GetDataMemberOffset: obsolete call with (TVoxel,fBits)

Error in TBranchElement::GetDataMemberOffset: obsolete call with (TVoxel,fUniqueID)

Error in TBranchElement::GetDataMemberOffset: obsolete call with (TVoxel,fBits)

Error: C++ exception caught FILE:C:\karin\runTest.C LINE:22
(Int_t)0
*** Interpreter error recovered ***
root [4][/quote]
But, then again, what I really want to do is to use VS c++ to write and run my root on windows. I have read your page about it, but beeing not only a beginner with root, I am even more so with VS, so I havn’t really managed to get that to work yet either. This will be my next step.

Best Regards,
Karin

1 Like

Hi Karin,

[quote=“karineklund”]I am sorry, but I am confused and I don’t understand.[/quote]That’s my fault, I’ll explain things a bit more detailed now.

[quote=“karineklund”]I added the ROOTSYS in enviroment variables (C:\root since this is where I have root, but should it not be root\bin or lib or something?).[/quote]Where did you add it? In the control panel / system? Good. It should point to C:\root - not C:\root\bin.

[quote=“karineklund”]But what is the compiler I use with .L?[/quote] It’s the one used to build root - they have to be compatible. So in your case that’s called “cl”. ROOT needs to be able to find that compiler, that’s why it has to be in the %PATH% (the windows version of $PATH). And to get it there you can either edit your PATH environment variable (just like you did for ROOTSYS) - but then you’ll also have to add LIB and INCLUDE, which are needed by the compiler. Or you run the “Visual Studio Command Prompt”, which is just a “windows shell”, but with the proper environment variables set.

[quote=“karineklund”]I have gcc and it seems to be working. Good enough?[/quote]Depends on what ROOT build you’re using. Use the Microsoft compiler with the win32 build, and gcc with win32gcc. The first one is the official windows build.

[quote=“karineklund”]Should I write .h or .h+? If I write .h+ I get:

root [0] .L TVoxel.h+ Info in <TWinNTSystem::ACLiC>: creating shared library C:\karin\TVoxel_h.dll 'cl' is not recognized as an internal or external command, operable program or batch file. Internal error: G__copytotmpfile() 2 FILE:C:\DOCUME~1\ked\LOCALS~1\Temp/\s244._rootcint.h LINE:0 Error: cannot open file "C:\DOCUME~1\ked\LOCALS~1\Temp/\s244._rootcint.h" FILE: LINE:0 !!!Removing C:\karin\sh8_.cxx C:\karin\sh8_.h !!! Error: rootcint: failed to open C:\karin\sh8_.cxx in ReplaceBundleInDict() 'cl' is not recognized as an internal or external command, operable program or batch file. Error in <ACLiC>: Compilation failed![/quote]That’s because the compiler is not in your PATH - you didn’t start root from within a Visual Studio Command prompt. Alternatively, you can start a regular command prompt, and run C:\Program Files\Microsoft Visual Studio 7\Common7\Tools\vsvars.bat before running root - that will set the environment variables.

[quote=“karineklund”]If I write .h it does not complain until I get to actually running testRun(), and then it says:

Error in <TBranchElement::GetDataMemberOffset>: obsolete call with (TVoxel,fUniqueID) [...] Error: C++ exception caught FILE:C:\karin\runTest.C LINE:22 (Int_t)0 *** Interpreter error recovered ***[/quote]Right, I/O of interpreted classes is not supported yet. You’ll have to compile TVoxel etc, e.g. by loading it as “.L TVoxel.h+”.

[quote=“karineklund”]But, then again, what I really want to do is to use VS c++ to write and run my root on windows. I have read your page about it, but beeing not only a beginner with root, I am even more so with VS, so I havn’t really managed to get that to work yet either. This will be my next step.[/quote]Let us know if you run into problems.

Cheers, Axel.

1 Like

Good morning!

Ok, I am able to compile in the VS prompt. But with a failure. It seems as if some setting is still not quite right… Do you make anything out of this?

[quote]C:\karin>root -l
root [0] .L TVoxel.h+
Info in TWinNTSystem::ACLiC: creating shared library C:\karin\TVoxel_h.dll
32036156_cint.cxx
Internal error: G__copytotmpfile() 2
FILE:C:\DOCUME~1\ked\LOCALS~1\Temp/\s1vk.rootcint.h LINE:0
Error: cannot open file "C:\DOCUME~1\ked\LOCALS~1\Temp/\s1vk.rootcint.h" FILE:
LINE:0
!!!Removing C:\karin\s3m8
.cxx C:\karin\s3m8
.h !!!
Error: rootcint: failed to open C:\karin\s3m8_.cxx in ReplaceBundleInDict()
s3m8_.cxx
C:\karin\s3m8_.cxx(16) : fatal error C1083: Cannot open include file: ‘s3m8_.h’:
No such file or directory
Error in : Compilation failed!
root [1][/quote]

/Karin

Hi Karin,
you’re not working as administrator on your computer, right? There is an ancient problem with that; I’ll try to get it fixed on Monday next week.
Cheers, Axel.

That is correctly asumed, I am not admin.
/Karin

Hi Karin,
compiling code as a regular user should now work, with the current CVS version of root. You can also wait for the next release version of root, to be published in a few days.
Cheers, Axel.