50 #include <sys/resource.h> 68 maxfiles = _getmaxstdio();
71 if (getrlimit(RLIMIT_NOFILE,&filelimit)==0) {
72 maxfiles = filelimit.rlim_cur;
80 }
else if (maxfiles > 5) {
93 fLocal(isLocal), fHistoOneGo(histoOneGo), fObjectNames()
104 gROOT->GetListOfCleanups()->Add(
this);
114 gROOT->GetListOfCleanups()->Remove(
this);
162 if (!
TFile::Cp(url, localcopy, cpProgress)) {
163 Error(
"AddFile",
"cannot get a local copy of file %s", url);
172 if (newfile && newfile->IsZombie()) {
179 Error(
"AddFile",
"cannot open local copy %s of URL %s",
180 localcopy.
Data(), url);
182 Error(
"AddFile",
"cannot open file %s", url);
227 if (source == 0 || source->
IsZombie()) {
243 if (!source->
Cp(localcopy, cpProgress)) {
244 Error(
"AddFile",
"cannot get a local copy of file %s", source->
GetName());
249 if (newfile && newfile->IsZombie()) {
259 Error(
"AddFile",
"cannot open local copy %s of URL %s",
262 Error(
"AddFile",
"cannot open file %s", source->
GetName());
267 if (own || newfile != source) {
280 if (newfile != source && own) {
292 return OutputFile(outputfile,(force?
"RECREATE":
"CREATE"),compressionLevel);
380 path.
Remove(0, path.Last(
':') + 2);
390 allNames.
Add(arr->
At(iname));
406 current_sourcedir = target;
411 while (current_file || current_sourcedir) {
414 if (current_sourcedir && (current_file == 0 || current_sourcedir != target)) {
421 while ( (key = (
TKey*)nextkey())) {
429 if (strcmp(key->GetClassName(),
"TProcessID") == 0) { key->ReadObj();
continue;}
435 oldkeyname = key->GetName();
441 Info(
"MergeRecursive",
"cannot indentify object type (%s), name: %s title: %s",
442 key->GetClassName(), key->GetName(), key->GetTitle());
455 oldkeyname = key->GetName();
461 oldkeyname = key->GetName();
464 oldkeyname = key->GetName();
473 oldkeyname = key->GetName();
477 if (!(type&kNonResetable)) {
480 oldkeyname = key->GetName();
487 if (type & kIncremental) {
490 obj = key->ReadObj();
493 obj = key->ReadObj();
496 Info(
"MergeRecursive",
"could not read object for key {%s, %s}",
497 key->GetName(), key->GetTitle());
500 if (cl->
IsTObject() && cl != obj->IsA()) {
501 Error(
"MergeRecursive",
"TKey and object retrieve disagree on type (%s vs %s). Continuing with %s.",
502 key->GetClassName(), obj->IsA()->
GetName(), obj->IsA()->
GetName());
514 if (type & kIncremental || alreadyseen) {
528 if (onlyListed) type &= ~kOnlyListed;
531 if (!status)
return status;
535 if (alreadyseen)
continue;
542 if (nextsource == 0) {
545 func(obj, &inputs, &info);
557 Info(
"MergeRecursive",
"could not read object for key {%s, %s}; skipping file %s",
558 key->GetName(), key->GetTitle(), nextsource->
GetName());
559 nextsource = (
TFile*)sourcelist->
After(nextsource);
573 Error(
"MergeRecursive",
"calling Merge() on '%s' with the corresponding object in '%s'",
580 nextsource = (
TFile*)sourcelist->
After( nextsource );
581 }
while (nextsource);
585 func(obj, &inputs, &info);
595 if (alreadyseen)
continue;
599 listHargs.
Form(
"(TCollection*)0x%lx,(TFileMergeInfo*)0x%lx", (
ULong_t)&listH,(
ULong_t)&info);
603 if (nextsource == 0) {
609 Error(
"MergeRecursive",
"calling Merge() on '%s' with the corresponding object in '%s'",
610 obj->
GetName(), key->GetName());
622 Info(
"MergeRecursive",
"could not read object for key {%s, %s}; skipping file %s",
623 key->GetName(), key->GetTitle(), nextsource->
GetName());
624 nextsource = (
TFile*)sourcelist->
After(nextsource);
637 Error(
"MergeRecursive",
"calling Merge() on '%s' with the corresponding object in '%s'",
643 nextsource = (
TFile*)sourcelist->
After( nextsource );
658 if (alreadyseen)
continue;
662 listHargs.
Form(
"((TCollection*)0x%lx)", (
ULong_t)&listH);
666 if (nextsource == 0) {
671 Error(
"MergeRecursive",
"calling Merge() on '%s' with the corresponding object in '%s'",
672 obj->
GetName(), key->GetName());
684 Info(
"MergeRecursive",
"could not read object for key {%s, %s}; skipping file %s",
685 key->GetName(), key->GetTitle(), nextsource->
GetName());
686 nextsource = (
TFile*)sourcelist->
After(nextsource);
699 Error(
"MergeRecursive",
"calling Merge() on '%s' with the corresponding object in '%s'",
705 nextsource = (
TFile*)sourcelist->
After( nextsource );
726 oldkeyname = key->GetName();
734 if (!(type&kIncremental) ||
dynamic_cast<TDirectory*
>(obj)->GetFile() != target) {
752 if ( target->
WriteObjectAny( (
void*)obj, cl, oldkeyname, canBeMerged ?
"OverWrite" :
"" ) <= 0) {
761 current_file = current_file ? (
TFile*)sourcelist->
After(current_file) : (
TFile*)sourcelist->
First();
765 current_sourcedir = 0;
769 if (!(type&kIncremental)) {
797 Info(
"PartialMerge",
"will merge the results to the file %s\n" 798 "since you didn't specify a merge filename",
799 TUrl(outf).GetFile());
813 if (!file || (file && file->
IsZombie())) {
814 Error(
"PartialMerge",
"one-file case: problem attaching to file");
819 Error(
"PartialMerge",
"one-file case: could not copy '%s' to '%s'",
829 Warning(
"PartialMerge",
"problems removing temporary local file '%s'", u.GetFile());
847 while ((file = (
TFile*) next())) {
854 p = p(0, p.Index(
':',0));
869 Error(
"Merge",
"error during merge of your ROOT files");
909 Error(
"OpenExcessFiles",
"cannot get a local copy of file %s", url->
GetName());
919 Error(
"OpenExcessFiles",
"cannot open local copy %s of URL %s",
922 Error(
"OpenExcessFiles",
"cannot open file %s", url->
GetName());
942 Fatal(
"RecursiveRemove",
"Output file of the TFile Merger (targeting %s) has been deleted (likely due to a TTree larger than 100Gb)",
fOutputFilename.
Data());
956 if (newmax < sysmax) {
virtual void Clear(Option_t *="")
virtual const char * GetName() const
Returns name of object.
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Int_t fPrintLevel
How much information to print out at run time.
virtual TList * GetListOfKeys() const
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Collectable string class.
Long64_t(* MergeFunc_t)(void *, TCollection *, TFileMergeInfo *)
This class represents a WWW compatible URL.
Bool_t TestBit(UInt_t f) const
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Bool_t Merge(Bool_t=kTRUE)
Merge the files.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Int_t GetEntries() const
Normal merge, overwritting the output file.
Bool_t OpenExcessFiles()
Open up to fMaxOpenedFiles of the excess files.
Short_t Min(Short_t a, Short_t b)
virtual TDirectory * mkdir(const char *name, const char *title="")
Create a sub-directory "a" or a hierarchy of sub-directories "a/b/c/...".
R__EXTERN TVirtualMutex * gROOTMutex
TString fMergeOptions
Options (in string format) to be passed down to the Merge functions.
TObject * At(Int_t idx) const
TObject * FindObject(const char *name) const
Find object using its name.
Bool_t fCompressionChange
True if the output and input have different compression level (default kFALSE)
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
overwrite existing object with same name
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
if object in a list can be deleted
Only the objects specified in fObjectNames list.
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=1, Int_t netopt=0)
Create / open a file.
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t buffersize=1000000)
Allows to copy this file to the dst URL.
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
virtual void RecursiveRemove(TObject *obj)
Intercept the case where the output TFile is deleted!
virtual int Unlink(const char *name)
Unlink, i.e. remove, a file.
Merge all type of objects (default)
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
TList * fExcessFiles
! List of TObjString containing the name of the files not yet added to fFileList due to user or syste...
void Clear()
Clear string without changing its capacity.
Skip objects specified in fObjectNames list.
TString & Append(const char *cs)
virtual Int_t WriteObjectAny(const void *, const char *, const char *, Option_t *="", Int_t=0)
virtual TList * GetList() const
Merge the input file with the content of the output file (if already exising).
virtual const char * TempDirectory() const
Return a user configured or systemwide directory to create temporary files in.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Bool_t fHistoOneGo
Merger histos in one go (default is kTRUE)
ROOT::MergeFunc_t GetMerge() const
void SetMsgPrefix(const char *prefix)
Set the prefix to be used when printing informational message.
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...
TFileMerger(const TFileMerger &)
virtual Bool_t OutputFile(const char *url, Bool_t force)
Open merger output file.
TFile * fOutputFile
The outputfile for merging.
TClassRef R__TTree_Class("TTree")
TList * fMergeList
list of TObjString containing the name of the files need to be merged
const char * GetName() const
Returns name of object.
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...
TClassRef R__TH1_Class("TH1")
static const Int_t kCpProgress
TString fOutputFilename
The name of the outputfile for merging.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
R__EXTERN TSystem * gSystem
static Int_t R__GetSystemMaxOpenedFiles()
Return the maximum number of allowed opened files minus some wiggle room for CINT or at least of the ...
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
virtual void Execute(const char *method, const char *params, Int_t *error=0)
Execute method on this object with the given parameter string, e.g.
This class provides file copy and merging services.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Collection abstract base class.
Keep compression level unchanged for each input files.
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Int_t GetEntriesFast() const
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TString fMsgPrefix
Prefix to be used when printing informational message (default TFileMerger)
The ROOT global object gROOT contains a list of all defined classes.
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
write collection with single key
virtual TDirectory * GetDirectory(const char *apath, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory named "apath".
virtual const char * GetPath() const
Returns the full path of the directory.
TString fObjectNames
List of object names to be either merged exclusively or skipped.
if object destructor must call RecursiveRemove()
void SetMaxOpenedFiles(Int_t newmax)
Set a limit to the number of files that TFileMerger will open simultaneously.
#define R__LOCKGUARD2(mutex)
virtual void SaveSelf(Bool_t=kFALSE)
TString & Remove(Ssiz_t pos)
virtual Bool_t MergeRecursive(TDirectory *target, TList *sourcelist, Int_t type=kRegular|kAll)
Merge all objects in a directory.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
ROOT::ResetAfterMergeFunc_t GetResetAfterMerge() const
Describe directory structure in memory.
double func(double *x, double *p)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static const Int_t kCintFileNumber
Bool_t fLocal
Makes local copies of merging files if True (default is kTRUE)
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.
virtual void Clear(Option_t *option="")
Remove all objects from the list.
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
Mother of all ROOT objects.
Bool_t fFastMethod
True if using Fast merging algorithm (default)
Only the objects without a MergeAfterReset member function.
TClassRef is used to implement a permanent reference to a TClass object.
virtual const char * GetTitle() const
Returns title of object.
Bool_t IsTObject() const
Return kTRUE is the class inherits from TObject.
virtual TObject * ReadObj()
To read a TObject* from the file.
Bool_t fNoTrees
True if Trees should not be merged (default is kFALSE)
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
virtual Bool_t PartialMerge(Int_t type=kAll|kIncremental)
Merge the files.
virtual void Add(TObject *obj)
virtual TDirectory * GetDirectory(const char *namecycle, Bool_t printError=false, const char *funcname="GetDirectory")
Find a directory using apath.
virtual ~TFileMerger()
Cleanup.
virtual void PrintFiles(Option_t *options)
Print list of files being merged.
virtual void Fatal(const char *method, const char *msgfmt,...) const
Issue fatal error message.
virtual void Print(Option_t *option="") const
Default print for collections, calls Print(option, 1).
Only the objects with a MergeAfterReset member function.
virtual const char * GetName() const
Returns name of object.
virtual Int_t GetSize() const
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
virtual void Reset()
Reset merger file list.
Int_t GetCompressionLevel() const
Int_t fMaxOpenedFiles
Maximum number of files opened at the same time by the TFileMerger.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
TList * fFileList
A list the file (TFile*) which shall be merged.
virtual void Close(Option_t *option="")
Close a file.
Bool_t fExplicitCompLevel
True if the user explicitly requested a compressio level change (default kFALSE)
const char * Data() const