#include "TFile.h"
#include "TMacro.h"
#include "TProofLog.h"
#include "TProofMgr.h"
#include "TObjString.h"
#include "TUrl.h"
ClassImp(TProofLog)
TProofLog::TProofLog(const char *stag, const char *url, TProofMgr *mgr)
: TNamed(stag, url)
{
SetLogToBox();
fFILE = 0;
fElem = new TList;
fElem->SetOwner();
fMgr = mgr;
}
TProofLog::~TProofLog()
{
SafeDelete(fElem);
}
TProofLogElem *TProofLog::Add(const char *ord, const char *url)
{
TProofLogElem *ple = new TProofLogElem(ord, url, this);
fElem->Add(ple);
return ple;
}
Int_t TProofLog::Retrieve(const char *ord, TProofLog::ERetrieveOpt opt,
const char *fname, const char *pattern)
{
if (opt == TProofLog::kGrep && (!pattern || strlen(pattern) <= 0)) {
Error("Retrieve", "option 'Grep' requires a pattern");
return -1;
}
Int_t nel = (ord[0] == '*') ? fElem->GetSize() : 1;
TIter nxe(fElem);
TProofLogElem *ple = 0;
Int_t nd = 0, nb = 0;
while ((ple = (TProofLogElem *) nxe())) {
if (ord[0] == '*' || !strcmp(ord, ple->GetName())) {
if (ple->Retrieve(opt, pattern) != 0) {
nb++;
} else {
nd++;
}
Int_t frac = (nd + nb) / nel * 100;
Prt(Form("Retrieving logs: %d ok, %d not ok (%d %% processed) \r", nd, nb, frac));
}
}
Prt("\n");
if (fname)
Save(ord, fname);
return 0;
}
void TProofLog::Display(const char *ord, Int_t from, Int_t to)
{
if (ord[0] == '*') {
Int_t nel = (fElem) ? fElem->GetSize() : 0;
Prt(Form("\n// --------- Displaying PROOF Session logs --------\n"));
Prt(Form("// Server: %s \n", GetTitle()));
Prt(Form("// Session: %s \n", GetName()));
Prt(Form("// # of elements: %d \n", nel));
Prt(Form("// ------------------------------------------------\n\n"));
}
TIter nxe(fElem);
TProofLogElem *ple = 0;
while ((ple = (TProofLogElem *) nxe())) {
if (ord[0] == '*' || !strcmp(ord, ple->GetName()))
ple->Display(from, to);
}
if (ord[0] == '*')
Prt(Form("// --------- End of PROOF Session logs ---------\n"));
}
void TProofLog::Print(Option_t *opt) const
{
Int_t nel = (fElem) ? fElem->GetSize() : 0;
fprintf(stderr,Form("// --------- PROOF Session logs object --------\n"));
fprintf(stderr,Form("// Server: %s \n", GetTitle()));
fprintf(stderr,Form("// Session: %s \n", GetName()));
fprintf(stderr,Form("// # of elements: %d \n", nel));
fprintf(stderr,Form("// --------------------------------------------\n"));
TIter nxe(fElem);
TProofLogElem *ple = 0;
while ((ple = (TProofLogElem *) nxe()))
ple->Print(opt);
fprintf(stderr,Form("// --------------------------------------------\n"));
}
void TProofLog::Prt(const char *what)
{
if (what) {
if (LogToBox()) {
EmitVA("Prt(const char*)", 2, what, kFALSE);
} else {
FILE *where = (fFILE) ? (FILE *)fFILE : stderr;
fprintf(where, "%s\n", what);
}
}
}
Int_t TProofLog::Save(const char *ord, const char *fname, Option_t *opt)
{
if (!fname) {
Warning("Save", "filename undefined - do nothing");
return -1;
}
TString option = opt;
option.ToLower();
FILE *fout=0;
if (option.Contains("a")){
fout = fopen(fname, "a");
} else {
fout = fopen(fname, "w");
}
if (!fout) {
Warning("Save", "file could not be opened - do nothing");
return -1;
}
fFILE = (void *) fout;
if (ord[0] == '*') {
Int_t nel = (fElem) ? fElem->GetSize() : 0;
Prt(Form("\n// --------- Displaying PROOF Session logs --------\n"));
Prt(Form("// Server: %s \n", GetTitle()));
Prt(Form("// Session: %s \n", GetName()));
Prt(Form("// # of elements: %d \n", nel));
Prt(Form("// ------------------------------------------------\n\n"));
}
TIter nxe(fElem);
TProofLogElem *ple = 0;
while ((ple = (TProofLogElem *) nxe())) {
if (ord[0] == '*' || !strcmp(ord, ple->GetName()))
ple->Display(0);
}
if (ord[0] == '*') {
Prt(Form("// --------- End of PROOF Session logs ---------\n"));
}
fclose(fout);
fFILE = 0;
return 0;
}
Int_t TProofLog::Grep(const char *txt, Int_t from)
{
if (!txt || strlen(txt) <= 0) {
Warning("Grep", "text to be searched for is undefined - do nothing");
return -1;
}
Int_t nel = (fElem) ? fElem->GetSize() : 0;
Prt(Form("\n// --------- Search in PROOF Session logs --------\n"));
Prt(Form("// Server: %s \n", GetTitle()));
Prt(Form("// Session: %s \n", GetName()));
Prt(Form("// # of elements: %d \n", nel));
Prt(Form("// Text searched for: \"%s\"", txt));
if (from > 1)
Prt(Form("// starting from line %d \n", from));
else
Prt("\n");
Prt(Form("// ------------------------------------------------\n"));
TIter nxe(fElem);
TProofLogElem *ple = 0;
while ((ple = (TProofLogElem *) nxe())) {
TString res;
Int_t nf = ple->Grep(txt, res, from);
if (nf > 0)
Prt(Form("// Ord: %s - line(s): %s\n", ple->GetName(), res.Data()));
}
Prt(Form("// ------------------------------------------------\n"));
return 0;
}
void TProofLog::SetMaxTransferSize(Long64_t maxsz)
{
TProofLogElem::SetMaxTransferSize(maxsz);
}
Long64_t TProofLogElem::fgMaxTransferSize = 100000;
TProofLogElem::TProofLogElem(const char *ord, const char *url,
TProofLog *logger)
: TNamed(ord, url)
{
fLogger = logger;
fMacro = new TMacro;
fSize = -1;
fFrom = -1;
fTo = -1;
}
TProofLogElem::~TProofLogElem()
{
SafeDelete(fMacro);
}
Long64_t TProofLogElem::GetMaxTransferSize()
{
return fgMaxTransferSize;
}
void TProofLogElem::SetMaxTransferSize(Long64_t maxsz)
{
fgMaxTransferSize = maxsz;
}
Int_t TProofLogElem::Retrieve(TProofLog::ERetrieveOpt opt, const char *pattern)
{
if (!fLogger->fMgr || !fLogger->fMgr->IsValid()) {
Warning("Retrieve","No reference manager: corruption?");
return -1;
}
if (opt == TProofLog::kAll) {
fFrom = 0;
fTo = -1;
} else if (opt == TProofLog::kLeading) {
fFrom = 0;
fTo = fgMaxTransferSize;
} else if (opt == TProofLog::kGrep) {
if (!pattern || strlen(pattern) <= 0) {
Error("Retrieve", "option 'Grep' requires a pattern");
return -1;
}
} else {
fFrom = -fgMaxTransferSize;
fTo = -1;
}
SafeDelete(fMacro);
fMacro = new TMacro;
Long64_t len = (fTo > fFrom) ? fTo - fFrom : -1;
TObjString *os = 0;
if (fLogger->fMgr) {
if (opt == TProofLog::kGrep)
os = fLogger->fMgr->ReadBuffer(GetTitle(), pattern);
else
os = fLogger->fMgr->ReadBuffer(GetTitle(), fFrom, len);
}
if (os) {
TString ln;
Ssiz_t from = 0;
while (os->String().Tokenize(ln, from, "\n"))
fMacro->AddLine(ln.Data());
delete os;
}
if (strstr(GetTitle(), "worker-")) {
fRole = "worker";
} else {
if (strchr(GetName(), '.')) {
fRole = "submaster";
} else {
fRole = "master";
}
}
return 0;
}
void TProofLogElem::Display(Int_t from, Int_t to)
{
Int_t nls = (fMacro->GetListOfLines()) ?
fMacro->GetListOfLines()->GetSize() : 0;
Int_t i = 0;
Int_t ie = (to > -1 && to < nls) ? to : nls;
if (from > 1) {
if (from <= nls)
i = from - 1;
} else if (from < 0) {
if (-from <= nls)
i = nls + from;
ie = nls;
}
Prt(Form("// --------- Start of element log -----------------\n"));
Prt(Form("// Ordinal: %s (role: %s)\n", GetName(), fRole.Data()));
TString path(GetTitle());
Int_t ic = path.Index(",");
if (ic != kNPOS) {
TString subm(path);
path.Remove(0, ic+1);
subm.Remove(ic);
Prt(Form("// Submaster: %s \n", subm.Data()));
}
Prt(Form("// Path: %s \n", path.Data()));
Prt(Form("// # of retrieved lines: %d ", nls));
if (i > 0 || ie < nls)
Prt(Form("(displaying lines: %d -> %d)\n", i+1, ie));
else
Prt("\n");
Prt(Form("// ------------------------------------------------\n"));
for ( ; i < ie; i++) {
TObjString *os = (TObjString *) fMacro->GetListOfLines()->At(i);
if (os)
Prt(Form("%s", os->GetName()));
}
Prt(Form("// --------- End of element log -------------------\n\n"));
}
void TProofLogElem::Print(Option_t *) const
{
Int_t nls = (fMacro->GetListOfLines()) ?
fMacro->GetListOfLines()->GetSize() : 0;
const char *role = (strstr(GetTitle(), "worker-")) ? "worker" : "master";
fprintf(stderr, Form("Ord: %s Host: Role: %s lines: %d\n", GetName(), role, nls));
}
void TProofLogElem::Prt(const char *what)
{
if (fLogger)
fLogger->Prt(what);
}
Int_t TProofLogElem::Grep(const char *txt, TString &res, Int_t from)
{
Int_t nls = (fMacro->GetListOfLines()) ?
fMacro->GetListOfLines()->GetSize() : 0;
Int_t nf = 0;
Int_t i = (from > 0) ? (from - 1) : 0;
for( ; i < nls; i++) {
TObjString *os = (TObjString *) fMacro->GetListOfLines()->At(i);
if (os) {
if (strstr(os->GetName(), txt)) {
if (res.Length() > 0)
res += " ";
res += (i + 1);
nf++;
}
}
}
return nf;
}
Last change: Wed Aug 6 12:15:23 2008
Last generated: 2008-08-06 12:15
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.