Problem with stl vector of string in ROOT Tree branch

Dear ROOT users and experts

I am trying to fill a tree having branch of stl vector of string. The string contains the outcome of the particle name in the simulation. I am filling this tree on event by event basis in Geant4. When I am opening the tree using start viewer this displays the names fines, however when I am trying to acess the name with MakeSelector programme of ROOT Tree then is crashes at tree entry number 138622 and show null address of partName. I do not understand this behaviour of ROOT. Here is the code snippet in .cc file of event action pAnalysis->partName->push_back(particlenm[i]);pAnalysis->anlTree->Fill(). The analysis file where I have defined the branches has the following code in .hh file std::vector<string> *partName; in .cc file anlTree->Branch("partName",&partName); :frowning:


what was the value of the pointer at the moment of filling?

You need to make sure that “partName” is initialized before it is used in “anlTree->Branch(…)”, “anlTree->SetBranchAddress(…)”, … so, first either:
partName = 0;
partName = new std::vectorstd::string;

Thank you for the response

yes I have already intialize the vector in Analysis class as

partName = new std::vector;

with the definition in branch as


and it shows the address upto 138621 entry after that it shows 0 as 0x30b0830 Entry = 138619 Total Entry = 782280 0x30b0830 Entry = 138620 Total Entry = 782280 0x30b0830 Entry = 138621 Total Entry = 782280 0 Entry = 138622 Total Entry = 782280 0 Entry = 138622 Total Entry = 782280

But when I am opning this variable in TreeViewer then it shows fine without any crash ??? Event though I check this address in simulation runtime there also I am not getting 0 address ?? I do not know what is going on…

So, maybe you could put your ROOT file somewhere for “closer inspection”.

Thank you for the response. The file size is of 28 MB so you can download it from the following link. This file is the outcome of the simulation which I have stopped in between otherwise its size become to large. However, ROOT is recovering its keys on its prompt … =drive_web