// -*- C++ -*- #include "TFile.h" #include "TClonesArray.h" #include "TChain.h" #include "TTree.h" #include "TAuthenticate.h" #include "TBranch.h" #include "TObjArray.h" #include "time.h" #include "dout.h" #include #include #include #include #include #include #include "optionUtils.h" using namespace std; // input list of root files (list) char gInputA[500]; char gInputB[500]; char gOutput[500]; char treename[100]; int main(int argc, char** argv) { //////////////////////////////////////////////////////// // ////////////////////////////////////////////////// // // // //////////////////////////////////////////// // // // // // Parse Command Line Arguments // // // // // // Decide Which Files and How Many Events // // // // // //////////////////////////////////////////// // // // ////////////////////////////////////////////////// // //////////////////////////////////////////////////////// strcpy(gInputA,argv[1]); strcpy(gInputB,argv[2]); strcpy(gOutput,argv[3]); strcpy(treename,argv[4]); cout << "Merging tree " << treename << " From " << gInputA << ", " << gInputB << " into " << gOutput << endl; //////////////////////////////////////// // ////////////////////////////////// // // // //////////////////////////// // // // // // Setup Input Tree Chain // // // // // //////////////////////////// // // // ////////////////////////////////// // //////////////////////////////////////// TChain *chainPtr = new TChain(treename); chainPtr->AddFile(gInputA); cout << "Found " << chainPtr->GetEntries() << " events" << endl; chainPtr->AddFile(gInputB); if (0 == chainPtr) { // something bad has happened cerr << "Can't get " << treename << " Sorry, eh." << endl; return 0; } else { cout << "Found " << chainPtr->GetEntries() << " events" << endl; } /////////////////////////////////// // ///////////////////////////// // // // /////////////////////// // // // // // Setup Output Tree // // // // // /////////////////////// // // // ///////////////////////////// // /////////////////////////////////// TFile *filePtr = new TFile (gOutput, "RECREATE"); if (! filePtr->IsOpen()) { cerr << "Did not successfully open " << gOutput << " for output. Aborting." << endl; return 0; } TTree *treePtr = chainPtr->CloneTree(0); // split up file if larger than 1000 MB treePtr->SetMaxTreeSize( 1048576000 ); //////////////////////////////////////////// // ////////////////////////////////////// // // // //////////////////////////////// // // // // // ////////////////////////// // // // // // // // Start The Large Loop // // // // // // // ////////////////////////// // // // // // //////////////////////////////// // // // ////////////////////////////////////// // //////////////////////////////////////////// Int_t nentries = Int_t(chainPtr->GetEntries()); cout << "Possible entries: " << nentries << endl; cout << " We are looping over " << nentries << " events." << endl; int numActual = 0; for (Int_t entryIndex = 0; entryIndex < nentries; ++entryIndex) { // just so I know somethingg is happening if (entryIndex % 100 == 0) cout << entryIndex << endl; /////////////////////////// // Get event from ntuple // /////////////////////////// // check run chainPtr->GetEntry(entryIndex, 0); // Do we want this event? bool takeEvent = true; //////////////////////// // Fill the Skim Tree // //////////////////////// if (takeEvent) { treePtr->Fill(); ++numActual; } } cout << "Finished skimming with " << numActual << " out of " << nentries << " events." << endl; treePtr->Write(); cout << "Writing complete." << endl; return 0; }