Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "TString.h"
- #include <TFile.h>
- #include <TTree.h>
- #include <TNtuple.h>
- #include <TTreeCache.h>
- void test_cache() {
- TString in_fname("/tmp/test_in.root");
- // create a tree in file
- {
- TFile * in_file = TFile::Open(in_fname, "RECREATE");
- in_file->cd();
- TNtuple * in_tree = new TNtuple("in_tree", "blah","a:b:c");
- for (int i = 0; i < 10; ++i) {
- in_tree->Fill(i,2 * i,3 * i);
- }
- in_tree->Write();
- in_file->Close();
- }
- TFile * in_file = TFile::Open(in_fname);
- TNtuple * in_tree = (TNtuple*) in_file->Get("in_tree");
- // set cache on input file (mimic TEventIterTree::GetTrees)
- TTreeCache *fTreeCache = 0;
- int fCacheSize = 100000;
- bool fTreeCacheIsLearning = 1;
- TTree * main = (TTree*) in_tree;
- TFile *curfile = main->GetCurrentFile();
- if (!fTreeCache) {
- main->SetCacheSize(fCacheSize);
- fTreeCache = (TTreeCache *)curfile->GetCacheRead(main);
- if (fCacheSize < 0) fCacheSize = main->GetCacheSize();
- } else {
- curfile->SetCacheRead(fTreeCache, main);
- fTreeCache->UpdateBranches(main);
- }
- if (fTreeCache) {
- fTreeCacheIsLearning = fTreeCache->IsLearning();
- //~ if (fTreeCacheIsLearning)
- //~ Info("GetTrees","the tree cache is in learning phase");
- }
- TFile * out_file = TFile::Open("/tmp/test_out.root", "RECREATE");
- in_file->cd(); // Probably somewhere inside PROOF code
- TNtuple * out_tree = (TNtuple*) in_tree->CloneTree(0);
- out_tree->SetName("out_tree");
- // vvv uncomment the following line to work around the bug
- //~ out_tree->SetDirectory(0);
- out_tree->SetDirectory(out_file);
- out_tree->SetAutoSave();
- out_tree->Fill(-1, -1, -1);
- in_file->Close();
- out_file->cd();
- out_tree->Write();
- out_file->Close();
- }
- int main() {
- test_cache();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement