Logo ROOT   6.14/05
Reference Guide
pq2wrappers.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: G. Ganis, Mar 2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 //////////////////////////////////////////////////////////////////////////
13 // //
14 // pq2wrappers //
15 // //
16 // This file implements the wrapper functions used in PQ2 //
17 // //
18 //////////////////////////////////////////////////////////////////////////
19 #include <stdlib.h>
20 
21 #include "pq2wrappers.h"
22 #include "redirguard.h"
23 
24 #include "TDataSetManager.h"
25 #include "TEnv.h"
26 #include "TFileInfo.h"
27 #include "TPluginManager.h"
28 #include "TProof.h"
29 #include "TROOT.h"
30 
32 
33 // Global variables defined by other PQ2 components
34 extern TUrl gUrl;
35 extern Bool_t gIsProof;
36 extern TString flog;
37 extern TString ferr;
38 extern TString fres;
39 extern Int_t gverbose;
40 
41 // How to start PROOF (new VerifyDataSet wants it parallel)
42 static bool doParallel = kFALSE;
43 
44 Int_t getProof(const char *where, Int_t verbose = 1);
45 Int_t getDSMgr(const char *where);
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// ShowCache wrapper
49 
50 void DataSetCache(bool clear, const char *ds)
51 {
52  if (gIsProof) {
54  if (!gProof && getProof("DataSetCache", 0) != 0) return;
55  return (clear ? gProof->ClearDataSetCache(ds) : gProof->ShowDataSetCache(ds));
56  } else {
57  if (!gDataSetManager && getDSMgr("DataSetCache") != 0) return;
58  Int_t rc = (clear) ? gDataSetManager->ClearCache(ds) : gDataSetManager->ShowCache(ds);
59  if (rc != 0)
60  Printf("DataSetCache: problems running '%s'", (clear ? "clear" : "show"));
61  return;
62  }
63  // Done
64  return;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// ShowDataSets wrapper
69 
70 void ShowDataSets(const char *ds, const char *opt)
71 {
72  if (gIsProof) {
74  if (!gProof && getProof("ShowDataSets", 0) != 0) return;
75  return gProof->ShowDataSets(ds, opt);
76  } else {
77  if (!gDataSetManager && getDSMgr("ShowDataSets") != 0) return;
78  return gDataSetManager->ShowDataSets(ds, opt);
79  }
80  // Done
81  return;
82 }
83 
84 ////////////////////////////////////////////////////////////////////////////////
85 /// GetDataSet wrapper
86 
87 TFileCollection *GetDataSet(const char *ds, const char *server)
88 {
89  TFileCollection *fc = 0;
90  if (gIsProof) {
92  if (!gProof && getProof("GetDataSet") != 0) return fc;
93  return gProof->GetDataSet(ds, server);
94  } else {
95  if (!gDataSetManager && getDSMgr("ShowDataSets") != 0) return fc;
96  return gDataSetManager->GetDataSet(ds, server);
97  }
98  // Done
99  return fc;
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// GetDataSets wrapper
104 
105 TMap *GetDataSets(const char *owner, const char *server, const char *opt)
106 {
107  TMap *dss = 0;
108  if (gIsProof) {
109  doParallel = kFALSE;
110  if (!gProof && getProof("GetDataSets") != 0) return dss;
111  return gProof->GetDataSets(owner, server);
112  } else {
113  if (!gDataSetManager && getDSMgr("GetDataSets") != 0) return dss;
114  // Get the datasets and fill a map
115  UInt_t oo = (opt && !strcmp(opt, "list")) ? (UInt_t)TDataSetManager::kList
117  dss = gDataSetManager->GetDataSets(owner, oo);
118  // If defines, option gives the name of a server for which to extract the information
119  if (dss) {
120  if (server && strlen(server) > 0) {
121  // The return map will be in the form </group/user/datasetname> --> <dataset>
122  TMap *rmap = new TMap;
123  TObject *k = 0;
124  TFileCollection *fc = 0, *xfc = 0;
125  TIter nxd(dss);
126  while ((k = nxd()) && (fc = (TFileCollection *) dss->GetValue(k))) {
127  // Get subset on specified server, if any
128  if ((xfc = fc->GetFilesOnServer(server))) {
129  rmap->Add(new TObjString(k->GetName()), xfc);
130  }
131  }
132  dss->DeleteAll();
133  delete dss;
134  dss = 0;
135  if (rmap->GetSize() > 0) {
136  dss = rmap;
137  } else {
138  Printf("GetDataSets: no dataset found on server '%s' for owner '%s'", server, owner);
139  delete rmap;
140  }
141  }
142  } else {
143  Printf("GetDataSets: no dataset found for '%s'", owner);
144  }
145  }
146  // Done
147  return dss;
148 }
149 
150 ////////////////////////////////////////////////////////////////////////////////
151 /// RemoveDataSet wrapper
152 
153 Int_t RemoveDataSet(const char *dsname)
154 {
155  if (gIsProof) {
156  doParallel = kFALSE;
157  if (!gProof && getProof("RemoveDataSet") != 0) return -1;
158  return gProof->RemoveDataSet(dsname);
159  } else {
160  if (!gDataSetManager && getDSMgr("RemoveDataSet") != 0) return -1;
161  return gDataSetManager->RemoveDataSet(dsname);
162  }
163  // Done
164  return -1;
165 }
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// VerifyDataSet wrapper
169 
170 Int_t VerifyDataSet(const char *dsname, const char *opt, const char *redir)
171 {
172  Int_t rc = -1;
173  // Honour the 'redir' if required
174  TString srvmaps;
175  if (redir && strlen(redir) > 0) srvmaps.Form("|%s", redir);
176  if (gIsProof) {
177  // Honour the 'redir' if required
178  if (!(srvmaps.IsNull())) {
179  TProof::AddEnvVar("DATASETSRVMAPS", srvmaps);
180  }
181  TString sopt(opt);
182  doParallel = (sopt.Contains("S")) ? kFALSE : kTRUE;
183  if (gProof && doParallel && gProof->GetParallel() == 0) {
184  gProof->Close();
185  delete gProof;
186  gProof = 0;
187  }
188  if (!gProof && getProof("VerifyDataSet") != 0) return -1;
189  if ((rc = gProof->VerifyDataSet(dsname, opt)) == 0) {
190  // Success; partial at least. Check if all files are staged
191  TFileCollection *fcs = gProof->GetDataSet(dsname, "S:");
192  if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
193  }
194  } else {
195  // Honour the 'redir' if required
196  if (!(srvmaps.IsNull())) {
197  gEnv->SetValue("DataSet.SrvMaps", srvmaps);
198  }
199  if (!gDataSetManager && getDSMgr("VerifyDataSet") != 0) return -1;
200  if ((rc = gDataSetManager->ScanDataSet(dsname, opt)) == 0) {
201  // Success; partial at least. Check if all files are staged
202  TFileCollection *fcs = gDataSetManager->GetDataSet(dsname, "S:");
203  if (fcs && fcs->GetStagedPercentage() < 99.99999) rc = 1;
204  }
205  }
206  // Done
207  return rc;
208 }
209 
210 ////////////////////////////////////////////////////////////////////////////////
211 /// ExistsDataSet wrapper
212 
213 Bool_t ExistsDataSet(const char *dsname)
214 {
215  if (gIsProof) {
216  doParallel = kFALSE;
217  if (!gProof && getProof("ExistsDataSet") != 0) return kFALSE;
218  return gProof->ExistsDataSet(dsname);
219  } else {
220  if (!gDataSetManager && getDSMgr("ExistsDataSet") != 0) return kFALSE;
221  return gDataSetManager->ExistsDataSet(dsname);
222  }
223  return kFALSE;
224 }
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// RegisterDataSet wrapper
228 
229 Int_t RegisterDataSet(const char *dsname, TFileCollection *fc, const char* opt)
230 {
231  if (gIsProof) {
232  doParallel = kFALSE;
233  if (!gProof && getProof("GetDataSet") != 0) return -1;
234  return gProof->RegisterDataSet(dsname, fc, opt);
235  } else {
236  if (!gDataSetManager && getDSMgr("RegisterDataSet") != 0) return -1;
237  return gDataSetManager->RegisterDataSet(dsname, fc, opt);
238  }
239  return -1;
240 }
241 
242 ////////////////////////////////////////////////////////////////////////////////
243 /// Open a PROOF session at gUrl
244 
245 Int_t getProof(const char *where, Int_t verbose)
246 {
247  { redirguard rog(flog.Data(), "a", verbose);
248  const char *popt = (doParallel) ? "" : "masteronly";
249  TProof::Open(gUrl.GetUrl(), popt);
250  }
251  if (!gProof || !gProof->IsValid()) {
252  Printf("getProof:%s: problems starting a PROOF session at '%s'", where, gUrl.GetUrl());
253  return -1;
254  }
255  if (gverbose >= 2) gProof->SetLogLevel(2);
256  // Done
257  return 0;
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 /// Open a dataset manager for gUrl
262 
263 Int_t getDSMgr(const char *where)
264 {
265  Int_t rc = -1;
266  if (gROOT->GetPluginManager()) {
267  // Find the appropriate handler
268  TPluginHandler *h = gROOT->GetPluginManager()->FindHandler("TDataSetManager", "file");
269  if (h && h->LoadPlugin() != -1) {
270  TString group(getenv("PQ2GROUP")), user(getenv("PQ2USER"));
271  TString dsm, opt("opt:-Ar:-Av:");
272  const char *o = getenv("PQ2DSMGROPTS");
273  if (o) {
274  opt = "";
275  if (strlen(o) > 0) opt.Form("opt:%s", o);
276  }
277  dsm.Form("file dir:%s %s", gUrl.GetUrl(), opt.Data());
278  gDataSetManager = reinterpret_cast<TDataSetManager*>(h->ExecPlugin(3,
279  group.Data(), user.Data(),
280  dsm.Data()));
281  if (gDataSetManager) {
282  rc = 0;
283  } else {
284  Printf("getDSMgr:%s: problems creating a dataset manager at '%s'", where, gUrl.GetUrl());
285  }
286  }
287  }
288  // Done
289  return rc;
290 }
Int_t RemoveDataSet(const char *dsname)
RemoveDataSet wrapper.
TFileCollection * GetFilesOnServer(const char *server)
Return the subset of files served by &#39;server&#39;.
virtual Int_t ClearCache(const char *uri)
Clear cached information matching uri.
virtual Bool_t ExistsDataSet(const char *dataset)
Returns kTRUE if &#39;dataset&#39; exists, kFALSE otherwise.
Definition: TProof.cxx:10840
virtual Bool_t RegisterDataSet(const char *name, TFileCollection *dataset, const char *optStr="")
Register the &#39;dataSet&#39; on the cluster under the current user, group and the given &#39;dataSetName&#39;...
Definition: TProof.cxx:10679
Collectable string class.
Definition: TObjString.h:28
virtual void ShowDataSetCache(const char *dataset=0)
Display the content of the dataset cache, if any (matching &#39;dataset&#39;, if defined).
Definition: TProof.cxx:10886
This class represents a WWW compatible URL.
Definition: TUrl.h:35
Float_t GetStagedPercentage() const
TFileCollection * GetDataSet(const char *ds, const char *server)
GetDataSet wrapper.
Definition: pq2wrappers.cxx:87
virtual Bool_t RemoveDataSet(const char *uri)
Removes the indicated dataset.
virtual TFileCollection * GetDataSet(const char *dataset, const char *optStr="")
Get a list of TFileInfo objects describing the files of the specified dataset.
Definition: TProof.cxx:10909
virtual TFileCollection * GetDataSet(const char *uri, const char *server=0)
Utility function used in various methods for user dataset upload.
void Add(TObject *obj)
This function may not be used (but we need to provide it since it is a pure virtual in TCollection)...
Definition: TMap.cxx:53
#define gROOT
Definition: TROOT.h:410
Int_t LoadPlugin()
Load the plugin library for this handler.
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual void ShowDataSets(const char *uri="*", const char *opt="")
Prints formatted information about the dataset &#39;uri&#39;.
Int_t RegisterDataSet(const char *dsname, TFileCollection *fc, const char *opt)
RegisterDataSet wrapper.
TString ferr
Definition: pq2main.cxx:38
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:387
virtual void SetValue(const char *name, const char *value, EEnvLevel level=kEnvChange, const char *type=0)
Set the value of a resource or create a new resource.
Definition: TEnv.cxx:736
static struct mg_connection * fc(struct mg_context *ctx)
Definition: civetweb.c:3352
Int_t gverbose
Definition: pq2main.cxx:40
void SetLogLevel(Int_t level, UInt_t mask=TProofDebug::kAll)
Set server logging level.
Definition: TProof.cxx:7051
TString flog
Definition: pq2main.cxx:37
virtual Int_t RegisterDataSet(const char *uri, TFileCollection *dataSet, const char *opt)
Register a dataset, perfoming quota checkings, if needed.
void DeleteAll()
Remove all (key,value) pairs from the map AND delete the keys AND values when they are allocated on t...
Definition: TMap.cxx:167
virtual TMap * GetDataSets(const char *uri="", const char *optStr="")
Lists all datasets that match given uri.
Definition: TProof.cxx:10781
virtual void ShowDataSets(const char *uri="", const char *optStr="")
Shows datasets in locations that match the uri.
Definition: TProof.cxx:10818
static TProof * Open(const char *url=0, const char *conffile=0, const char *confdir=0, Int_t loglevel=0)
Start a PROOF session on a specific cluster.
Definition: TProof.cxx:11555
Bool_t gIsProof
Definition: pq2ping.cxx:50
Int_t getProof(const char *where, Int_t verbose=1)
Open a PROOF session at gUrl.
TString fres
Definition: pq2main.cxx:39
Long_t ExecPlugin(int nargs, const T &... params)
virtual Bool_t ExistsDataSet(const char *uri)
Checks if the indicated dataset exits.
virtual Int_t ShowCache(const char *uri)
Show cached information matching uri.
virtual void ClearDataSetCache(const char *dataset=0)
Clear the content of the dataset cache, if any (matching &#39;dataset&#39;, if defined).
Definition: TProof.cxx:10868
Bool_t ExistsDataSet(const char *dsname)
ExistsDataSet wrapper.
virtual Int_t VerifyDataSet(const char *dataset, const char *optStr="")
Verify if all files in the specified dataset are available.
Definition: TProof.cxx:11102
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition: TString.cxx:2264
unsigned int UInt_t
Definition: RtypesCore.h:42
Int_t ScanDataSet(const char *uri, const char *opt)
Scans the dataset indicated by &#39;uri&#39; following the &#39;opts&#39; directives.
static void AddEnvVar(const char *name, const char *value)
Add an variable to the list of environment variables passed to proofserv on the master and slaves...
Definition: TProof.cxx:11732
TMap * GetDataSets(const char *owner, const char *server, const char *opt)
GetDataSets wrapper.
Int_t getDSMgr(const char *where)
Open a dataset manager for gUrl.
#define h(i)
Definition: RSha256.hxx:106
#define Printf
Definition: TGeoToOCC.h:18
static bool doParallel
Definition: pq2wrappers.cxx:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
TUrl gUrl
Definition: pq2ping.cxx:49
R__EXTERN TProof * gProof
Definition: TProof.h:1077
void Close(Option_t *option="")
Close all open slave servers.
Definition: TProof.cxx:1776
Int_t GetParallel() const
Returns number of slaves active in parallel mode.
Definition: TProof.cxx:2282
TMap implements an associative array of (key,value) pairs using a THashTable for efficient retrieval ...
Definition: TMap.h:40
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:619
Int_t VerifyDataSet(const char *dsname, const char *opt, const char *redir)
VerifyDataSet wrapper.
void DataSetCache(bool clear, const char *ds)
ShowCache wrapper.
Definition: pq2wrappers.cxx:50
Bool_t IsNull() const
Definition: TString.h:402
Mother of all ROOT objects.
Definition: TObject.h:37
Class that contains a list of TFileInfo&#39;s and accumulated meta data information about its entries...
TObject * GetValue(const char *keyname) const
Returns a pointer to the value associated with keyname as name of the key.
Definition: TMap.cxx:235
void ShowDataSets(const char *ds, const char *opt)
ShowDataSets wrapper.
Definition: pq2wrappers.cxx:70
Bool_t IsValid() const
Definition: TProof.h:937
virtual Int_t RemoveDataSet(const char *dataset, const char *optStr="")
Remove the specified dataset from the PROOF cluster.
Definition: TProof.cxx:10963
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:357
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual TMap * GetDataSets(const char *uri, UInt_t=TDataSetManager::kExport)
Returns all datasets for the <group> and <user> specified by <uri>.
TDataSetManager * gDataSetManager
Definition: pq2wrappers.cxx:31
const char * Data() const
Definition: TString.h:364