20 #define TSelHandleDataSet_cxx
37 ClassImp(TSelHandleDataSet);
42 void TSelHandleDataSet::SlaveBegin(TTree *)
45 TObject *o = fInput->FindObject(
"PROOF_Benchmark_HandleDSType");
46 if (o) fType =
dynamic_cast<TPBHandleDSType *
>(o);
48 TNamed *n =
dynamic_cast<TNamed *
>(fInput->FindObject(
"PROOF_Benchmark_DestDir"));
50 fDestDir = n->GetTitle();
51 if (gSystem->AccessPathName(fDestDir)) {
53 if (gSystem->mkdir(fDestDir, kTRUE) != 0) {
55 Error(
"SlaveBegin",
"could not create dir '%s'", fDestDir.Data());
57 if (gSystem->AccessPathName(fDestDir, kWritePermission)) {
59 Error(
"SlaveBegin",
"dir '%s' is not writable by this process", fDestDir.Data());
61 Info(
"SlaveBegin",
"dir '%s' successfully created", fDestDir.Data());
68 if (!fType) fType =
new TPBHandleDSType(TPBHandleDSType::kReleaseCache);
74 void TSelHandleDataSet::ReleaseCache(
const char *fn)
79 fd = open(filename.Data(), O_RDONLY);
82 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
84 Info(
"ReleaseCache",
"file cache for file '%s' cleaned ...", filename.Data());
86 Error(
"ReleaseCache",
"cannot open file '%s' for cache clean up; errno=%d",
87 filename.Data(), errno);
90 Info(
"ReleaseCache",
"dummy function: file '%s' untouched ...", fn);
99 void TSelHandleDataSet::CheckCache(
const char * )
101 Warning(
"CheckCache",
"cache checker not implemented yet");
109 void TSelHandleDataSet::RemoveFile(
const char *fn)
111 if (!gSystem->AccessPathName(fn, kWritePermission)) {
112 if (gSystem->Unlink(fn) != 0) {
113 Error(
"RemoveFile",
"problems removing file '%s' ...", fn);
115 if (!gSystem->AccessPathName(fn))
116 Warning(
"RemoveFile",
"'unlink' returned success but the file still exists ('%s')", fn);
119 if (!gSystem->AccessPathName(fn)) {
120 Error(
"RemoveFile",
"file '%s' cannot removed by this process", fn);
122 Error(
"RemoveFile",
"file '%s' does not exists", fn);
132 void TSelHandleDataSet::CopyFile(
const char *fn)
135 if (fDestDir.IsNull()) {
136 Error(
"CopyFile",
"destination dir undefined: file '%s' not copied", fn);
140 TString basefn = gSystem->BaseName(TUrl(fn, kTRUE).GetFile());
141 TString dst = TString::Format(
"%s/%s", fDestDir.Data(), basefn.Data());
142 if (!TFile::Cp(fn, dst.Data())) {
143 Error(
"CopyFile",
"problems copying file '%s' to '%s'", fn, dst.Data());
146 Info(
"CopyFile",
"file '%s' created ...", dst.Data());
165 Bool_t TSelHandleDataSet::Process(Long64_t entry)
173 TDSetElement *fCurrent = 0;
175 if (fInput && (elemPair = dynamic_cast<TPair *>
176 (fInput->FindObject(
"PROOF_CurrentElement")))) {
177 if ((fCurrent = dynamic_cast<TDSetElement *>(elemPair->Value()))) {
178 Info(
"Process",
"entry %lld: file: '%s'", entry, fCurrent->GetName());
180 Error(
"Process",
"entry %lld: no file specified!", entry);
186 TUrl url(fCurrent->GetName());
188 TString lfname = gEnv->GetValue(
"Path.Localroot",
"");
189 TFile::EFileType type = TFile::GetType(url.GetUrl(),
"", &lfname);
190 if (type == TFile::kLocal &&
191 strcmp(url.GetProtocol(),
"root") && strcmp(url.GetProtocol(),
"xrd"))
192 lfname = url.GetFileAndOptions();
194 if (fType->GetType() == TPBHandleDSType::kReleaseCache) {
196 if (type == TFile::kLocal) {
197 ReleaseCache(lfname);
198 }
else if (type == TFile::kFile) {
199 ReleaseCache(url.GetFile());
202 "attempt to call ReleaseCache for a non-local file: '%s'", url.GetUrl());
204 }
else if (fType->GetType() == TPBHandleDSType::kCheckCache) {
206 if (type == TFile::kLocal) {
208 }
else if (type == TFile::kFile) {
209 CheckCache(url.GetFile());
212 "attempt to call CheckCache for a non-local file: '%s'", url.GetUrl());
214 }
else if (fType->GetType() == TPBHandleDSType::kRemoveFiles) {
216 RemoveFile(url.GetFileAndOptions());
217 }
else if (fType->GetType() == TPBHandleDSType::kCopyFiles) {
219 CopyFile(url.GetFileAndOptions());
222 Warning(
"Process",
"type: %d is unknown", fType->GetType());