key4hep / k4FWCore

Core Components for the Gaudi-based Key4hep Framework
Apache License 2.0
10 stars 26 forks source link

Issues with EDM4hep #9

Closed mirguest closed 4 years ago

mirguest commented 4 years ago

I have created an example in https://github.com/ihep-sft-group/K4FWCore to write and read the EDM4hep data using K4FWCore and Gaudi v33r1. One problem is that the contents of the branches are not shown due to the dictionary are not linked to the module.

Following is how to repeat the problem:

$ git clone git@github.com:ihep-sft-group/K4FWCore.git K4FWCoreIHEPSFT
$ cd K4FWCoreIHEPSFT
$ mkdir build && cd build
$ cmake .. -DHOST_BINARY_TAG=${BINARY_TAG}
$ make

Then, run the script and file test.root is created:

$ ./run gaudirun.py ../Examples/options/edm4hep_write.py

Using root to explore the content:

$ root -l test.root
Warning in <TInterpreter::ReadRootmapFile>: class  podio::CollectionBase found in libpodioDict.so  is already in libpodio.so
Warning in <TInterpreter::ReadRootmapFile>: class  podio::CollectionIDTable found in libpodioDict.so  is already in libpodio.so
Warning in <TInterpreter::ReadRootmapFile>: class  podio::ObjectID found in libpodioDict.so  is already in libpodio.so
Warning in <TInterpreter::ReadRootmapFile>: class  podio::PythonEventStore found in libpodioDict.so  is already in libpodio.so
root [0]
Attaching file test.root as _file0...
Warning in <TClass::Init>: no dictionary for class podio::ObjectID is available
Warning in <TClass::Init>: no dictionary for class podio::CollectionIDTable is available
(TFile *) 0x2c2c960
root [1] events->Print()
******************************************************************************
*Tree    :events    : Events tree                                            *
*Entries :       10 : Total =           16731 bytes  File  Size =       2494 *
*        :          : Tree compression factor =   8.23                       *
******************************************************************************
*Br    0 :EventHeader : vector<edm4hep::EventHeaderData>                     *
*Entries :       10 : Total  Size=        981 bytes  File Size  =        182 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   2.57     *
*............................................................................*
*Br    1 :MCParticle : vector<edm4hep::MCParticleData>                       *
*Entries :       10 : Total  Size=       9376 bytes  File Size  =        342 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=  25.93     *
*............................................................................*
*Br    2 :MCParticle#0 : Int_t MCParticle#0_                                 *
*Entries :       10 : Total  Size=       2460 bytes  File Size  =        134 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.26     *
*............................................................................*
*Br    3 :MCParticle#0.index : Int_t index[MCParticle#0_]                    *
*Entries :       10 : Total  Size=       1086 bytes  File Size  =        147 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   3.10     *
*............................................................................*
*Br    4 :MCParticle#0.collectionID : Int_t collectionID[MCParticle#0_]      *
*Entries :       10 : Total  Size=       1121 bytes  File Size  =        152 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   3.04     *
*............................................................................*
*Br    5 :MCParticle#1 : Int_t MCParticle#1_                                 *
*Entries :       10 : Total  Size=       2460 bytes  File Size  =        134 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   1.26     *
*............................................................................*
*Br    6 :MCParticle#1.index : Int_t index[MCParticle#1_]                    *
*Entries :       10 : Total  Size=       1086 bytes  File Size  =        155 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   2.94     *
*............................................................................*
*Br    7 :MCParticle#1.collectionID : Int_t collectionID[MCParticle#1_]      *
*Entries :       10 : Total  Size=       1121 bytes  File Size  =        152 *
*Baskets :        1 : Basket Size=      32000 bytes  Compression=   3.04     *
*............................................................................*

As you see here, the contents of the branches are not split and shown here.

My current solution is forcing linking the dictionary library.

gaudi_add_module(Examples ${Examples_srcs}
    INCLUDE_DIRS FWCore GaudiAlgLib GaudiKernel ${podio_INCLUDE_DIRS}
    LINK_LIBRARIES FWCore GaudiAlgLib GaudiKernel
      # Force loading the libraries.
      -Wl,--no-as-needed EDM4HEP::edm4hep EDM4HEP::edm4hepDict ${podio_LIBRARIES} podio::podioRootIO -Wl,--as-needed
)

I am not sure where I am wrong. Thank you!

Tao Lin (IHEP)

vvolkl commented 4 years ago

Hi Tao Lin @mirguest , thanks for opening this issue and the detailed explanations! I think you are completely right, any program that writes edm4hep data to a root file must link against the edm4hepDict target. I don't think the additional compiler flags are necessary. I also overlooked this in the https://github.com/key4hep/k4-project-template repository. I'm also unsure where the warnings about the missing dictionary are coming from, I'll investigate.

