#include "TError.h"
#include "TEnv.h"
#include "TList.h"
#include "TProof.h"
#include "TProofMgr.h"
#include "TProofMgrLite.h"
#include "TROOT.h"
ClassImp(TProofMgr)
TList TProofMgr::fgListOfManagers;
TProofMgr_t TProofMgr::fgTXProofMgrHook = 0;
TProofMgr::TProofMgr(const char *url, Int_t, const char *alias)
: TNamed("",""), fRemoteProtocol(-1), fServType(kXProofd), fSessions(0)
{
fServType = kProofd;
fUrl = (!url || strlen(url) <= 0) ? TUrl("proof://localhost") : TUrl(url);
if (!strcmp(fUrl.GetProtocol(), TUrl("a").GetProtocol()))
fUrl.SetProtocol("proof");
if (fUrl.GetPort() == TUrl("a").GetPort()) {
Int_t port = gSystem->GetServiceByName("proofd");
if (port < 0) {
if (gDebug > 0)
Info("TProofMgr","service 'proofd' not found by GetServiceByName"
": using default IANA assigned tcp port 1093");
port = 1093;
} else {
if (gDebug > 1)
Info("TProofMgr","port from GetServiceByName: %d", port);
}
fUrl.SetPort(port);
}
if (strlen(fUrl.GetUser()) <= 0) {
UserGroup_t *pw = gSystem->GetUserInfo();
if (pw) {
fUrl.SetUser(pw->fUser);
delete pw;
}
}
if (strcmp(fUrl.GetHost(), fUrl.GetHostFQDN()))
fUrl.SetHost(fUrl.GetHostFQDN());
SetName(fUrl.GetUrl(kTRUE));
if (alias)
SetAlias(alias);
else
SetAlias(fUrl.GetHost());
}
TProofMgr::~TProofMgr()
{
SafeDelete(fSessions);
fgListOfManagers.Remove(this);
gROOT->GetListOfProofs()->Remove(this);
}
TProof *TProofMgr::AttachSession(Int_t id, Bool_t gui)
{
TProofDesc *d = GetProofDesc(id);
if (d)
return AttachSession(d, gui);
Info("AttachSession","invalid proofserv id (%d)", id);
return 0;
}
TProof *TProofMgr::AttachSession(TProofDesc *d, Bool_t)
{
if (!d) {
Warning("AttachSession","invalid description object - do nothing");
return 0;
}
if (d->GetProof())
return d->GetProof();
Warning("AttachSession","session not available - do nothing");
return 0;
}
void TProofMgr::DetachSession(Int_t id, Option_t *opt)
{
TProofDesc *d = GetProofDesc(id);
if (d) {
if (d->GetProof())
d->GetProof()->Detach(opt);
fSessions->Remove(d);
delete d;
}
return;
}
TList *TProofMgr::QuerySessions(Option_t *opt)
{
if (opt && !strncasecmp(opt,"L",1))
return fSessions;
if (!fSessions) {
fSessions = new TList();
fSessions->SetOwner();
}
if (gROOT->GetListOfProofs()) {
TIter nxp(gROOT->GetListOfProofs());
TProof *p = 0;
Int_t ns = 0;
while ((p = (TProof *)nxp())) {
if (MatchUrl(p->GetUrl())) {
if (!(fSessions->FindObject(p->GetSessionTag()))) {
Int_t st = (p->IsIdle()) ? TProofDesc::kIdle
: TProofDesc::kRunning;
TProofDesc *d =
new TProofDesc(p->GetName(), p->GetTitle(), p->GetUrl(),
++ns, p->GetSessionID(), st, p);
fSessions->Add(d);
}
}
}
}
if (fSessions->GetSize() > 0) {
TIter nxd(fSessions);
TProofDesc *d = 0;
while ((d = (TProofDesc *)nxd())) {
if (d->GetProof()) {
if (!(gROOT->GetListOfProofs()->FindObject(d->GetProof()))) {
fSessions->Remove(d);
SafeDelete(d);
} else {
if (opt && !strncasecmp(opt,"S",1))
d->Print("");
}
}
}
}
return fSessions;
}
Int_t TProofMgr::SendMsgToUsers(const char *, const char *)
{
Warning("SendMsgToUsers","functionality not supported");
return -1;
}
Int_t TProofMgr::Reset(Bool_t, const char *)
{
Warning("Reset","functionality not supported");
return -1;
}
void TProofMgr::ShowWorkers()
{
AbstractMethod("ShowWorkers");
}
TProofDesc *TProofMgr::GetProofDesc(Int_t id)
{
if (id > 0) {
TProofDesc *d = 0;
QuerySessions("");
if (fSessions) {
TIter nxd(fSessions);
while ((d = (TProofDesc *)nxd())) {
if (d->MatchId(id))
return d;
}
}
}
return 0;
}
void TProofMgr::ShutdownSession(TProof *p)
{
if (p) {
TProofDesc *d = 0;
if (fSessions) {
TIter nxd(fSessions);
while ((d = (TProofDesc *)nxd())) {
if (p == d->GetProof()) {
fSessions->Remove(d);
delete d;
break;
}
}
}
}
}
TProof *TProofMgr::CreateSession(const char *cfg,
const char *cfgdir, Int_t loglevel)
{
if (IsProofd())
fUrl.SetOptions("std");
TProof *p = new TProof(fUrl.GetUrl(), cfg, cfgdir, loglevel, 0, this);
if (p && p->IsValid()) {
Int_t ns = 1;
if (fSessions) {
if (fSessions->Last())
ns = ((TProofDesc *)(fSessions->Last()))->GetLocalId() + 1;
} else {
fSessions = new TList;
}
Int_t st = (p->IsIdle()) ? TProofDesc::kIdle : TProofDesc::kRunning ;
TProofDesc *d =
new TProofDesc(p->GetName(), p->GetTitle(), p->GetUrl(),
ns, p->GetSessionID(), st, p);
fSessions->Add(d);
} else {
if (gDebug > 0) Error("CreateSession", "PROOF session creation failed");
SafeDelete(p);
}
return p;
}
Bool_t TProofMgr::MatchUrl(const char *url)
{
TUrl u(url);
if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
u.SetProtocol("proof");
if (u.GetPort() == TUrl("a").GetPort()) {
Int_t port = gSystem->GetServiceByName("rootd");
if (port < 0)
port = 1094;
u.SetPort(port);
}
if (!strcmp(u.GetHostFQDN(), fUrl.GetHostFQDN()))
if (u.GetPort() == fUrl.GetPort())
if (strlen(u.GetUser()) <= 0 || !strcmp(u.GetUser(),fUrl.GetUser()))
return kTRUE;
return kFALSE;
}
TList *TProofMgr::GetListOfManagers()
{
if (gROOT->GetListOfProofs()) {
TIter nxp(gROOT->GetListOfProofs());
TObject *o = 0;
while ((o = nxp())) {
if (o->InheritsFrom("TProofMgr") && !fgListOfManagers.FindObject(o))
fgListOfManagers.Add(o);
}
}
if (fgListOfManagers.GetSize() > 0) {
TIter nxp(&fgListOfManagers);
TObject *o = 0;
Int_t nm = 0;
while ((o = nxp())) {
if (!(gROOT->GetListOfProofs()->FindObject(o))) {
fgListOfManagers.Remove(o);
} else {
TProofMgr *p = (TProofMgr *)o;
if (gDebug > 0)
Printf("// #%d: \"%s\" (%s)", ++nm, p->GetName(), p->GetTitle());
}
}
} else {
if (gDebug > 0)
Printf("No managers found");
}
return &fgListOfManagers;
}
TProofMgr *TProofMgr::Create(const char *uin, Int_t loglevel,
const char *alias, Bool_t xpd)
{
TProofMgr *m= 0;
Bool_t isLite = kFALSE;
TUrl u(uin);
TString host = u.GetHost();
if (host.IsNull()) {
host = gEnv->GetValue("Proof.LocalDefault", "lite");
if (host != "lite")
u.SetUrl("localhost");
}
if (host == "lite" || host == "__lite__") {
#ifndef WIN32
isLite = kTRUE;
u.SetHost("__lite__");
u.SetProtocol("proof");
u.SetPort(1093);
#else
::Info("TProofMgr::Create","'lite' not yet supported on Windows");
return m;
#endif
}
if (!isLite) {
if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
u.SetProtocol("proof");
if (u.GetPort() == TUrl("a").GetPort())
u.SetPort(1093);
}
const char *url = u.GetUrl();
TList *lm = TProofMgr::GetListOfManagers();
if (lm) {
TIter nxm(lm);
while ((m = (TProofMgr *)nxm())) {
if (m->IsValid()) {
if (m->MatchUrl(url)) return m;
} else {
fgListOfManagers.Remove(m);
SafeDelete(m);
break;
}
}
}
if (isLite) {
return new TProofMgrLite(url, loglevel, alias);
}
m = 0;
Bool_t trystd = kTRUE;
if (xpd) {
TProofMgr_t cm = TProofMgr::GetXProofMgrHook();
if (cm) {
m = (TProofMgr *) (*cm)(url, loglevel, alias);
trystd = (m && !(m->IsValid()) && m->IsProofd()) ? kTRUE : kFALSE;
}
}
if (trystd) {
SafeDelete(m);
m = new TProofMgr(url, loglevel, alias);
}
if (m) {
fgListOfManagers.Add(m);
if (m->IsValid() && !(m->IsProofd())) {
R__LOCKGUARD2(gROOTMutex);
gROOT->GetListOfProofs()->Add(m);
gROOT->GetListOfSockets()->Add(m);
}
}
return m;
}
TProofMgr_t TProofMgr::GetXProofMgrHook()
{
if (!fgTXProofMgrHook) {
TString prooflib = "libProofx";
char *p = 0;
if ((p = gSystem->DynamicPathName(prooflib, kTRUE))) {
delete[] p;
if (gSystem->Load(prooflib) == -1)
::Error("TProofMgr::GetXProofMgrCtor",
"can't load %s", prooflib.Data());
} else
::Error("TProofMgr::GetXProofMgrCtor",
"can't locate %s", prooflib.Data());
}
return fgTXProofMgrHook;
}
void TProofMgr::SetTXProofMgrHook(TProofMgr_t pmh)
{
fgTXProofMgrHook = pmh;
}
ClassImp(TProofDesc)
void TProofDesc::Print(Option_t *) const
{
const char *st[] = { "unknown", "idle", "processsing", "shutting down"};
Printf("// # %d", fLocalId);
Printf("// alias: %s, url: \"%s\"", GetTitle(), GetUrl());
Printf("// tag: %s", GetName());
Printf("// status: %s, attached: %s (remote ID: %d)",st[fStatus+1], (fProof ? "YES" : "NO"), fRemoteId);
}
Last change: Mon Dec 8 10:00:47 2008
Last generated: 2008-12-08 10:00
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.