pq2wrappers.cxx

Go to the documentation of this file.
00001 // @(#)root/proof:$Id: pq2wrappers.cxx 33549 2010-05-18 10:28:05Z ganis $
00002 // Author: G. Ganis, Mar 2010
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 // pq2wrappers                                                          //
00015 //                                                                      //
00016 // This file implements the wrapper functions used in PQ2               //
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 // Global variables defined by other PQ2 components
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    // ShowCache wrapper
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    // Done
00059    return;
00060 }
00061 
00062 //_______________________________________________________________________________________
00063 void ShowDataSets(const char *ds, const char *opt)
00064 {
00065    // ShowDataSets wrapper
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    // Done
00074    return;
00075 }
00076 
00077 //_______________________________________________________________________________________
00078 TFileCollection *GetDataSet(const char *ds, const char *server)
00079 {
00080    // GetDataSet wrapper
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    // Done
00090    return fc;
00091 }
00092 
00093 //_______________________________________________________________________________________
00094 TMap *GetDataSets(const char *owner, const char *server, const char *opt)
00095 {
00096    // GetDataSets wrapper
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       // Get the datasets and fill a map
00104       UInt_t oo = (opt && !strcmp(opt, "list")) ? (UInt_t)TDataSetManager::kList
00105                                                 : (UInt_t)TDataSetManager::kExport;
00106       dss = gDataSetManager->GetDataSets(owner, oo);
00107       // If defines, option gives the name of a server for which to extract the information
00108       if (dss) {
00109          if (server && strlen(server) > 0) {
00110             // The return map will be in the form   </group/user/datasetname> --> <dataset>
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                // Get subset on specified server, if any
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    // Done
00136    return dss;
00137 }
00138 
00139 //_______________________________________________________________________________________
00140 Int_t RemoveDataSet(const char *dsname)
00141 {
00142    // RemoveDataSet wrapper
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    // Done
00151    return -1;
00152 }
00153 
00154 //_______________________________________________________________________________________
00155 Int_t VerifyDataSet(const char *dsname, const char *opt, const char *redir)
00156 {
00157    // VerifyDataSet wrapper
00158 
00159    Int_t rc = -1;
00160    // Honour the 'redir' if required
00161    TString srvmaps;
00162    if (redir && strlen(redir) > 0) srvmaps.Form("|%s", redir);
00163    if (gIsProof) {
00164       // Honour the 'redir' if required
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          // Success; partial at least. Check if all files are staged
00171          TFileCollection *fcs = gProof->GetDataSet(dsname, "S:");
00172          if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
00173       }
00174    } else {
00175       // Honour the 'redir' if required
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          // Success; partial at least. Check if all files are staged
00182          TFileCollection *fcs = gDataSetManager->GetDataSet(dsname, "S:");
00183          if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
00184       }
00185    }
00186    // Done
00187    return rc;
00188 }
00189 
00190 //_______________________________________________________________________________________
00191 Bool_t ExistsDataSet(const char *dsname)
00192 {
00193    // ExistsDataSet wrapper
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    // RegisterDataSet wrapper
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    // Open a PROOF session at gUrl
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    // Done
00232    return 0;
00233 }
00234 
00235 //_______________________________________________________________________________________
00236 Int_t getDSMgr(const char *where)
00237 {
00238    // Open a dataset manager for gUrl
00239 
00240    Int_t rc = -1;
00241    if (gROOT->GetPluginManager()) {
00242       // Find the appropriate handler
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    // Done
00264    return rc;
00265 }

Generated on Tue Jul 5 14:50:54 2011 for ROOT_528-00b_version by  doxygen 1.5.1