#include "TFile.h" #include "TTree.h" #include "TString.h" #include "TEventList.h" #include "TDirectory.h" #include #include "TObjArray.h" #include "TRegexp.h" #include typedef std::vector StrVec; int SplitString(TString s, TString delim, StrVec &toks) { toks.clear(); TObjArray *tok = s.Tokenize(delim); int N = tok->GetEntries(); for (int i=0;iAt(i))->String()).Strip(TString::kBoth); toks.push_back(token); } return toks.size(); } void compress(TString ntp, TString fnamein, TString fnameout, TString bnames="", TString precut="tag" ) { if (bnames=="*" && precut=="") { cout <<"Nothing to compress. Exiting."<=0) SplitString(bnames," ", toks); else SplitString(bnames,"§", toks); TFile *fi = new TFile(fnamein,"READ"); TTree *ti = (TTree*) fi->Get(ntp); cout <<"Converting tree '"<GetNbranches()<<" br, "<GetEntriesFast()<<" ev) ... "<Draw(">>el",precut); TEventList *el = (TEventList*)gDirectory->Get("el"); ti->SetBranchStatus("*",0); for (int i=0;iSetBranchStatus(tmp,0); } else ti->SetBranchStatus(toks[i].Data(),1); } ti->SetEventList(el); TFile *fo = new TFile(fnameout, "RECREATE"); TTree *to = ti->CopyTree(""); // to->SetEventList(el); cout <<"to "<GetNbranches()<<" br, "<GetEntriesFast()<<" ev) "<Write(); fo->Close(); fi->Close(); }