00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "TError.h"
00024 #include "TEnv.h"
00025 #include "TList.h"
00026 #include "TProof.h"
00027 #include "TProofMgr.h"
00028 #include "TProofMgrLite.h"
00029 #include "TROOT.h"
00030
00031 ClassImp(TProofMgr)
00032
00033
00034 TList TProofMgr::fgListOfManagers;
00035 TProofMgr_t TProofMgr::fgTXProofMgrHook = 0;
00036
00037
00038 TProofMgr::TProofMgr(const char *url, Int_t, const char *alias)
00039 : TNamed("",""), fRemoteProtocol(-1), fServType(kXProofd),
00040 fSessions(0), fIntHandler(0)
00041 {
00042
00043
00044 fServType = kProofd;
00045
00046
00047 fUrl = (!url || strlen(url) <= 0) ? TUrl("proof://localhost") : TUrl(url);
00048
00049
00050 if (!strcmp(fUrl.GetProtocol(), TUrl("a").GetProtocol()))
00051 fUrl.SetProtocol("proof");
00052
00053
00054 if (fUrl.GetPort() == TUrl("a").GetPort()) {
00055
00056
00057
00058 Int_t port = gSystem->GetServiceByName("proofd");
00059 if (port < 0) {
00060 if (gDebug > 0)
00061 Info("TProofMgr","service 'proofd' not found by GetServiceByName"
00062 ": using default IANA assigned tcp port 1093");
00063 port = 1093;
00064 } else {
00065 if (gDebug > 1)
00066 Info("TProofMgr","port from GetServiceByName: %d", port);
00067 }
00068 fUrl.SetPort(port);
00069 }
00070
00071
00072 if (strlen(fUrl.GetUser()) <= 0) {
00073
00074 UserGroup_t *pw = gSystem->GetUserInfo();
00075 if (pw) {
00076 fUrl.SetUser(pw->fUser);
00077 delete pw;
00078 }
00079 }
00080
00081
00082 if (strcmp(fUrl.GetHost(), "__lite__")) {
00083 if (strcmp(fUrl.GetHost(), fUrl.GetHostFQDN()))
00084 fUrl.SetHost(fUrl.GetHostFQDN());
00085 }
00086
00087 SetName(fUrl.GetUrl(kTRUE));
00088 if (alias)
00089 SetAlias(alias);
00090 else
00091 SetAlias(fUrl.GetHost());
00092 }
00093
00094
00095 TProofMgr::~TProofMgr()
00096 {
00097
00098
00099 SafeDelete(fSessions);
00100 SafeDelete(fIntHandler);
00101
00102 fgListOfManagers.Remove(this);
00103 gROOT->GetListOfProofs()->Remove(this);
00104 }
00105
00106
00107 TProof *TProofMgr::AttachSession(Int_t id, Bool_t gui)
00108 {
00109
00110
00111
00112
00113 TProofDesc *d = GetProofDesc(id);
00114 if (d)
00115 return AttachSession(d, gui);
00116
00117 Info("AttachSession","invalid proofserv id (%d)", id);
00118 return 0;
00119 }
00120
00121
00122 TProof *TProofMgr::AttachSession(TProofDesc *d, Bool_t)
00123 {
00124
00125
00126
00127
00128 if (!d) {
00129 Warning("AttachSession","invalid description object - do nothing");
00130 return 0;
00131 }
00132
00133 if (d->GetProof())
00134
00135 return d->GetProof();
00136
00137 Warning("AttachSession","session not available - do nothing");
00138 return 0;
00139 }
00140
00141
00142 void TProofMgr::DetachSession(Int_t id, Option_t *opt)
00143 {
00144
00145
00146
00147
00148
00149 if (!IsValid()) {
00150 Warning("DetachSession","invalid TProofMgr - do nothing");
00151 return;
00152 }
00153
00154 if (id > 0) {
00155
00156 TProofDesc *d = GetProofDesc(id);
00157 if (d) {
00158 if (d->GetProof())
00159 d->GetProof()->Detach(opt);
00160 TProof *p = d->GetProof();
00161 fSessions->Remove(d);
00162 SafeDelete(p);
00163 delete d;
00164 }
00165
00166 } else if (id == 0) {
00167
00168
00169 if (fSessions) {
00170
00171 TIter nxd(fSessions);
00172 TProofDesc *d = 0;
00173 while ((d = (TProofDesc *)nxd())) {
00174 if (d->GetProof())
00175 d->GetProof()->Detach(opt);
00176 TProof *p = d->GetProof();
00177 fSessions->Remove(d);
00178 SafeDelete(p);
00179 }
00180 fSessions->Delete();
00181 }
00182 }
00183
00184 return;
00185 }
00186
00187
00188 void TProofMgr::DetachSession(TProof *p, Option_t *opt)
00189 {
00190
00191
00192
00193 if (!IsValid()) {
00194 Warning("DetachSession","invalid TProofMgr - do nothing");
00195 return;
00196 }
00197
00198 if (p) {
00199
00200 TProofDesc *d = GetProofDesc(p);
00201 if (d) {
00202 if (d->GetProof())
00203
00204 d->GetProof()->Detach(opt);
00205 fSessions->Remove(d);
00206 delete d;
00207 }
00208 }
00209
00210 return;
00211 }
00212
00213
00214 TList *TProofMgr::QuerySessions(Option_t *opt)
00215 {
00216
00217
00218 if (opt && !strncasecmp(opt,"L",1))
00219
00220 return fSessions;
00221
00222
00223 if (!fSessions) {
00224 fSessions = new TList();
00225 fSessions->SetOwner();
00226 }
00227
00228
00229 if (gROOT->GetListOfProofs()) {
00230
00231 TIter nxp(gROOT->GetListOfProofs());
00232 TObject *o = 0;
00233 TProof *p = 0;
00234 Int_t ns = 0;
00235 while ((o = nxp())) {
00236 if (o->InheritsFrom(TProof::Class())) {
00237 p = (TProof *)o;
00238
00239 if (MatchUrl(p->GetUrl())) {
00240 if (!(fSessions->FindObject(p->GetSessionTag()))) {
00241 Int_t st = (p->IsIdle()) ? TProofDesc::kIdle
00242 : TProofDesc::kRunning;
00243 TProofDesc *d =
00244 new TProofDesc(p->GetName(), p->GetTitle(), p->GetUrl(),
00245 ++ns, p->GetSessionID(), st, p);
00246 fSessions->Add(d);
00247 }
00248 }
00249 }
00250 }
00251 }
00252
00253
00254 if (fSessions->GetSize() > 0) {
00255 TIter nxd(fSessions);
00256 TProofDesc *d = 0;
00257 while ((d = (TProofDesc *)nxd())) {
00258 if (d->GetProof()) {
00259 if (!(gROOT->GetListOfProofs()->FindObject(d->GetProof()))) {
00260 fSessions->Remove(d);
00261 SafeDelete(d);
00262 } else {
00263 if (opt && !strncasecmp(opt,"S",1))
00264 d->Print("");
00265 }
00266 }
00267 }
00268 }
00269
00270
00271 return fSessions;
00272 }
00273
00274
00275 Int_t TProofMgr::SendMsgToUsers(const char *, const char *)
00276 {
00277
00278
00279
00280
00281
00282
00283
00284 Warning("SendMsgToUsers","functionality not supported");
00285
00286 return -1;
00287 }
00288
00289
00290 Int_t TProofMgr::Reset(Bool_t, const char *)
00291 {
00292
00293
00294
00295
00296 Warning("Reset","functionality not supported");
00297
00298 return -1;
00299 }
00300
00301
00302 void TProofMgr::ShowWorkers()
00303 {
00304
00305
00306 AbstractMethod("ShowWorkers");
00307 }
00308
00309
00310 TProofDesc *TProofMgr::GetProofDesc(Int_t id)
00311 {
00312
00313
00314 TProofDesc *d = 0;
00315 if (id > 0) {
00316
00317 QuerySessions("");
00318 if (fSessions) {
00319 TIter nxd(fSessions);
00320 while ((d = (TProofDesc *)nxd())) {
00321 if (d->MatchId(id))
00322 return d;
00323 }
00324 }
00325 }
00326
00327 return d;
00328 }
00329
00330
00331 TProofDesc *TProofMgr::GetProofDesc(TProof *p)
00332 {
00333
00334
00335 TProofDesc *d = 0;
00336 if (p) {
00337
00338 QuerySessions("");
00339 if (fSessions) {
00340 TIter nxd(fSessions);
00341 while ((d = (TProofDesc *)nxd())) {
00342 if (p == d->GetProof())
00343 return d;
00344 }
00345 }
00346 }
00347
00348 return d;
00349 }
00350
00351
00352 void TProofMgr::DiscardSession(TProof *p)
00353 {
00354
00355
00356 if (p) {
00357 TProofDesc *d = 0;
00358 if (fSessions) {
00359 TIter nxd(fSessions);
00360 while ((d = (TProofDesc *)nxd())) {
00361 if (p == d->GetProof()) {
00362 fSessions->Remove(d);
00363 delete d;
00364 break;
00365 }
00366 }
00367 }
00368 }
00369 }
00370
00371
00372 TProof *TProofMgr::CreateSession(const char *cfg,
00373 const char *cfgdir, Int_t loglevel)
00374 {
00375
00376
00377
00378 if (IsProofd())
00379 fUrl.SetOptions("std");
00380
00381
00382 TProof *p = new TProof(fUrl.GetUrl(), cfg, cfgdir, loglevel, 0, this);
00383
00384 if (p && p->IsValid()) {
00385
00386
00387 Int_t ns = 1;
00388 if (fSessions) {
00389
00390 if (fSessions->Last())
00391 ns = ((TProofDesc *)(fSessions->Last()))->GetLocalId() + 1;
00392 } else {
00393
00394 fSessions = new TList;
00395 }
00396
00397
00398 Int_t st = (p->IsIdle()) ? TProofDesc::kIdle : TProofDesc::kRunning ;
00399 TProofDesc *d =
00400 new TProofDesc(p->GetName(), p->GetTitle(), p->GetUrl(),
00401 ns, p->GetSessionID(), st, p);
00402 fSessions->Add(d);
00403
00404 } else {
00405
00406 if (gDebug > 0) Error("CreateSession", "PROOF session creation failed");
00407 SafeDelete(p);
00408 }
00409
00410
00411 return p;
00412 }
00413
00414
00415 Bool_t TProofMgr::MatchUrl(const char *url)
00416 {
00417
00418
00419
00420 TUrl u(url);
00421
00422
00423 if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
00424 u.SetProtocol("proof");
00425
00426
00427 if (u.GetPort() == TUrl("a").GetPort()) {
00428 Int_t port = gSystem->GetServiceByName("proofd");
00429 if (port < 0)
00430 port = 1093;
00431 u.SetPort(port);
00432 }
00433
00434
00435 if (!strcmp(u.GetHostFQDN(), fUrl.GetHostFQDN()))
00436 if (u.GetPort() == fUrl.GetPort())
00437 if (strlen(u.GetUser()) <= 0 || !strcmp(u.GetUser(),fUrl.GetUser()))
00438 return kTRUE;
00439
00440
00441 return kFALSE;
00442 }
00443
00444
00445 TList *TProofMgr::GetListOfManagers()
00446 {
00447
00448
00449
00450 if (gROOT->GetListOfProofs()) {
00451 TIter nxp(gROOT->GetListOfProofs());
00452 TObject *o = 0;
00453 while ((o = nxp())) {
00454 if (o->InheritsFrom(TProofMgr::Class()) && !fgListOfManagers.FindObject(o))
00455 fgListOfManagers.Add(o);
00456 }
00457 }
00458
00459
00460 if (fgListOfManagers.GetSize() > 0) {
00461 TIter nxp(&fgListOfManagers);
00462 TObject *o = 0;
00463 Int_t nm = 0;
00464 while ((o = nxp())) {
00465 if (!(gROOT->GetListOfProofs()->FindObject(o))) {
00466 fgListOfManagers.Remove(o);
00467 } else {
00468 TProofMgr *p = (TProofMgr *)o;
00469 if (gDebug > 0)
00470 Printf("// #%d: \"%s\" (%s)", ++nm, p->GetName(), p->GetTitle());
00471 }
00472 }
00473 } else {
00474 if (gDebug > 0)
00475 Printf("No managers found");
00476 }
00477
00478
00479 return &fgListOfManagers;
00480 }
00481
00482
00483 TProofMgr *TProofMgr::Create(const char *uin, Int_t loglevel,
00484 const char *alias, Bool_t xpd)
00485 {
00486
00487
00488 TProofMgr *m= 0;
00489
00490 Bool_t isLite = kFALSE;
00491
00492 TUrl u(uin);
00493 TString host = u.GetHost();
00494 if (host.IsNull()) {
00495 host = gEnv->GetValue("Proof.LocalDefault", "lite");
00496 if (host != "lite")
00497 u.SetUrl("localhost");
00498 }
00499 if (host == "lite" || host == "__lite__") {
00500 #ifndef WIN32
00501 isLite = kTRUE;
00502 u.SetHost("__lite__");
00503 u.SetProtocol("proof");
00504 u.SetPort(1093);
00505 #else
00506 ::Info("TProofMgr::Create","'lite' not yet supported on Windows");
00507 return m;
00508 #endif
00509 }
00510
00511 if (!isLite) {
00512
00513
00514 if (!strcmp(u.GetProtocol(), TUrl("a").GetProtocol()))
00515 u.SetProtocol("proof");
00516 if (u.GetPort() == TUrl("a").GetPort())
00517 u.SetPort(1093);
00518 }
00519
00520
00521 const char *url = u.GetUrl();
00522
00523
00524 TList *lm = TProofMgr::GetListOfManagers();
00525 if (lm) {
00526 TIter nxm(lm);
00527 while ((m = (TProofMgr *)nxm())) {
00528 if (m->IsValid()) {
00529 if (m->MatchUrl(url)) return m;
00530 } else {
00531 fgListOfManagers.Remove(m);
00532 SafeDelete(m);
00533 break;
00534 }
00535 }
00536 }
00537
00538 if (isLite) {
00539
00540 return new TProofMgrLite(url, loglevel, alias);
00541 }
00542
00543 m = 0;
00544 Bool_t trystd = kTRUE;
00545
00546
00547 if (xpd) {
00548 TProofMgr_t cm = TProofMgr::GetXProofMgrHook();
00549 if (cm) {
00550 m = (TProofMgr *) (*cm)(url, loglevel, alias);
00551
00552 trystd = (m && !(m->IsValid()) && m->IsProofd()) ? kTRUE : kFALSE;
00553 }
00554 }
00555
00556
00557 if (trystd) {
00558 SafeDelete(m);
00559 m = new TProofMgr(url, loglevel, alias);
00560 }
00561
00562
00563 if (m) {
00564 fgListOfManagers.Add(m);
00565 if (m->IsValid() && !(m->IsProofd())) {
00566 R__LOCKGUARD2(gROOTMutex);
00567 gROOT->GetListOfProofs()->Add(m);
00568 gROOT->GetListOfSockets()->Add(m);
00569 }
00570 }
00571
00572
00573 return m;
00574 }
00575
00576
00577 TProofMgr_t TProofMgr::GetXProofMgrHook()
00578 {
00579
00580
00581
00582
00583 if (!fgTXProofMgrHook) {
00584
00585 TString prooflib = "libProofx";
00586 char *p = 0;
00587 if ((p = gSystem->DynamicPathName(prooflib, kTRUE))) {
00588 delete[] p;
00589 if (gSystem->Load(prooflib) == -1)
00590 ::Error("TProofMgr::GetXProofMgrCtor",
00591 "can't load %s", prooflib.Data());
00592 } else
00593 ::Error("TProofMgr::GetXProofMgrCtor",
00594 "can't locate %s", prooflib.Data());
00595 }
00596
00597
00598 return fgTXProofMgrHook;
00599 }
00600
00601
00602 void TProofMgr::SetTXProofMgrHook(TProofMgr_t pmh)
00603 {
00604
00605
00606 fgTXProofMgrHook = pmh;
00607 }
00608
00609
00610
00611
00612
00613
00614 ClassImp(TProofDesc)
00615
00616
00617 void TProofDesc::Print(Option_t *) const
00618 {
00619
00620 const char *st[] = { "unknown", "idle", "processsing", "shutting down"};
00621
00622 Printf("// # %d", fLocalId);
00623 Printf("// alias: %s, url: \"%s\"", GetTitle(), GetUrl());
00624 Printf("// tag: %s", GetName());
00625 Printf("// status: %s, attached: %s (remote ID: %d)",st[fStatus+1], (fProof ? "YES" : "NO"), fRemoteId);
00626 }