I have been using something like
[code] tr_x_sec = new TTree(“CrossX”,“CrossX info”);
in order to read from a text file
How can I write some string / values to a text file and save it as well?
try, for example, “ofstream”: http://www.cplusplus.com/reference/iostream/ofstream
Examples: create/open/close a file: http://www.cplusplus.com/reference/iostream/ofstream/ofstream/ and/or http://www.cplusplus.com/reference/iostream/ofstream/open/ and/or http://www.cplusplus.com/reference/iostream/ofstream/close/
Example: write data: http://www.cplusplus.com/reference/iostream/ostream/operator%3C%3C/
Unless what you wanted was just something like:
root […] tr_x_sec->SetScanField(0);
root […] tr_x_sec->Scan("*"); > tr_x_sec.out.txt
See: http://root.cern.ch/root/html/TTree.html#TTree:Scan and http://root.cern.ch/root/html/TTreePlayer.html#TTreePlayer:Scan for details.
However, I don’t know if ROOT is able to parse such a text output afterwards, for example in order to ‘tr_x_sec->ReadFile(“tr_x_sec.out.txt”)’. You might need to edit this file manually. If you have just one “text row” per “tree entry”, remove the first column (called “Row”) and get rid of all “*” characters that are present inside (and possibly modify/add the first line which can keep all branch descriptions - see http://root.cern.ch/root/html/TTree.html#TTree:ReadFile for details).
An expert’s advice is needed here.
I am stupid. No?
Pepe Le Pew.
You can also redirect the output of Scan as follow:
// Read and dump the tree entries
t->GetPlayer()->SetScanRedirect(kTRUE); // You may have to cast t.GetPlayer() to a TTreePlayer*
produces the same output text file format as the one in my previous post here.
The question is … can ROOT read it back?
If not, is there any other simple method to “dump” a TTree into an ascii file and read it back later (let’s assume that the TTree is “simple enough”, whatever this “requirement” may mean in the context here)?
No. short of writing your own MakeClass/MakeSelector/MakeProxy or TTree::Draw script listing explicitly the variable and the format.
where can I find this .txt file then…??? in the root session, I do not have this file…
where an I find this .txt file. In the root session, this file is absent…??
root  ((TTreePlayer*)(ntuple->GetPlayer()))->SetScanRedirect(kTRUE);
root  ((TTreePlayer*)(ntuple->GetPlayer()))->SetScanFileName("output.txt");
root  ntuple->Scan();
File <output.txt> created
root  .! ls -l output.txt
-rw-r--r-- 1 couet staff 1825292 Sep 3 13:22 output.txt
Thankyou Dear couet…God Bless you…!!