19 #include "utilities.hh" 23 int main(
int argc,
char *argv[]){
24 time_t startTime, curTime;
28 int begrun(-1), endrun(-1);
30 while((c=getopt(argc, argv,
"f:i:o:b:e:"))!=-1){
51 if(file_datasets==
"" ||
infolder==
""){
52 cout<<endl<<
"Specify input folder and datasets: " 53 <<
"./run/combine_datasets.exe -i <infolder> -o <outfolder=out> -f <file_datasets=txt/singlelep.txt> -b <begrun=-1> -e <endrun=-1>"<<endl<<endl;
57 TString run_s=
"_runs"; run_s += begrun;
59 run_s +=
"-"; run_s += endrun;
63 cout<<
"You set begrun to "<<begrun<<
", and endrun to "<<endrun
64 <<
", but endrun has to be >= to begrun. Exiting"<<endl<<endl;
67 cout<<
"Combining "<<run_s<<
" of ntuples in "<<
infolder<<endl;
71 TString buffer, basename(
"Run2016");
72 ifstream indata(file_datasets);
76 datasets.push_back(buffer);
77 basename += (
"_"+buffer);
80 if(begrun>0) basename += run_s;
82 map<int, map<int, set<Long64_t> > >
runs;
86 for(
unsigned idata(0); idata < datasets.size(); idata++){
89 int files = chain.Add(filename);
91 cout<<
"No files found for "<<filename<<endl;
94 gSystem->mkdir(outfolder, kTRUE);
95 TString
outname(outfolder+
"/baby_");
97 outname +=
"_"+basename;
99 TFile
outfile(outname,
"RECREATE");
102 TTree *outtree(chain.CloneTree(0));
106 TBranch *b_event(
nullptr), *b_lumiblock(
nullptr), *b_run(
nullptr);
107 chain.SetBranchAddress(
"event", &event, &b_event);
108 chain.SetBranchAddress(
"lumiblock", &lumiblock, &b_lumiblock);
109 chain.SetBranchAddress(
"run", &run, &b_run);
111 long entries(chain.GetEntries()), tree_entry;
113 cout<<endl<<
"Doing "<<files<<
" files in "<<filename<<
" with "<<entries<<
" entries"<<endl;
115 for(
int entry(0); entry<entries; entry++){
116 if(entry!=0 && entry%250000==0) {
118 int seconds(difftime(curTime,startTime));
121 <<
" Took "<<setw(6)<<seconds<<
" seconds at " 122 <<setw(4)<<
roundNumber(entry,1,seconds*1000.)<<
" kHz"<<endl;
126 tree_entry = chain.LoadTree(entry);
127 b_run->GetEntry(tree_entry);
128 if(begrun>0 && (run<begrun || run>endrun))
continue;
129 b_lumiblock->GetEntry(tree_entry);
130 b_event->GetEntry(tree_entry);
132 if(runs.find(run) == runs.end()) runs.emplace(run, map<
int, set<Long64_t> >{});
133 auto &lumiblocks = runs.at(run);
134 if(lumiblocks.find(lumiblock) == lumiblocks.end()) lumiblocks.emplace(lumiblock, set<Long64_t>{});
135 auto &events = lumiblocks.at(lumiblock);
136 if(events.find(event) == events.end()){
137 events.emplace(event);
139 chain.GetEntry(entry);
147 cout<<
"Took "<<difftime(curTime,startTime) <<
" seconds to write "<<outname<<endl;
156 TString txtname(outfolder+
"/runs_"+basename+
".txt");
157 ofstream txtfile(txtname);
159 for(map<
int, map<
int, set<Long64_t> > >::const_iterator it = runs.begin(); it != runs.end(); ++it) {
161 if(run/1000 != prevrun){
165 txtfile << run <<
" ";
169 cout<<endl<<
"Written run numbers in "<<txtname<<endl;
tuple run
Parsing run from file name.
int main(int argc, char *argv[])
TString addCommas(double num)
TString roundNumber(double num, int decimals, double denom=1.)