Problem mixing vector and array in a TTree

ROOT Version: 6.20/08
Platform: Built for linuxx8664gcc From tags/v6-20-08-alice1@v6-20-08-1-g700d618 on CentOS Linux release 7.9.2009 (Core)
Compiler: gcc version 7.3.0


Hello,

Is it possible to store in a TBranch objects containing vectors of other objects and include C array in the latter?

I have two classes AliEvent and AliParticle. Some AliEvent fields are std::vector of AliParticle and inside AliParticle some fields are standard C array with fixed size. If I store AliEvent objects in a TTree branch and save in a file everything works. Nevertheless, retrieving the objects from the file does not work.
If I try with TTreeReader the first access to TTreeReaderValue fails and the second succeed but the output is not correct (I have two vector of AliParticle and one is empty but it has at least 1 element).

root [1] #include "AliEvent.h"
root [2] TFile *currentFile = new TFile("MiniEventAnalysis_AnalysisResults.root", "READ");
root [3] TList *outputList = (TList *) currentFile->Get("MiniEvent_MyRareTest");
root [4] TTree * evts = (TTree*)(*outputList)("Events")
(TTree *) 0x78f6e30
root [5]  TTreeReader myTreeReaderEv(evts);
root [6] TTreeReaderValue<INFNCatania::AliEvent> event(myTreeReaderEv, "EventCollection");
root [7] myTreeReaderEv.Next()
(bool) true
root [8] event->GetK0()
#0  0x00007fc9a8b3646c in waitpid () from /lib64/libc.so.6
#1  0x00007fc9a8ab3f62 in do_system () from /lib64/libc.so.6
#2  0x00007fc9ae011300 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x722570) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/unix/src/TUnixSystem.cxx:2107
#3  TUnixSystem::StackTrace (this=0x722570) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/unix/src/TUnixSystem.cxx:2397
#4  0x00007fc9a3401768 in cling::MultiplexInterpreterCallbacks::PrintStackTrace() () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#5  0x00007fc9a34010de in cling_runtime_internal_throwIfInvalidPointer () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#6  0x00007fc9aea670f7 in ?? ()
#7  0x00000000007fb7f0 in ?? ()
#8  0x0000000008b8d230 in ?? ()
#9  0x00007fc9a3401090 in ?? () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#10 0x000000000581c230 in ?? ()
#11 0x000000017fcddf80 in ?? ()
#12 0x00000000074b8c20 in ?? ()
#13 0x00007fc9a3496040 in ?? () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#14 0x00007fff7fcde410 in ?? ()
#15 0x00007fc9aea67040 in ?? ()
#16 0x00007fc9a346ff34 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#17 0x00007fc9a3403306 in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#18 0x00007fc9a3404899 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#19 0x00007fc9a3404b42 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#20 0x00007fc9a34bf24d in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /home/centos/alice/sw/slc7_x86-64/ROOT/v6-20-08-alice1-35/lib/libCling.so
#21 0x00007fc9a337ae8e in HandleInterpreterException (metaProcessor=0x22445c0, input_line=<optimized out>, compRes=
0x7fff7fcde2e4: cling::Interpreter::kSuccess, result=result
entry=0x7fff7fcde410) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/metacling/src/TCling.cxx:2287
#22 0x00007fc9a338c5dc in TCling::ProcessLine (this=0x7fa110, line=<optimized out>, error=0x7fff7fcde7dc) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/metacling/src/TCling.cxx:2445
#23 0x00007fc9aded6bb9 in TApplication::ProcessLine (this=0x5aed980, line=<optimized out>, sync=<optimized out>, err=0x7fff7fcde7dc) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/base/src/TApplication.cxx:1471
#24 0x00007fc9adb28cc2 in TRint::ProcessLineNr (this=this
entry=0x5aed980, filestem=filestem
entry=0x7fc9adb3abed "ROOT_prompt_", line=0x6b6a790 "event->GetK0()", error=0x7fff7fcde7dc, error
entry=0x0) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/rint/src/TRint.cxx:748
#25 0x00007fc9adb29014 in TRint::HandleTermInput (this=0x5aed980) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/rint/src/TRint.cxx:609
#26 0x00007fc9ae012de8 in TUnixSystem::CheckDescriptors (this=this
entry=0x722570) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/unix/src/TUnixSystem.cxx:1310
#27 0x00007fc9ae014508 in TUnixSystem::DispatchOneEvent (this=0x722570, pendingOnly=<optimized out>) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/unix/src/TUnixSystem.cxx:1065
#28 0x00007fc9adf3c694 in TSystem::InnerLoop (this=0x722570) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/base/src/TSystem.cxx:413
#29 0x00007fc9adf3b3af in TSystem::Run (this=0x722570) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/base/src/TSystem.cxx:363
#30 0x00007fc9aded4bff in TApplication::Run (this=this
entry=0x5aed980, retrn=retrn
entry=false) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/base/src/TApplication.cxx:1623
#31 0x00007fc9adb2a3eb in TRint::Run (this=this
entry=0x5aed980, retrn=retrn
entry=false) at /jenkins/workspace/build-any-ib/sw/20156213/1/SOURCES/ROOT/v6-20-08-alice1/v6-20-08-alice1/core/rint/src/TRint.cxx:462
#32 0x000000000040171b in main (argc=<optimized out>, argv=0x7fff7fce0c68) at /home/centos/alice/sw/SOURCES/AliRoot/v5-09-56/v5-09-56/ALIROOT/aliroot.cxx:152
E-HandleInterpreterException: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_8:1:1: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
event->GetK0()
^~~~~
root [9] event->GetK0()
(std::vector<INFNCatania::AliParticle>) { @0x5837060, @0x5837190, @0x58372c0, @0x58373f0, @0x5837520, @0x5837650, @0x5837780, @0x58378b0, @0x58379e0, @0x5837b10, @0x5837c40, @0x5837d70, @0x5837ea0, @0x5837fd0, @0x5838100, @0x5838230, @0x5838360, @0x5838490, @0x58385c0, @0x58386f0, @0x5838820, @0x5838950, @0x5838a80 }
root [10] event->GetXi()
(std::vector<INFNCatania::AliParticle>) {}

