00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020
00021 #include "pq2wrappers.h"
00022 #include "redirguard.h"
00023
00024 #include "TDataSetManager.h"
00025 #include "TEnv.h"
00026 #include "TFileInfo.h"
00027 #include "TPluginManager.h"
00028 #include "TProof.h"
00029 #include "TROOT.h"
00030
00031 TDataSetManager *gDataSetManager = 0;
00032
00033
00034 extern TUrl gUrl;
00035 extern Bool_t gIsProof;
00036 extern TString flog;
00037 extern TString ferr;
00038 extern TString fres;
00039 extern Int_t gverbose;
00040
00041 Int_t getProof(const char *where, Int_t verbose = 1);
00042 Int_t getDSMgr(const char *where);
00043
00044
00045 void DataSetCache(bool clear, const char *ds)
00046 {
00047
00048 if (gIsProof) {
00049 if (!gProof && getProof("DataSetCache", 0) != 0) return;
00050 return (clear ? gProof->ClearDataSetCache(ds) : gProof->ShowDataSetCache(ds));
00051 } else {
00052 if (!gDataSetManager && getDSMgr("DataSetCache") != 0) return;
00053 Int_t rc = (clear) ? gDataSetManager->ClearCache(ds) : gDataSetManager->ShowCache(ds);
00054 if (rc != 0)
00055 Printf("DataSetCache: problems running '%s'", (clear ? "clear" : "show"));
00056 return;
00057 }
00058
00059 return;
00060 }
00061
00062
00063 void ShowDataSets(const char *ds, const char *opt)
00064 {
00065
00066 if (gIsProof) {
00067 if (!gProof && getProof("ShowDataSets", 0) != 0) return;
00068 return gProof->ShowDataSets(ds, opt);
00069 } else {
00070 if (!gDataSetManager && getDSMgr("ShowDataSets") != 0) return;
00071 return gDataSetManager->ShowDataSets(ds, opt);
00072 }
00073
00074 return;
00075 }
00076
00077
00078 TFileCollection *GetDataSet(const char *ds, const char *server)
00079 {
00080
00081 TFileCollection *fc = 0;
00082 if (gIsProof) {
00083 if (!gProof && getProof("GetDataSet") != 0) return fc;
00084 return gProof->GetDataSet(ds, server);
00085 } else {
00086 if (!gDataSetManager && getDSMgr("ShowDataSets") != 0) return fc;
00087 return gDataSetManager->GetDataSet(ds, server);
00088 }
00089
00090 return fc;
00091 }
00092
00093
00094 TMap *GetDataSets(const char *owner, const char *server, const char *opt)
00095 {
00096
00097 TMap *dss = 0;
00098 if (gIsProof) {
00099 if (!gProof && getProof("GetDataSets") != 0) return dss;
00100 return gProof->GetDataSets(owner, server);
00101 } else {
00102 if (!gDataSetManager && getDSMgr("GetDataSets") != 0) return dss;
00103
00104 UInt_t oo = (opt && !strcmp(opt, "list")) ? (UInt_t)TDataSetManager::kList
00105 : (UInt_t)TDataSetManager::kExport;
00106 dss = gDataSetManager->GetDataSets(owner, oo);
00107
00108 if (dss) {
00109 if (server && strlen(server) > 0) {
00110
00111 TMap *rmap = new TMap;
00112 TObject *k = 0;
00113 TFileCollection *fc = 0, *xfc = 0;
00114 TIter nxd(dss);
00115 while ((k = nxd()) && (fc = (TFileCollection *) dss->GetValue(k))) {
00116
00117 if ((xfc = fc->GetFilesOnServer(server))) {
00118 rmap->Add(new TObjString(k->GetName()), xfc);
00119 }
00120 }
00121 dss->DeleteAll();
00122 delete dss;
00123 dss = 0;
00124 if (rmap->GetSize() > 0) {
00125 dss = rmap;
00126 } else {
00127 Printf("GetDataSets: no dataset found on server '%s' for owner '%s'", server, owner);
00128 delete rmap;
00129 }
00130 }
00131 } else {
00132 Printf("GetDataSets: no dataset found for '%s'", owner);
00133 }
00134 }
00135
00136 return dss;
00137 }
00138
00139
00140 Int_t RemoveDataSet(const char *dsname)
00141 {
00142
00143 if (gIsProof) {
00144 if (!gProof && getProof("RemoveDataSet") != 0) return -1;
00145 return gProof->RemoveDataSet(dsname);
00146 } else {
00147 if (!gDataSetManager && getDSMgr("RemoveDataSet") != 0) return -1;
00148 return gDataSetManager->RemoveDataSet(dsname);
00149 }
00150
00151 return -1;
00152 }
00153
00154
00155 Int_t VerifyDataSet(const char *dsname, const char *opt, const char *redir)
00156 {
00157
00158
00159 Int_t rc = -1;
00160
00161 TString srvmaps;
00162 if (redir && strlen(redir) > 0) srvmaps.Form("|%s", redir);
00163 if (gIsProof) {
00164
00165 if (!(srvmaps.IsNull())) {
00166 TProof::AddEnvVar("DATASETSRVMAPS", srvmaps);
00167 }
00168 if (!gProof && getProof("VerifyDataSet") != 0) return -1;
00169 if ((rc = gProof->VerifyDataSet(dsname, opt)) == 0) {
00170
00171 TFileCollection *fcs = gProof->GetDataSet(dsname, "S:");
00172 if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
00173 }
00174 } else {
00175
00176 if (!(srvmaps.IsNull())) {
00177 gEnv->SetValue("DataSet.SrvMaps", srvmaps);
00178 }
00179 if (!gDataSetManager && getDSMgr("VerifyDataSet") != 0) return -1;
00180 if ((rc = gDataSetManager->ScanDataSet(dsname, opt)) == 0) {
00181
00182 TFileCollection *fcs = gDataSetManager->GetDataSet(dsname, "S:");
00183 if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
00184 }
00185 }
00186
00187 return rc;
00188 }
00189
00190
00191 Bool_t ExistsDataSet(const char *dsname)
00192 {
00193
00194 if (gIsProof) {
00195 if (!gProof && getProof("ExistsDataSet") != 0) return kFALSE;
00196 return gProof->ExistsDataSet(dsname);
00197 } else {
00198 if (!gDataSetManager && getDSMgr("ExistsDataSet") != 0) return kFALSE;
00199 return gDataSetManager->ExistsDataSet(dsname);
00200 }
00201 return kFALSE;
00202 }
00203
00204
00205 Int_t RegisterDataSet(const char *dsname, TFileCollection *fc, const char* opt)
00206 {
00207
00208 if (gIsProof) {
00209 if (!gProof && getProof("GetDataSet") != 0) return -1;
00210 return gProof->RegisterDataSet(dsname, fc, opt);
00211 } else {
00212 if (!gDataSetManager && getDSMgr("RegisterDataSet") != 0) return -1;
00213 return gDataSetManager->RegisterDataSet(dsname, fc, opt);
00214 }
00215 return -1;
00216 }
00217
00218
00219 Int_t getProof(const char *where, Int_t verbose)
00220 {
00221
00222
00223 { redirguard rog(flog.Data(), "a", verbose);
00224 TProof::Open(gUrl.GetUrl(), "masteronly");
00225 }
00226 if (!gProof || !gProof->IsValid()) {
00227 Printf("getProof:%s: problems starting a PROOF session at '%s'", where, gUrl.GetUrl());
00228 return -1;
00229 }
00230 if (gverbose >= 2) gProof->SetLogLevel(2);
00231
00232 return 0;
00233 }
00234
00235
00236 Int_t getDSMgr(const char *where)
00237 {
00238
00239
00240 Int_t rc = -1;
00241 if (gROOT->GetPluginManager()) {
00242
00243 TPluginHandler *h = gROOT->GetPluginManager()->FindHandler("TDataSetManager", "file");
00244 if (h && h->LoadPlugin() != -1) {
00245 TString group(getenv("PQ2GROUP")), user(getenv("PQ2USER"));
00246 TString dsm, opt("opt:-Ar:-Av:");
00247 const char *o = getenv("PQ2DSMGROPTS");
00248 if (o) {
00249 opt = "";
00250 if (strlen(o) > 0) opt.Form("opt:%s", o);
00251 }
00252 dsm.Form("file dir:%s %s", gUrl.GetUrl(), opt.Data());
00253 gDataSetManager = reinterpret_cast<TDataSetManager*>(h->ExecPlugin(3,
00254 group.Data(), user.Data(),
00255 dsm.Data()));
00256 if (gDataSetManager) {
00257 rc = 0;
00258 } else {
00259 Printf("getDSMgr:%s: problems creating a dataset manager at '%s'", where, gUrl.GetUrl());
00260 }
00261 }
00262 }
00263
00264 return rc;
00265 }