00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "TPEAC.h"
00022
00023 #include "TClarens.h"
00024 #include "TDSet.h"
00025 #include "TEnv.h"
00026 #include "TGM.h"
00027 #include "TObjString.h"
00028 #include "TPluginManager.h"
00029 #include "TROOT.h"
00030 #include "TSystem.h"
00031 #include "TUrl.h"
00032 #include "TProof.h"
00033
00034
00035 namespace {
00036
00037
00038
00039 struct TPEACStartup {
00040 TPEACStartup() {TPEAC::Init();}
00041 } PEACStartup;
00042
00043
00044
00045 };
00046
00047
00048 TPEAC *gPEAC = 0;
00049
00050 ClassImp(TPEAC)
00051
00052
00053
00054 TPEAC::TPEAC()
00055 : fGM(0), fProof(0)
00056 {
00057 TClarens::Init();
00058 }
00059
00060
00061
00062 TPEAC::~TPEAC()
00063 {
00064 if (!fSessionID.IsNull()) EndSession();
00065 delete fGM;
00066 }
00067
00068
00069
00070 void TPEAC::Init()
00071 {
00072 if (gPEAC == 0) {
00073 gPEAC = new TPEAC;
00074 }
00075 }
00076
00077
00078
00079 TDSet *TPEAC::StartSession(const Char_t *dataset)
00080 {
00081 if (fGM == 0) {
00082
00083 const Char_t *gmUrl = gEnv->GetValue("PEAC.GmUrl",
00084 "http://localhost:8080/clarens/");
00085
00086 fGM = gClarens->CreateGM(gmUrl);
00087
00088 if (!fGM) {
00089 Error("TPEAC", "Could not get Global Manager for URL: %s", gmUrl);
00090 return 0;
00091 }
00092 }
00093
00094 if (!fSessionID.IsNull()) {
00095 Error("StartSession", "Session associated with dataset '%s' still open",
00096 fDataSet.Data());
00097 Error("StartSession", "That session must end before"
00098 " starting a new session");
00099 return 0;
00100 }
00101
00102 if (gDebug > 0) fGM->Print();
00103
00104 TList* files = 0;
00105 TString sessionid;
00106 TUrl purl("");
00107 if (!fGM->CreateSession(dataset, sessionid, files, purl)) {
00108 delete fGM;
00109 fGM = 0;
00110 return 0;
00111 }
00112
00113
00114
00115 if (gDebug > 0) {
00116 Info("StartSession", "sessionid = %s @ %s", sessionid.Data(), purl.GetUrl());
00117 files->Print();
00118 }
00119
00120
00121 TDSet *dset = 0;
00122 TIter NextFile(files);
00123 while (TGM::TFileParams *fp = dynamic_cast<TGM::TFileParams*>(NextFile())) {
00124
00125 if (dset == 0) dset = new TDSet(fp->fObjClass, fp->fObjName, fp->fDir);
00126
00127 dset->Add(fp->fFileName, fp->fObjName, fp->fDir, fp->fFirst, fp->fNum);
00128 }
00129 Int_t nfiles = files->GetSize();
00130 delete files;
00131
00132
00133 fSessionID = sessionid;
00134 fDataSet = dataset;
00135
00136
00137 fProof = TProof::Open(purl.GetUrl(), Form("peac:%s", sessionid.Data()));
00138
00139 if (!fProof || !fProof->IsValid()) {
00140 Error("StartSession", "PROOF session could not be started");
00141 EndSession();
00142 delete dset;
00143 return 0;
00144 }
00145
00146
00147 fProof->Connect("~TProof()", "TPEAC", this, "EndSessionCallback()");
00148
00149
00150 Long64_t totalbytes, bytesready;
00151 Bool_t dataready = fProof->IsDataReady(totalbytes, bytesready);
00152
00153
00154 if (!gROOT->IsBatch()) {
00155 if (TPluginManager *pm = gROOT->GetPluginManager()) {
00156 if (TPluginHandler *h = pm->FindHandler("TProofStartupDialog")) {
00157 if(h->LoadPlugin() != -1) {
00158 h->ExecPlugin(4, fProof, dataset, nfiles, totalbytes);
00159
00160 dataready = fProof->IsDataReady(totalbytes, bytesready);
00161 }
00162 }
00163 }
00164 }
00165
00166 if (!dataready) {
00167 gSystem->Sleep(500);
00168 while (!fProof->IsDataReady(totalbytes, bytesready)) {
00169 gSystem->Sleep(500);
00170 }
00171 }
00172
00173 return dset;
00174 }
00175
00176
00177
00178 void TPEAC::EndSessionCallback()
00179 {
00180 if (fSessionID.IsNull()) {
00181 Error("EndSession", "No session active. Don't call EndSessionCallback() directly");
00182 return;
00183 }
00184
00185 if (!fGM) {
00186 Error("EndSession", "Global manager does not exist");
00187 return;
00188 }
00189
00190 if (fProof) {
00191 fProof->Disconnect("~TProof()", this, "EndSessionCallback()");
00192 fProof = 0;
00193 }
00194 fGM->DestroySession(fSessionID);
00195 fSessionID = "";
00196 fDataSet = "";
00197
00198 }
00199
00200
00201
00202 void TPEAC::EndSession()
00203 {
00204 if (fSessionID.IsNull()) {
00205 Info("EndSession", "No session active");
00206 return;
00207 }
00208
00209 if (!fGM) {
00210 Error("EndSession", "Global manager does not exist");
00211 return;
00212 }
00213
00214 if (fProof) {
00215 fProof->Disconnect("~TProof()", this, "EndSessionCallback()");
00216 delete fProof;
00217 fProof = 0;
00218 }
00219 fGM->DestroySession(fSessionID);
00220 fSessionID = "";
00221 fDataSet = "";
00222 }