Alternatively, if I try to read the file with the method GetEntry() of the TTree I get -1 and the results are still not correct.

I have done several tests and If I set the C arrays as transient data everything work properly but this is not an option.

Is there something I am doing wrong or the combination I would store is not supported?

Thanks in advance,
Marco

Welcome to the ROOT forum!
I’m not sure to understand what you do in your code, but maybe @pcanal could take a look,

Humm … something is ‘wrong’ as this should work fine.

What does

TFile *currentFile = new TFile("MiniEventAnalysis_AnalysisResults.root", "READ");
TList *outputList = (TList *) currentFile->Get("MiniEvent_MyRareTest");
TTree * evts = (TTree*)(*outputList)("Events");
INFNCatania::AliEvent *event = nullptr;
evts->SetBranchAddress("EventCollection", &event);
event->GetK0()
event->GetXi()

prints and/or complains about.

Hi,

in the above code I am trying to read object stored in a TTree and I am not sure if I am doing something wrong or not supported

I have created the File with a list and added a TTree. This is the snippet of code creating the TTree:

      fEventsStore = new TList();
      fEventsStore->SetOwner();
      fEventSelected = new TTree("Events", "Storage of all selected events");

      fEvent = new INFNCatania::AliEvent();
      fEventSelected->Branch("EventCollection", "INFNCatania::AliEvent", &fEvent);

      fEventsStore->Add(fEventSelected);
      PostData(2, fEventsStore);

The PostData add the llist to the file in AliAnalysisManager.
Then I fill with the code:

INFNCatania::AliEvent ae(fMiniEvent);
...
...
for (....){
         INFNCatania::AliParticle ap(miniParticlePtr);
         if(ap.AddSelectionValues(cursor, fRsnEvent)){
            ae.AddParticle(ap);
         }
}
...
      fEvent = &ae;
      if(ae.GetK0().size()>0 && ae.GetXi().size()>0){
         fEventSelected->Fill();
      }

I am attaching the interface of the class I have created AliEvent and AliParticle.

This work without error or warning, the problem is to retrieve the objects.

AliEvent.h (1.6 KB) AliParticle.h (8.3 KB)