#include "TStatus.h"
#include "Riostream.h"
#include "TClass.h"
#include "TProofDebug.h"
ClassImp(TStatus)
TStatus::TStatus() : fIter(&fMsgs), fExitStatus(-1),
fVirtMemMax(-1), fResMemMax(-1),
fVirtMaxMst(-1), fResMaxMst(-1)
{
SetName("PROOF_Status");
fMsgs.SetOwner(kTRUE);
fInfoMsgs.SetOwner(kTRUE);
ResetBit(TStatus::kNotOk);
}
void TStatus::Add(const char *mesg)
{
fMsgs.Add(new TObjString(mesg));
SetBit(TStatus::kNotOk);
Reset();
}
void TStatus::AddInfo(const char *mesg)
{
fInfoMsgs.Add(new TObjString(mesg));
}
Int_t TStatus::Merge(TCollection *li)
{
TIter stats(li);
PDB(kOutput,1)
Info("Merge", "start: max virtual memory: %.2f MB \tmax resident memory: %.2f MB ",
GetVirtMemMax()/1024., GetResMemMax()/1024.);
while (TObject *obj = stats()) {
TStatus *s = dynamic_cast<TStatus*>(obj);
if (s == 0) continue;
TObjString *os = 0;
TIter nxem(&(s->fMsgs));
while ((os = (TObjString *) nxem())) {
Add(os->GetName());
}
TIter nxwm(&(s->fInfoMsgs));
while ((os = (TObjString *) nxwm())) {
if (!fInfoMsgs.FindObject(os->GetName()))
AddInfo(os->GetName());
}
SetMemValues(s->GetVirtMemMax(), s->GetResMemMax());
SetMemValues(s->GetVirtMemMax(kTRUE), s->GetResMemMax(kTRUE), kTRUE);
PDB(kOutput,1)
Info("Merge", "during: max virtual memory: %.2f MB \t"
"max resident memory: %.2f MB ",
GetVirtMemMax()/1024., GetResMemMax()/1024.);
if (GetVirtMemMax(kTRUE) > 0) {
PDB(kOutput,1)
Info("Merge", "during: max master virtual memory: %.2f MB \t"
"max master resident memory: %.2f MB ",
GetVirtMemMax(kTRUE)/1024., GetResMemMax(kTRUE)/1024.);
}
}
return fMsgs.GetSize();
}
void TStatus::Print(Option_t * ) const
{
Printf("OBJ: %s\t%s\t%s", IsA()->GetName(), GetName(), (IsOk() ? "OK" : "ERROR"));
TObjString *os = 0;
if (fMsgs.GetSize() > 0) {
Printf("\n Errors:");
TIter nxem(&fMsgs);
while ((os = (TObjString *) nxem()))
Printf("\t%s",os->GetName());
Printf(" ");
}
if (fInfoMsgs.GetSize() > 0) {
Printf("\n Infos:");
TIter nxem(&fInfoMsgs);
while ((os = (TObjString *) nxem()))
Printf("\t%s",os->GetName());
Printf(" ");
}
Printf(" Max worker virtual memory: %.2f MB \tMax worker resident memory: %.2f MB ",
GetVirtMemMax()/1024., GetResMemMax()/1024.);
Printf(" Max master virtual memory: %.2f MB \tMax master resident memory: %.2f MB ",
GetVirtMemMax(kTRUE)/1024., GetResMemMax(kTRUE)/1024.);
}
void TStatus::Reset()
{
fIter.Reset();
}
const char *TStatus::NextMesg()
{
TObjString *os = (TObjString *) fIter();
if (os) return os->GetName();
return 0;
}
void TStatus::SetMemValues(Long_t vmem, Long_t rmem, Bool_t master)
{
if (master) {
if (vmem > 0. && (fVirtMaxMst < 0. || vmem > fVirtMaxMst)) fVirtMaxMst = vmem;
if (rmem > 0. && (fResMaxMst < 0. || rmem > fResMaxMst)) fResMaxMst = rmem;
} else {
if (vmem > 0. && (fVirtMemMax < 0. || vmem > fVirtMemMax)) fVirtMemMax = vmem;
if (rmem > 0. && (fResMemMax < 0. || rmem > fResMemMax)) fResMemMax = rmem;
}
}
void TStatus::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
if (R__v > 4) {
R__b.ReadClassBuffer(TStatus::Class(), this, R__v, R__s, R__c);
} else {
TNamed::Streamer(R__b);
std::set<std::string> msgs;
TClass *cl = TClass::GetClass("set<string>");
if (cl) {
UInt_t SS__s = 0, SS__c = 0;
UInt_t SS__v = cl->GetClassVersion();
R__b.ReadClassBuffer(cl, &msgs, SS__v, SS__s, SS__c);
} else {
Error("Streamer", "no info found for 'set<string>' - skip");
return;
}
std::set<std::string>::const_iterator it;
for (it = msgs.begin(); it != msgs.end(); it++) {
fMsgs.Add(new TObjString((*it).c_str()));
}
if (R__v > 2) {
R__b >> fExitStatus;
}
if (R__v > 1) {
R__b >> fVirtMemMax;
R__b >> fResMemMax;
}
if (R__v > 3) {
R__b >> fVirtMaxMst;
R__b >> fResMaxMst;
}
}
} else {
R__b.WriteClassBuffer(TStatus::Class(),this);
}
}