00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TError.h"
00013 #include "TGFrame.h"
00014 #include "TGTextView.h"
00015 #include "TGScrollBar.h"
00016 #include "TGLabel.h"
00017 #include "TProof.h"
00018 #include "TProofProgressDialog.h"
00019 #include "TProofProgressLog.h"
00020 #include "TProofLog.h"
00021 #include "TGNumberEntry.h"
00022 #include "TGListBox.h"
00023 #include "TGMenu.h"
00024 #include "TGButton.h"
00025
00026 const UInt_t kLogElemFilled = BIT(17);
00027 const UInt_t kDefaultActive = BIT(18);
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 ClassImp(TProofProgressLog)
00040
00041
00042 TProofProgressLog::TProofProgressLog(TProofProgressDialog *d, Int_t w, Int_t h) :
00043 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
00044 {
00045
00046
00047 fDialog = d;
00048 if (fDialog) fSessionUrl = fDialog->fSessionUrl;
00049 fSessionIdx = 0;
00050
00051 Init(w, h);
00052 }
00053
00054
00055 TProofProgressLog::TProofProgressLog(const char *url, Int_t idx, Int_t w, Int_t h) :
00056 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
00057 {
00058
00059
00060 fDialog = 0;
00061 fSessionUrl = url;
00062 fSessionIdx = (idx > 0) ? -idx : idx;
00063
00064 Init(w, h);
00065 }
00066
00067
00068 void TProofProgressLog::Init(Int_t w, Int_t h)
00069 {
00070
00071
00072 fProofLog = 0;
00073 fFullText = kFALSE;
00074 fTextType = kStd;
00075
00076 SetCleanup(kDeepCleanup);
00077
00078
00079 TGHorizontalFrame *htotal = new TGHorizontalFrame(this, w, h);
00080 TGVerticalFrame *vtextbox = new TGVerticalFrame(htotal, w, h);
00081
00082 fText = new TGTextView(vtextbox, w, h);
00083 vtextbox->AddFrame(fText, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
00084
00085
00086 fVworkers = new TGVerticalFrame(htotal);
00087
00088 TGLabel *laburl = new TGLabel(fVworkers, "Enter cluster URL:");
00089 fVworkers->AddFrame(laburl, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 2, 2, 2));
00090 fUrlText = new TGTextEntry(fVworkers);
00091 fUrlText->SetText(fSessionUrl.Data());
00092 fVworkers->AddFrame(fUrlText, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 0, 0, 0));
00093
00094 TGHorizontalFrame *hfurlbox = new TGHorizontalFrame(fVworkers, 20, 20);
00095 TGLabel *labsess = new TGLabel(hfurlbox, "Enter session:");
00096 hfurlbox->AddFrame(labsess, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 2, 2, 2));
00097 fSessNum = new TGNumberEntry(hfurlbox, 0, 5, -1, TGNumberFormat::kNESInteger);
00098 fSessNum->SetLimits(TGNumberFormat::kNELLimitMax, 0., 0.);
00099 fSessNum->SetIntNumber(0);
00100 fSessNum->GetNumberEntry()->SetToolTipText("Use 0 for the last known one,"
00101 " negative numbers for the previous ones, e.g. -1 for the last-but-one");
00102 hfurlbox->AddFrame(fSessNum, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 0, 0, 0));
00103 fUrlButton = new TGTextButton(hfurlbox, "Get logs info");
00104 fUrlButton->Connect("Clicked()", "TProofProgressLog", this, "Rebuild()");
00105 hfurlbox->AddFrame(fUrlButton, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
00106 fVworkers->AddFrame(hfurlbox, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00107
00108 TGNumberEntry *nent = new TGNumberEntry(hfurlbox);
00109 fVworkers->AddFrame(nent, new TGLayoutHints(kLHintsTop | kLHintsLeft, 4, 0, 0, 0));
00110
00111
00112 fLogList = 0;
00113 BuildLogList(kTRUE);
00114 fLogList->Resize(102,52);
00115 fLogList->SetMultipleSelections(kTRUE);
00116
00117
00118 TGHorizontalFrame *hfselbox = new TGHorizontalFrame(fVworkers, 20, 20);
00119 TGLabel *label1 = new TGLabel(hfselbox,"Choose workers:");
00120 hfselbox->AddFrame(label1, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 0, 0, 0, 0));
00121 TGTextButton *selall = new TGTextButton(hfselbox, " &All ");
00122 selall->Connect("Clicked()", "TProofProgressLog", this, "Select(=0)");
00123 hfselbox->AddFrame(selall, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
00124 TGTextButton *clearall = new TGTextButton(hfselbox, " &Clear ");
00125 clearall->Connect("Clicked()", "TProofProgressLog", this, "Select(=1)");
00126 hfselbox->AddFrame(clearall, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
00127
00128
00129 Select(0, kFALSE);
00130
00131
00132 fLogNew = new TGTextButton(fVworkers, "&Display");
00133 fLogNew->Connect("Clicked()", "TProofProgressLog", this, "DoLog(=kFALSE)");
00134
00135
00136 fLogNew->SetTextColor(0xffffff, kFALSE);
00137 fLogNew->SetBackgroundColor(0x000044);
00138 fVworkers->AddFrame(hfselbox, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 2, 2, 2));
00139 fVworkers->AddFrame(fLogList, new TGLayoutHints(kLHintsExpandX | kLHintsTop | kLHintsExpandY, 2, 2, 5, 2));
00140 fVworkers->AddFrame(fLogNew, new TGLayoutHints(kLHintsExpandX | kLHintsTop , 2, 2, 1, 5));
00141
00142 htotal->AddFrame(fVworkers, new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandY, 2, 2, 2, 2));
00143
00144
00145 TGHorizontalFrame *hflogbox = new TGHorizontalFrame(vtextbox, 550, 20);
00146 fClose = new TGTextButton(hflogbox, " &Close ");
00147 fClose->Connect("Clicked()", "TProofProgressLog", this, "CloseWindow()");
00148 hflogbox->AddFrame(fClose, new TGLayoutHints(kLHintsCenterY |
00149 kLHintsRight, 10, 2, 2, 2));
00150
00151
00152 fSave = new TGTextButton(hflogbox, "&Save");
00153 fSave->Connect("Clicked()", "TProofProgressLog", this, "SaveToFile()");
00154 hflogbox->AddFrame(fSave, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
00155 fFileName = new TGTextEntry(hflogbox);
00156 fFileName->SetText("<session-tag>.log");
00157 hflogbox->AddFrame(fFileName, new TGLayoutHints(kLHintsCenterY | kLHintsRight));
00158 TGLabel *label10 = new TGLabel(hflogbox, "Save to a file:");
00159 hflogbox->AddFrame(label10, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 50, 2, 2, 2));
00160
00161
00162 TGVerticalFrame *vlines = new TGVerticalFrame(hflogbox);
00163 TGHorizontalFrame *vlines_buttons = new TGHorizontalFrame(vlines);
00164 TGLabel *label2 = new TGLabel(vlines_buttons, "Lines:");
00165 vlines_buttons->AddFrame(label2, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00166
00167 fAllLines = new TGCheckButton(vlines_buttons, "all");
00168 fAllLines->SetToolTipText("Retrieve all lines (service messages excluded)");
00169 fAllLines->SetState(kButtonUp);
00170 fAllLines->Connect("Clicked()", "TProofProgressLog", this, "NoLineEntry()");
00171 vlines_buttons->AddFrame(fAllLines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00172
00173 fRawLines = new TGCheckButton(vlines_buttons, "svcmsg");
00174 fRawLines->SetToolTipText("Retrieve all type of lines, service messages included");
00175 fRawLines->SetState(kButtonUp);
00176 vlines_buttons->AddFrame(fRawLines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00177
00178 TGLabel *label11 = new TGLabel(vlines_buttons, "From");
00179 vlines_buttons->AddFrame(label11, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00180
00181 fLinesFrom = new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
00182 fLinesFrom->SetIntNumber(-100);
00183 fLinesFrom->GetNumberEntry()->SetToolTipText("Negative values indicate \"tail\" action");
00184
00185
00186 vlines_buttons->AddFrame(fLinesFrom, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00187
00188 TGLabel *label3 = new TGLabel(vlines_buttons, "to");
00189 vlines_buttons->AddFrame(label3, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00190 fLinesTo = new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
00191 vlines_buttons->AddFrame(fLinesTo, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00192 vlines->AddFrame(vlines_buttons, new TGLayoutHints(kLHintsCenterY));
00193 hflogbox->AddFrame(vlines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
00194
00195
00196 TGLabel *label4 = new TGLabel(hflogbox, "Grep for:");
00197 hflogbox->AddFrame(label4, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 2, 2, 2));
00198 fGrepText = new TGTextEntry(hflogbox);
00199 hflogbox->AddFrame(fGrepText, new TGLayoutHints(kLHintsCenterY | kLHintsLeft));
00200
00201 fGrepButton = new TGTextButton(hflogbox, "Grep");
00202 fGrepButton->Connect("Clicked()", "TProofProgressLog", this, "DoLog(=kTRUE)");
00203 hflogbox->AddFrame(fGrepButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4, 0, 0, 0));
00204
00205 vtextbox->AddFrame(hflogbox, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
00206 htotal->AddFrame(vtextbox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kLHintsRight, 3, 3, 3, 3));
00207 AddFrame(htotal, new TGLayoutHints(kLHintsExpandX |
00208 kLHintsExpandY, 3, 3, 3, 3));
00209 MapSubwindows();
00210 Resize();
00211 CenterOnParent();
00212 Popup();
00213 }
00214
00215
00216 TProofProgressLog::~TProofProgressLog()
00217 {
00218
00219
00220
00221 SafeDelete(fProofLog);
00222
00223
00224 if (fDialog) {
00225 fDialog->fLogWindow = 0;
00226 fDialog->fProof->Disconnect("LogMessage(const char*,Bool_t)", this,
00227 "LogMessage(const char*,Bool_t)");
00228 }
00229 }
00230
00231
00232 void TProofProgressLog::Popup()
00233 {
00234
00235
00236 MapWindow();
00237 }
00238
00239
00240 void TProofProgressLog::Clear(Option_t *)
00241 {
00242
00243
00244 if (fText)
00245 fText->Clear();
00246 }
00247
00248
00249 void TProofProgressLog::LoadBuffer(const char *buffer)
00250 {
00251
00252
00253 if (fText)
00254 fText->LoadBuffer(buffer);
00255 }
00256
00257
00258 void TProofProgressLog::LoadFile(const char *file)
00259 {
00260
00261
00262 if (fText)
00263 fText->LoadFile(file);
00264 }
00265
00266
00267 void TProofProgressLog::AddBuffer(const char *buffer)
00268 {
00269
00270
00271 if (fText) {
00272 TGText txt;
00273 txt.LoadBuffer(buffer);
00274 fText->AddText(&txt);
00275 }
00276 }
00277
00278
00279 void TProofProgressLog::CloseWindow()
00280 {
00281
00282
00283 DeleteWindow();
00284 }
00285
00286
00287 void TProofProgressLog::BuildLogList(Bool_t create)
00288 {
00289
00290
00291
00292
00293 TString title;
00294 title.Form("PROOF - Processing logs for session 'undefined'");
00295 SetWindowName(title.Data());
00296 SetIconName(title.Data());
00297
00298
00299 if (create) {
00300 if (fLogList) delete fLogList;
00301 fLogList = new TGListBox(fVworkers);
00302 } else {
00303
00304 Int_t nent = fLogList->GetNumberOfEntries();
00305 fLogList->RemoveEntries(0,nent);
00306 fLogList->Layout();
00307 }
00308
00309 if (fSessionUrl.IsNull()) {
00310 if (gDebug > 0)
00311 Info("BuildLogList", "sesssion URL undefined - do nothing");
00312 return;
00313 }
00314 TProofMgr *mgr = TProof::Mgr(fSessionUrl.Data());
00315 if (!mgr || !mgr->IsValid()) {
00316 Warning("BuildLogList", "unable open a manager connection to %s",
00317 fSessionUrl.Data());
00318 return;
00319 }
00320 if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx,"NR"))) {
00321 Warning("BuildLogList", "unable to get logs from %s",
00322 fSessionUrl.Data());
00323 return;
00324 }
00325
00326 title.Form("PROOF - Processing logs for session '%s', started on %s at %s",
00327 fProofLog->GetName(), fProofLog->StartTime().AsString(),
00328 fProofLog->GetTitle());
00329 SetWindowName(title.Data());
00330 SetIconName(title.Data());
00331
00332 TList *elem = fProofLog->GetListOfLogs();
00333 TIter next(elem);
00334 TProofLogElem *pe = 0;
00335
00336 Int_t is = 0;
00337 TGLBEntry *ent = 0;
00338 TString buf;
00339 while ((pe=(TProofLogElem*)next())){
00340 TUrl url(pe->GetTitle());
00341 buf.Form("%s %s", pe->GetName(), url.GetHost());
00342 fLogList->AddEntry(buf.Data(), is);
00343 if ((ent = fLogList->FindEntry(buf.Data()))) {
00344 ent->ResetBit(kLogElemFilled);
00345 ent->ResetBit(kDefaultActive);
00346 if (!(pe->IsWorker())) ent->SetBit(kDefaultActive);
00347 }
00348 is++;
00349 }
00350
00351
00352 return;
00353 }
00354
00355
00356 void TProofProgressLog::DoLog(Bool_t grep)
00357 {
00358
00359
00360 Clear();
00361
00362 if (!fGrepText) {
00363 Warning("DoLog", "no text: do nothing!");
00364 return;
00365 }
00366
00367 TString greptext = fGrepText->GetText();
00368 Int_t from, to;
00369 if (fAllLines->IsOn()){
00370 from = 0;
00371 to = -1;
00372 } else {
00373 from = fLinesFrom->GetIntNumber();
00374 to = fLinesTo->GetIntNumber();
00375 }
00376
00377
00378 if (!fProofLog) {
00379 TProofMgr *mgr = 0;
00380 if ((mgr = TProof::Mgr(fSessionUrl.Data()))) {
00381 if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx, "NR"))) {
00382 Warning("DoLog", "unable to instantiate TProofLog for %s",
00383 fSessionUrl.Data());
00384 }
00385 } else {
00386 Warning("DoLog", "unable to instantiate a TProofMgr for %s",
00387 fSessionUrl.Data());
00388 }
00389 }
00390
00391
00392 Bool_t retrieve = kFALSE;
00393 if (!grep) {
00394 if (!fFullText ||
00395 ((fTextType != kRaw && fRawLines->IsOn()) ||
00396 (fTextType != kStd && !fRawLines->IsOn())) ||
00397 (fDialog && fDialog->fStatus==TProofProgressDialog::kRunning)) {
00398 retrieve = kTRUE;
00399 if (fRawLines->IsOn()) {
00400 fTextType = kRaw;
00401 } else {
00402 fTextType = kStd;
00403 }
00404 if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
00405 fFullText = kTRUE;
00406 }
00407 } else {
00408 retrieve = kTRUE;
00409 fTextType = kGrep;
00410 if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
00411 fFullText = kTRUE;
00412 }
00413
00414
00415 if (fProofLog) {
00416 TList *selected = new TList;
00417 fLogList->GetSelectedEntries(selected);
00418 TIter next(selected);
00419 TGTextLBEntry *selentry;
00420 Bool_t logonly = fProofLog->LogToBox();
00421 fProofLog->SetLogToBox(kTRUE);
00422
00423 fProofLog->Connect("Prt(const char*)", "TProofProgressLog",
00424 this, "LogMessage(const char*, Bool_t)");
00425 while ((selentry=(TGTextLBEntry*)next())){
00426 TString ord = selentry->GetText()->GetString();
00427 Int_t is = ord.Index(" ");
00428 if (is != kNPOS) ord.Remove(is);
00429 if (retrieve || !selentry->TestBit(kLogElemFilled)) {
00430 if (fTextType == kGrep) {
00431 fProofLog->Retrieve(ord.Data(), TProofLog::kGrep, 0, greptext.Data());
00432 } else if (fTextType == kRaw) {
00433 fProofLog->Retrieve(ord.Data(), TProofLog::kTrailing, 0, 0);
00434 } else {
00435 fProofLog->Retrieve(ord.Data(), TProofLog::kGrep, 0, "-v \"| SvcMsg\"");
00436 }
00437 selentry->SetBit(kLogElemFilled);
00438 }
00439 fProofLog->Display(ord.Data(), from, to);
00440 }
00441 fProofLog->SetLogToBox(logonly);
00442 fProofLog->Disconnect("Prt(const char*)", this, "LogMessage(const char*, Bool_t)");
00443 delete selected;
00444 }
00445 }
00446
00447
00448 void TProofProgressLog::LogMessage(const char *msg, Bool_t all)
00449 {
00450
00451
00452 if (all) {
00453
00454 LoadBuffer(msg);
00455 } else {
00456
00457 AddBuffer(msg);
00458 }
00459 }
00460
00461
00462 void TProofProgressLog::SaveToFile()
00463 {
00464
00465
00466
00467 if (!fProofLog) DoLog();
00468
00469
00470 TString filename = fFileName->GetText();
00471 if (filename.IsNull() || filename == "<session-tag>.log") {
00472 filename = (fDialog && fDialog->fProof) ?
00473 TString::Format("%s.log", fDialog->fProof->GetName()) :
00474 "proof.log";
00475 }
00476
00477 TList *selected = new TList;
00478 fLogList->GetSelectedEntries(selected);
00479 TIter next(selected);
00480 TGTextLBEntry *selentry;
00481 Bool_t writemode=kTRUE;
00482 const char *option;
00483 TString ord;
00484 while ((selentry=(TGTextLBEntry*)next())){
00485 ord = selentry->GetText()->GetString();
00486 Int_t isp = ord.Index(' ');
00487 if (isp != kNPOS) ord.Remove(isp);
00488
00489 option = writemode ? "w" : "a";
00490 fProofLog->Save(ord.Data(), filename.Data(), option);
00491 writemode=kFALSE;
00492 }
00493
00494 Info("SaveToFile", "logs saved to file %s", filename.Data());
00495 return;
00496 }
00497
00498
00499 void TProofProgressLog::NoLineEntry()
00500 {
00501
00502
00503 if (fAllLines->IsOn()){
00504
00505 fLinesFrom->SetState(kFALSE);
00506 fLinesTo->SetState(kFALSE);
00507 } else {
00508 fLinesFrom->SetState(kTRUE);
00509 fLinesTo->SetState(kTRUE);
00510 }
00511 }
00512
00513
00514 void TProofProgressLog::Select(Int_t id, Bool_t all)
00515 {
00516
00517
00518 Int_t nen = fLogList->GetNumberOfEntries();
00519 Bool_t sel = id ? 0 : 1;
00520
00521 TGLBEntry *ent = 0;
00522 for (Int_t ie=0; ie<nen; ie++) {
00523 if (all) {
00524 fLogList->Select(ie, sel);
00525 } else {
00526 if ((ent = fLogList->GetEntry(ie))) {
00527 if (ent->TestBit(kDefaultActive)) fLogList->Select(ie, sel);
00528 }
00529 }
00530 }
00531 }
00532
00533
00534
00535 void TProofProgressLog::Rebuild()
00536 {
00537
00538
00539
00540 Bool_t sameurl = kFALSE;
00541 TUrl url(fUrlText->GetText());
00542 TUrl urlref(fSessionUrl.Data());
00543 if (!strcmp(url.GetHostFQDN(), urlref.GetHostFQDN())) {
00544 if (url.GetPort() == urlref.GetPort()) {
00545 if (!strcmp(url.GetUser(), urlref.GetUser())) {
00546 sameurl = kTRUE;
00547 }
00548 }
00549 }
00550 Int_t idx = 0;
00551 if (sameurl) {
00552 idx = fSessNum->GetIntNumber();
00553 if (idx == fSessionIdx) {
00554 Info("Rebuild", "same paremeters {%s, %s}, {%d, %d}: no need to rebuild TProofLog",
00555 url.GetUrl(), urlref.GetUrl(), idx, fSessionIdx);
00556 return;
00557 }
00558 }
00559
00560 if (fProofLog) delete fProofLog;
00561
00562
00563 fSessionUrl = fUrlText->GetText();
00564 fSessionIdx = idx;
00565
00566
00567 BuildLogList(kFALSE);
00568
00569
00570 Select(0, kFALSE);
00571
00572 fLogList->Layout();
00573
00574
00575 return;
00576 }