void MergeFlowd() { TGrid *alien = TGrid::Connect("alien"); if (alien->IsZombie()) { delete alien; cout << "Fatal: Alien is a zombie!" << endl; return; } Int_t runlist[] = { // Counter /*170309, 170308, 170306, 170270, 170269, 170268, 170230, 170228,*/ 170204, 170203, // 10 170193, 170163, 170159, 170155, 170081, 170027, 169859, 169858, 169855, 169846, // 20 169838, 169837, 169835, 169417, 169415, 169411, 169238, 169167, 169160, 169156, // 30 169148, 169145, 169144, 169138, 169094, 169091, 169035, 168992, 168988, 168826, // 40 168777, 168514, 168512, 168511, 168467, 168464, 168460, 168458, 168362, 168361, // 50 168342, 168341, 168325, 168322, 168311, 168310, 167988, 167987 // 58 }; TFileMerger merger; TString dataBaseDir = "/alice/cern.ch/user/m/mpuccio/Flowd_PbPb2011/output/000"; merger.OutputFile("FileMerger.root"); for (int iRun = 0; iRun < 1; ++iRun) { TString runDir = Form("%s%i",dataBaseDir.Data(),runlist[iRun]); TGridResult *res = alien->Command(Form("find %s */mpuccio_Flowd.root",runDir.Data())); TIter iter(res); TMap *map; while ((map = (TMap*)iter())) { TObjString *obj = dynamic_cast<TObjString*>(map->GetValue("turl")); if (!obj || !obj->String().Length()) { delete res; break; } TFile *f = TFile::Open(obj->String().Data()); if (!f->IsOpen()) { cout << "File " << obj->String().Data() << " has some problems..." << endl; continue; } merger.AddFile(f); merger.PartialMerge(); f->Close(); } } merger.Merge(); merger.Write(); }
void mergeSelective(Int_t nfiles=5) { // This macro demonstrates how to merge only a part of the content of a set // of input files, specified via the interface: // TFileMerger::AddObjectNames(const char *names) // The method can be called several times to add object names, or using a single // strings with names separated by a blank. Directory names contained in the files // to be merged are accepted. // // Two modes are supported: // == kOnlyListed: via TFileMerger::PartialMerge(kOnlyListed) // This will merge only the objects in the files having the names in the // specified list. If a folder is specified, it whole content will be merged // // == kSkipListed: via TFileMerger::PartialMerge(kSkipListed) // This will skip merging of specified objects. If a folder is specified, its // whole content will be skipped. // // Important note: the kOnlyListed and kSkipListed flags have to be bitwise OR-ed // on top of the merging defaults: kAll | kIncremental (as in the example) // // The files to be merged have the following structure: // - hpx (TH1F) // - hpxpy (TH2F) // - hprof (TProfile) // - ntuple (TNtuple) // = folder (TDirectory) // - hpx1 (TH1F) // // The example first merges exclusively hprof and the content of "folder", // producing the file exclusive.root, then merges all content but skipping // hprof and the content of "folder". The result can be inspected in the // browser. // Create the files to be merged TStopwatch timer; timer.Start(); if (gROOT->LoadMacro("$ROOTSYS/tutorials/hsimple.C")) return; Int_t i; for (i=0; i<nfiles; i++) CreateFile(Form("tomerge%03d.root",i)); //------------------------------------ // Merge only the listed objects //------------------------------------ TFileMerger *fm; fm = new TFileMerger(kFALSE); fm->OutputFile("exclusive.root"); fm->AddObjectNames("hprof folder"); for (i=0; i<nfiles; i++) fm->AddFile(Form("tomerge%03d.root",i)); // Must add new merging flag on top of the the default ones Int_t default_mode = TFileMerger::kAll | TFileMerger::kIncremental; Int_t mode = default_mode | TFileMerger::kOnlyListed; fm->PartialMerge(mode); fm->Reset(); //------------------------------------ // Skip merging of the listed objects //------------------------------------ fm->OutputFile("skipped.root"); fm->AddObjectNames("hprof folder"); for (i=0; i<nfiles; i++) fm->AddFile(Form("tomerge%03d.root",i)); // Must add new merging flag on top of the the default ones mode = default_mode | TFileMerger::kSkipListed; fm->PartialMerge(mode); delete fm; // Cleanup initial files for (i=0; i<nfiles; i++) gSystem->Unlink(Form("tomerge%03d.root",i)); // Open files to inspect in the browser TFile::Open("exclusive.root"); TFile::Open("skipped.root"); new TBrowser(); timer.Stop(); timer.Print(); }