Hello!
I got stuck trying to use the GetUserInfo() method to store metadata in a ROOT TTree.
I have a class, inheriting from TNamed, which has a data member that is a std::vector of pairs of std::string, where I intend to store the parameters of my simulation.
class MacrosInfo: public TNamed
{
public:
/// Constructor
MacrosInfo(const char* name, const char* title): TNamed(name, title) {}
/// Destructor
~MacrosInfo() {}
void AddContent(const std::string& k, const std::string& v);
std::vector<std::pair<std::string, std::string> > GetContent() const;
private:
std::vector<std::pair<std::string, std::string> > _content;
};
inline void MacrosInfo::AddContent(const std::string& k, const std::string& v) {_content.push_back(std::make_pair(k, v));}
inline std::vector<std::pair<std::string, std::string> > MacrosInfo::GetContent() const {return _content;}
Im my simulation, I do
MacrosInfo* myinfo = new MacrosInfo("all", "all");
myinfo->AddContent("particle","electron");
_evtTree->GetUserInfo()->Add(myinfo);
and a ROOT file is created correctly and it seems to have UserInfo stored, when inspected with TBrowser().
The problem arises when I try to open the file and read the metadata. Doing
MacrosInfo* myinfo = (MacrosInfo*) fEvtTree->GetUserInfo()->FindObject("all");
myinfo->Print();
myinfo->GetContent();
the myinfo->Print() method gives
OBJ: TNamed all all
but the second line (myinfo->GetContent()) causes a crash. It seems to me that the cast is not done correctly.
I attach the root file.
Anyone can see where is the problem?
Thank you very much
Paola