Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TFileMerger.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Andreas Peters + Fons Rademakers + Rene Brun 26/5/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**
13\class TFileMerger TFileMerger.cxx
14\ingroup io_files
15
16This class provides file copy and merging services.
17
18It can be used to copy files (not only ROOT files), using TFile or
19any of its remote file access plugins. It is therefore useful in
20a Grid environment where the files might be accessible only remotely.
21The merging interface allows files containing histograms and trees
22to be merged, like the standalone hadd program.
23*/
24
25#include "TFileMerger.h"
26#include "TDirectory.h"
27#include "TError.h"
28#include "TUrl.h"
29#include "TFile.h"
30#include "TUUID.h"
31#include "TSystem.h"
32#include "TKey.h"
33#include "THashList.h"
34#include "TObjString.h"
35#include "TObjArray.h"
36#include "TClass.h"
37#include "TFileMergeInfo.h"
38#include "TClassRef.h"
39#include "TROOT.h"
40#include "TMemFile.h"
41#include "TVirtualMutex.h"
42
43#ifdef WIN32
44// For _getmaxstdio
45#include <cstdio>
46#else
47// For getrlimit
48#include <sys/time.h>
49#include <sys/resource.h>
50#endif
51
52#include <cstring>
53#include <map>
54
55
58TClassRef R__RNTuple_Class("ROOT::RNTuple");
59
60static const Int_t kCpProgress = BIT(14);
61static const Int_t kClingFileNumber = 100;
62////////////////////////////////////////////////////////////////////////////////
63/// Return the maximum number of allowed opened files minus some wiggle room
64/// for Cling or at least of the standard library (stdio).
65
67{
68 int maxfiles;
69#ifdef WIN32
70 maxfiles = _getmaxstdio();
71#else
72 rlimit filelimit;
73 if (getrlimit(RLIMIT_NOFILE,&filelimit)==0) {
74 maxfiles = filelimit.rlim_cur;
75 } else {
76 // We could not get the value from getrlimit, let's return a reasonable default.
77 maxfiles = 512;
78 }
79#endif
80 if (maxfiles > kClingFileNumber) {
81 // Limit the maximum number of opened files to 128 to mitigate memory
82 // consumption issues that may arise during merges with many files.
83 // For further details see analysis at:
84 // https://github.com/root-project/root/issues/21660
85 return std::min(128, maxfiles - kClingFileNumber);
86 } else if (maxfiles > 5) {
87 return maxfiles - 5;
88 } else {
89 return maxfiles;
90 }
91}
92
93////////////////////////////////////////////////////////////////////////////////
94/// Create file merger object.
95
98 fLocal(isLocal), fHistoOneGo(histoOneGo)
99{
100 fMergeList.SetOwner(kTRUE);
101 fExcessFiles.SetOwner(kTRUE);
102
104 gROOT->GetListOfCleanups()->Add(this);
105}
106
107////////////////////////////////////////////////////////////////////////////////
108/// Cleanup.
109
111{
112 {
114 gROOT->GetListOfCleanups()->Remove(this);
115 }
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Reset merger file list.
121
123{
124 fFileList.Clear();
125 fMergeList.Clear();
126 fExcessFiles.Clear();
127 fObjectNames.Clear();
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Closes output file
132
138
139////////////////////////////////////////////////////////////////////////////////
140/// Add file to file merger.
141
142Bool_t TFileMerger::AddFile(const char *url, Bool_t cpProgress)
143{
144 if (fPrintLevel > 0) {
145 Printf("%s Source file %d: %s", fMsgPrefix.Data(), fFileList.GetEntries() + fExcessFiles.GetEntries() + 1, url);
146 }
147
148 TFile *newfile = nullptr;
149 TString localcopy;
150
151 if (fFileList.GetEntries() >= (fMaxOpenedFiles-1)) {
152
153 TObjString *urlObj = new TObjString(url);
154 fMergeList.Add(urlObj);
155
156 urlObj = new TObjString(url);
157 urlObj->SetBit(kCpProgress);
158 fExcessFiles.Add(urlObj);
159 return kTRUE;
160 }
161
162 // We want gDirectory untouched by anything going on here
164
165 if (fLocal) {
166 TUUID uuid;
167 localcopy.Form("file:%s/ROOTMERGE-%s.root", gSystem->TempDirectory(), uuid.AsString());
168 if (!TFile::Cp(url, localcopy, cpProgress)) {
169 Error("AddFile", "cannot get a local copy of file %s", url);
170 return kFALSE;
171 }
172 newfile = TFile::Open(localcopy, "READ");
173 } else {
174 newfile = TFile::Open(url, "READ");
175 }
176
177 // Zombie files should also be skipped
178 if (newfile && newfile->IsZombie()) {
179 delete newfile;
180 newfile = nullptr;
181 }
182
183 if (!newfile) {
184 if (fLocal)
185 Error("AddFile", "cannot open local copy %s of URL %s",
186 localcopy.Data(), url);
187 else
188 Error("AddFile", "cannot open file %s", url);
189 return kFALSE;
190 } else {
191 if (fOutputFile && fOutputFile->GetCompressionSettings() != newfile->GetCompressionSettings())
193
194 newfile->SetBit(kCanDelete);
195 fFileList.Add(newfile);
196
197 TObjString *urlObj = new TObjString(url);
198 fMergeList.Add(urlObj);
199
200 return kTRUE;
201 }
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Add the TFile to this file merger and *do not* give ownership of the TFile to this
206/// object.
207///
208/// Return kTRUE if the addition was successful.
209
211{
212 return AddFile(source,kFALSE,cpProgress);
213}
214
215////////////////////////////////////////////////////////////////////////////////
216/// Add the TFile to this file merger and give ownership of the TFile to this
217/// object (unless kFALSE is returned).
218///
219/// Return kTRUE if the addition was successful.
220
222{
223 return AddFile(source,kTRUE,cpProgress);
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Add the TFile to this file merger and give ownership of the TFile to this
228/// object (unless kFALSE is returned).
229///
230/// Return kTRUE if the addition was successful.
231
233{
234 if (source == 0 || source->IsZombie()) {
235 return kFALSE;
236 }
237
238 if (fPrintLevel > 0) {
239 Printf("%s Source file %d: %s",fMsgPrefix.Data(),fFileList.GetEntries()+1,source->GetName());
240 }
241
242 TFile *newfile = 0;
243 TString localcopy;
244
245 // We want gDirectory untouched by anything going on here
247 if (fLocal && !source->InheritsFrom(TMemFile::Class())) {
248 TUUID uuid;
249 localcopy.Form("file:%s/ROOTMERGE-%s.root", gSystem->TempDirectory(), uuid.AsString());
250 if (!source->Cp(localcopy, cpProgress)) {
251 Error("AddFile", "cannot get a local copy of file %s", source->GetName());
252 return kFALSE;
253 }
254 newfile = TFile::Open(localcopy, "READ");
255 // Zombie files should also be skipped
256 if (newfile && newfile->IsZombie()) {
257 delete newfile;
258 newfile = 0;
259 }
260 } else {
261 newfile = source;
262 }
263
264 if (!newfile) {
265 if (fLocal)
266 Error("AddFile", "cannot open local copy %s of URL %s",
267 localcopy.Data(), source->GetName());
268 else
269 Error("AddFile", "cannot open file %s", source->GetName());
270 return kFALSE;
271 } else {
272 if (fOutputFile && fOutputFile->GetCompressionSettings() != newfile->GetCompressionSettings()) fCompressionChange = kTRUE;
273
274 if (own || newfile != source) {
275 newfile->SetBit(kCanDelete);
276 } else {
277 newfile->ResetBit(kCanDelete);
278 }
279 fFileList.Add(newfile);
280
281 TObjString *urlObj = new TObjString(source->GetName());
282 fMergeList.Add(urlObj);
283
284 if (newfile != source && own) {
285 delete source;
286 }
287 return kTRUE;
288 }
289}
290
291////////////////////////////////////////////////////////////////////////////////
292/// Open merger output file.
293
294Bool_t TFileMerger::OutputFile(const char *outputfile, Bool_t force, Int_t compressionLevel)
295{
296 return OutputFile(outputfile,(force?"RECREATE":"CREATE"),compressionLevel);
297}
298
299////////////////////////////////////////////////////////////////////////////////
300/// Open merger output file.
301
302Bool_t TFileMerger::OutputFile(const char *outputfile, Bool_t force)
303{
304 Bool_t res = OutputFile(outputfile,(force?"RECREATE":"CREATE"),1); // 1 is the same as the default from the TFile constructor.
307 return res;
308}
309
310////////////////////////////////////////////////////////////////////////////////
311/// Open merger output file.
312///
313/// The 'mode' parameter is passed to the TFile constructor as the option, it
314/// should be one of 'NEW','CREATE','RECREATE','UPDATE'
315/// 'UPDATE' is usually used in conjunction with IncrementalMerge.
316
317Bool_t TFileMerger::OutputFile(const char *outputfile, const char *mode, Int_t compressionLevel)
318{
319 // We want gDirectory untouched by anything going on here
321 if (TFile *outputFile = TFile::Open(outputfile, mode, "", compressionLevel))
322 return OutputFile(std::unique_ptr<TFile>(outputFile));
323
324 Error("OutputFile", "cannot open the MERGER output file %s", fOutputFilename.Data());
325 return kFALSE;
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Set an output file opened externally by the users
330
331Bool_t TFileMerger::OutputFile(std::unique_ptr<TFile> outputfile)
332{
333 if (!outputfile || outputfile->IsZombie()) {
334 Error("OutputFile", "cannot open the MERGER output file %s", (outputfile) ? outputfile->GetName() : "");
335 return kFALSE;
336 }
337
338 if (!outputfile->IsWritable()) {
339 Error("OutputFile", "output file %s is not writable", outputfile->GetName());
340 return kFALSE;
341 }
342
344
345 TFile *oldfile = fOutputFile;
346 fOutputFile = 0; // This avoids the complaint from RecursiveRemove about the file being deleted which is here
347 // spurrious. (see RecursiveRemove).
348 SafeDelete(oldfile);
349
350 fOutputFilename = outputfile->GetName();
351 // We want gDirectory untouched by anything going on here
353 fOutputFile = outputfile.release(); // Transfer the ownership of the file.
354
355 return kTRUE;
356}
357
358////////////////////////////////////////////////////////////////////////////////
359/// Open merger output file. 'mode' is passed to the TFile constructor as the option, it should
360/// be one of 'NEW','CREATE','RECREATE','UPDATE'
361/// 'UPDATE' is usually used in conjunction with IncrementalMerge.
362
363Bool_t TFileMerger::OutputFile(const char *outputfile, const char *mode /* = "RECREATE" */)
364{
365 Bool_t res = OutputFile(outputfile,mode,1); // 1 is the same as the default from the TFile constructor.
367 return res;
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Print list of files being merged.
372
374{
375 fFileList.Print(options);
376 fExcessFiles.Print(options);
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Merge the files.
381///
382/// If no output file was specified it will write into
383/// the file "FileMerger.root" in the working directory. Returns true
384/// on success, false in case of error.
385
390
391namespace {
392
393Bool_t IsMergeable(TClass *cl)
394{
395 return (cl->GetMerge() || cl->InheritsFrom(TDirectory::Class()) ||
396 (cl->IsTObject() && !cl->IsLoaded() &&
397 /* If it has a dictionary and GetMerge() is nullptr then we already know the answer
398 to the next question is 'no, if we were to ask we would useless trigger
399 auto-parsing */
400 (cl->GetMethodWithPrototype("Merge", "TCollection*,TFileMergeInfo*") ||
401 cl->GetMethodWithPrototype("Merge", "TCollection*"))));
402};
403
404Bool_t WriteOneAndDelete(const TString &name, TClass *cl, TObject *obj, bool canBeMerged, Bool_t ownobj, TDirectory *target)
405{
406 Bool_t status = kTRUE;
407 if (cl->InheritsFrom(TCollection::Class())) {
408 // Don't overwrite, if the object were not merged.
409 if (obj->Write(name, canBeMerged ? TObject::kSingleKey | TObject::kOverwrite : TObject::kSingleKey) <= 0) {
410 status = kFALSE;
411 }
412 ((TCollection *)obj)->SetOwner();
413 if (ownobj)
414 delete obj;
415 } else {
416 // Don't overwrite, if the object were not merged.
417 // NOTE: this is probably wrong for emulated objects.
418 if (cl->IsTObject()) {
419 if (obj->Write(name, canBeMerged ? TObject::kOverwrite : 0) <= 0) {
420 status = kFALSE;
421 }
423 } else {
424 if (target->WriteObjectAny((void *)obj, cl, name, canBeMerged ? "OverWrite" : "") <= 0) {
425 status = kFALSE;
426 }
427 }
428 if (ownobj)
429 cl->Destructor(obj); // just in case the class is not loaded.
430 }
431 return status;
432}
433
434Bool_t WriteCycleInOrder(const TString &name, TIter &nextkey, TIter &peeknextkey, TDirectory *target)
435{
436 // Recurse until we find a different name or type appear.
437 TKey *key = (TKey*)peeknextkey();
438 if (!key || name != key->GetName()) {
439 return kTRUE;
440 }
442 if (IsMergeable(cl))
443 return kTRUE;
444 // Now we can advance the real iterator
445 (void)nextkey();
446 Bool_t result = WriteCycleInOrder(name, nextkey, peeknextkey, target);
447 TObject *obj = key->ReadObj();
448
449 return WriteOneAndDelete(name, cl, obj, kFALSE, kTRUE, target) && result;
450};
451
452} // anonymous namespace
453
455 TString &oldkeyname, THashList &allNames, Bool_t &status, Bool_t &onlyListed,
456 const TString &path, TDirectory *current_sourcedir, TFile *current_file, TKey *key,
457 TObject *obj, TIter &nextkey)
458{
459 const char *keyname = obj ? obj->GetName() : key->GetName();
460 const char *keyclassname = obj ? obj->IsA()->GetName() : key->GetClassName();
461 const char *keytitle = obj ? obj->GetTitle() : key->GetTitle();
462
463 // Keep only the highest cycle number for each key for mergeable objects. They are stored
464 // in the (hash) list consecutively and in decreasing order of cycles, so we can continue
465 // until the name changes. We flag the case here and we act consequently later.
466 Bool_t alreadyseen = (oldkeyname == keyname) ? kTRUE : kFALSE;
467 Bool_t ownobj = kFALSE;
468
469 // Read in but do not copy directly the processIds.
470 if (strcmp(keyclassname, "TProcessID") == 0 && key) {
471 key->ReadObj();
472 return kTRUE;
473 }
474
475 // If we have already seen this object [name], we already processed
476 // the whole list of files for this objects and we can just skip it
477 // and any related cycles.
478 if (allNames.FindObject(keyname)) {
479 oldkeyname = keyname;
480 return kTRUE;
481 }
482
483 TClass *cl = TClass::GetClass(keyclassname);
484 if (!cl) {
485 Info("MergeRecursive", "cannot indentify object type (%s), name: %s title: %s",
486 keyclassname, keyname, keytitle);
487 return kTRUE;
488 }
489 // For mergeable objects we add the names in a local hashlist handling them
490 // again (see above)
491 if (IsMergeable(cl))
492 allNames.Add(new TObjString(keyname));
493
495 // Skip the TTree objects and any related cycles.
496 oldkeyname = keyname;
497 return kTRUE;
498 }
499 // Check if only the listed objects are to be merged
500 if (type & kOnlyListed) {
501 oldkeyname = keyname;
502 oldkeyname += " ";
503 onlyListed = fObjectNames.Contains(oldkeyname);
504 oldkeyname = keyname;
505 if ((!onlyListed) && (!cl->InheritsFrom(TDirectory::Class()))) return kTRUE;
506 }
507
508 if (!(type&kResetable && type&kNonResetable)) {
509 // If neither or both are requested at the same time, we merger both types.
510 if (!(type&kResetable)) {
511 if (cl->GetResetAfterMerge()) {
512 // Skip the object with a reset after merge routine (TTree and other incrementally mergeable objects)
513 oldkeyname = keyname;
514 return kTRUE;
515 }
516 }
517 if (!(type&kNonResetable)) {
518 if (!cl->GetResetAfterMerge()) {
519 // Skip the object without a reset after merge routine (Histograms and other non incrementally mergeable objects)
520 oldkeyname = keyname;
521 return kTRUE;
522 }
523 }
524 }
525 // read object from first source file
526 if (type & kIncremental) {
527 if (!obj)
528 obj = current_sourcedir->GetList()->FindObject(keyname);
529 if (!obj && key) {
530 obj = key->ReadObj();
531 ownobj = kTRUE;
532 } else if (obj && info.fIsFirst && current_sourcedir != target
533 && !cl->InheritsFrom( TDirectory::Class() )) {
534 R__ASSERT(cl->IsTObject());
535 TDirectory::TContext ctxt(current_sourcedir);
536 obj = obj->Clone();
537 ownobj = kTRUE;
538 }
539 } else if (key) {
540 obj = key->ReadObj();
541 ownobj = kTRUE;
542 }
543 if (!obj) {
544 Info("MergeRecursive", "could not read object for key {%s, %s}",
545 keyname, keytitle);
546 return kTRUE;
547 }
548 Bool_t canBeFound = (type & kIncremental) && (target->GetList()->FindObject(keyname) != nullptr);
549
550 // if (cl->IsTObject())
551 // obj->ResetBit(kMustCleanup);
552 if (cl->IsTObject() && cl != obj->IsA()) {
553 Error("MergeRecursive", "TKey and object retrieve disagree on type (%s vs %s). Continuing with %s.",
554 keyclassname, obj->IsA()->GetName(), obj->IsA()->GetName());
555 cl = obj->IsA();
556 }
557 Bool_t canBeMerged = kTRUE;
558
559 std::map<std::tuple<std::string, std::string, std::string>, TDirectory*> dirtodelete;
560 auto getDirectory = [&dirtodelete](TDirectory *parent, const char *name, const TString &pathname) {
561 auto mapkey = std::make_tuple(parent->GetName(), name, pathname.Data());
562 auto result = dirtodelete.find(mapkey);
563 if (result != dirtodelete.end()) {
564 return result->second;
565 }
566
567 auto dir = dynamic_cast<TDirectory *>(parent->GetDirectory(pathname));
568 if (dir)
569 dirtodelete[mapkey] = dir;
570
571 return dir;
572 };
573
574 if ( cl->InheritsFrom( TDirectory::Class() ) ) {
575 // it's a subdirectory
576
577 target->cd();
578 TDirectory *newdir;
579
580 // For incremental or already seen we may have already a directory created
581 if (type & kIncremental || alreadyseen) {
582 newdir = target->GetDirectory(obj->GetName());
583 if (!newdir) {
584 newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
585 // newdir->ResetBit(kMustCleanup);
586 }
587 } else {
588 newdir = target->mkdir( obj->GetName(), obj->GetTitle() );
589 // newdir->ResetBit(kMustCleanup);
590 }
591
592 // newdir is now the starting point of another round of merging
593 // newdir still knows its depth within the target file via
594 // GetPath(), so we can still figure out where we are in the recursion
595
596 // If this folder is a onlyListed object, merge everything inside.
597 const auto mergeType = onlyListed ? type & ~kOnlyListed : type;
598 status = MergeRecursive(newdir, sourcelist, mergeType);
599
600 if ((type & kOnlyListed) && !(type & kIncremental) && !onlyListed && newdir->GetNkeys() == 0) {
601 // None of the children were merged, and the directory is not listed
602 delete newdir;
603 newdir = nullptr;
604 target->rmdir(obj->GetName());
605 }
606 // Delete newdir directory after having written it (merged)
607 if (!(type&kIncremental)) delete newdir;
608 if (onlyListed) type |= kOnlyListed;
609 if (!status) return kFALSE;
610 } else if (!cl->IsTObject() && cl->GetMerge()) {
611 // merge objects that don't derive from TObject
613 Warning("MergeRecursive", "Merging RNTuples is experimental");
614
615 // Collect all the data to be passed on to the merger
616 TList mergeData;
617 // First entry is the TKey of the ntuple
618 mergeData.Add(key);
619 // Second entry is the output file
620 mergeData.Add(target->GetFile());
621 // Remaining entries are the input files
622 TIter nextFile(sourcelist);
623 while (const auto &inFile = nextFile()) {
624 mergeData.Add(inFile);
625 }
626 // Get the merge fuction and pass the data
627 ROOT::MergeFunc_t func = cl->GetMerge();
628 Long64_t result = func(obj, &mergeData, &info);
629 mergeData.Clear("nodelete");
630 if (result < 0) {
631 Error("MergeRecursive", "Could NOT merge RNTuples!");
632 return kFALSE;
633 }
634 } else {
635 TFile *nextsource = current_file ? (TFile*)sourcelist->After( current_file ) : (TFile*)sourcelist->First();
636 Error("MergeRecursive", "Merging objects that don't inherit from TObject is unimplemented (key: %s of type %s in file %s)",
637 keyname, keyclassname, nextsource->GetName());
638 canBeMerged = kFALSE;
639 }
640 } else if (cl->IsTObject() && cl->GetMerge()) {
641 // Check if already treated
642 if (alreadyseen) return kTRUE;
643
644 TList inputs;
645 TList todelete;
647
648 // Loop over all source files and merge same-name object
649 TFile *nextsource = current_file ? (TFile*)sourcelist->After( current_file ) : (TFile*)sourcelist->First();
650 if (nextsource == 0) {
651 // There is only one file in the list
652 ROOT::MergeFunc_t func = cl->GetMerge();
653 func(obj, &inputs, &info);
654 info.fIsFirst = kFALSE;
655 } else {
656 do {
657 // make sure we are at the correct directory level by cd'ing to path
658 TDirectory *ndir = getDirectory(nextsource, target->GetName(), path);
659 if (ndir) {
660 // For consistency (and persformance), we reset the MustCleanup be also for those
661 // 'key' retrieved indirectly.
662 // ndir->ResetBit(kMustCleanup);
663 ndir->cd();
664 TObject *hobj = ndir->GetList()->FindObject(keyname);
665 if (!hobj) {
666 TKey *key2 = (TKey*)ndir->GetListOfKeys()->FindObject(keyname);
667 if (key2) {
668 if (strcmp(key2->GetClassName(), keyclassname) != 0) {
669 Error("MergeRecursive",
670 "Object type mismatch for key '%s' in file '%s': expected '%s' but found '%s'.", keyname,
671 nextsource->GetName(), keyclassname, key2->GetClassName());
672 nextsource = (TFile *)sourcelist->After(nextsource);
673 return kFALSE;
674 }
675 hobj = key2->ReadObj();
676 if (!hobj) {
677 switch (fErrBehavior) {
679 Error("MergeRecursive", "could not read object for key {%s, %s}; in file %s", keyname,
680 keytitle, nextsource->GetName());
681 nextsource = (TFile *)sourcelist->After(nextsource);
682 return kFALSE;
684 Warning("MergeRecursive", "could not read object for key {%s, %s}; skipping file %s",
685 keyname, keytitle, nextsource->GetName());
686 nextsource = (TFile *)sourcelist->After(nextsource);
687 return kTRUE;
688 }
689 }
690 todelete.Add(hobj);
691 }
692 }
693 if (hobj) {
694 // Set ownership for collections
695 if (hobj->InheritsFrom(TCollection::Class())) {
696 ((TCollection*)hobj)->SetOwner();
697 }
698 hobj->ResetBit(kMustCleanup);
699 inputs.Add(hobj);
700 if (!oneGo) {
701 ROOT::MergeFunc_t func = cl->GetMerge();
702 Long64_t result = func(obj, &inputs, &info);
703 info.fIsFirst = kFALSE;
704 if (result < 0) {
705 Error("MergeRecursive", "calling Merge() on '%s' with the corresponding object in '%s'",
706 keyname, nextsource->GetName());
707 }
708 inputs.Clear();
709 todelete.Delete();
710 }
711 }
712 }
713 nextsource = (TFile*)sourcelist->After( nextsource );
714 } while (nextsource);
715 // Merge the list, if still to be done
716 if (oneGo || info.fIsFirst) {
717 ROOT::MergeFunc_t func = cl->GetMerge();
718 func(obj, &inputs, &info);
719 info.fIsFirst = kFALSE;
720 inputs.Clear();
721 todelete.Delete();
722 }
723 }
724 } else if (cl->IsTObject()) {
725 // try synthesizing the Merge method call according to the TObject
726 TList listH;
727 TString listHargs;
728 if (cl->GetMethodWithPrototype("Merge", "TCollection*,TFileMergeInfo*")) {
729 listHargs.Form("(TCollection*)0x%zx,(TFileMergeInfo*)0x%zx",
730 (size_t)&listH, (size_t)&info);
731 } else if (cl->GetMethodWithPrototype("Merge", "TCollection*")) {
732 listHargs.Form("((TCollection*)0x%zx)", (size_t)&listH);
733 } else {
734 // pass unmergeable objects through to the output file
735 canBeMerged = kFALSE;
736 }
737 if (canBeMerged) {
738 if (alreadyseen) {
739 // skip already seen mergeable objects, don't skip unmergeable objects
740 return kTRUE;
741 }
742 // Loop over all source files and merge same-name object
743 TFile *nextsource = current_file ? (TFile*)sourcelist->After( current_file ) : (TFile*)sourcelist->First();
744 if (nextsource == 0) {
745 // There is only one file in the list
746 Int_t error = 0;
747 obj->Execute("Merge", listHargs.Data(), &error);
748 info.fIsFirst = kFALSE;
749 if (error) {
750 Error("MergeRecursive", "calling Merge() on '%s' with the corresponding object in '%s'",
751 obj->GetName(), keyname);
752 }
753 } else {
754 while (nextsource) {
755 // make sure we are at the correct directory level by cd'ing to path
756 TDirectory *ndir = getDirectory(nextsource, target->GetName(), path);
757 if (ndir) {
758 ndir->cd();
759 TKey *key2 = (TKey*)ndir->GetListOfKeys()->FindObject(keyname);
760 if (key2) {
761 TObject *hobj = key2->ReadObj();
762 if (!hobj) {
763 switch (fErrBehavior) {
765 Error("MergeRecursive", "could not read object for key {%s, %s}; in file %s", keyname,
766 keytitle, nextsource->GetName());
767 nextsource = (TFile *)sourcelist->After(nextsource);
768 return kFALSE;
770 Warning("MergeRecursive", "could not read object for key {%s, %s}; skipping file %s",
771 keyname, keytitle, nextsource->GetName());
772 nextsource = (TFile *)sourcelist->After(nextsource);
773 return kTRUE;
774 }
775 }
776 // Set ownership for collections
777 if (hobj->InheritsFrom(TCollection::Class())) {
778 ((TCollection*)hobj)->SetOwner();
779 }
780 hobj->ResetBit(kMustCleanup);
781 listH.Add(hobj);
782 Int_t error = 0;
783 obj->Execute("Merge", listHargs.Data(), &error);
784 info.fIsFirst = kFALSE;
785 if (error) {
786 Error("MergeRecursive", "calling Merge() on '%s' with the corresponding object in '%s'",
787 obj->GetName(), nextsource->GetName());
788 }
789 listH.Delete();
790 }
791 }
792 nextsource = (TFile*)sourcelist->After( nextsource );
793 }
794 // Merge the list, if still to be done
795 if (info.fIsFirst) {
796 Int_t error = 0;
797 obj->Execute("Merge", listHargs.Data(), &error);
798 info.fIsFirst = kFALSE;
799 listH.Delete();
800 }
801 }
802 }
803 } else {
804 // Object is of no type that we can merge
805 canBeMerged = kFALSE;
806 }
807
808 // now write the merged histogram (which is "in" obj) to the target file
809 // note that this will just store obj in the current directory level,
810 // which is not persistent until the complete directory itself is stored
811 // by "target->SaveSelf()" below
812 target->cd();
813
814 oldkeyname = keyname;
815 // if the object is a tree, it is stored in globChain...
816 if (cl->InheritsFrom(TDirectory::Class())) {
817 // printf("cas d'une directory\n");
818
819 auto dirobj = dynamic_cast<TDirectory *>(obj);
820 TString dirpath(dirobj->GetPath());
821 // coverity[unchecked_value] 'target' is from a file so GetPath always returns path starting with filename:
822 dirpath.Remove(0, std::strlen(dirobj->GetFile()->GetPath()));
823
824 // Do not delete the directory if it is part of the output
825 // and we are in incremental mode (because it will be reused
826 // and has not been written to disk (for performance reason).
827 // coverity[var_deref_model] the IsA()->InheritsFrom guarantees that the dynamic_cast will succeed.
828 if (ownobj && (!(type & kIncremental) || dirobj->GetFile() != target)) {
829 dirobj->ResetBit(kMustCleanup);
830 delete dirobj;
831 }
832 // Let's also delete the directory from the other source (thanks to the 'allNames'
833 // mechanism above we will not process the directories when tranversing the next
834 // files).
835 for (const auto &[_, ndir] : dirtodelete) {
836 // For consistency (and performance), we reset the MustCleanup be also for those
837 // 'key' retrieved indirectly.
838 ndir->ResetBit(kMustCleanup);
839 delete ndir;
840 }
841 } else if (!canBeFound) { // object (TTree, TH1) is not yet owned by the target, thus write it
842 if (gDebug > 0)
843 Info("MergeOne", "Writing partial result of %s into target", oldkeyname.Data());
844 if (!canBeMerged) {
845 TIter peeknextkey(nextkey);
846 status = WriteCycleInOrder(oldkeyname, nextkey, peeknextkey, target) && status;
847 status = WriteOneAndDelete(oldkeyname, cl, obj, kFALSE, ownobj, target) && status;
848 } else {
849 status = WriteOneAndDelete(oldkeyname, cl, obj, kTRUE, ownobj, target) && status;
850 }
851 }
852 info.Reset();
853 return kTRUE;
854}
855
856////////////////////////////////////////////////////////////////////////////////
857/// Merge all objects in a directory
858///
859/// The type is defined by the bit values in TFileMerger::EPartialMergeType.
860
861Bool_t TFileMerger::MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type /* = kRegular | kAll */)
862{
863 Bool_t status = kTRUE;
864 Bool_t onlyListed = kFALSE;
865 if (fPrintLevel > 0) {
866 Printf("%s Target path: %s",fMsgPrefix.Data(),target->GetPath());
867 }
868
869 // Get the dir name
870 TString path(target->GetPath());
871 // coverity[unchecked_value] 'target' is from a file so GetPath always returns path starting with filename:
872 path.Remove(0, std::strlen(target->GetFile()->GetPath()));
873
874 Int_t nguess = sourcelist->GetSize()+1000;
875 THashList allNames(nguess);
876 allNames.SetOwner(kTRUE);
877 // If the mode is set to skipping list objects, add names to the allNames list
878 if (type & kSkipListed) {
879 TObjArray *arr = fObjectNames.Tokenize(" ");
880 arr->SetOwner(kFALSE);
881 for (Int_t iname=0; iname<arr->GetEntriesFast(); iname++)
882 allNames.Add(arr->At(iname));
883 delete arr;
884 }
885 ((THashList*)target->GetList())->Rehash(nguess);
886 ((THashList*)target->GetListOfKeys())->Rehash(nguess);
887
888 TFileMergeInfo info(target);
890 info.fOptions = fMergeOptions;
891 if (fFastMethod && ((type&kKeepCompression) || !fCompressionChange) ) {
892 info.fOptions.Append(" fast");
893 }
894
895 TFile *current_file;
896 TDirectory *current_sourcedir;
897 if (type & kIncremental) {
898 current_file = 0;
899 current_sourcedir = target;
900 } else {
901 current_file = (TFile*)sourcelist->First();
902 current_sourcedir = current_file->GetDirectory(path);
903 }
904 while (current_file || current_sourcedir) {
905 // When current_sourcedir != 0 and current_file == 0 we are going over the target
906 // for an incremental merge.
907 if (current_sourcedir && (current_file == 0 || current_sourcedir != target)) {
908 TString oldkeyname;
909
910 // Loop over live objects
911 TIter nextobj( current_sourcedir->GetList() );
912 TObject *obj;
913 while ( (obj = (TKey*)nextobj())) {
914 auto result = MergeOne(target, sourcelist, type,
915 info, oldkeyname, allNames, status, onlyListed, path,
916 current_sourcedir, current_file,
917 nullptr, obj, nextobj);
918 if (!result)
919 return kFALSE; // Stop completely in case of error.
920 } // while ( (obj = (TKey*)nextobj()))
921
922 // loop over all keys in this directory
923 TIter nextkey( current_sourcedir->GetListOfKeys() );
924 TKey *key;
925
926 while ( (key = (TKey*)nextkey())) {
927 auto result = MergeOne(target, sourcelist, type,
928 info, oldkeyname, allNames, status, onlyListed, path,
929 current_sourcedir, current_file,
930 key, nullptr, nextkey);
931 if (!result)
932 return kFALSE; // Stop completely in case of error.
933 } // while ( ( TKey *key = (TKey*)nextkey() ) )
934 }
935 current_file = current_file ? (TFile*)sourcelist->After(current_file) : (TFile*)sourcelist->First();
936 if (current_file) {
937 current_sourcedir = current_file->GetDirectory(path);
938 } else {
939 current_sourcedir = 0;
940 }
941 }
942 // save modifications to the target directory.
943 if (!(type&kIncremental)) {
944 // In case of incremental build, we will call Write on the top directory/file, so we do not need
945 // to call SaveSelf explicilty.
946 target->SaveSelf(kTRUE);
947 }
948
949 return status;
950}
951
952////////////////////////////////////////////////////////////////////////////////
953/// Merge the files. If no output file was specified it will write into
954/// the file "FileMerger.root" in the working directory. Returns true
955/// on success, false in case of error.
956/// The type is defined by the bit values in EPartialMergeType:
957///
958/// kRegular : normal merge, overwriting the output file
959/// kIncremental : merge the input file with the content of the output file (if already exising) (default)
960/// kResetable : merge only the objects with a MergeAfterReset member function.
961/// kNonResetable : merge only the objects without a MergeAfterReset member function.
962/// kDelayWrite : delay the TFile write (to reduce the number of write when reusing the file)
963/// kAll : merge all type of objects (default)
964/// kAllIncremental : merge incrementally all type of objects.
965/// kOnlyListed : merge only the objects specified in fObjectNames list
966/// kSkipListed : skip objects specified in fObjectNames list
967/// kKeepCompression: keep compression level unchanged for each input
968///
969/// If the type is not set to kIncremental, the output file is deleted at the end of this operation.
970
972{
973 if (!fOutputFile) {
975 if (outf.IsNull()) {
976 outf.Form("file:%s/FileMerger.root", gSystem->TempDirectory());
977 Info("PartialMerge", "will merge the results to the file %s\n"
978 "since you didn't specify a merge filename",
979 TUrl(outf).GetFile());
980 }
981 if (!OutputFile(outf.Data())) {
982 return kFALSE;
983 }
984 }
985
986 // Special treatment for the single file case to improve efficiency...
987 if ((fFileList.GetEntries() == 1) && !fExcessFiles.GetEntries() &&
989 fOutputFile->Close();
991
992 TFile *file = (TFile *) fFileList.First();
993 if (!file || (file && file->IsZombie())) {
994 Error("PartialMerge", "one-file case: problem attaching to file");
995 return kFALSE;
996 }
997 Bool_t result = kTRUE;
998 if (!(result = file->Cp(fOutputFilename))) {
999 Error("PartialMerge", "one-file case: could not copy '%s' to '%s'",
1000 file->GetPath(), fOutputFilename.Data());
1001 return kFALSE;
1002 }
1003 if (file->TestBit(kCanDelete)) file->Close();
1004
1005 // Remove the temporary file
1006 if (fLocal && !file->InheritsFrom(TMemFile::Class())) {
1007 TUrl u(file->GetPath(), kTRUE);
1008 if (gSystem->Unlink(u.GetFile()) != 0)
1009 Warning("PartialMerge", "problems removing temporary local file '%s'", u.GetFile());
1010 }
1011 fFileList.Clear();
1012 return result;
1013 }
1014
1015 fOutputFile->SetBit(kMustCleanup);
1017
1019
1020 Bool_t result = kTRUE;
1021 Int_t type = in_type;
1022 while (result && fFileList.GetEntries()>0) {
1023 result = MergeRecursive(fOutputFile, &fFileList, type);
1024
1025 // Remove local copies if there are any
1026 TIter next(&fFileList);
1027 TFile *file;
1028 while ((file = (TFile*) next())) {
1029 // close the files
1030 if (file->TestBit(kCanDelete)) file->Close();
1031 // remove the temporary files
1032 if(fLocal && !file->InheritsFrom(TMemFile::Class())) {
1033 TString p(file->GetPath());
1034 // coverity[unchecked_value] Index is return a value with range or NPos to select the whole name.
1035 p = p(0, p.Index(':',0));
1036 gSystem->Unlink(p);
1037 }
1038 }
1039 fFileList.Clear();
1040 if (result && fExcessFiles.GetEntries() > 0) {
1041 // We merge the first set of files in the output,
1042 // we now need to open the next set and make
1043 // sure we accumulate into the output, so we
1044 // switch to incremental merging (if not already set)
1045 type = type | kIncremental;
1046 result = OpenExcessFiles();
1047 }
1048 }
1049 if (!result) {
1050 Error("Merge", "error during merge of your ROOT files");
1051 } else {
1052 // Close or write is required so the file is complete.
1053 if (in_type & kIncremental) {
1054 // In the case of 'kDelayWrite' the caller want to avoid having to
1055 // write the output objects once for every input file and instead
1056 // write it only once at the end of the process.
1057 if (!(in_type & kDelayWrite))
1059 } else {
1060 // If in_type is not incremental but type is incremental we are now in
1061 // the case where the user "explicitly" request a non-incremental merge
1062 // but we still have internally an incremental merge. Because the user
1063 // did not request the incremental merge they also probably do not to a
1064 // final Write of the file and thus not doing the write here would lead
1065 // to data loss ...
1066 if (type & kIncremental)
1068 gROOT->GetListOfFiles()->Remove(fOutputFile);
1069 fOutputFile->Close();
1070 }
1071 }
1072
1073 // Cleanup
1074 if (in_type & kIncremental) {
1075 Clear();
1076 } else {
1077 fOutputFile->ResetBit(kMustCleanup);
1080 }
1081 return result;
1082}
1083
1084////////////////////////////////////////////////////////////////////////////////
1085/// Open up to (fMaxOpenedFiles-1) of the excess files.
1086
1088{
1089 if (fPrintLevel > 0) {
1090 Printf("%s Opening the next %d files", fMsgPrefix.Data(), std::min(fExcessFiles.GetEntries(), fMaxOpenedFiles - 1));
1091 }
1092 Int_t nfiles = 0;
1093 TIter next(&fExcessFiles);
1094 TObjString *url = 0;
1095 TString localcopy;
1096 // We want gDirectory untouched by anything going on here
1098 while( nfiles < (fMaxOpenedFiles-1) && ( url = (TObjString*)next() ) ) {
1099 TFile *newfile = 0;
1100 if (fLocal) {
1101 TUUID uuid;
1102 localcopy.Form("file:%s/ROOTMERGE-%s.root", gSystem->TempDirectory(), uuid.AsString());
1103 if (!TFile::Cp(url->GetName(), localcopy, url->TestBit(kCpProgress))) {
1104 Error("OpenExcessFiles", "cannot get a local copy of file %s", url->GetName());
1105 return kFALSE;
1106 }
1107 newfile = TFile::Open(localcopy, "READ");
1108 } else {
1109 newfile = TFile::Open(url->GetName(), "READ");
1110 }
1111
1112 if (!newfile) {
1113 if (fLocal)
1114 Error("OpenExcessFiles", "cannot open local copy %s of URL %s",
1115 localcopy.Data(), url->GetName());
1116 else
1117 Error("OpenExcessFiles", "cannot open file %s", url->GetName());
1118 return kFALSE;
1119 } else {
1120 if (fOutputFile && fOutputFile->GetCompressionLevel() != newfile->GetCompressionLevel()) fCompressionChange = kTRUE;
1121
1122 newfile->SetBit(kCanDelete);
1123 fFileList.Add(newfile);
1124 ++nfiles;
1125 fExcessFiles.Remove(url);
1126 }
1127 }
1128 return kTRUE;
1129}
1130
1131////////////////////////////////////////////////////////////////////////////////
1132/// Intercept the case where the output TFile is deleted!
1133
1135{
1137 Fatal("RecursiveRemove","Output file of the TFile Merger (targeting %s) has been deleted (likely due to a TTree larger than 100Gb)", fOutputFilename.Data());
1138 }
1139
1140}
1141
1142////////////////////////////////////////////////////////////////////////////////
1143/// Set a limit to the number of files that TFileMerger will open simultaneously.
1144///
1145/// This number includes both the read input files and the output file.
1146/// \param newmax if higher than the system limit, we reset it to the system limit;
1147/// if less than two, we reset it to 2 (one for the output file and one for the input file).
1148
1150{
1152 if (newmax < sysmax) {
1153 fMaxOpenedFiles = newmax;
1154 } else {
1155 fMaxOpenedFiles = sysmax;
1156 }
1157 if (fMaxOpenedFiles < 2) {
1158 fMaxOpenedFiles = 2;
1159 }
1160}
1161
1162////////////////////////////////////////////////////////////////////////////////
1163/// Set the prefix to be used when printing informational message.
1164
1165void TFileMerger::SetMsgPrefix(const char *prefix)
1166{
1167 fMsgPrefix = prefix;
1168}
1169
#define SafeDelete(p)
Definition RConfig.hxx:525
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
long long Long64_t
Portable signed long integer 8 bytes.
Definition RtypesCore.h:83
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
#define BIT(n)
Definition Rtypes.h:91
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
TClassRef R__TH1_Class("TH1")
static const Int_t kClingFileNumber
static Int_t R__GetSystemMaxOpenedFiles()
Return the maximum number of allowed opened files minus some wiggle room for Cling or at least of the...
TClassRef R__RNTuple_Class("ROOT::RNTuple")
TClassRef R__TTree_Class("TTree")
static const Int_t kCpProgress
char name[80]
Definition TGX11.cxx:148
@ kMustCleanup
Definition TObject.h:376
Int_t gDebug
Definition TROOT.cxx:777
#define gROOT
Definition TROOT.h:417
externTVirtualMutex * gROOTMutex
Definition TROOT.h:63
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2510
externTSystem * gSystem
Definition TSystem.h:582
#define R__LOCKGUARD(mutex)
#define _(A, B)
Definition cfortran.h:108
TClassRef is used to implement a permanent reference to a TClass object.
Definition TClassRef.h:29
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:84
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4514
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5470
ROOT::ResetAfterMergeFunc_t GetResetAfterMerge() const
Return the wrapper around Merge.
Definition TClass.cxx:7604
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
Definition TClass.cxx:6017
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
Definition TClass.cxx:6043
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4932
ROOT::MergeFunc_t GetMerge() const
Return the wrapper around Merge.
Definition TClass.cxx:7596
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2994
Collection abstract base class.
Definition TCollection.h:65
static TClass * Class()
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory") override
Find a directory using apath.
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
Describe directory structure in memory.
Definition TDirectory.h:45
static TClass * Class()
virtual TList * GetList() const
Definition TDirectory.h:223
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual Int_t GetNkeys() const
Definition TDirectory.h:228
virtual const char * GetPath() const
Returns the full path of the directory.
virtual void rmdir(const char *name)
Removes subdirectory from the directory When directory is deleted, all keys in all subdirectories wil...
virtual Int_t WriteObjectAny(const void *, const char *, const char *, Option_t *="", Int_t=0)
Definition TDirectory.h:301
virtual TFile * GetFile() const
Definition TDirectory.h:221
virtual Bool_t cd()
Change current directory to "this" directory.
virtual void SaveSelf(Bool_t=kFALSE)
Definition TDirectory.h:256
virtual TDirectory * mkdir(const char *name, const char *title="", Bool_t returnExistingDirectory=kFALSE)
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
virtual TList * GetListOfKeys() const
Definition TDirectory.h:224
A class to pass information from the TFileMerger to the objects being merged.
TIOFeatures * fIOFeatures
Any ROOT IO features that should be explicitly enabled.
Bool_t fIsFirst
True if this is the first call to Merge for this series of object.
TString fOptions
Additional text based option being passed down to customize the merge.
TString fObjectNames
List of object names to be either merged exclusively or skipped.
Definition TFileMerger.h:63
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
TList fMergeList
list of TObjString containing the name of the files need to be merged
Definition TFileMerger.h:64
virtual Bool_t AddFile(TFile *source, Bool_t own, Bool_t cpProgress)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
virtual void PrintFiles(Option_t *options)
Print list of files being merged.
Bool_t fHistoOneGo
Merger histos in one go (default is kTRUE).
Definition TFileMerger.h:62
virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type=kRegular|kAll)
Merge all objects in a directory.
void RecursiveRemove(TObject *obj) override
Intercept the case where the output TFile is deleted!
TList fFileList
A list the file (TFile*) which shall be merged.
Definition TFileMerger.h:47
virtual Bool_t Merge(Bool_t=kTRUE)
Merge the files.
virtual Bool_t MergeOne(TDirectory *target, TList *sourcelist, Int_t type, TFileMergeInfo &info, TString &oldkeyname, THashList &allNames, Bool_t &status, Bool_t &onlyListed, const TString &path, TDirectory *current_sourcedir, TFile *current_file, TKey *key, TObject *obj, TIter &nextkey)
TString fOutputFilename
The name of the outputfile for merging.
Definition TFileMerger.h:49
TString fMsgPrefix
Prefix to be used when printing informational message (default TFileMerger).
Definition TFileMerger.h:57
TIOFeatures * fIOFeatures
IO features to use in the output file.
Definition TFileMerger.h:56
TFileMerger(const TFileMerger &)=delete
void SetMsgPrefix(const char *prefix)
Set the prefix to be used when printing informational message.
Bool_t fNoTrees
True if Trees should not be merged (default is kFALSE).
Definition TFileMerger.h:51
bool fOutFileWasExplicitlyClosed
! the user has called CloseOutputFile(), so we shouldn't error out in RecursiveRemove
Definition TFileMerger.h:67
@ kAll
Merge all type of objects (default).
Definition TFileMerger.h:87
@ kIncremental
Merge the input file with the content of the output file (if already existing).
Definition TFileMerger.h:82
@ kKeepCompression
Keep compression level unchanged for each input files.
Definition TFileMerger.h:92
@ kSkipListed
Skip objects specified in fObjectNames list.
Definition TFileMerger.h:91
@ kNonResetable
Only the objects without a MergeAfterReset member function.
Definition TFileMerger.h:84
@ kResetable
Only the objects with a MergeAfterReset member function.
Definition TFileMerger.h:83
@ kOnlyListed
Only the objects specified in fObjectNames list.
Definition TFileMerger.h:90
@ kRegular
Normal merge, overwriting the output file.
Definition TFileMerger.h:81
@ kDelayWrite
Delay the TFile write (to reduce the number of write when reusing the file).
Definition TFileMerger.h:85
Bool_t fExplicitCompLevel
True if the user explicitly requested a compression level change (default kFALSE).
Definition TFileMerger.h:52
Bool_t fCompressionChange
True if the output and input have different compression level (default kFALSE).
Definition TFileMerger.h:53
EErrorBehavior fErrBehavior
What to do in case of errors during merging.
Definition TFileMerger.h:58
Int_t fPrintLevel
How much information to print out at run time.
Definition TFileMerger.h:54
void SetMaxOpenedFiles(Int_t newmax)
Set a limit to the number of files that TFileMerger will open simultaneously.
TString fMergeOptions
Options (in string format) to be passed down to the Merge functions.
Definition TFileMerger.h:55
void CloseOutputFile()
Closes output file.
~TFileMerger() override
Cleanup.
@ kFailOnError
The merging process will stop and yield failure when encountering invalid objects.
Definition TFileMerger.h:34
@ kSkipOnError
The merging process will skip invalid objects and continue.
Definition TFileMerger.h:36
Bool_t OpenExcessFiles()
Open up to (fMaxOpenedFiles-1) of the excess files.
TList fExcessFiles
! List of TObjString containing the name of the files not yet added to fFileList due to user or syste...
Definition TFileMerger.h:65
TFile * fOutputFile
The outputfile for merging.
Definition TFileMerger.h:48
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
Bool_t fLocal
Makes local copies of merging files if True (default is kTRUE).
Definition TFileMerger.h:61
virtual void Reset()
Reset merger file list.
Int_t fMaxOpenedFiles
Maximum number of files opened at the same time by the TFileMerger.
Definition TFileMerger.h:60
virtual Bool_t AddAdoptFile(TFile *source, Bool_t cpProgress=kTRUE)
Add the TFile to this file merger and give ownership of the TFile to this object (unless kFALSE is re...
Bool_t fFastMethod
True if using Fast merging algorithm (default).
Definition TFileMerger.h:50
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
Int_t GetCompressionSettings() const
Definition TFile.h:489
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t bufsize=1000000)
Allows to copy this file to the dst URL.
Definition TFile.cxx:4706
Int_t GetCompressionLevel() const
Definition TFile.h:483
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition TFile.cxx:3787
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:981
@ kCancelTTreeChangeRequest
Definition TFile.h:275
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition THashList.h:34
TObject * FindObject(const char *name) const override
Find object using its name.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
const char * GetTitle() const override
Returns title (title can contain 32x32 xpm thumbnail/icon).
Definition TKey.cxx:1536
virtual const char * GetClassName() const
Definition TKey.h:77
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:792
A doubly linked list.
Definition TList.h:38
TObject * After(const TObject *obj) const override
Returns the object after object obj.
Definition TList.cxx:460
void Clear(Option_t *option="") override
Remove all objects from the list.
Definition TList.cxx:532
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:708
void Add(TObject *obj) override
Definition TList.h:81
TObject * First() const override
Return the first object in the list. Returns 0 when list is empty.
Definition TList.cxx:789
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:600
static TClass * Class()
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
An array of TObjects.
Definition TObjArray.h:31
Int_t GetEntriesFast() const
Definition TObjArray.h:58
TObject * At(Int_t idx) const override
Definition TObjArray.h:170
Collectable string class.
Definition TObjString.h:28
const char * GetName() const override
Returns name of object.
Definition TObjString.h:38
Mother of all ROOT objects.
Definition TObject.h:42
virtual void Clear(Option_t *="")
Definition TObject.h:127
Bool_t TestBit(UInt_t f) const
Definition TObject.h:204
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:462
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
Definition TObject.cxx:243
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1084
virtual void Execute(const char *method, const char *params, Int_t *error=nullptr)
Execute method on this object with the given parameter string, e.g.
Definition TObject.cxx:378
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition TObject.cxx:989
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:888
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
Definition TObject.cxx:1126
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:507
virtual TClass * IsA() const
Definition TObject.h:248
@ kOverwrite
overwrite existing object with same name
Definition TObject.h:101
@ kSingleKey
write collection with single key
Definition TObject.h:100
TObject()
TObject constructor.
Definition TObject.h:259
Bool_t IsZombie() const
Definition TObject.h:161
void ResetBit(UInt_t f)
Definition TObject.h:203
@ kCanDelete
if object in a list can be deleted
Definition TObject.h:71
@ kMustCleanup
if object destructor must call RecursiveRemove()
Definition TObject.h:73
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1072
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384
Bool_t IsNull() const
Definition TString.h:422
TString & Remove(Ssiz_t pos)
Definition TString.h:694
TString & Append(const char *cs)
Definition TString.h:581
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
Definition TUUID.h:42
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Definition TUUID.cxx:602
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetFile() const
Definition TUrl.h:69
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)
Definition Rtypes.h:121