By the way, are you planning to extend this repository and use it for the experiment software? My experience from FCCSW is that it can be helpful to split the framework into different repositories, so I set up the k4-project-template repository, which can be built on top of the common components in K4FWCore and used as a template for the actual experiment framework. Of course it is also possible to work with a fork of this repository. If you can open Pull Requests to this repository with any work you do on it, it is highly appreciated and will help to stay in sync.

Another small thing I noticed: both ${podio_INCLUDE_DIRS} and ${podio_LIBRARIES} are no longer needed, writing the target podio::podioRootIO should be enough.

andresailer commented 4 years ago

What was the compiler and operating system used?

mirguest commented 4 years ago

What was the compiler and operating system used?

Hi @andresailer , we use SL6 and gcc 8.3.0:

[lint@lxslc607]$ which g++
/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-slc6/bin/g++
[lint@lxslc607]$ lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID: Scientific
Description:    Scientific Linux release 6.9 (Carbon)
Release:        6.9
Codename:       Carbon
andresailer commented 4 years ago

Does Gaudi add the as-needed flag? Can you run make VERBOSE=1 when compiling and linking the example?

mirguest commented 4 years ago

@andresailer , you are right. It looks like Gaudi add the flags:

[ 69%] Linking CXX shared module ../lib/libExamples.so
cd /dev/shm/lint/K4FWCoreIHEPSFT/build/Examples && /cvmfs/sft.cern.ch/lcg/releases/CMake/3.14.3-34449/x86_64-slc6-gcc8-opt/bin/cmake -E cmake_link_script CMakeFiles/Examples.dir/link.txt --verbose=1
/cvmfs/sft.cern.ch/lcg/releases/gcc/8.3.0-cebb0/x86_64-slc6/bin/g++ -fPIC -fmessage-length=0 -pipe -Wall -Wextra -Werror=return-type -pthread -pedantic -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-long-long -Wno-shadow -Wl,--as-needed -Wl,--no-undefined  -Wl,-z,max-page-size=0x1000 -shared  -o ../lib/libExamples.so  CMakeFiles/Examples.dir/src/Edm4hepTest/Edm4hepReadAlg.cpp.o CMakeFiles/Examples.dir/src/Edm4hepTest/Edm4hepWriteAlg.cpp.o  -L/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib -Wl,-rpath,/dev/shm/lint/K4FWCoreIHEPSFT/build/lib:/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/Gaudi/lib:/cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib:/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/EDM4hep/lib64:/cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64:/cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib: ../lib/libFWCore.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/Gaudi/lib/libGaudiAlgLib.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/Gaudi/lib/libGaudiUtilsLib.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/Gaudi/lib/libGaudiKernel.so -ldl /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_filesystem.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_thread.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_system.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_regex.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_chrono.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_date_time.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libboost_atomic.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libCore.so -ltbb /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/Gaudi/lib/libGaudiPluginService.so -lstdc++fs -lrt /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/liblzma.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libRIO.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libHist.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libXMLIO.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libThread.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libMatrix.so /cvmfs/sft.cern.ch/lcg/views/LCG_97/x86_64-slc6-gcc8-opt/lib/libMathCore.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/EDM4hep/lib64/libedm4hep.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/EDM4hep/lib64/libedm4hepDict.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodioRootIO.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodioRootIO.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodioDict.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodio.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libCore.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libImt.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libRIO.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libNet.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libHist.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libGraf.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libGraf3d.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libGpad.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libROOTDataFrame.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libTree.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libTreePlayer.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libRint.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libPostscript.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libMatrix.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libPhysics.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libMathCore.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libThread.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libMultiProc.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodioDict.so /cvmfs/cepcsw.ihep.ac.cn/prototype/releases/externals/97.0.0/podio/lib64/libpodio.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libTree.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libImt.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libNet.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libRIO.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libThread.so /cvmfs/sft.cern.ch/lcg/releases/ROOT/v6.20.02-d9e99/x86_64-slc6-gcc8-opt/lib/libCore.so -lpthread
make[2]: Leaving directory `/dev/shm/lint/K4FWCoreIHEPSFT/build'
andresailer commented 4 years ago

Should we link the edm4hepDict into the podioDataSvc? Then that would remove the need to link it into other libraries, right?

vvolkl commented 4 years ago

Yes, we could link edm4hepDict publicly. I think the FWCore library still needs to be linked to all modules using the DataService though.

vvolkl commented 4 years ago

See #11

andresailer commented 4 years ago

From our meeting discussion: maybe root should load the library via the rootmap file?

andresailer commented 4 years ago

Maybe this solves the problem without having to link the dictionaries https://github.com/AIDASoft/podio/pull/99 https://github.com/key4hep/EDM4hep/pull/68

mirguest commented 4 years ago

@andresailer Thanks! It works now. After deploying the latest PODIO and EDM4hep, ROOT could load the correct dictionary using the latest rootmap.