72#define _XOPEN_SOURCE 600
84# include <sys/types.h>
89#include "RConfigure.h"
125#include "compiledata.h"
154#define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0)
164static struct AddPseudoGlobals {
181 Info(
"TFile",
"default ctor");
317 ::Fatal(
"TFile::TFile",
"ROOT system not initialized");
319 auto zombify = [
this] {
323 gROOT->GetListOfClosedObjects()->Add(
this);
333 "please use TFile::Open to access remote files:\n\tauto f = std::unique_ptr<TFile>{TFile::Open(\"%s\")};",
414 if (!create && !recreate && !
update && !read) {
421 if (!fname1 || !fname1[0]) {
422 Error(
"TFile",
"file name is not specified");
428 if (!strcmp(fname1,
"/dev/null") &&
449 Error(
"TFile",
"error expanding path %s", fname1);
465 SysError(
"TFile",
"could not delete %s (errno: %d)",
476 Error(
"TFile",
"file %s already exists", fname);
486 Error(
"TFile",
"no write permission, could not open file %s", fname);
493 Error(
"TFile",
"file %s does not exist", fname);
498 Error(
"TFile",
"no read permission, could not open file %s", fname);
512 SysError(
"TFile",
"file %s can not be opened", fname);
524 SysError(
"TFile",
"file %s can not be opened for reading", fname);
567 gROOT->GetListOfClosedObjects()->Remove(
this);
578 Info(
"~TFile",
"dtor called for %s [%zx]",
GetName(),(
size_t)
this);
604 Error(
"Init",
"archive %s can only be opened in read mode",
GetName());
623 Error(
"Init",
"member %s not found in archive %s",
661 char *header =
new char[
kBEGIN+200];
666 Error(
"Init",
"%s failed to read the file type data.",
673 if (strncmp(header,
"root", 4)) {
679 char *buffer = header + 4;
682 frombuf(buffer, &headerLength);
685 Int_t send,sfree,sinfo;
706 if (fBEGIN < 0 || fBEGIN >
fEND) {
708 Error(
"Init",
"file %s has an incorrect header length (%lld) or incorrect end of file length (%lld)",
720 Warning(
"Init",
"file %s probably not closed, cannot read free segments",
GetName());
725 char *buffer_keyloc =
nullptr;
730 Error(
"Init",
"file %s has an incorrect header length (%lld) or incorrect end of file length (%lld)",
737 header =
new char[nbytes];
742 Error(
"Init",
"%s failed to read the file header information at %lld (size=%d)",
748 buffer_keyloc = header;
751 buffer_keyloc = header+
fBEGIN;
754 frombuf(buffer,&version); versiondir = version%1000;
759 if (version > 1000) {
764 Int_t sdir,sparent,skeys;
772 buffer_keyloc +=
sizeof(
Int_t);
774 frombuf(buffer_keyloc, &keyversion);
776 if (keyversion > 1000) {
783 cname.ReadBuffer(buffer_keyloc);
784 cname.ReadBuffer(buffer_keyloc);
787 if (fNbytesName < 10 || fNbytesName > 10000) {
788 Error(
"Init",
"cannot read directory info of file %s",
GetName());
824 Error(
"Init",
"file %s is truncated at %lld bytes: should be %lld, "
827 Error(
"Init",
"file %s is truncated at %lld bytes: should be %lld",
833 Warning(
"Init",
"file %s probably not closed, "
834 "trying to recover",
GetName());
842 Warning(
"Init",
"successfully recovered %d keys", nrecov);
844 Warning(
"Init",
"no keys recovered, file has been made a Zombie");
852 gROOT->GetListOfFiles()->Add(
this);
858 Int_t lenIndex =
gROOT->GetListOfStreamerInfo()->GetSize()+1;
859 if (lenIndex < 5000) lenIndex = 5000;
866 gROOT->GetListOfFiles()->Remove(
this);
872 Warning(
"Init",
"no StreamerInfo found in %s therefore preventing schema evolution when reading this file."
873 " The file was produced with version %d.%02d/%02d of ROOT.",
884 while ((key = (
TKey*)next())) {
895 gROOT->GetListOfClosedObjects()->Add(
this);
943 while ((key = iter()) !=
nullptr) {
1001 gROOT->GetListOfFiles()->Remove(
this);
1002 gROOT->GetListOfBrowsers()->RecursiveRemove(
this);
1003 gROOT->GetListOfClosedObjects()->Add(
this);
1014 return new TKey(obj,
name, bufsize, mother);
1022 return new TKey(obj, cl,
name, bufsize, mother);
1034 static TFile *currentFile =
nullptr;
1066 Info(
"Delete",
"deleting name = %s", namecycle);
1096 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFileDrawMap"))) {
1097 if (
h->LoadPlugin() == -1)
1138 tobuf(buffer, version);
1154 if (
result >= (
double)std::numeric_limits<Int_t>::max()) {
1155 return std::numeric_limits<Int_t>::max() -1;
1171 Int_t nbytes, objlen, nwh = 64;
1172 char *header =
new char[
fBEGIN];
1178 while (idcur <
fEND-100) {
1193 if (nbytes == 0)
break;
1199 if (!objlen) objlen = nbytes-keylen;
1201 uncomp += keylen + objlen;
1274 Int_t nread = maxbytes;
1277 Warning(
"GetRecordHeader",
"%s: parameter maxbytes = %d must be >= 4",
1283 Warning(
"GetRecordHeader",
"%s: failed to read header data (maxbytes = %d)",
1294 if (nb < 0)
return nread;
1296 const Int_t headerSize = 16;
1297 if (nread < headerSize)
return nread;
1302 if (!olen) olen = nbytes-klen;
1321 Error(
"GetSize",
"cannot stat the file %s",
GetName());
1347 TList *list =
nullptr;
1350 auto key = std::make_unique<TKey>(
this);
1352 auto buf = buffer.data();
1356 Warning(
"GetRecordHeader",
"%s: failed to read the StreamerInfo data from disk.",
1358 return {
nullptr, 1, hash};
1361 if (lookupSICache) {
1368 Info(
"GetStreamerInfo",
"The streamer info record for file %s has already been treated, skipping it.",
GetName());
1369 for(
auto uid : *si_uids)
1371 return {
nullptr, 0, hash};
1374 key->ReadKeyBuffer(buf);
1375 list =
dynamic_cast<TList*
>(key->ReadObjWithBuffer(buffer.data()));
1378 list = (
TList*)
Get(
"StreamerInfo");
1382 Info(
"GetStreamerInfoList",
"cannot find the StreamerInfo record in file %s",
1384 return {
nullptr, 1, hash};
1387 return {list, 0, hash};
1454 if(!newfree)
return;
1458 if (nbytesl > 2000000000) nbytesl = 2000000000;
1461 char * buffer =
new char[nb];
1462 char * psave = buffer;
1463 tobuf(buffer, nbytes);
1536 bool forComp = options.
Contains(
"forcomp");
1537 bool extended = options.
Contains(
"extended");
1541 Int_t nbytes,date,time,objlen;
1549 constexpr Int_t nwheader = 512;
1551 char header[nwheader];
1552 char classname[512];
1557 unsigned char nDigits = std::log10(
fEND) + 1;
1559 while (idcur <
fEND) {
1561 Int_t nread = nwheader;
1562 if (idcur+nread >=
fEND) nread =
fEND-idcur-1;
1565 Warning(
"Map",
"%s: failed to read the key data from disk at %lld.",
1573 Printf(
"Address = %lld\tNbytes = %d\t=====E R R O R=======", idcur, nbytes);
1578 Printf(
"Address = %lld\tNbytes = %d\t=====G A P===========", idcur, nbytes);
1589 if (versionkey > 1000) {
1598 if ( ((buffer-header) + nwhc) > nwheader )
1599 nwhc = nwheader - (buffer-header);
1600 for (
int i = 0;i < nwhc; i++)
frombuf(buffer, &classname[i]);
1601 classname[(
int)nwhc] =
'\0';
1602 if (idcur ==
fSeekFree) strlcpy(classname,
"FreeSegments",512);
1603 if (idcur ==
fSeekInfo) strlcpy(classname,
"StreamerInfo",512);
1604 if (idcur ==
fSeekKeys) strlcpy(classname,
"KeysList",512);
1607 if ( (buffer-header) >= nwheader )
1613 else if ( ((buffer-header) + nwhc) > nwheader )
1614 nwhc = nwheader - (buffer-header);
1616 for (
int i = 0;i < nwhc; i++)
frombuf(buffer, &keyname[i]);
1617 keyname[(
int)nwhc] =
'\0';
1619 if ( (buffer-header) >= nwheader )
1625 else if ( ((buffer-header) + nwhc) > nwheader )
1626 nwhc = nwheader - (buffer-header);
1628 for (
int i = 0;i < nwhc; i++)
frombuf(buffer, &keytitle[i]);
1629 keytitle[(
int)nwhc] =
'\0';
1631 extrainfo.
Form(
" name: %-16s title: %s", keyname, keytitle);
1636 if (objlen != nbytes - keylen) {
1638 Printf(
"%d/%06d At:%-*lld N=%-8d %-14s CX = %5.2f %s", date, time, nDigits + 1, idcur, nbytes, classname,
1639 cx, extrainfo.
Data());
1641 Printf(
"%d/%06d At:%-*lld N=%-8d %-14s %s", date, time, nDigits + 1, idcur, nbytes, classname, extrainfo.
Data());
1645 if (objlen != nbytes - keylen) {
1647 Printf(
"At:%-*lld N=%-8d K=%-3d O=%-8d %-14s CX = %5.2f %s", nDigits+1, idcur, nbytes, keylen, objlen, classname, cx, extrainfo.
Data());
1649 Printf(
"At:%-*lld N=%-8d K=%-3d O=%-8d %-14s CX = 1 %s", nDigits+1, idcur, nbytes, keylen, objlen, classname, extrainfo.
Data());
1655 Printf(
"%d/%06d At:%-*lld N=%-8d %-14s",date,time, nDigits+1, idcur,1,
"END");
1657 Printf(
"At:%-*lld N=%-8d K= O= %-14s", nDigits+1, idcur,1,
"END");
1712 Error(
"ReadBuffer",
"error reading all requested bytes from file %s, got %ld of %d",
1759 Error(
"ReadBuffer",
"error reading all requested bytes from file %s, got %ld of %d",
1790 for (
Int_t j = 0; j < nbuf; j++) {
1804 char *buf2 =
nullptr;
1807 cur = pos[i]+
len[i];
1810 if (bigRead || (i>=nbuf)) {
1829 for (
Int_t j=0;j<
n;j++) {
1830 memcpy(&buf[k],&buf2[pos[i-
n+j]-curbegin],
len[i-
n+j]);
1840 curbegin = i < nbuf ? pos[i] : 0;
1843 if (buf2)
delete [] buf2;
1893 if (fNbytesFree < 0 || fNbytesFree >
fEND) {
1929 snprintf(pidname,32,
"ProcessID%d",pidf);
1932 printf(
"ReadProcessID, name=%s, file=%s, pid=%zx\n",pidname,
GetName(),(
size_t)pid);
1941 TIter next(pidslist);
1958 p->IncrementCount();
2017 Int_t nbytes,date,time,objlen,nwheader;
2020 char *buffer, *bufread;
2026 Error(
"Recover",
"cannot stat the file %s",
GetName());
2037 Int_t nread = nwheader;
2039 while (idcur <
fEND) {
2041 if (idcur+nread >=
fEND) nread =
fEND-idcur-1;
2044 Error(
"Recover",
"%s: failed to read the key data from disk at %lld.",
2052 Error(
"Recover",
"Address = %lld\tNbytes = %d\t=====E R R O R=======", idcur, nbytes);
2067 if (versionkey > 1000) {
2076 char *classname =
nullptr;
2077 if (nwhc <= 0 || nwhc > 100)
break;
2078 classname =
new char[nwhc+1];
2079 int i, nwhci = nwhc;
2080 for (i = 0;i < nwhc; i++)
frombuf(buffer, &classname[i]);
2081 classname[nwhci] =
'\0';
2085 && strcmp(classname,
"TBasket")) {
2086 key =
new TKey(
this);
2088 if (!strcmp(key->
GetName(),
"StreamerInfo")) {
2099 delete [] classname;
2104 if (max_file_size <
fEND) max_file_size =
fEND+1000000000;
2111 if (nrecov)
Write();
2134 if (opt !=
"READ" && opt !=
"UPDATE") {
2135 Error(
"ReOpen",
"mode must be either READ or UPDATE, not %s", opt.
Data());
2142 if (opt ==
"READ") {
2178 SysError(
"ReOpen",
"file %s can not be opened in read mode",
GetName());
2200 SysError(
"ReOpen",
"file %s can not be opened in update mode",
GetName());
2209 Warning(
"ReOpen",
"file %s probably not closed, cannot read free segments",
GetName());
2230 Error(
"SetOffset",
"seeking from end in archive is not (yet) supported");
2254 Error(
"Seek",
"seeking from end in archive is not (yet) supported");
2259 SysError(
"Seek",
"cannot seek to position %lld in file %s, retpos=%lld",
2286 if (level < 0) level = 0;
2287 if (level > 99) level = 99;
2342 if (cache) cache->
SetFile(
this, action);
2372 if (
b.IsReading()) {
2433 Error(
"Write const",
"A const TFile object should not be saved. We try to proceed anyway.");
2434 return const_cast<TFile*
>(
this)->
Write(
n, opt, bufsize);
2465 Error(
"WriteBuffer",
"error writing all requested bytes to file %s, wrote %ld of %d",
2492 Error(
"WriteBuffer",
"error writing to cache");
2517 auto createKey = [
this]() {
2521 while ((afree = (
TFree*) next())) {
2522 nbytes += afree->
Sizeof();
2524 if (!nbytes)
return (
TKey*)
nullptr;
2530 return (
TKey*)
nullptr;
2535 TKey *key = createKey();
2552 char *start = buffer;
2556 while ((afree = (
TFree*) next())) {
2561 auto actualBytes = buffer-start;
2562 if ( actualBytes != nbytes ) {
2563 if (actualBytes < nbytes) {
2566 memset(buffer,0,nbytes-actualBytes);
2568 Error(
"WriteFree",
"The free block list TKey wrote more data than expected (%d vs %ld). Most likely there has been an out-of-bound write.",nbytes,(
long int)actualBytes);
2585 const char *root =
"root";
2586 char *psave =
new char[
fBEGIN];
2587 char *buffer = psave;
2589 memcpy(buffer, root, 4); buffer += 4;
2592 tobuf(buffer, version);
2594 if (version < 1000000) {
2598 tobuf(buffer, nfree);
2608 tobuf(buffer, nfree);
2619 Int_t nbytes = buffer - psave;
2710 path +=
"/PROOF-INF";
2712 const char *afile = 0;
2715 if (strcmp(afile,
".") == 0)
continue;
2716 if (strcmp(afile,
"..") == 0)
continue;
2717 filepath.
Form(
"%s/%s", path.
Data(), afile);
2719 Warning(
"MakeProject",
"1: problems unlinking '%s' ('%s', '%s')", filepath.
Data(), path.
Data(), afile);
2726 if (strcmp(afile,
".") == 0)
continue;
2727 if (strcmp(afile,
"..") == 0)
continue;
2728 filepath.
Form(
"%s/%s", path.
Data(), afile);
2730 Warning(
"MakeProject",
"2: problems unlinking '%s' ('%s', '%s')", filepath.
Data(), path.
Data(), afile);
2734 Warning(
"MakeProject",
"problems unlinking '%s'", path.
Data());
2738 path.
Form(
"%s/%s/PROOF-INF", pardir.
Data(), parname.
Data());
2740 Error(
"MakeProject",
"problems creating '%s'", path.
Data());
2755 }
else if (opt.
Contains(
"recreate")) {
2759 Error(
"MakeProject",
"cannot create directory '%s'",dirname);
2767 if (strcmp(afile,
".") == 0)
continue;
2768 if (strcmp(afile,
"..") == 0)
continue;
2769 dirpath.
Form(
"%s/%s",dirname,afile);
2777 Error(
"MakeProject",
"cannot create directory %s, already existing",dirname);
2782 Error(
"MakeProject",
"cannot create directory '%s'",dirname);
2795 if (filelist) filelist = (
TList*)filelist->
Clone();
2797 Error(
"MakeProject",
"file %s has no StreamerInfo",
GetName());
2801 TString clean_dirname(dirname);
2802 if (makepar) clean_dirname.
Form(
"%s/%s", pardir.
Data(), parname.
Data());
2803 if (clean_dirname[clean_dirname.
Length()-1]==
'/') {
2805 }
else if (clean_dirname[clean_dirname.
Length()-1]==
'\\') {
2807 if (clean_dirname[clean_dirname.
Length()-1]==
'\\') {
2812 if (makepar) subdirname = parname;
2813 if (subdirname ==
"") {
2814 Error(
"MakeProject",
"Directory name must not be empty.");
2819 TString spath; spath.
Form(
"%s/%sProjectSource.cxx",clean_dirname.
Data(),subdirname.
Data());
2820 FILE *sfp = fopen(spath.
Data(),
"w");
2822 Error(
"MakeProject",
"Unable to create the source file %s.",spath.
Data());
2825 fprintf(sfp,
"namespace std {}\nusing namespace std;\n");
2826 fprintf(sfp,
"#include \"%sProjectHeaders.h\"\n\n",subdirname.
Data() );
2827 if (!
genreflex) fprintf(sfp,
"#include \"%sLinkDef.h\"\n\n",subdirname.
Data() );
2828 fprintf(sfp,
"#include \"%sProjectDict.cxx\"\n\n",subdirname.
Data() );
2829 fprintf(sfp,
"struct DeleteObjectFunctor {\n");
2830 fprintf(sfp,
" template <typename T>\n");
2831 fprintf(sfp,
" void operator()(const T *ptr) const {\n");
2832 fprintf(sfp,
" delete ptr;\n");
2833 fprintf(sfp,
" }\n");
2834 fprintf(sfp,
" template <typename T, typename Q>\n");
2835 fprintf(sfp,
" void operator()(const std::pair<T,Q> &) const {\n");
2836 fprintf(sfp,
" // Do nothing\n");
2837 fprintf(sfp,
" }\n");
2838 fprintf(sfp,
" template <typename T, typename Q>\n");
2839 fprintf(sfp,
" void operator()(const std::pair<T,Q*> &ptr) const {\n");
2840 fprintf(sfp,
" delete ptr.second;\n");
2841 fprintf(sfp,
" }\n");
2842 fprintf(sfp,
" template <typename T, typename Q>\n");
2843 fprintf(sfp,
" void operator()(const std::pair<T*,Q> &ptr) const {\n");
2844 fprintf(sfp,
" delete ptr.first;\n");
2845 fprintf(sfp,
" }\n");
2846 fprintf(sfp,
" template <typename T, typename Q>\n");
2847 fprintf(sfp,
" void operator()(const std::pair<T*,Q*> &ptr) const {\n");
2848 fprintf(sfp,
" delete ptr.first;\n");
2849 fprintf(sfp,
" delete ptr.second;\n");
2850 fprintf(sfp,
" }\n");
2851 fprintf(sfp,
"};\n\n");
2858 TIter flnext(filelist);
2865 if (strstr(info->
GetName(),
"@@")) {
2882 for(
auto rule : rules) {
2883 if( rule->IsRenameRule() || rule->IsAliasRule() )
2886 if ( rule->HasTarget( el->
GetName()) && rule->GetAttributes()[0] != 0 ) {
2889 if (
attr.Contains(
"owner")) {
2890 if (
attr.Contains(
"notowner")) {
2913 TIter nextextra(&extrainfos);
2916 filelist->
Add(info);
2927 TIter subnext(list);
2942 subClasses.
Add(subinfo);
2947 subClasses.
Clear(
"nodelete");
2949 extrainfos.
Clear(
"nodelete");
2952 path.
Form(
"%s/%sProjectHeaders.h",clean_dirname.
Data(),subdirname.
Data());
2953 FILE *allfp = fopen(path,
"a");
2955 Error(
"MakeProject",
"Cannot open output file:%s\n",path.
Data());
2957 fprintf(allfp,
"#include \"%sProjectInstances.h\"\n", subdirname.
Data());
2961 printf(
"MakeProject has generated %d classes in %s\n",ngener,clean_dirname.
Data());
2964 if (!opt.
Contains(
"+") && !makepar) {
2972 FILE *fpMAKE =
nullptr;
2977 path.
Form(
"%s/makep.cmd",clean_dirname.
Data());
2979 path.
Form(
"%s/MAKEP",clean_dirname.
Data());
2982 fpMAKE = fopen(path,
"wb");
2984 fpMAKE = fopen(path,
"w");
2987 Error(
"MakeProject",
"cannot open file %s", path.
Data());
2996 FILE *ifp =
nullptr;
2997 path.
Form(
"%s/%sProjectInstances.h",clean_dirname.
Data(),subdirname.
Data());
2999 ifp = fopen(path,
"wb");
3001 ifp = fopen(path,
"w");
3004 Error(
"MakeProject",
"cannot open path file %s", path.
Data());
3014 fprintf(fpMAKE,
"genreflex %sProjectHeaders.h -o %sProjectDict.cxx --comments --iocomments %s ",subdirname.
Data(),subdirname.
Data(),
gSystem->
GetIncludePath());
3015 path.
Form(
"%s/%sSelection.xml",clean_dirname.
Data(),subdirname.
Data());
3018 path.
Form(
"%s/%sLinkDef.h",clean_dirname.
Data(),subdirname.
Data());
3021 path.
Form(
"%s/%sLinkDef.h",clean_dirname.
Data(),subdirname.
Data());
3027 FILE *fp = fopen(path,
"wb");
3029 FILE *fp = fopen(path,
"w");
3032 Error(
"MakeProject",
"cannot open path file %s", path.
Data());
3041 fprintf(fp,
"<lcgdict>\n");
3044 fprintf(fp,
"#ifdef __CINT__\n");
3056 if (strncmp(info->
GetName(),
"auto_ptr<", strlen(
"auto_ptr<")) == 0) {
3065 for(
auto rule : rules) {
3068 rule->AsString(strrule,
"x");
3071 selections.
Append(strrule);
3074 rule->AsString(strrule);
3075 if (strncmp(strrule.
Data(),
"type=",5)==0) {
3078 fprintf(fp,
"#pragma %s;\n",strrule.
Data());
3085 std::vector<std::string> inside;
3092 switch ( stlkind ) {
3096 what =
"std::pair<";
3106 tmp.
Form(
"<class name=\"%s\" />\n",
what.Data());
3110 tmp.
Form(
"template class %s;\n",
what.Data());
3118 fprintf(fp,
"#pragma link C++ class %s+;\n",
what.Data());
3126 tmp.
Form(
"<class name=\"%s\" />\n",key->
GetName());
3136 fprintf(fp,
"#pragma link C++ class %s+;\n",key->
GetName());
3147 tmp.
Form(
"<class name=\"%s\" />\n",
what.Data());
3151 if (
what[
what.Length()-1] ==
'>') {
3152 tmp.
Form(
"template class %s;\n",
what.Data());
3159 fprintf(fp,
"#pragma link C++ class %s+;\n",
what.Data());
3169 tmp.
Form(
"<class name=\"%s\" />\n",
what.Data());
3173 tmp.
Form(
"template class %s;\n",
what.Data());
3182 fprintf(ifp,
"#ifndef PROJECT_INSTANCES_H\n");
3183 fprintf(ifp,
"#define PROJECT_INSTANCES_H\n");
3184 fprintf(ifp,
"%s",instances.
Data());
3185 fprintf(ifp,
"#endif\n");
3186 fprintf(fp,
"%s",selections.
Data());
3187 fprintf(fp,
"</lcgdict>\n");
3189 fprintf(fp,
"#endif\n");
3203 cmd.
ReplaceAll(
"$ObjectFiles",
object.Data());
3210 TString rootbuild = ROOTBUILD;
3219 fprintf(fpMAKE,
"-s %sSelection.xml \n",subdirname.
Data());
3221 fprintf(fpMAKE,
"%sProjectHeaders.h ",subdirname.
Data());
3222 fprintf(fpMAKE,
"%sLinkDef.h \n",subdirname.
Data());
3225 fprintf(fpMAKE,
"%s\n",cmd.
Data());
3227 printf(
"%s/MAKEP file has been generated\n", clean_dirname.
Data());
3236 Error(
"MakeProject",
"problems creating PAR make file '%s'", filemake.
Data());
3245 Warning(
"MakeProject",
"problems expanding '%s'", mkarchsrc.
Data());
3248 Error(
"MakeProject",
"problems retrieving '%s' to '%s'", mkarchsrc.
Data(), mkarchdst.
Data());
3257 Error(
"MakeProject",
"problems creating BUILD.sh and/or SETUP.C under '%s'", proofinf.
Data());
3270 chmod(cmod.
Data(), 00700);
3272 Printf(
"Files Makefile, Makefile.arch, PROOF-INF/BUILD.sh and"
3273 " PROOF-INF/SETUP.C have been generated under '%s'", clean_dirname.
Data());
3282 Info(
"MakeProject",
"PAR file %s.par generated", clean_dirname.
Data());
3284 Warning(
"MakeProject",
"problems changing directory back to '%s'", curdir.
Data());
3287 Error(
"MakeProject",
"problems changing directory to '%s' - skipping PAR file generation", pardir.
Data());
3290 Warning(
"MakeProject",
"on Windows systems the PAR file cannot be generated out of the package directory!");
3295 if (!makepar && !opt.
Contains(
"nocompilation")) {
3304 chmod(
"makep.cmd",00700);
3309 if (res) printf(
"Shared lib %s has been generated\n",path.
Data());
3314 if (res) printf(
"Shared lib %s has been dynamically linked\n",path.
Data());
3332 if (!filemake || (filemake && strlen(filemake) <= 0)) {
3333 Error(
"MakeProjectParMake",
"path for output file undefined!");
3338 if (!pack || (pack && strlen(pack) <= 0)) {
3339 Error(
"MakeProjectParMake",
"package name undefined!");
3344 FILE *fmk = fopen(filemake,
"wb");
3346 FILE *fmk = fopen(filemake,
"w");
3354 fprintf(fmk,
"# Makefile for the ROOT test programs.\n");
3355 fprintf(fmk,
"# This Makefile shows how to compile and link applications\n");
3356 fprintf(fmk,
"# using the ROOT libraries on all supported platforms.\n");
3357 fprintf(fmk,
"#\n");
3358 fprintf(fmk,
"# Copyright (c) 2000 Rene Brun and Fons Rademakers\n");
3359 fprintf(fmk,
"#\n");
3360 fprintf(fmk,
"# Author: this makefile has been automatically generated via TFile::MakeProject\n");
3362 fprintf(fmk,
"include Makefile.arch\n");
3364 fprintf(fmk,
"#------------------------------------------------------------------------------\n");
3366 fprintf(fmk,
"PACKO = %sProjectSource.$(ObjSuf)\n", pack);
3367 fprintf(fmk,
"PACKS = %sProjectSource.$(SrcSuf) %sProjectDict.$(SrcSuf)\n", pack, pack);
3368 fprintf(fmk,
"PACKSO = lib%s.$(DllSuf)\n", pack);
3370 fprintf(fmk,
"ifeq ($(PLATFORM),win32)\n");
3371 fprintf(fmk,
"PACKLIB = lib%s.lib\n", pack);
3372 fprintf(fmk,
"else\n");
3373 fprintf(fmk,
"PACKLIB = $(PACKSO)\n");
3374 fprintf(fmk,
"endif\n");
3376 fprintf(fmk,
"OBJS = $(PACKO)\n");
3378 fprintf(fmk,
"PROGRAMS =\n");
3380 fprintf(fmk,
"#------------------------------------------------------------------------------\n");
3382 fprintf(fmk,
".SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)\n");
3384 fprintf(fmk,
"all: $(PACKLIB)\n");
3386 fprintf(fmk,
"$(PACKSO): $(PACKO)\n");
3387 fprintf(fmk,
"ifeq ($(ARCH),aix)\n");
3388 fprintf(fmk,
"\t\t/usr/ibmcxx/bin/makeC++SharedLib $(OutPutOpt) $@ $(LIBS) -p 0 $^\n");
3389 fprintf(fmk,
"else\n");
3390 fprintf(fmk,
"ifeq ($(ARCH),aix5)\n");
3391 fprintf(fmk,
"\t\t/usr/vacpp/bin/makeC++SharedLib $(OutPutOpt) $@ $(LIBS) -p 0 $^\n");
3392 fprintf(fmk,
"else\n");
3393 fprintf(fmk,
"ifeq ($(PLATFORM),macosx)\n");
3394 fprintf(fmk,
"# We need to make both the .dylib and the .so\n");
3395 fprintf(fmk,
"\t\t$(LD) $(SOFLAGS)$@ $(LDFLAGS) $^ $(OutPutOpt) $@ $(LIBS)\n");
3396 fprintf(fmk,
"ifneq ($(subst $(MACOSX_MINOR),,1234),1234)\n");
3397 fprintf(fmk,
"ifeq ($(MACOSX_MINOR),4)\n");
3398 fprintf(fmk,
"\t\tln -sf $@ $(subst .$(DllSuf),.so,$@)\n");
3399 fprintf(fmk,
"else\n");
3400 fprintf(fmk,
"\t\t$(LD) -bundle -undefined $(UNDEFOPT) $(LDFLAGS) $^ \\\n");
3401 fprintf(fmk,
"\t\t $(OutPutOpt) $(subst .$(DllSuf),.so,$@)\n");
3402 fprintf(fmk,
"endif\n");
3403 fprintf(fmk,
"endif\n");
3404 fprintf(fmk,
"else\n");
3405 fprintf(fmk,
"ifeq ($(PLATFORM),win32)\n");
3406 fprintf(fmk,
"\t\tbindexplib $* $^ > $*.def\n");
3407 fprintf(fmk,
"\t\tlib -nologo -MACHINE:IX86 $^ -def:$*.def \\\n");
3408 fprintf(fmk,
"\t\t $(OutPutOpt)$(PACKLIB)\n");
3409 fprintf(fmk,
"\t\t$(LD) $(SOFLAGS) $(LDFLAGS) $^ $*.exp $(LIBS) \\\n");
3410 fprintf(fmk,
"\t\t $(OutPutOpt)$@\n");
3411 fprintf(fmk,
"else\n");
3412 fprintf(fmk,
"\t\t$(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ $(LIBS) $(EXPLLINKLIBS)\n");
3413 fprintf(fmk,
"endif\n");
3414 fprintf(fmk,
"endif\n");
3415 fprintf(fmk,
"endif\n");
3416 fprintf(fmk,
"endif\n");
3417 fprintf(fmk,
"\t\t@echo \"$@ done\"\n");
3419 fprintf(fmk,
"clean:\n");
3420 fprintf(fmk,
"\t\t@rm -f $(OBJS) core\n");
3422 fprintf(fmk,
"distclean: clean\n");
3423 fprintf(fmk,
"\t\t@rm -f $(PROGRAMS) $(PACKSO) $(PACKLIB) *Dict.* *.def *.exp \\\n");
3424 fprintf(fmk,
"\t\t *.so *.lib *.dll *.d *.log .def so_locations\n");
3425 fprintf(fmk,
"\t\t@rm -rf cxx_repository\n");
3427 fprintf(fmk,
"# Dependencies\n");
3429 fprintf(fmk,
"%sProjectSource.$(ObjSuf): %sProjectHeaders.h %sLinkDef.h %sProjectDict.$(SrcSuf)\n", pack, pack, pack, pack);
3431 fprintf(fmk,
"%sProjectDict.$(SrcSuf): %sProjectHeaders.h %sLinkDef.h\n", pack, pack, pack);
3432 fprintf(fmk,
"\t\t@echo \"Generating dictionary $@...\"\n");
3433 fprintf(fmk,
"\t\t@rootcint -f $@ $^\n");
3435 fprintf(fmk,
".$(SrcSuf).$(ObjSuf):\n");
3436 fprintf(fmk,
"\t\t$(CXX) $(CXXFLAGS) -c $<\n");
3454 if (!proofinf || (proofinf && strlen(proofinf) <= 0)) {
3455 Error(
"MakeProjectParProofInf",
"directory path undefined!");
3463 Error(
"MakeProjectParProofInf",
"path '%s' %s", proofinf,
3464 ((rcst == 0) ?
"is not a directory" :
"does not exist"));
3469 if (!pack || (pack && strlen(pack) <= 0)) {
3470 Error(
"MakeProjectParProofInf",
"package name undefined!");
3477 path.
Form(
"%s/BUILD.sh", proofinf);
3479 FILE *
f = fopen(path.
Data(),
"wb");
3481 FILE *
f = fopen(path.
Data(),
"w");
3484 Error(
"MakeProjectParProofInf",
"cannot create file '%s' (errno: %d)",
3489 fprintf(
f,
"#! /bin/sh\n");
3490 fprintf(
f,
"# Build libEvent library.\n");
3493 fprintf(
f,
"# The environment variables ROOTPROOFLITE and ROOTPROOFCLIENT can be used to\n");
3494 fprintf(
f,
"# adapt the script to the calling environment\n");
3496 fprintf(
f,
"# if test ! \"x$ROOTPROOFLITE\" = \"x\"; then\n");
3497 fprintf(
f,
"# echo \"event-BUILD: PROOF-Lite node (session has $ROOTPROOFLITE workers)\"\n");
3498 fprintf(
f,
"# elif test ! \"x$ROOTPROOFCLIENT\" = \"x\"; then\n");
3499 fprintf(
f,
"# echo \"event-BUILD: PROOF client\"\n");
3500 fprintf(
f,
"# else\n");
3501 fprintf(
f,
"# echo \"event-BUILD: standard PROOF node\"\n");
3502 fprintf(
f,
"# fi\n");
3504 fprintf(
f,
"if [ \"\" = \"clean\" ]; then\n");
3505 fprintf(
f,
" make distclean\n");
3506 fprintf(
f,
" exit 0\n");
3509 fprintf(
f,
"make\n");
3510 fprintf(
f,
"rc=$?\n");
3511 fprintf(
f,
"echo \"rc=$?\"\n");
3512 fprintf(
f,
"if [ $? != \"0\" ] ; then\n");
3513 fprintf(
f,
" exit 1\n");
3515 fprintf(
f,
"exit 0\n");
3521 path.
Form(
"%s/SETUP.C", proofinf);
3523 f = fopen(path.
Data(),
"wb");
3525 f = fopen(path.
Data(),
"w");
3528 Error(
"MakeProjectParProofInf",
"cannot create file '%s' (errno: %d)",
3533 fprintf(
f,
"Int_t SETUP()\n");
3537 fprintf(
f,
"// The environment variables ROOTPROOFLITE and ROOTPROOFCLIENT can be used to\n");
3538 fprintf(
f,
"// adapt the macro to the calling environment\n");
3540 fprintf(
f,
"// if (gSystem->Getenv(\"ROOTPROOFLITE\")) {\n");
3541 fprintf(
f,
"// Printf(\"event-SETUP: PROOF-Lite node (session has %%s workers)\",\n");
3542 fprintf(
f,
"// gSystem->Getenv(\"ROOTPROOFLITE\"));\n");
3543 fprintf(
f,
"// } else if (gSystem->Getenv(\"ROOTPROOFCLIENT\")) {\n");
3544 fprintf(
f,
"// Printf(\"event-SETUP: PROOF client\");\n");
3545 fprintf(
f,
"// } else {\n");
3546 fprintf(
f,
"// Printf(\"event-SETUP: standard PROOF node\");\n");
3547 fprintf(
f,
"// }\n");
3549 fprintf(
f,
" if (gSystem->Load(\"lib%s\") == -1)\n", pack);
3550 fprintf(
f,
" return -1;\n");
3551 fprintf(
f,
" return 0;\n");
3573 TList *list = listRetcode.fList;
3574 auto retcode = listRetcode.fReturnCode;
3587 if (version > 1000000) version -= 1000000;
3588 if (version < 53419 || (59900 < version && version < 59907)) {
3603 if (!base)
continue;
3614 std::vector<Int_t> si_uids;
3629 if (strcmp(obj->
GetName(),
"listOfRules")==0) {
3637 rulelnk = rulelnk->
Next();
3651 Warning(
"ReadStreamerInfo",
"The StreamerInfo for %s does not have a list of elements.",info->
GetName());
3656 Bool_t isstl = element && strcmp(
"This",element->
GetName())==0;
3658 if ( (!isstl &&
mode ==0) || (isstl &&
mode ==1) ) {
3665 if (uid >= 0 && uid < fClassIndex->
GetSize()) {
3666 si_uids.push_back(uid);
3670 printf(
"ReadStreamerInfo, class:%s, illegal uid=%d\n",info->
GetName(),uid);
3734 for (
Int_t i=0;i<npids;i++) {
3746 Info(
"WriteProcessID",
"name=%s, file=%s", name,
GetName());
3780 listOfRules.
SetName(
"listOfRules");
3781 std::set<TClass*> classSet;
3787 if (
gDebug > 0) printf(
" -class: %s info number %d saved\n",info->
GetName(),uid);
3793 if ( classSet.find( clinfo ) == classSet.end() ) {
3794 if (
gDebug > 0) printf(
" -class: %s stored the I/O customization rules\n",info->
GetName());
3801 listOfRules.
Add(obj);
3803 classSet.insert(clinfo);
3814 list.
Add(&listOfRules);
3846 "you want to read through a cache, but you have no valid cache "
3847 "directory set - reading remotely");
3848 ::Info(
"TFile::OpenFromCache",
"set cache directory using TFile::SetCacheFileDir()");
3856 "you want to read through a cache, but you are reading "
3857 "local files - CACHEREAD disabled");
3864 cachefilepath += fileurl.
GetFile();
3868 ::Warning(
"TFile::OpenFromCache",
"you want to read through a cache, but I "
3869 "cannot create the directory %s - CACHEREAD disabled",
3870 cachefilepathbasedir.
Data());
3875 cachefilepath +=
"__";
3879 if (strstr(
name,
"zip=")) {
3884 Int_t optioncount = 0;
3893 if (optioncount!=0) {
3898 newoptions +=
value;
3908 cachefilepath +=
"__";
3909 cachefilepath += zipname;
3923 char cacheblock[256];
3924 char remotblock[256];
3927 cfurl = cachefilepath;
3928 cfurl +=
"?filetype=raw";
3931 ropt +=
"&filetype=raw";
3944 ::Error(
"TFile::OpenFromCache",
3945 "cannot open the cache file to check cache consistency");
3950 ::Error(
"TFile::OpenFromCache",
3951 "cannot open the remote file to check cache consistency");
3958 if ((!cachefile->
ReadBuffer(cacheblock,256)) &&
3960 if (memcmp(cacheblock, remotblock, 256)) {
3961 ::Warning(
"TFile::OpenFromCache",
"the header of the cache file "
3962 "differs from the remote file - forcing an update");
3966 ::Warning(
"TFile::OpenFromCache",
"the header of the cache and/or "
3967 "remote file are not readable - forcing an update");
3982 const auto cachefilepathtmp = cachefilepath + std::to_string(
gSystem->
GetPid()) +
".tmp";
3985 "you want to read through a cache, but I "
3986 "cannot make a cache copy of %s - CACHEREAD disabled",
3987 cachefilepathbasedir.
Data());
3997 ::Info(
"TFile::OpenFromCache",
"using local cache copy of %s [%s]",
name, cachefilepath.
Data());
4000 fileurl.
SetFile(cachefilepath);
4003 tagfile = cachefilepath;
4004 tagfile +=
".ROOT.cachefile";
4062 if (!url || strlen(url) <= 0) {
4063 ::Error(
"TFile::Open",
"no url specified");
4072 if (
gEnv->
GetValue(
"TFile.CrossProtocolRedirects", 1) == 1) {
4075 ssize_t
len = getxattr(fileurl.
GetFile(),
"eos.url.xroot",
nullptr, 0);
4077 std::string xurl(
len, 0);
4078 if (getxattr(fileurl.
GetFile(),
"eos.url.xroot", &xurl[0],
len) ==
len) {
4079 if ((
f =
TFile::Open(xurl.c_str(), options, ftitle, compress, netopt))) {
4080 if (!
f->IsZombie()) {
4099 TString sto = opts(ito + strlen(
"TIMEOUT="), opts.
Length());
4104 if (
gDebug > 0)
::Info(
"TFile::Open",
"timeout of %d millisec requested", toms);
4106 sto.
Insert(0,
"TIMEOUT=");
4124 ::Info(
"TFile::Open",
"waited %d millisec for asynchronous open", toms - xtms);
4126 ::Info(
"TFile::Open",
"timeout option not supported (requires asynchronous"
4131 ::Error(
"TFile::Open",
"timeout expired while opening '%s'", expandedUrl.
Data());
4138 ::Warning(
"TFile::Open",
"incomplete 'TIMEOUT=' option specification - ignored");
4144 const char *
option = opts;
4147 TString namelist(expandedUrl);
4164 while (namelist.
Tokenize(
n, from,
"|") && !
f) {
4167 if (!strcasecmp(
option,
"CACHEREAD") ||
4207 lfname = urlname.
GetUrl();
4214 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name))) {
4215 if (
h->LoadPlugin() == -1)
4223 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name))) {
4224 if (
h->LoadPlugin() == -1)
4232 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name)) &&
4233 h->LoadPlugin() == 0) {
4234 name.ReplaceAll(
"file:",
"");
4242 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name.Data()))) {
4243 if (
h->LoadPlugin() == -1)
4259 if (
f &&
f->IsZombie()) {
4282 f &&
f->IsWritable() && !
f->IsRaw()) {
4317 const char *ftitle,
Int_t compress,
4325 if (!url || strlen(url) <= 0) {
4326 ::Error(
"TFile::AsyncOpen",
"no url specified");
4338 TString outf =
".TFileAsyncOpen_";
4349 while (namelist.
Tokenize(
n, from,
"|") && !
f) {
4364 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name)) &&
4365 (!strcmp(
h->GetClass(),
"TXNetFile") || !strcmp(
h->GetClass(),
"TNetXNGFile"))
4366 &&
h->LoadPlugin() == 0) {
4371 if ((
h =
gROOT->GetPluginManager()->FindHandler(
"TFile",
name)) &&
4372 !strcmp(
h->GetClass(),
"TAlienFile") &&
h->LoadPlugin() == 0) {
4383 if (!notfound && !
f)
4428 if ((
f = fh->
GetFile()) && !(
f->IsZombie())) {
4430 Bool_t cr = (!strcmp(
f->GetOption(),
"CREATE") ||
4431 !strcmp(
f->GetOption(),
"RECREATE") ||
4442 if (
f)
f->fAsyncHandle = fh;
4454#if defined(R__WINGCC)
4458#elif defined(R__SEEK64)
4459 return ::open64(pathname, flags,
mode);
4461 return ::open(pathname, flags,
mode);
4470 if (fd < 0)
return 0;
4479 return ::read(fd, buf,
len);
4487 return ::write(fd, buf,
len);
4498#if defined (R__SEEK64)
4499 return ::lseek64(fd,
offset, whence);
4501 return ::_lseeki64(fd,
offset, whence);
4503 return ::lseek(fd,
offset, whence);
4530 return ::_commit(fd);
4601 if (!cached.EndsWith(
"/"))
4608 ::Error(
"TFile::SetCacheFileDir",
"no sufficient permissions on cache directory %s or cannot create it",
TString(cachedir).Data());
4650 cachetagfile +=
".tag.ROOT.cache";
4654 if (lastcleanuptime < cleanupinterval) {
4655 ::Info(
"TFile::ShrinkCacheFileDir",
"clean-up is skipped - last cleanup %lu seconds ago - you requested %lu", lastcleanuptime, cleanupinterval);
4661 cachetagfile +=
"?filetype=raw";
4662 TFile *tagfile =
nullptr;
4664 if (!(tagfile =
TFile::Open(cachetagfile,
"RECREATE"))) {
4665 ::Error(
"TFile::ShrinkCacheFileDir",
"cannot create the cache tag file %s", cachetagfile.
Data());
4673#if defined(R__WIN32)
4674 cmd =
"echo <TFile::ShrinkCacheFileDir>: cleanup to be implemented";
4675#elif defined(R__MACOSX)
4676 cmd.
Form(
"perl -e 'my $cachepath = \"%s\"; my $cachesize = %lld;my $findcommand=\"find $cachepath -type f -exec stat -f \\\"\\%%a::\\%%N::\\%%z\\\" \\{\\} \\\\\\;\";my $totalsize=0;open FIND, \"$findcommand | sort -k 1 |\";while (<FIND>) { my ($accesstime, $filename, $filesize) = split \"::\",$_; $totalsize += $filesize;if ($totalsize > $cachesize) {if ( ( -e \"${filename}.ROOT.cachefile\" ) || ( -e \"${filename}\" ) ) {unlink \"$filename.ROOT.cachefile\";unlink \"$filename\";}}}close FIND;' ",
fgCacheFileDir.
Data(),shrinksize);
4678 cmd.
Form(
"perl -e 'my $cachepath = \"%s\"; my $cachesize = %lld;my $findcommand=\"find $cachepath -type f -exec stat -c \\\"\\%%x::\\%%n::\\%%s\\\" \\{\\} \\\\\\;\";my $totalsize=0;open FIND, \"$findcommand | sort -k 1 |\";while (<FIND>) { my ($accesstime, $filename, $filesize) = split \"::\",$_; $totalsize += $filesize;if ($totalsize > $cachesize) {if ( ( -e \"${filename}.ROOT.cachefile\" ) || ( -e \"${filename}\" ) ) {unlink \"$filename.ROOT.cachefile\";unlink \"$filename\";}}}close FIND;' ",
fgCacheFileDir.
Data(),shrinksize);
4685 ::Error(
"TFile::ShrinkCacheFileDir",
"error executing clean-up script");
4815 forceRemote =
kTRUE;
4816 else if (opts.
Contains(
"remote=0"))
4825 if (fname[0] ==
'/') {
4827 lfname.
Form(
"%s%s", prefix->
Data(), fname);
4830 }
else if (fname[0] ==
'~' || fname[0] ==
'$') {
4848 if (localFile && prefix)
4855 }
else if (
TPMERegexp(
"^(http[s]?|s3http[s]?|[a]?s3|gs|gshttp[s]?){1}:",
"i").Match(
name)) {
4859 }
else if (!strncmp(
name,
"file:", 5)) {
4885 if (of && (of->
GetSize() > 0)) {
4888 while ((
f = (
TFile *)nxf()))
4889 if (
f->Matches(
name))