36 ClassImp(TProofMgrLite);
41 TProofMgrLite::TProofMgrLite(
const char *url, Int_t dbg,
const char *alias)
42 : TProofMgr(url, dbg, alias)
45 fServType = kProofLite;
51 TProof *TProofMgrLite::CreateSession(
const char *cfg,
52 const char *, Int_t loglevel)
54 TString c(fUrl.GetOptions());
55 if (!c.Contains(
"workers=") && cfg && strstr(cfg,
"workers=")) c = cfg;
56 Int_t nwrk = TProofLite::GetNumberOfWorkers(c);
57 if (nwrk == 0)
return (TProof *)0;
60 if (gProof && gProof->IsLite()) {
61 if (gProof->IsValid()) {
62 if (nwrk > 0 && gProof->GetParallel() != nwrk) {
78 if (strlen(fUrl.GetOptions()) > 0) u.Form(
"lite/?%s", fUrl.GetOptions());
79 TProof *p =
new TProofLite(u, cfg, 0, loglevel, 0,
this);
81 if (p && p->IsValid()) {
87 if (fSessions->Last())
88 ns = ((TProofDesc *)(fSessions->Last()))->GetLocalId() + 1;
91 fSessions =
new TList;
95 Int_t st = (p->IsIdle()) ? TProofDesc::kIdle : TProofDesc::kRunning ;
97 new TProofDesc(p->GetName(), p->GetTitle(), p->GetUrl(),
98 ns, p->GetSessionID(), st, p);
103 Error(
"CreateSession",
"creating PROOF session");
129 TProofLog *TProofMgrLite::GetSessionLogs(Int_t isess,
const char *stag,
130 const char *pattern, Bool_t)
135 isess = (isess < 0) ? -isess : isess;
146 TString sandbox(gSystem->WorkingDirectory());
147 sandbox.ReplaceAll(gSystem->HomeDirectory(),
"");
148 sandbox.ReplaceAll(
"/",
"-");
149 sandbox.Replace(0,1,
"/",1);
150 if (strlen(gEnv->GetValue(
"ProofLite.Sandbox",
"")) > 0) {
151 sandbox.Insert(0, gEnv->GetValue(
"ProofLite.Sandbox",
""));
152 }
else if (strlen(gEnv->GetValue(
"Proof.Sandbox",
"")) > 0) {
153 sandbox.Insert(0, gEnv->GetValue(
"Proof.Sandbox",
""));
156 sb.Form(
"~/%s", kPROOF_WorkDir);
157 sandbox.Insert(0, sb.Data());
159 gSystem->ExpandPathName(sandbox);
162 if (tag.Length() > 0) {
163 sessiondir.Form(
"%s/session-%s", sandbox.Data(), tag.Data());
164 if (gSystem->AccessPathName(sessiondir, kReadPermission)) {
165 Error(
"GetSessionLogs",
"information for session '%s' not available", tag.Data());
166 return (TProofLog *)0;
170 TSortedList *olddirs =
new TSortedList(kFALSE);
171 void *dirp = gSystem->OpenDirectory(sandbox);
174 while ((e = gSystem->GetDirEntry(dirp))) {
175 if (!strncmp(e,
"session-", 8)) {
177 Int_t i = d.Last(
'-');
178 if (i != kNPOS) d.Remove(i);
180 if (i != kNPOS) d.Remove(0,i+1);
181 TString path = Form(
"%s/%s", sandbox.Data(), e);
182 olddirs->Add(
new TNamed(d, path));
185 gSystem->FreeDirectory(dirp);
189 if (isess > olddirs->GetSize() - 1) {
190 Warning(
"GetSessionLogs",
191 "session index out of range (%d): take oldest available session", isess);
192 isess = olddirs->GetSize() - 1;
197 TNamed *n = (TNamed *) olddirs->First();
201 n = (TNamed *) olddirs->First();
204 Error(
"GetSessionLogs",
"cannot locate session dir for index '%d' under '%s':"
205 " cannot continue!", isess, sandbox.Data());
206 return (TProofLog *)0;
208 sessiondir = n->GetTitle();
209 tag = gSystem->BaseName(sessiondir);
210 tag.ReplaceAll(
"session-",
"");
216 Info(
"GetSessionLogs",
"analysing session dir %s", sessiondir.Data());
219 pl =
new TProofLog(tag,
"",
this);
221 void *dirp = gSystem->OpenDirectory(sessiondir);
223 TSortedList *logs =
new TSortedList;
225 while ((e = gSystem->GetDirEntry(dirp))) {
227 if (fn.EndsWith(
".log") && fn.CountChar(
'-') > 0) {
229 if (fn.BeginsWith(
"session-")) {
231 }
else if (fn.BeginsWith(
"worker-")) {
233 ord.ReplaceAll(
"worker-",
"");
234 Int_t
id = ord.First(
'-');
237 }
else if (ord.Contains(
".valgrind")) {
239 ord.ReplaceAll(
".valgrind.log",
"-valgrind");
244 if (!ord.IsNull()) ord.ReplaceAll(
"0.",
"");
247 url = Form(
"%s/%s", sessiondir.Data(), e);
249 logs->Add(
new TNamed(ord, url));
252 Info(
"GetSessionLogs",
"ord: %s, url: %s", ord.Data(), url.Data());
256 gSystem->FreeDirectory(dirp);
260 while ((n = (TNamed *) nxl())) {
261 TString ord = Form(
"0.%s", n->GetName());
262 if (ord ==
"0.-1") ord =
"0";
264 pl->Add(ord, n->GetTitle());
273 if (pl && retrieve) {
274 const char *pat = pattern ? pattern :
"-v \"| SvcMsg\"";
275 if (pat && strlen(pat) > 0)
276 pl->Retrieve(
"*", TProofLog::kGrep, 0, pat);
289 TObjString *TProofMgrLite::ReadBuffer(
const char *fin, Long64_t ofs, Int_t len)
291 if (!fin || strlen(fin) <= 0) {
292 Error(
"ReadBuffer",
"undefined path!");
293 return (TObjString *)0;
297 TString fn = TUrl(fin).GetFile();
298 Int_t fd = open(fn.Data(), O_RDONLY);
300 Error(
"ReadBuffer",
"problems opening file %s", fn.Data());
301 return (TObjString *)0;
305 off_t start = 0, end = lseek(fd, (off_t) 0, SEEK_END);
308 if (ofs > 0 && ofs < end) {
309 start = lseek(fd, (off_t) ofs, SEEK_SET);
311 start = lseek(fd, (off_t) 0, SEEK_SET);
313 if (len > (end - start + 1) || len <= 0)
314 len = end - start + 1;
317 const Int_t kMAXBUF = 32768;
320 Int_t wanted = (left > kMAXBUF - 1) ? kMAXBUF - 1 : left;
322 while ((len = read(fd, buf, wanted)) < 0 && TSystem::GetErrno() == EINTR)
323 TSystem::ResetErrno();
326 Error(
"ReadBuffer",
"error reading file %s", fn.Data());
328 return (TObjString *)0;
329 }
else if (len > 0) {
338 wanted = (left > kMAXBUF - 1) ? kMAXBUF - 1 : left;
340 }
while (len > 0 && left > 0);
346 return new TObjString(outbuf.Data());
353 TObjString *TProofMgrLite::ReadBuffer(
const char *fin,
const char *pattern)
356 if (!pattern || strlen(pattern) <= 0)
357 return (TObjString *)0;
359 if (!fin || strlen(fin) <= 0) {
360 Error(
"ReadBuffer",
"undefined path!");
361 return (TObjString *)0;
363 TString fn = TUrl(fin).GetFile();
365 TString pat(pattern);
367 Bool_t excl = kFALSE;
368 if (pat.Contains(
"-v ")) {
369 pat.ReplaceAll(
"-v ",
"");
372 pat = pat.Strip(TString::kLeading,
' ');
373 pat = pat.Strip(TString::kTrailing,
' ');
374 pat = pat.Strip(TString::kLeading,
'\"');
375 pat = pat.Strip(TString::kTrailing,
'\"');
394 if ((excl && line.Index(re) != kNPOS) ||
395 (!excl && line.Index(re) == kNPOS))
continue;
398 if (!line.EndsWith(
"\n")) line.Append(
'\n');
406 return new TObjString(outbuf.Data());