importClassCode using Renamed version of RooSimultaneous

Hi

I am using root-6.18.04 on MacOS Catalina. I want to importClass code of a renamed version of RooSimultaneous into my RooWorkspace. So I have managed to store simpdf using RooSimultaneous1 which is the renamed version of RooSimultaneous. I am thinking that the first step to do this is:

combined->addClassImplImportDir("/Users/cashcrusaders/Documents/UJ_LimitSetting/src/")

which is the directory where my implementation code is located.
But I get the following error:

Error in <TBufferFile::ReadObject>: trying to read an emulated class (RooSimultaneous1) to store in a compiled pointer (RooAbsArg)

 *** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TGenCollectionStreamer::ReadBufferGeneric(TBuffer&, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TGenCollectionStreamer.cxx:1337
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadFastArray(void*, TClass const*, int, TMemberStreamer*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:1609
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] int TStreamerInfoActions::ReadSTL<&(TStreamerInfoActions::ReadSTLMemberWiseSameClass(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*, short)), &(TStreamerInfoActions::ReadSTLObjectWiseFastArray(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*, short, unsigned int))>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoActions.cxx:0
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1390
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadClassBuffer(TClass const*, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3486
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoReadBuffer.cxx:1315
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoActions.cxx:185
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1390
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadClassBuffer(TClass const*, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3486
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRooFitCore.so] RooAbsArg::Streamer(TBuffer&) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/deque:2614
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libCore.so] TStreamerBase::ReadBuffer(TBuffer&, char*) /Users/cashcrusaders/Applications/root-6.18.04_limit/core/meta/src/TStreamerElement.cxx:0
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoReadBuffer.cxx:1342
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoActions.cxx:185
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1390
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadClassBuffer(TClass const*, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3486
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libCore.so] TStreamerBase::ReadBuffer(TBuffer&, char*) /Users/cashcrusaders/Applications/root-6.18.04_limit/core/meta/src/TStreamerElement.cxx:0
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoReadBuffer.cxx:1342
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoActions.cxx:185
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1390
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadClassBuffer(TClass const*, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3486
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libCore.so] TStreamerBase::ReadBuffer(TBuffer&, char*) /Users/cashcrusaders/Applications/root-6.18.04_limit/core/meta/src/TStreamerElement.cxx:0
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoReadBuffer.cxx:1342
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TStreamerInfoActions.cxx:185
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1390
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadClassEmulated(TClass const*, void*, TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3254
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadObjectAny(TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:2473
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::CheckObject(unsigned int, TClass const*, bool) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:3140
[/Users/cashcrusaders/Applications/root-6.18.04_limit/root-6.18.04-builddir/lib/libRIO.so] TBufferFile::ReadObjectAny(TClass const*) /Users/cashcrusaders/Applications/root-6.18.04_limit/io/io/src/TBufferFile.cxx:2423

You must load the library that implements RooSimultaneous1

Thanks for the reply.

So I tried loading the library using

gSystem->Load("libRooSimultaneous1.a")

but when I try the following command for instance:

pdf = dynamic_cast<RooSimultaneous1*>(combined->genobj("ModelConfig"))

I get the following error:

Error in <TInterpreter::TCling::AutoLoad>: failure loading library libRooSimultaneous1.dylib for RooSimultaneous1
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libRooSimultaneous1.dylib for RooSimultaneous1
Error in <TInterpreter::TCling::AutoLoad>: failure loading library libRooSimultaneous1.dylib for RooSimultaneous1
ROOT_prompt_7:1:20: error: unknown type name 'RooSimultaneous1'
pdf = dynamic_cast<RooSimultaneous1*>(combined->genobj("ModelConfig"))
                   ^
ROOT_prompt_7:1:39: error: use of undeclared identifier 'combined'
pdf = dynamic_cast<RooSimultaneous1*>(combined->genobj("ModelConfig"))

Might the reason be that I am loading a static library instead of a shared library?

Might the reason be that I am loading a static library instead of a shared library?

Yes. Given the output you give the dictionary is clearly not being loaded/executed as a result of loading the static library (which is expected since linking again a static library will bring in only the symbol requested/used so far)

I knew it. So I have been trying to modify my CMakeList.txt so that it can generate shared libraries instead of static libraries. Here it is:

cmake_minimum_required(VERSION 3.5)

project(HypoTestInv LANGUAGES CXX)

# Using ROOT's CONFIG mode search
# The Makefile method also included (non-explicitly, though): Foam Html MathMore Minuit XMLParser
list(APPEND CMAKE_PREFIX_PATH /Users/cashcrusaders/Applications/root-6.18.04_hist)
find_package(ROOT CONFIG REQUIRED COMPONENTS RooStats RooFit RooFitCore HistFactory)


if(TARGET ROOT::Minuit2)
    message(STATUS "Minuit2 included in ROOT")
else()
    message(STATUS "Minuit2 missing from ROOT, using standalone edition")
    find_package(Minuit2 CONFIG REQUIRED)
endif()


# Set flags and things automagically (not ideal, but simplest for now)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc/)
include("${ROOT_USE_FILE}")
message(STATUS "Root use_file Path is: " ${ROOT_USE_FILE})


# This function adds a LinkDef and ROOT dictionary for a library
function(ADD_LIBRARY_LINK_DEF NAME)
    file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/RootDict/${NAME}Dict_LinkDef.h"
            "#ifdef __CINT__\n"
            "#pragma link C++ nestedclasses;\n"
            "#pragma link C++ nestedtypedefs;\n"
            "#pragma link C++ defined_in \"${CMAKE_CURRENT_SOURCE_DIR}/inc/${NAME}.h\";\n"
            "#endif\n")

    root_generate_dictionary(
            G__${NAME}
            ${NAME}.h
            LINKDEF
            "${CMAKE_CURRENT_BINARY_DIR}/RootDict/${NAME}Dict_LinkDef.h"
    )

    add_library(${NAME} SHARED G__${NAME}.cxx ${NAME}.cxx)

    target_link_libraries(${NAME} INTERFACE ${ROOT_LIBRARIES})

    # Link to ROOT's Minuit 2 if available, otherwise standalone edition
    if(TARGET ROOT::Minuit2)
        target_link_libraries(${NAME} INTERFACE ROOT::Minuit2)
    else()
        target_link_libraries(${NAME} INTERFACE Minuit2::Minuit2)
    endif()
endfunction()
# Adding core libraries

add_library_link_def(WorkspaceCalculator)
add_library_link_def(ProfileLikelihoodTestStatEnhanced)
add_library_link_def(LimitCalculator)
add_library_link_def(LikelihoodCalculator)
add_library_link_def(PValueCalculator)
add_library_link_def(FitCalculator)
add_library_link_def(RooSimultaneous1)



# Adding executables

add_executable(StandardHypoTestInv StandardHypoTestInv.cxx)
target_link_libraries(StandardHypoTestInv PUBLIC
        WorkspaceCalculator ProfileLikelihoodTestStatEnhanced LimitCalculator RooSimultaneous1)

#add_executable(StandardFrequentistDiscovery StandardFrequentistDiscovery.cxx)
#target_link_libraries(StandardFrequentistDiscovery PUBLIC
#    WorkspaceCalculator ProfileLikelihoodTestStatEnhanced PValueCalculator)

#add_executable(LikelihoodScan LikelihoodScan.cxx)
#target_link_libraries(LikelihoodScan PUBLIC
#    WorkspaceCalculator ProfileLikelihoodTestStatEnhanced LikelihoodCalculator)

#add_executable(SimpleFit SimpleFit.cxx)
#target_link_libraries(SimpleFit PUBLIC
#    WorkspaceCalculator ProfileLikelihoodTestStatEnhanced FitCalculator)


but I keep getting a long “Undefined symbols for architecture x86_64” error. Is there something I can do to modify this code?

What is the exact complete message? (What needs to be done completely depend on its content :slight_smile: )

Its quite long so I put it in a text file :sweat_smile: error.txt (182.2 KB)

Clearly, the library is missing the link to all the ROOT libraries it uses, i.e. maybe adding something like

LIBRARIES  RooStats RooFit RooFitCore HistFactory

to the library declaration in your cmake file.

1 Like

I thought that the lines below do this

list(APPEND CMAKE_PREFIX_PATH /Users/cashcrusaders/Applications/root-6.18.04_hist)
find_package(ROOT CONFIG REQUIRED COMPONENTS RooStats RooFit RooFitCore HistFactory)

No. The find_package just makes sure that those libraries are available but does not use them.

I apologize if i am a bit slow, my experience with cmake is quite limited.

I have tried using the command above as it is but apparently the is

LIBRARIES(RooStats RooFit RooFitCore HistFactory)

but i get

Unknown CMake command "LIBRARIES".

I also tried

    find_library(RooFitCore /Users/cashcrusaders/Applications/root-6.18.04_hist/root-6.18.04-builddir/lib/)

but they are not yielding different results.

Hi @pcanal

I ended up being able to generate the shared library by adding the line

link_libraries(RooFit)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.