#include "TFile.h"
#include "TTree.h"
#include "TString.h"
#include "TEventList.h"
#include "TDirectory.h"
#include <iostream>
#include "TObjArray.h"
#include "TRegexp.h"
#include <vector>
Go to the source code of this file.
Definition at line 26 of file examples/analysistools/compress.C.
References bnam, COMSplitString(), fi, i, name, printf(), and TString.
28 if (ntp==
"" || fnamein==
"" || fnameout==
"")
30 cout <<
"USAGE:\ncompress(TString tree, TString infile, TString outfile, TString bnames, TString precut)\n\n";
31 cout <<
" tree : name of the TTree to be compressed.\n";
32 cout <<
" infile : input file name.\n";
33 cout <<
" outfile : output file name.\n";
34 cout <<
" bnames : blank separated list of branch variable names to be copied; can make use of name* / *name /*name*; !(*)name(*) excludes variables (default = \"*\").\n";
35 cout <<
" precut : cut to be applied before compressing branches (default = \"\"). Either bnames!=\"*\" or precut!=\"\".\n\n";
40 if (bnames==
"*" && precut==
"")
42 cout <<
"Nothing to compress. Exiting."<<endl;
47 TFile *
fi =
new TFile(fnamein,
"READ");
48 TTree *ti = (TTree*) fi->Get(ntp);
49 ti->Draw(
">>el",precut);
56 ti->SetBranchStatus(
"*",0);
57 for (uint
i=0;
i<bnam.size();++
i)
58 if (bnam[
i].BeginsWith(
"!")) ti->SetBranchStatus(
TString(bnam[
i](1,1000)),0);
59 else ti->SetBranchStatus(bnam[
i],1);
62 TObjArray* blist = ti->GetListOfBranches();
63 for(
int i=0; i<=blist->GetLast(); ++
i)
65 TString name = ((TBranch*)blist->UncheckedAt(i))->GetName();
66 if (ti->GetBranchStatus(name)>0) bnam.push_back(name);
70 cout<<
"**** Branch pattern: \""<<bnames<<
"\""<<endl;
71 cout<<
"**** "<<bnam.size()<<
" branches found: \n";
72 for (uint i=0;i<bnam.size();++
i)
printf(
"%s ",bnam[i].Data());
75 cout <<
"Converting tree '"<<ntp<<
"': "<<fnamein<<
" ("<<ti->GetNbranches()<<
" br, "<<ti->GetEntriesFast()<<
" ev) ... "<<flush;
77 TEventList *el = (TEventList*)gDirectory->Get(
"el");
80 TFile *fo =
new TFile(fnameout,
"RECREATE");
81 TTree *to = ti->CopyTree(
"");
83 cout <<
"to "<<fnameout<<
" ("<<to->GetNbranches()<<
" br, "<<to->GetEntriesFast()<<
" ev) "<<endl;
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)