This function will be called twice and type will be different (read different files). When it is called 2nd time I got the error message, many.
Notice that when I directly open the 2nd ROOT file by root file.root (I’m sure that root version is the same) I won’t get any error message. Only when the file is opened in this function I will get error messages. Why?
So something went wrong in between. Can you identify which piece of code causes the error by reintroducing it step by step until the error appears again? Start with the empty while loop, and so on.
But comment out the else part, the number of error messages became one. And in my 1st file this if will not be processed, in my 2nd file this if will only be processed once (only 1 TGraph called g_deadtime).
Does this mean something wront with TGraph* g_in = dynamic_cast<TGraph*>(key->ReadObj());? Do I need to delete this pointer?
And if I comment out code inside if(g_in)part, there is no error message anymore, which means if I only use dynamic_cast it doesn’t cause the error
One thing maybe I need to mention: When I created those 2 ROOT files, I used a newer ROOT version v6.32.04, and for the 1st file I set the TFile::k630forwardCompatibility right after TFile::Open(name, “RECREATE”), for the 2nd file I set the TFile::k630forwardCompatibility right before the TFile::Close() instead of right after opening. Will this cause the error messages?
root [0] TFile* f = TFile::Open("RECBE_TDCResponse.root", "READ")
(TFile *) 0x2984870
root [1] TGraph* g = (TGraph*)gDirectory->Get("g_50")
(TGraph *) 0x2fc8640
root [2] std::shared_ptr<TGraph> gg = std::make_shared<TGraph>(*g)
(std::shared_ptr<TGraph> &) std::shared_ptr -> 0x2f27800
root [3] f->Close()
Error in <THashList::Delete>: A list is accessing an object (0x3ab3970) already deleted (list name = THashList)
root [4] std::cout<< g->ClassName() <<std::endl
TGraph
(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &) @0x7f61bda26480
root [5] std::cout<< gg->ClassName() <<std::endl
TGraph
(std::basic_ostream<char, std::char_traits<char> >::__ostream_type &) @0x7f61bda26480
root [6]
Here is what I got.
After I set the TFile::k630forwardCompatibility right after creating the 2nd ROOT file (then write TGraphs in it) instead of before closing it, this error message disappeared. So it should caused by the compability?
May I also ask that do I need to delete he pointer g_in or key (in the top code block)? It always confuses me about the ownership when I use ROOT classes…