#ifdef R__HAVE_CONFIG
#include "RConfigure.h"
#endif
#include "TError.h"
#include "TInetAddress.h"
#include "TList.h"
#include "TROOT.h"
#include "TSystem.h"
#include "TVirtualMutex.h"
#include "TVirtualProof.h"
#include "TVirtualProofMgr.h"
ClassImp(TVirtualProofMgr)
TList TVirtualProofMgr::fgListOfManagers;
TVirtualProofMgr_t TVirtualProofMgr::fgTProofMgrHook[2] = { 0, 0 };
TVirtualProofMgr::TVirtualProofMgr(const char *url, Int_t, const char *)
: TNamed("",""), fRemoteProtocol(-1),
fServType(kXProofd), fSessions(0)
{
fUrl = (!url || strlen(url) <= 0) ? TUrl("proof://localhost") : TUrl(url);
}
TVirtualProofMgr::~TVirtualProofMgr()
{
SafeDelete(fSessions);
fgListOfManagers.Remove(this);
gROOT->GetListOfProofs()->Remove(this);
}
void TVirtualProofMgr::ShowWorkers()
{
AbstractMethod("ShowWorkers");
}
TVirtualProofDesc *TVirtualProofMgr::GetProofDesc(Int_t id)
{
if (id > 0) {
TVirtualProofDesc *d = 0;
QuerySessions("");
if (fSessions) {
TIter nxd(fSessions);
while ((d = (TVirtualProofDesc *)nxd())) {
if (d->MatchId(id))
return d;
}
}
}
return 0;
}
void TVirtualProofMgr::ShutdownSession(TVirtualProof *p)
{
if (p) {
TVirtualProofDesc *d = 0;
if (fSessions) {
TIter nxd(fSessions);
while ((d = (TVirtualProofDesc *)nxd())) {
if (p == d->GetProof()) {
fSessions->Remove(d);
delete d;
break;
}
}
}
}
}
TVirtualProof *TVirtualProofMgr::CreateSession(const char *cfg,
const char *cfgdir, Int_t loglevel)
{
if (IsProofd())
fUrl.SetOptions("std");
TProof_t proofhook = TVirtualProof::GetTProofHook();
if (!proofhook) {
#ifdef ROOTLIBDIR
TString prooflib = TString(ROOTLIBDIR) + "/libProof";
#else
#ifndef WIN32
TString prooflib = TString(gRootDir) + "/lib/libProof";
#else
TString prooflib = TString(gRootDir) + "/bin/libProof";
#endif
#endif
char *p = 0;
if ((p = gSystem->DynamicPathName(prooflib, kTRUE))) {
delete[] p;
if (gSystem->Load(prooflib) == -1)
Error("CreateSession", "can't load %s", prooflib.Data());
proofhook = TVirtualProof::GetTProofHook();
} else
Error("CreateSession", "can't locate %s", prooflib.Data());
}
if (!proofhook) {
Error("CreateSession", "hook for TVirtualProof could not be loaded");
return 0;
}
TVirtualProof *p =
(TVirtualProof*) (*proofhook)(fUrl.GetUrl(), cfg, cfgdir, loglevel, 0, this);
if (p && p->IsValid()) {
Int_t ns = 1;
if (fSessions) {
if (fSessions->Last())
ns = ((TVirtualProofDesc *)(fSessions->Last()))->GetLocalId() + 1;
} else {
fSessions = new TList;
}
Int_t st = (p->IsIdle()) ? TVirtualProofDesc::kIdle : TVirtualProofDesc::kRunning ;
TVirtualProofDesc *d =
new TVirtualProofDesc(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 TVirtualProofMgr::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 *TVirtualProofMgr::GetListOfManagers()
{
if (gROOT->GetListOfProofs()) {
TIter nxp(gROOT->GetListOfProofs());
TVirtualProofMgr *p = 0;
while ((p = dynamic_cast<TVirtualProofMgr *> (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 {
TVirtualProofMgr *p = (TVirtualProofMgr *)o;
Printf("// #%d: \"%s\" (%s)", ++nm, p->GetName(), p->GetTitle());
}
}
} else {
if (gDebug > 0)
Printf("No managers found");
}
return &fgListOfManagers;
}
TVirtualProofMgr *TVirtualProofMgr::Create(const char *url, Int_t loglevel,
const char *alias, Bool_t xpd)
{
TVirtualProofMgr *m= 0;
TList *lm = TVirtualProofMgr::GetListOfManagers();
if (lm) {
TIter nxm(lm);
while ((m = (TVirtualProofMgr *)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) {
TVirtualProofMgr_t cm = TVirtualProofMgr::GetProofMgrHook("xpd");
if (cm) {
m = (TVirtualProofMgr *) (*cm)(url, loglevel, alias);
trystd = (m && !(m->IsValid()) && m->IsProofd()) ? kTRUE : kFALSE;
}
}
if (trystd) {
SafeDelete(m);
TVirtualProofMgr_t cm = TVirtualProofMgr::GetProofMgrHook("std");
if (cm)
m = (TVirtualProofMgr *) (*cm)(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;
}
TVirtualProofMgr_t TVirtualProofMgr::GetProofMgrHook(const char *type)
{
static const char *libs[] = { "/libProof", "/libProofx" };
Int_t idx = (type && !strncmp(type,"xpd",3)) ? 1 : 0;
if (!fgTProofMgrHook[idx]) {
#ifdef ROOTLIBDIR
TString prooflib = TString(ROOTLIBDIR);
#else
#ifndef WIN32
TString prooflib = TString(gRootDir) + "/lib";
#else
TString prooflib = TString(gRootDir) + "/bin";
#endif
#endif
prooflib += libs[idx];
char *p = 0;
if ((p = gSystem->DynamicPathName(prooflib, kTRUE))) {
delete[] p;
if (gSystem->Load(prooflib) == -1)
::Error("TVirtualProofMgr::GetProofMgrCtor",
"can't load %s", prooflib.Data());
} else
::Error("TVirtualProofMgr::GetProofMgrCtor",
"can't locate %s", prooflib.Data());
}
return fgTProofMgrHook[idx];
}
void TVirtualProofMgr::SetTProofMgrHook(TVirtualProofMgr_t pmh, const char *t)
{
Int_t idx = (t && !strncmp(t,"xpd",3)) ? 1 : 0;
fgTProofMgrHook[idx] = pmh;
}
ClassImp(TVirtualProofDesc)
void TVirtualProofDesc::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.