31 ClassImp(TQueryResult);
36 TQueryResult::TQueryResult(Int_t seqnum,
const char *opt, TList *inlist,
37 Long64_t entries, Long64_t first,
const char *selec)
38 : fSeqNum(seqnum), fStatus(kSubmitted), fUsedCPU(0.), fOptions(opt),
39 fEntries(entries), fFirst(first),
40 fBytes(0), fParList(
"-"), fOutputList(0),
41 fFinalized(kFALSE), fArchived(kFALSE), fResultFile(
"-"),
42 fPrepTime(0.), fInitTime(0.), fProcTime(0.), fMergeTime(0.),
43 fRecvTime(-1), fTermTime(-1), fNumWrks(-1), fNumMergers(-1)
46 SetName(TString::Format(
"q%d", fSeqNum));
47 SetTitle(TString::Format(
"session-localhost-%ld-%d",
48 (Long_t)TTimeStamp().GetSec(), gSystem->GetPid()));
52 fEnd.Set(fStart.Convert()-1);
57 fInputList = (TList *) (inlist->Clone());
58 fInputList->SetOwner();
62 fLogFile =
new TMacro(
"LogFile");
65 fDraw = selec ? TSelector::IsStandardDraw(selec) : kFALSE;
71 TIter nxo(fInputList);
74 if (!strcmp(o->GetName(),
"varexp")) {
75 varsel = o->GetTitle();
76 Int_t iht = varsel.Index(
">>htemp");
79 varsel.Form(
"\"%s\";", varsel.Data());
81 if (!strcmp(o->GetName(),
"selection"))
82 varsel += TString::Format(
"\"%s\"", o->GetTitle());
85 Info(
"TQueryResult",
"selec: %s, varsel: %s", selec, varsel.Data());
87 fLogFile->AddLine(TString::Format(
"TQueryResult: selec: %s, varsel: %s",
88 selec, varsel.Data()));
91 fSelecImp =
new TMacro(selec, varsel);
95 fSelecHdr =
new TMacro;
96 fSelecImp =
new TMacro;
101 const char *pl = gSystem->GetLibraries();
102 fLibList = (pl && (strlen(pl) > 0)) ? pl :
"-";
108 TQueryResult::~TQueryResult()
110 SafeDelete(fInputList);
111 SafeDelete(fOutputList);
112 SafeDelete(fLogFile);
113 SafeDelete(fSelecImp);
114 SafeDelete(fSelecHdr);
123 TQueryResult *TQueryResult::CloneInfo()
126 TQueryResult *qr =
new TQueryResult(fSeqNum, fOptions, 0, fEntries,
130 qr->fStatus = fStatus;
131 qr->fStart.Set(fStart.Convert());
132 qr->fEnd.Set(fEnd.Convert());
133 qr->fUsedCPU = fUsedCPU;
134 qr->fEntries = fEntries;
137 qr->fParList = fParList;
138 qr->fResultFile = fResultFile;
139 qr->fArchived = fArchived;
140 qr->fPrepTime = fPrepTime;
141 qr->fInitTime = fInitTime;
142 qr->fProcTime = fProcTime;
143 qr->fMergeTime = fMergeTime;
144 qr->fRecvTime = fRecvTime;
145 qr->fTermTime = fTermTime;
146 qr->fNumWrks = fNumWrks;
147 qr->fNumMergers = fNumMergers;
151 qr->fSelecHdr =
new TMacro();
152 qr->fSelecHdr->SetName(GetSelecHdr()->GetName());
153 qr->fSelecHdr->SetTitle(GetSelecHdr()->GetTitle());
157 qr->fSelecImp =
new TMacro();
158 qr->fSelecImp->SetName(GetSelecImp()->GetName());
159 qr->fSelecImp->SetTitle(GetSelecImp()->GetTitle());
163 qr->SetName(GetName());
164 qr->SetTitle(GetTitle());
174 void TQueryResult::SaveSelector(
const char *selector)
180 TString selec = selector;
184 selec = gSystem->SplitAclicMode(selec, aclicMode, arguments, io);
187 if (aclicMode.Length() > 0)
188 fOptions += TString::Format(
"#%s", aclicMode.Data());
192 TString selname = gSystem->BaseName(selec);
193 fSelecImp->SetName(selname);
194 Int_t idx = selname.Index(
".");
198 Info(
"SaveSelector",
"precompiled selector: just save the name");
199 fSelecImp->SetTitle(selname);
204 fSelecImp->SetTitle(selname);
207 char *selc = gSystem->Which(TROOT::GetMacroPath(), selec, kReadPermission);
210 Warning(
"SaveSelector",
211 "could not locate selector implementation file (%s)", selec.Data());
216 fSelecImp->ReadFile(selc);
217 fSelecImp->SetName(gSystem->BaseName(selc));
220 char *p = (
char *) strrchr(selc,
'.');
222 strlcpy(p+1,
"h",strlen(p));
225 Warning(
"SaveSelector",
226 "bad formatted name (%s): could not build header file name", selc);
228 if (!(gSystem->AccessPathName(selc, kReadPermission))) {
229 fSelecHdr->ReadFile(selc);
230 fSelecHdr->SetName(gSystem->BaseName(selc));
231 fSelecHdr->SetTitle(selname);
234 Warning(
"SaveSelector",
235 "could not locate selector header file (%s)", selc);
245 void TQueryResult::RecordEnd(EQueryStatus status, TList *outlist)
251 fStatus = (status < kAborted || status > kCompleted) ? kAborted : status;
254 if (outlist && fOutputList != outlist) {
256 fOutputList->Delete();
257 SafeDelete(fOutputList);
259 if ((fOutputList = (TList *) (outlist->Clone()))) {
260 fOutputList->SetOwner();
261 Info(
"RecordEnd",
"output list cloned successfully!");
263 Warning(
"RecordEnd",
"unable to clone output list!!!");
271 void TQueryResult::SetProcessInfo(Long64_t ent, Float_t cpu, Long64_t bytes,
272 Float_t init, Float_t proc)
274 fEntries = (ent > 0) ? ent : fEntries;
275 fUsedCPU = (cpu > 0.) ? cpu : fUsedCPU;
276 fBytes = (bytes > 0.) ? bytes : fBytes;
277 fInitTime = (init > 0.) ? init : fInitTime;
278 fProcTime = (proc > 0.) ? proc : fProcTime;
284 void TQueryResult::AddLogLine(
const char *logline)
287 fLogFile->AddLine(logline);
293 void TQueryResult::AddInput(TObject *obj)
295 if (fInputList && obj)
296 fInputList->Add(obj);
302 void TQueryResult::SetArchived(
const char *archfile)
306 if (archfile && (strlen(archfile) > 0))
307 fResultFile = archfile;
314 void TQueryResult::Print(Option_t *opt)
const
317 const char *qst[] = {
318 "aborted ",
"submitted",
"running ",
"stopped ",
"completed"
322 Int_t st = (fStatus > 0 && fStatus <= kCompleted) ? fStatus : 0;
325 Long64_t last = (fEntries > -1) ? fFirst+fEntries-1 : -1;
328 Bool_t full = ((strchr(opt,
'F') || strchr(opt,
'f'))) ? kTRUE : kFALSE;
334 Int_t i1 = qn.Index(re);
337 qn.Remove(qn.Index(
"N"));
342 if (full) Printf(
"+++");
345 if (!full && (last > -1))
346 range.Form(
"evts:%lld-%lld", fFirst, last);
350 const char *fin = fFinalized ?
"finalized" : qst[st];
351 const char *arc = fArchived ?
"(A)" :
"";
352 Printf(
"+++ #:%d ref:\"%s:%s\" sel:%s %9s%s %s",
353 qry, GetTitle(), GetName(), fSelecImp->GetTitle(), fin, arc,
356 Printf(
"+++ #:%d ref:\"%s:%s\" varsel:%s %s",
357 qry, GetTitle(), GetName(), fSelecImp->GetTitle(),
365 Float_t elapsed = (fProcTime > 0.) ? fProcTime
366 : (Float_t)(fEnd.Convert() - fStart.Convert());
367 Printf(
"+++ started: %s", fStart.AsString());
369 Printf(
"+++ prepare: %.3f sec", fPrepTime);
370 Printf(
"+++ init: %.3f sec", fInitTime);
371 Printf(
"+++ process: %.3f sec (CPU time: %.1f sec)", elapsed, fUsedCPU);
372 if (fNumMergers > 0) {
373 Printf(
"+++ merge: %.3f sec (%d mergers)", fMergeTime, fNumMergers);
375 Printf(
"+++ merge: %.3f sec ", fMergeTime);
378 Printf(
"+++ transfer: %.3f sec", fRecvTime);
380 Printf(
"+++ terminate: %.3f sec", fTermTime);
384 if (fEntries > -1 && elapsed > 0)
385 rate = fEntries / (Double_t)elapsed ;
386 Float_t size = ((Float_t)fBytes) / TMath::Power(2.,20.);
387 Printf(
"+++ processed: %lld events (size: %.3f MBs)", fEntries, size);
388 Printf(
"+++ rate: %.1f evts/sec", rate);
390 Printf(
"+++ # workers: %d ", fNumWrks);
393 if (fParList.Length() > 1)
394 Printf(
"+++ packages: %s", fParList.Data());
397 TString res = fResultFile;
399 Int_t dq = res.Index(
"queries");
401 res.Remove(0,res.Index(
"queries"));
402 res.Insert(0,
"<PROOF_SandBox>/");
404 if (res.BeginsWith(
"-")) {
405 res = (fStatus == kAborted) ?
"not available" :
"sent to client";
408 if (res.Length() > 1)
409 Printf(
"+++ results: %s", res.Data());
411 if (fOutputList && fOutputList->GetSize() > 0)
412 Printf(
"+++ outlist: %d objects", fOutputList->GetSize());
418 void TQueryResult::Browse(TBrowser *b)
421 b->Add(fOutputList, fOutputList->Class(),
"OutputList");
430 void TQueryResult::SetInputList(TList *in, Bool_t adopt)
432 if (!in || in != fInputList)
433 SafeDelete(fInputList);
435 if (in && in != fInputList) {
437 fInputList = (TList *) (in->Clone());
439 fInputList =
new TList;
444 in->SetOwner(kFALSE);
446 fInputList->SetOwner();
456 void TQueryResult::SetOutputList(TList *out, Bool_t adopt)
459 SafeDelete(fOutputList);
463 if (out && out != fOutputList) {
466 TIter nxoo(fOutputList);
467 while ((o = nxoo())) {
468 if (out->FindObject(o)) fOutputList->Remove(o);
470 SafeDelete(fOutputList);
473 fOutputList = (TList *) (out->Clone());
475 fOutputList =
new TList;
480 out->SetOwner(kFALSE);
482 fOutputList->SetOwner();
490 Bool_t operator==(
const TQueryResult &qr1,
const TQueryResult &qr2)
492 if (!strcmp(qr1.GetTitle(), qr2.GetTitle()))
493 if (qr1.GetSeqNum() == qr2.GetSeqNum())
501 Bool_t TQueryResult::Matches(
const char *ref)
503 TString lref; lref.Form(
"%s:%s", GetTitle(), GetName());
515 TObject *TQueryResult::GetInputObject(
const char *classname)
const
518 if (classname && fInputList) {
519 TIter nxi(fInputList);
521 if (!strncmp(o->ClassName(), classname, strlen(classname)))