A proper way to use TNamed/TParameter in TTree::GetUserInfo::Add()

Hi,

In my custom class that includes a TTree I have:

	this->tadc->GetUserInfo()->Add(new TNamed("type", this->type));
	this->tadc->GetUserInfo()->Add(new TNamed("comment", this->comment));
	this->tadc->GetUserInfo()->Add(new TParameter<int>("creation_datetime", this->creation_datetime));
	this->tadc->GetUserInfo()->Add(new TNamed("modification_history", this->modification_history));
	this->tadc->GetUserInfo()->Add(new TParameter<int>("source_datetime", this->source_datetime));
	this->tadc->GetUserInfo()->Add(new TNamed("modification_software", this->modification_software));
	this->tadc->GetUserInfo()->Add(new TNamed("modification_software_version", this->modification_software_version));
	this->tadc->GetUserInfo()->Add(new TParameter<int>("analysis_level", this->analysis_level));

where type, comment etc. are TStrings, and creation_datetime etc. are ints, members of the class.

Valgrind reports:

==62976== 16 bytes in 1 blocks are possibly lost in loss record 1,066 of 22,597                                                                                                                                                              
==62976==    at 0x4840A3A: operator new[](unsigned long) (vg_replace_malloc.c:729)                                                                                                                                                           
==62976==    by 0x48E68A9: TString::Init(int, int) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                       
==62976==    by 0x48E6F33: TString::TString(char const*) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                 
==62976==    by 0x5BE9232: TLeaf::TLeaf(TBranch*, char const*, char const*) (in /home/lewhoo/software/root/root/lib/libTree.so)                                                                                                              
==62976==    by 0x5BEB23A: TLeafElement::TLeafElement(TBranch*, char const*, int, int) (in /home/lewhoo/software/root/root/lib/libTree.so)                                                                                                   
==62976==    by 0x5BBECFC: TBranchElement::Init(TTree*, TBranch*, char const*, TVirtualCollectionProxy*, int, int, int) (in /home/lewhoo/software/root/root/lib/libTree.so)                                                                  
==62976==    by 0x5BBF20B: TBranchElement::TBranchElement(TTree*, char const*, TVirtualCollectionProxy*, int, int, int) (in /home/lewhoo/software/root/root/lib/libTree.so)                                                                  
==62976==    by 0x5C1DAE1: TTree::BronchExec(char const*, char const*, void*, bool, int, int) (in /home/lewhoo/software/root/root/lib/libTree.so)                                                                                            
==62976==    by 0x420715: TADC::CreateTree() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                           
==62976==    by 0x423389: TADC::TADC(bool) (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                             
==62976==    by 0x4067BB: main (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)

many times, referring to the lines that I pasted above. I know that the blocks are “possibly” lost, and I don’t know which lines exactly are at fault, but it made me wonder: do I use Tnamed/TParameter with GetUserInfo::Add() properly?

Thanks!


ROOT Version: 6.37.01
Platform: Fedora 42


The stack trace provided and GetUserInfo seem unrelated. Does the issue really only appear if you add the the list of UserInfo?

It seems so. Just commented out the relevant parts of the function:

//! Initialises the TTree metadata fields
void TADC::InitialiseMetadata()
{
	this->creation_datetime = TDatime().Convert(true);

	// this->tadc->GetUserInfo()->Add(new TNamed("type", this->type));
	// this->tadc->GetUserInfo()->Add(new TNamed("comment", this->comment));
	// this->tadc->GetUserInfo()->Add(new TParameter<int>("creation_datetime", this->creation_datetime));
	// this->tadc->GetUserInfo()->Add(new TNamed("modification_history", this->modification_history));
	// this->tadc->GetUserInfo()->Add(new TParameter<int>("source_datetime", this->source_datetime));
	// this->tadc->GetUserInfo()->Add(new TNamed("modification_software", this->modification_software));
	// this->tadc->GetUserInfo()->Add(new TNamed("modification_software_version", this->modification_software_version));
	// this->tadc->GetUserInfo()->Add(new TParameter<int>("analysis_level", this->analysis_level));
}

And all mentions of InitaliseMedatada() in Valgrind output disappeared.

And all mentions of InitaliseMedatada() in Valgrind output disappeared.

I am confused. There is no mention (that I can see) of InitaliseMedatada() in the single valgrind output at A proper way to use TNamed/TParameter in TTree::GetUserInfo::Add() … what am I missing?

I’m sorry, you are missing nothing. I copied a wrong part of the Valgrind output. Here are some proper ones:

==62976== 32 bytes in 1 blocks are possibly lost in loss record 4,460 of 22,597                                                                                                                                                              
==62976==    at 0x4840A3A: operator new[](unsigned long) (vg_replace_malloc.c:729)                                                                                                                                                           
==62976==    by 0x48E68A9: TString::Init(int, int) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                       
==62976==    by 0x48E6F33: TString::TString(char const*) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                 
==62976==    by 0x41FC42: TADC::InitialiseMetadata() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                   
==62976==    by 0x4202EE: TADC::CreateTree() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                           
==62976==    by 0x423389: TADC::TADC(bool) (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                             
==62976==    by 0x4067BB: main (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                                         
==62976==                                                                                                                                                                                                                                    
==62976== 32 bytes in 1 blocks are possibly lost in loss record 4,461 of 22,597                                                                                                                                                              
==62976==    at 0x4840A3A: operator new[](unsigned long) (vg_replace_malloc.c:729)                                                                                                                                                           
==62976==    by 0x48E68A9: TString::Init(int, int) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                       
==62976==    by 0x48E6ED6: TString::TString(TString const&) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                              
==62976==    by 0x41FD05: TADC::InitialiseMetadata() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                   
==62976==    by 0x4202EE: TADC::CreateTree() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                           
==62976==    by 0x423389: TADC::TADC(bool) (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                             
==62976==    by 0x4067BB: main (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                                         
==62976==                                                                                                                                                                                                                                    
==62976== 32 bytes in 1 blocks are possibly lost in loss record 4,462 of 22,597                                                                                                                                                              
==62976==    at 0x4840A3A: operator new[](unsigned long) (vg_replace_malloc.c:729)                                                                                                                                                           
==62976==    by 0x48E68A9: TString::Init(int, int) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                       
==62976==    by 0x48E6ED6: TString::TString(TString const&) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                              
==62976==    by 0x41FE76: TADC::InitialiseMetadata() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                   
==62976==    by 0x4202EE: TADC::CreateTree() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                           
==62976==    by 0x423389: TADC::TADC(bool) (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                             
==62976==    by 0x4067BB: main (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                                         
==62976==                                                                                                                                                                                                                                    
==62976== 32 bytes in 1 blocks are possibly lost in loss record 4,463 of 22,597                                                                                                                                                              
==62976==    at 0x4840A3A: operator new[](unsigned long) (vg_replace_malloc.c:729)                                                                                                                                                           
==62976==    by 0x48E68A9: TString::Init(int, int) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                                       
==62976==    by 0x48E6ED6: TString::TString(TString const&) (in /home/lewhoo/software/root/root/lib/libCore.so)                                                                                                                              
==62976==    by 0x41FF48: TADC::InitialiseMetadata() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                   
==62976==    by 0x4202EE: TADC::CreateTree() (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                           
==62976==    by 0x423389: TADC::TADC(bool) (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)                                                                                                                                             
==62976==    by 0x4067BB: main (in /home/lewhoo/GRAND/gtot/cmake-build-release/gtot)

Are you using $ROOTSYS/etc/valgrind-root.supp? Are you deleting the TTree (directly or indirectly)?

Thanks! It seems that the culprit was not deleted TTree. With proper management, this complaint of Valgrind disappeared.

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