Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TProofProgressLog.cxx
Go to the documentation of this file.
1 // @(#)root/sessionviewer:$Id$
2 // Author: G Ganis, Jul 2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TError.h"
13 #include "TPRegexp.h"
14 #include "TGFrame.h"
15 #include "TGTextView.h"
16 #include "TGScrollBar.h"
17 #include "TGLabel.h"
18 #include "TProof.h"
19 #include "TProofProgressDialog.h"
20 #include "TProofProgressLog.h"
21 #include "TProofLog.h"
22 #include "TGNumberEntry.h"
23 #include "TGListBox.h"
24 #include "TGMenu.h"
25 #include "TGButton.h"
26 
27 const UInt_t kLogElemFilled = BIT(17); // If the log element has been retrieved at least once
28 const UInt_t kDefaultActive = BIT(18); // If the log element is active by default
29 
30 ///////////////////////////////////////////////////////////////////////////
31 // //
32 // TProofProgressLog //
33 // //
34 // Dialog used to display Proof session logs from the Proof progress //
35 // dialog. //
36 // It uses TProofMgr::GetSessionLogs() mechanism internally //
37 // //
38 ///////////////////////////////////////////////////////////////////////////
39 
40 ClassImp(TProofProgressLog);
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Create a window frame for log messages.
44 
45 TProofProgressLog::TProofProgressLog(TProofProgressDialog *d, Int_t w, Int_t h) :
46  TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
47 {
48  fDialog = d;
49  if (fDialog) fSessionUrl = fDialog->fSessionUrl;
50  fSessionIdx = 0;
51 
52  Init(w, h);
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// Create a window frame for log messages.
57 
58 TProofProgressLog::TProofProgressLog(const char *url, Int_t idx, Int_t w, Int_t h) :
59  TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), w, h)
60 {
61  fDialog = 0;
62  fSessionUrl = url;
63  fSessionIdx = (idx > 0) ? -idx : idx;
64 
65  Init(w, h);
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Init window frame for log messages.
70 
71 void TProofProgressLog::Init(Int_t w, Int_t h)
72 {
73  fProofLog = 0;
74  fFullText = kFALSE;
75  fTextType = kStd;
76  // use hierarchical cleaning
77  SetCleanup(kDeepCleanup);
78 
79  //The text window
80  TGHorizontalFrame *htotal = new TGHorizontalFrame(this, w, h);
81  TGVerticalFrame *vtextbox = new TGVerticalFrame(htotal, w, h);
82  //fText = new TGTextView(this, w, h);
83  fText = new TGTextView(vtextbox, w, h);
84  vtextbox->AddFrame(fText, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 3, 3, 3, 3));
85 
86  //The frame for choosing workers
87  fVworkers = new TGVerticalFrame(htotal);
88  // URL choice
89  TGLabel *laburl = new TGLabel(fVworkers, "Enter cluster URL:");
90  fVworkers->AddFrame(laburl, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 2, 2, 2));
91  fUrlText = new TGTextEntry(fVworkers);
92  fUrlText->SetText(fSessionUrl.Data());
93  fVworkers->AddFrame(fUrlText, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 0, 0, 0));
94  //The lower row of number entries and buttons
95  TGHorizontalFrame *hfurlbox = new TGHorizontalFrame(fVworkers, 20, 20);
96  TGLabel *labsess = new TGLabel(hfurlbox, "Enter session:");
97  hfurlbox->AddFrame(labsess, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 5, 2, 2, 2));
98  fSessNum = new TGNumberEntry(hfurlbox, 0, 5, -1, TGNumberFormat::kNESInteger);
99  fSessNum->SetLimits(TGNumberFormat::kNELLimitMax, 0., 0.);
100  fSessNum->SetIntNumber(0);
101  fSessNum->GetNumberEntry()->SetToolTipText("Use 0 for the last known one,"
102  " negative numbers for the previous ones, e.g. -1 for the last-but-one");
103  hfurlbox->AddFrame(fSessNum, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 0, 0, 0));
104  fUrlButton = new TGTextButton(hfurlbox, "Get logs info");
105  fUrlButton->Connect("Clicked()", "TProofProgressLog", this, "Rebuild()");
106  hfurlbox->AddFrame(fUrlButton, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
107  fVworkers->AddFrame(hfurlbox, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
108 
109  TGNumberEntry *nent = new TGNumberEntry(hfurlbox);
110  fVworkers->AddFrame(nent, new TGLayoutHints(kLHintsTop | kLHintsLeft, 4, 0, 0, 0));
111 
112  //The list of workers
113  fLogList = 0;
114  BuildLogList(kTRUE);
115  fLogList->Resize(102,52);
116  fLogList->SetMultipleSelections(kTRUE);
117 
118  //The SelectAll/ClearAll buttons
119  TGHorizontalFrame *hfselbox = new TGHorizontalFrame(fVworkers, 20, 20);
120  TGLabel *label1 = new TGLabel(hfselbox,"Choose workers:");
121  hfselbox->AddFrame(label1, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 0, 0, 0, 0));
122  TGTextButton *selall = new TGTextButton(hfselbox, " &All ");
123  selall->Connect("Clicked()", "TProofProgressLog", this, "Select(=0)");
124  hfselbox->AddFrame(selall, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
125  TGTextButton *clearall = new TGTextButton(hfselbox, " &Clear ");
126  clearall->Connect("Clicked()", "TProofProgressLog", this, "Select(=1)");
127  hfselbox->AddFrame(clearall, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 10, 0, 0, 0));
128 
129  //select the defaut actives to start with
130  Select(0, kFALSE);
131 
132  //Display button
133  fLogNew = new TGTextButton(fVworkers, "&Display");
134  fLogNew->Connect("Clicked()", "TProofProgressLog", this, "DoLog(=kFALSE)");
135  //fLogNew->Resize(102, 20);
136  // fLogNew->SetMargins(1, 1, 0, 1);
137  fLogNew->SetTextColor(0xffffff, kFALSE);
138  fLogNew->SetBackgroundColor(0x000044);
139  fVworkers->AddFrame(hfselbox, new TGLayoutHints(kLHintsExpandX | kLHintsTop, 5, 2, 2, 2));
140  fVworkers->AddFrame(fLogList, new TGLayoutHints(kLHintsExpandX | kLHintsTop | kLHintsExpandY, 2, 2, 5, 2));
141  fVworkers->AddFrame(fLogNew, new TGLayoutHints(kLHintsExpandX | kLHintsTop , 2, 2, 1, 5));
142 
143  htotal->AddFrame(fVworkers, new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandY, 2, 2, 2, 2));
144 
145  //The lower row of number entries and buttons
146  TGHorizontalFrame *hflogbox = new TGHorizontalFrame(vtextbox, 550, 20);
147  fClose = new TGTextButton(hflogbox, " &Close ");
148  fClose->Connect("Clicked()", "TProofProgressLog", this, "CloseWindow()");
149  hflogbox->AddFrame(fClose, new TGLayoutHints(kLHintsCenterY |
150  kLHintsRight, 10, 2, 2, 2));
151 
152  //Saving to a file controls
153  fSave = new TGTextButton(hflogbox, "&Save");
154  fSave->Connect("Clicked()", "TProofProgressLog", this, "SaveToFile()");
155  hflogbox->AddFrame(fSave, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 4, 0, 0, 0));
156  fFileName = new TGTextEntry(hflogbox);
157  fFileName->SetText("<session-tag>.log");
158  hflogbox->AddFrame(fFileName, new TGLayoutHints(kLHintsCenterY | kLHintsRight | kLHintsExpandX));
159  TGLabel *label10 = new TGLabel(hflogbox, "Save to a file:");
160  hflogbox->AddFrame(label10, new TGLayoutHints(kLHintsCenterY | kLHintsRight, 50, 2, 2, 2));
161 
162  //Choose the number of lines to display
163  TGVerticalFrame *vlines = new TGVerticalFrame(hflogbox);
164  TGHorizontalFrame *vlines_buttons = new TGHorizontalFrame(vlines);
165  TGLabel *label2 = new TGLabel(vlines_buttons, "Lines:");
166  vlines_buttons->AddFrame(label2, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
167 
168  fAllLines = new TGCheckButton(vlines_buttons, "all");
169  fAllLines->SetToolTipText("Retrieve all lines (service messages excluded)");
170  fAllLines->SetState(kButtonUp);
171  fAllLines->Connect("Clicked()", "TProofProgressLog", this, "NoLineEntry()");
172  vlines_buttons->AddFrame(fAllLines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
173 
174  fRawLines = new TGCheckButton(vlines_buttons, "svcmsg");
175  fRawLines->SetToolTipText("Retrieve all type of lines, service messages included");
176  fRawLines->SetState(kButtonUp);
177  vlines_buttons->AddFrame(fRawLines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
178 
179  TGLabel *label11 = new TGLabel(vlines_buttons, "From");
180  vlines_buttons->AddFrame(label11, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
181 
182  fLinesFrom = new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
183  // coverity[negative_returns]: no problem with -100, the format is kNESInteger
184  fLinesFrom->SetIntNumber(-100);
185  fLinesFrom->GetNumberEntry()->SetToolTipText("Negative values indicate \"tail\" action");
186 
187 
188  vlines_buttons->AddFrame(fLinesFrom, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
189 
190  TGLabel *label3 = new TGLabel(vlines_buttons, "to");
191  vlines_buttons->AddFrame(label3, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
192  fLinesTo = new TGNumberEntry(vlines_buttons, 0, 5, -1, TGNumberFormat::kNESInteger);
193  vlines_buttons->AddFrame(fLinesTo, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
194  vlines->AddFrame(vlines_buttons, new TGLayoutHints(kLHintsCenterY));
195  hflogbox->AddFrame(vlines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
196 
197  //
198  // Lowest line, with filter (grep or cmd pipe) controls
199  //
200 
201  TGHorizontalFrame *hfgrepbox = new TGHorizontalFrame(vtextbox, 550, 20);
202 
203  // Grep/pipe label, textbox and button
204  fGrepLabel = new TGLabel(hfgrepbox, "");
205  hfgrepbox->AddFrame(fGrepLabel, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
206  fGrepText = new TGTextEntry(hfgrepbox);
207  {
208  TGDimension dim = fGrepText->GetDefaultSize();
209  fGrepText->SetDefaultSize(400, dim.fHeight);
210  }
211  hfgrepbox->AddFrame(fGrepText, new TGLayoutHints( kLHintsCenterY | kLHintsLeft | kLHintsExpandX));
212  fGrepButton = new TGTextButton(hfgrepbox, "Filter");
213  fGrepButton->Connect("Clicked()", "TProofProgressLog", this, "DoLog(=kTRUE)");
214  hfgrepbox->AddFrame(fGrepButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4, 10, 0, 0)); // l r t b
215 
216  // Checkbox for inverting selection or giving a pipe command
217  fGrepCheckInv = new TGCheckButton(hfgrepbox, "invert match");
218  fGrepCheckInv->Connect("Clicked()", "TProofProgressLog", this, "SetGrepView()");
219  hfgrepbox->AddFrame(fGrepCheckInv, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
220 
221  fGrepCheckCmd = new TGCheckButton(hfgrepbox, "is a pipe command");
222  fGrepCheckCmd->Connect("Clicked()", "TProofProgressLog", this, "SetGrepView()");
223  hfgrepbox->AddFrame(fGrepCheckCmd, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
224 
225  // fRawLines->SetToolTipText("Retrieve all type of lines, service messages included");
226  // fRawLines->SetState(kButtonUp);
227  // vlines_buttons->AddFrame(fRawLines, new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 2, 2, 2, 2));
228 
229  //
230  // Add frames to the global picture
231  //
232 
233  vtextbox->AddFrame(hflogbox, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
234  vtextbox->AddFrame(hfgrepbox, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 2, 2, 2, 2));
235  htotal->AddFrame(vtextbox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY | kLHintsRight, 3, 3, 3, 3));
236  AddFrame(htotal, new TGLayoutHints(kLHintsExpandX |
237  kLHintsExpandY, 3, 3, 3, 3));
238  SetGrepView();
239  MapSubwindows();
240  Resize();
241  CenterOnParent();
242  Popup();
243 }
244 
245 ////////////////////////////////////////////////////////////////////////////////
246 /// Destructor
247 
248 TProofProgressLog::~TProofProgressLog()
249 {
250  // Cleanup the log object
251  SafeDelete(fProofLog);
252 
253  // Detach from owner dialog
254  if (fDialog) {
255  fDialog->fLogWindow = 0;
256  fDialog->fProof->Disconnect("LogMessage(const char*,Bool_t)", this,
257  "LogMessage(const char*,Bool_t)");
258  }
259 }
260 
261 ////////////////////////////////////////////////////////////////////////////////
262 /// Show log window.
263 
264 void TProofProgressLog::Popup()
265 {
266  MapWindow();
267 }
268 
269 ////////////////////////////////////////////////////////////////////////////////
270 /// Clear log window.
271 
272 void TProofProgressLog::Clear(Option_t *)
273 {
274  if (fText)
275  fText->Clear();
276 }
277 
278 ////////////////////////////////////////////////////////////////////////////////
279 /// Load a text buffer in the window.
280 
281 void TProofProgressLog::LoadBuffer(const char *buffer)
282 {
283  if (fText)
284  fText->LoadBuffer(buffer);
285 }
286 
287 ////////////////////////////////////////////////////////////////////////////////
288 /// Load a file in the window.
289 
290 void TProofProgressLog::LoadFile(const char *file)
291 {
292  if (fText)
293  fText->LoadFile(file);
294 }
295 
296 ////////////////////////////////////////////////////////////////////////////////
297 /// Add text to the window.
298 
299 void TProofProgressLog::AddBuffer(const char *buffer)
300 {
301  if (fText) {
302  TGText txt;
303  txt.LoadBuffer(buffer);
304  fText->AddText(&txt);
305  }
306 }
307 
308 ////////////////////////////////////////////////////////////////////////////////
309 /// Handle close button or when closed via window manager action.
310 
311 void TProofProgressLog::CloseWindow()
312 {
313  DeleteWindow();
314 }
315 
316 ////////////////////////////////////////////////////////////////////////////////
317 /// Build the list of workers. For this, extract the logs and take the names
318 /// of TProofLogElements
319 
320 void TProofProgressLog::BuildLogList(Bool_t create)
321 {
322  // Set title
323  TString title;
324  title.Form("PROOF - Processing logs for session 'undefined'");
325  SetWindowName(title.Data());
326  SetIconName(title.Data());
327 
328  // Create the list-box now
329  if (create) {
330  if (fLogList) delete fLogList;
331  fLogList = new TGListBox(fVworkers);
332  } else {
333  // Reset
334  Int_t nent = fLogList->GetNumberOfEntries();
335  fLogList->RemoveEntries(0,nent);
336  fLogList->Layout();
337  }
338 
339  if (fSessionUrl.IsNull()) {
340  if (gDebug > 0)
341  Info("BuildLogList", "sesssion URL undefined - do nothing");
342  return;
343  }
344  TProofMgr *mgr = TProof::Mgr(fSessionUrl.Data());
345  if (!mgr || !mgr->IsValid()) {
346  Warning("BuildLogList", "unable open a manager connection to %s",
347  fSessionUrl.Data());
348  return;
349  }
350  if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx,"NR"))) {
351  Warning("BuildLogList", "unable to get logs from %s",
352  fSessionUrl.Data());
353  return;
354  }
355  // Set title
356  title.Form("PROOF - Processing logs for session '%s', started on %s at %s",
357  fProofLog->GetName(), fProofLog->StartTime().AsString(),
358  fProofLog->GetTitle());
359  SetWindowName(title.Data());
360  SetIconName(title.Data());
361 
362  TList *elem = fProofLog->GetListOfLogs();
363  TIter next(elem);
364  TProofLogElem *pe = 0;
365 
366  Int_t is = 0;
367  TGLBEntry *ent = 0;
368  TString buf;
369  while ((pe=(TProofLogElem*)next())){
370  TUrl url(pe->GetTitle());
371  buf.Form("%s %s", pe->GetName(), url.GetHost());
372  fLogList->AddEntry(buf.Data(), is);
373  if ((ent = fLogList->FindEntry(buf.Data()))) {
374  ent->ResetBit(kLogElemFilled);
375  ent->ResetBit(kDefaultActive);
376  if (!(pe->IsWorker())) ent->SetBit(kDefaultActive);
377  }
378  is++;
379  }
380 
381  // Done
382  return;
383 }
384 
385 ////////////////////////////////////////////////////////////////////////////////
386 /// Display logs. 'grep' is set to kTRUE if it is invoked by pressing the
387 /// 'Filter' button.
388 
389 void TProofProgressLog::DoLog(Bool_t grep)
390 {
391  Clear();
392 
393  if (!fGrepText) {
394  Warning("DoLog", "no text: do nothing!");
395  return;
396  }
397 
398  TString greptext = fGrepText->GetText();
399  greptext.Remove(TString::kBoth, ' ');
400  if (greptext.IsNull()) {
401  grep = kFALSE;
402  }
403  else if (!fGrepCheckCmd->IsOn()) {
404  // Not a command: sanitize string
405  TPMERegexp san("(^|[^\\\\])([^a-zA-Z0-9_=\\\\/.-])");
406  while ( san.Substitute(greptext, "$1\\$2") > 0 );
407  }
408 
409  Int_t from, to;
410  if (fAllLines->IsOn()){
411  from = 0;
412  to = -1;
413  } else {
414  from = fLinesFrom->GetIntNumber();
415  to = fLinesTo->GetIntNumber();
416  }
417 
418  // Create the TProofLog instance
419  if (!fProofLog) {
420  TProofMgr *mgr = 0;
421  if ((mgr = TProof::Mgr(fSessionUrl.Data()))) {
422  if (!(fProofLog = mgr->GetSessionLogs(fSessionIdx, "NR"))) {
423  Warning("DoLog", "unable to instantiate TProofLog for %s",
424  fSessionUrl.Data());
425  }
426  } else {
427  Warning("DoLog", "unable to instantiate a TProofMgr for %s",
428  fSessionUrl.Data());
429  }
430  }
431 
432  // Pipe command for filtering
433  TString pipeCommand;
434 
435  // Filter out SvcMsg
436  if (!fRawLines->IsOn()) {
437  pipeCommand = "grep -v \"| SvcMsg\"";
438  }
439 
440  // Default is not retrieving
441  Bool_t retrieve = kFALSE;
442  if (!grep) {
443  // Not invoked via 'Filter' button
444  if (!fFullText ||
445  ((fTextType != kRaw && fRawLines->IsOn()) ||
446  (fTextType != kStd && !fRawLines->IsOn())) ||
447  (fDialog && fDialog->fStatus==TProofProgressDialog::kRunning)) {
448  retrieve = kTRUE;
449  if (fRawLines->IsOn()) {
450  fTextType = kRaw;
451  } else {
452  fTextType = kStd;
453  }
454  if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
455  fFullText = kTRUE;
456  }
457  } else {
458  retrieve = kTRUE;
459  fTextType = kGrep;
460 
461  if (!pipeCommand.IsNull())
462  pipeCommand.Append('|');
463 
464  if (fGrepCheckCmd->IsOn()) {
465  pipeCommand.Append(greptext);
466  }
467  else {
468  pipeCommand.Append("grep ");
469  if (fGrepCheckInv->IsOn())
470  pipeCommand.Append("-v ");
471  pipeCommand.Append("-- ");
472  pipeCommand.Append(greptext); // sanitized
473  }
474 
475  if (fDialog && fDialog->fStatus != TProofProgressDialog::kRunning)
476  fFullText = kTRUE;
477  }
478 
479  // Display now
480  if (fProofLog) {
481  TList *selected = new TList;
482  fLogList->GetSelectedEntries(selected);
483  TIter next(selected);
484  TGTextLBEntry *selentry;
485  Bool_t logonly = fProofLog->LogToBox();
486  fProofLog->SetLogToBox(kTRUE);
487 
488  fProofLog->Connect("Prt(const char*)", "TProofProgressLog",
489  this, "LogMessage(const char*, Bool_t)");
490  while ((selentry=(TGTextLBEntry*)next())){
491  TString ord = selentry->GetText()->GetString();
492  Int_t is = ord.Index(" ");
493  if (is != kNPOS) ord.Remove(is);
494  if (retrieve || !selentry->TestBit(kLogElemFilled)) {
495  pipeCommand.Prepend('|');
496  if (fTextType == kRaw) {
497  if (gDebug >= 2)
498  Info("DoLog", "Retrieving unfiltered log for %s", ord.Data());
499  fProofLog->Retrieve(ord.Data(), TProofLog::kTrailing, 0, 0);
500  }
501  else {
502  if (gDebug >= 2)
503  Info("DoLog", "Retrieving log for %s filtered with %s",
504  ord.Data(), pipeCommand.Data());
505  fProofLog->Retrieve(ord.Data(), TProofLog::kGrep, 0, pipeCommand.Data());
506  }
507  selentry->SetBit(kLogElemFilled);
508  }
509  fProofLog->Display(ord.Data(), from, to);
510  }
511  fProofLog->SetLogToBox(logonly);
512  fProofLog->Disconnect("Prt(const char*)", this, "LogMessage(const char*, Bool_t)");
513  delete selected;
514  }
515 }
516 
517 ////////////////////////////////////////////////////////////////////////////////
518 /// Load/append a log msg in the log frame, if open
519 
520 void TProofProgressLog::LogMessage(const char *msg, Bool_t all)
521 {
522  if (all) {
523  // load buffer
524  LoadBuffer(msg);
525  } else {
526  // append
527  AddBuffer(msg);
528  }
529 }
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 ///Save the logs to a file
533 ///Only the name of the file is taken, no expansion
534 
535 void TProofProgressLog::SaveToFile()
536 {
537  if (!fProofLog) DoLog();
538 
539  // File name: the default is <session-tag>.log
540  TString filename = fFileName->GetText();
541  if (filename.IsNull() || filename == "<session-tag>.log") {
542  filename = (fDialog && fDialog->fProof) ?
543  TString::Format("%s.log", fDialog->fProof->GetName()) :
544  TString("proof.log");
545  }
546 
547  TList *selected = new TList;
548  fLogList->GetSelectedEntries(selected);
549  TIter next(selected);
550  TGTextLBEntry *selentry;
551  Bool_t writemode=kTRUE;
552  const char *option;
553  TString ord;
554  while ((selentry=(TGTextLBEntry*)next())){
555  ord = selentry->GetText()->GetString();
556  Int_t isp = ord.Index(' ');
557  if (isp != kNPOS) ord.Remove(isp);
558  //open the file in "w" mode for the first time
559  option = writemode ? "w" : "a";
560  fProofLog->Save(ord.Data(), filename.Data(), option);
561  writemode=kFALSE;
562  }
563 
564  Info("SaveToFile", "logs saved to file %s", filename.Data());
565  return;
566 }
567 
568 ////////////////////////////////////////////////////////////////////////////////
569 /// Sets the view of grep filters according to the value of checkboxes
570 
571 void TProofProgressLog::SetGrepView()
572 {
573  if (fGrepCheckCmd->IsOn()) {
574  fGrepLabel->SetText("Pipe log through command:");
575  fGrepCheckInv->SetDisabledAndSelected(kFALSE);
576  }
577  else {
578  fGrepLabel->SetText("Grep:");
579  Bool_t u = fGrepCheckInv->IsOn();
580  fGrepCheckInv->SetEnabled(kTRUE);
581  if (u) {
582  fGrepLabel->SetText("Show lines not matching:");
583  fGrepCheckInv->SetState(kButtonDown);
584  }
585  else {
586  fGrepLabel->SetText("Show lines matching:");
587  fGrepCheckInv->SetState(kButtonUp);
588  }
589  }
590 
591  // Ugly but necessary const_cast
592  TGFrame *frame = dynamic_cast<TGFrame *>( const_cast<TGWindow *>(fGrepLabel->GetParent()) );
593  if (frame) frame->Layout();
594 
595 }
596 
597 ////////////////////////////////////////////////////////////////////////////////
598 ///Enable/disable the line number entry
599 
600 void TProofProgressLog::NoLineEntry()
601 {
602  if (fAllLines->IsOn()){
603  //disable the line number entry
604  fLinesFrom->SetState(kFALSE);
605  fLinesTo->SetState(kFALSE);
606  } else {
607  fLinesFrom->SetState(kTRUE);
608  fLinesTo->SetState(kTRUE);
609  }
610 }
611 
612 ////////////////////////////////////////////////////////////////////////////////
613 ///actions of select all/clear all button
614 
615 void TProofProgressLog::Select(Int_t id, Bool_t all)
616 {
617  Int_t nen = fLogList->GetNumberOfEntries();
618  Bool_t sel = id ? 0 : 1;
619 
620  TGLBEntry *ent = 0;
621  for (Int_t ie=0; ie<nen; ie++) {
622  if (all) {
623  fLogList->Select(ie, sel);
624  } else {
625  if ((ent = fLogList->GetEntry(ie))) {
626  if (ent->TestBit(kDefaultActive)) fLogList->Select(ie, sel);
627  }
628  }
629  }
630 }
631 
632 
633 ////////////////////////////////////////////////////////////////////////////////
634 /// Rebuild the log info for a new entered session
635 
636 void TProofProgressLog::Rebuild()
637 {
638  // Check if we need to remake the TProofLog object
639  Bool_t sameurl = kFALSE;
640  TUrl url(fUrlText->GetText());
641  TUrl urlref(fSessionUrl.Data());
642  if (!strcmp(url.GetHostFQDN(), urlref.GetHostFQDN())) {
643  if (url.GetPort() == urlref.GetPort()) {
644  if (!strcmp(url.GetUser(), urlref.GetUser())) {
645  sameurl = kTRUE;
646  }
647  }
648  }
649  Int_t idx = 0;
650  if (sameurl) {
651  idx = fSessNum->GetIntNumber();
652  if (idx == fSessionIdx) {
653  Info("Rebuild", "same paremeters {%s, %s}, {%d, %d}: no need to rebuild TProofLog",
654  url.GetUrl(), urlref.GetUrl(), idx, fSessionIdx);
655  return;
656  }
657  }
658  // Cleanup current TProofLog
659  if (fProofLog) delete fProofLog;
660 
661  // Set new parameters
662  fSessionUrl = fUrlText->GetText();
663  fSessionIdx = idx;
664 
665  // Rebuild the list now
666  BuildLogList(kFALSE);
667 
668  // Select the defaut actives to start with
669  Select(0, kFALSE);
670  // Redraw
671  fLogList->Layout();
672 
673  // Done
674  return;
675 }