#include "TError.h"
#include "TList.h"
#include "TProof.h"
#include "TProofMgr.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 (strcmp(fUrl.GetHost(), fUrl.GetHostFQDN()))
fUrl.SetHost(fUrl.GetHostFQDN());
SetName(fUrl.GetUrl());
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)
{
TProofDesc *d = GetProofDesc(id);
if (d) {
if (d->GetProof())
return d->GetProof();
}
Info("AttachSession","invalid proofserv id (%d)", id);
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::Reset(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 {
Error("CreateSession", "creating PROOF session");
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());
TProofMgr *p = 0;
while ((p = dynamic_cast<TProofMgr *> (nxp())))
if (!fgListOfManagers.FindObject(p))
fgListOfManagers.Add(p);
}
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;
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;
TUrl u(uin);
if (!uin || !strlen(uin))
u.SetUrl("localhost");
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->MatchUrl(url))
if (m->IsValid()) {
return m;
} else {
fgListOfManagers.Remove(m);
SafeDelete(m);
break;
}
}
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) {
#ifdef ROOTLIBDIR
TString prooflib = TString(ROOTLIBDIR);
#else
#ifndef WIN32
TString prooflib = TString(gRootDir) + "/lib";
#else
TString prooflib = TString(gRootDir) + "/bin";
#endif
#endif
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);
}
ROOT page - Class index - Class Hierarchy - Top of the page
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.