Hello,
this concerns input and output of custom classes in root files.
Over the last few years I had used the dictionary generator and your guides to create custom classes and save run time instances of objects in root files to make them persistent. I had been mainly successful.
In my last attempt, I made a custom class (which does not inherit from TObject and I did not use CladdDef):
class MyClass{
public:
MyClass();
MyClass(float e, float t, uint16_t q, uint16_t pr,CaloGain::CaloGain g,Double_t x, Double_t y, Double_t z):
energy(e),time(t),quality(q),provenance(pr),gain(g){
position.SetXYZ(x,y,z);
sampling = -1;
id=0;
};
virtual ~MyClass();
float energy;
float time;
uint16_t quality;
uint16_t provenance;
int sampling;
TVector3 position;
TVector3 correctedPosition;
ULong64_t id;
};
#endif
This worked, I created many root files on the grid (where I did not monitor performance and memory consumption) and the objects are stored successfully even at branches with the quite complicate type:
std::vector<std::vector<MyClass*> >
The latest addition in the class was the two TVector3 objects which I somehow selected to create on the stack.
The root files are created successfully as i said, but when I run a TChain of all the files (combining to 1.2GB), the 3-4GB of RAM available on my system are very quickly depleted and cint (I use a “MakeClass” instance and call Loop() ) exits without a warning.
I don’t think this happened before I added the new TVector3 but I had been noticing the memory filling very quickly. I believe it’s just because of the creation of many MyClass object (each jentry has tens of thousands of entries of type MyClass in the std::vector<std::vector<MyClass*> > structure)
How do I make sure the objects created on access of the std::vector<std::vector<MyClass*> >
branch, are deleted? Where is it supposed to be handled?
I have disabled all code in the “Loop” function leaving it like so:
void TimingStudy::Loop()
{
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
}//end of for
}//Loop
so I am sure I don’t have any obvious memory leaks. The memory still gets depleted equally quickly.
Is it because I did not inherit from TObject? I thought that was not needed any more.
I am trying now to modify my class to inherit from TObject but I am having other problems, but maybe this is another issue.