I have a problem when trying to write a tree to a file (opened in “recreate” mode), while having other files opened in “read” mode. Root seems to try and write into one of the read-only files, since I get the message
Some more details:
I have created classes (PData and PAnalysis), which open files and read trees when instanciated.
For PAnalysis (an object of this class is created at the very beginning of the program):
myOutputFile = (TFile*) new TFile(..., "RECREATE");
myTree = (TTree*) new TTree("name","name");
Then, a few PData objects are created, where:
myFile = (TFile*) new TFile((xxx), "READ");
myTree = (TTree*) myFile->Get("Event");
The program then calls member functions of the PAnalysis object, which read the trees “owned” by the PData objects and fill the tree owned by the PAnalysis object. Then, I want to call this member function:
… But I get the error quoted above.
Actually, I get the same error when simply trying to write, say, a canvas owned by a PAnalysis object. In this particular case, it did work when I created the canvas, opened the writable file, wrote the canvas, and closed the file in the same member function. But of course this doesn’t work for the tree anymore, since it is always created at instanciation.
I’ve searched this forum and the internet for people having similar problems, but I couldn’t find a satisfactory answer and I don’t understand what I’m doing wrong in the order I open, read and write my files and trees…