Error Writing ROOT File?

ROOT Version: 6.13/02
Platform: Ubuntu 17.10
Compiler: Not Provided

I am having trouble writing a ROOT file. This problem only just appeared, and I have written ROOT files before in this manner. A small test macro is attached. When I write the file, it produces a file with two branches/trees of different number of entries, even though I am not trying to write more than one branch/tree.

void ClCut ()
// Define Cuts //
TCut timing = “abs(delvt)<1.002&&abs(stVp-vtime)<1.002&&abs(stVp2-vtime)<1.002”;
TCut targetFiducial = “sqrt(xx+yy)<2.0&&z>-110&&z<-70”;
TCut knockoutsAndFiducial = “fid1p1&&fid1p2&&tofkop1==1&&tofkop2==1”;
TCut mehCut = timing&&knockoutsAndFiducial&&targetFiducial;

// Import root files as trees //
TFile *f = new TFile("~/root/datastuff/newData/WillsData0817.root","READ"); // Original data
TTree* bb = (TTree*)f->Get("pp;1");
TFile *ff = new TFile("~/root/datastuff/preRecon.root","RECREATE"); // Output file: pre-reconstruction file
TTree* cc = bb->CopyTree(mehCut); // Copies old data tree with target, timing, and fiducial cuts applied.



Two suspicious things in your code:
a) no error checking at all! Avoid Get, use GetObject instead and check the result.
b) the “pp;1”: are you really really really sure you want the first cycle? Otherwise, just omit the “;1” and you will get the full tree.

Unrelated to your problem: create a new File with the static function TFile::Open(...) and free the object using delete. Close does not delete the object, but delete automatically closes the file.

I used GetObject instead of Get, and I omitted the ;1 to get the entire tree. However, I am still getting the same error message. The generated/overwritten file preRecon.root still contains the two /cycles/ (not “branches”), and the two cycles do not have the same number of entries. Any reason two cycles would be generated with different numbers of entries?

The error message suggests something is wrong with memory management, it can for example be caused by freeing an object more than once. So my next best guess is your WillsData0817.root. Could that already be corrupt? Can you share it?

The data file is 1.5 GB large, so it would take quite a while to upload. How can I check if it’s corrupt? Perhaps there is an issue with CopyTree?

The error does not come up if I use CopyTree("") i.e. no cuts. I confirmed the tree is the same as from WillsData0817. Is there an alternate to CopyTree?

UPDATE: I saved the new data file, preRecon.root, with the same tree as from WillsData0817. Then made preRecon2.root and saved the tree from preRecon.root with the cuts I was trying to apply. Oddly enough it worked with no issues. It seems I only get the error when trying to use CopyTree to copy selections of WillsData0817 to a new file.

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