Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TProofBenchDataSet.cxx
Go to the documentation of this file.
1 // @(#)root/proof:$Id$
2 // Author: Sangsu Ryu 22/06/2010
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, 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 /** \class TProofBenchDataSet
13 \ingroup proofbench
14 
15 Handle operations on datasets used by ProofBench
16 
17 */
18 
19 #include "RConfigure.h"
20 
21 #include "TProofBenchDataSet.h"
22 #include "TClass.h"
23 #include "TFileCollection.h"
24 #include "TList.h"
25 #include "TMap.h"
26 #include "TProof.h"
27 #include "TProofBenchTypes.h"
28 #include "TROOT.h"
29 
30 
31 ClassImp(TProofBenchDataSet);
32 
33 ////////////////////////////////////////////////////////////////////////////////
34 /// Constructor
35 
36 TProofBenchDataSet::TProofBenchDataSet(TProof *proof)
37 {
38  fProof = proof ? proof : gProof;
39 }
40 
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Release memory cache for dataset 'dset'
44 /// Return 0 on success, -1 on error
45 
46 Int_t TProofBenchDataSet::ReleaseCache(const char *dset)
47 {
48  // Clear the cache
49  TPBHandleDSType type(TPBHandleDSType::kReleaseCache);
50  if (Handle(dset, &type) != 0) {
51  Error("ReleaseCache", "problems clearing cache for '%s'", dset);
52  return -1;
53  }
54  // Done
55  return 0;
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// Physically remove the dataset 'dset', i.e. remove the dataset and the files
60 /// it describes
61 /// Return 0 on success, -1 on error
62 
63 Int_t TProofBenchDataSet::RemoveFiles(const char *dset)
64 {
65  // Phyically remove the files
66  TPBHandleDSType type(TPBHandleDSType::kRemoveFiles);
67  if (Handle(dset, &type) != 0) {
68  Error("RemoveFiles", "problems removing files for '%s'", dset);
69  return -1;
70  }
71  // Remove the meta information
72  if (!fProof || (fProof && fProof->RemoveDataSet(dset) != 0)) {
73  Error("RemoveFiles", "problems removing meta-information for dataset '%s'", dset);
74  return -1;
75  }
76  // Done
77  return 0;
78 }
79 
80 ////////////////////////////////////////////////////////////////////////////////
81 /// Copy the files of dataset 'dset' to another directory
82 /// Return 0 on success, -1 on error
83 
84 Int_t TProofBenchDataSet::CopyFiles(const char *dset, const char *destdir)
85 {
86  // Check input
87  if (!destdir || (destdir && strlen(destdir) <= 0)) {
88  Error("CopyFiles", "specifying a destination dir is mandatory!");
89  return -1;
90  }
91 
92  // Set the destination dir
93  if (fProof) fProof->SetParameter("PROOF_Benchmark_DestDir", destdir);
94 
95  // Copy the files
96  TPBHandleDSType type(TPBHandleDSType::kCopyFiles);
97  if (Handle(dset, &type) != 0) {
98  Error("CopyFiles", "problems copying files for '%s'", dset);
99  return -1;
100  }
101 
102  // Done
103  return 0;
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// Physically remove the dataset 'dset', i.e. remove the dataset and the files
108 /// it describes
109 /// Return 0 on success, -1 on error
110 
111 Int_t TProofBenchDataSet::Handle(const char *dset, TObject *type)
112 {
113  // Check input
114  if (!dset || (dset && strlen(dset) <= 0)) {
115  Error("Handle", "a valid dataset name is mandatory");
116  return -1;
117  }
118 
119  // The dataset must exist
120  if (!fProof || (fProof && !fProof->ExistsDataSet(dset))) {
121  Error("Handle", "dataset '%s' does not exist", dset);
122  return -1;
123  }
124 
125  // Get the dataset
126  TFileCollection *fc = fProof->GetDataSet(dset);
127  if (!fc) {
128  Error("Handle", "TFileCollection object for dataset '%s' could not be retrieved", dset);
129  return -1;
130  }
131 
132  // Get information per server
133  TMap *fcmap = fc->GetFilesPerServer(fProof->GetMaster(), kTRUE);
134  if (!fcmap) {
135  Error("Handle", "could not create map with per-server info for dataset '%s'", dset);
136  return -1;
137  }
138  fcmap->Print();
139 
140  // Load the selector, if needed
141  TString selName("TSelHandleDataSet");
142  if (!TClass::GetClass(selName)) {
143  // Load the parfile
144  TString par = TString::Format("%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
145  Info("Handle", "Uploading '%s' ...", par.Data());
146  if (fProof->UploadPackage(par) != 0) {
147  Error("Handle", "problems uploading '%s' - cannot continue", par.Data());
148  return -1;
149  }
150  Info("Handle", "Enabling '%s' ...", kPROOF_BenchDataSelPar);
151  if (fProof->EnablePackage(kPROOF_BenchDataSelPar) != 0) {
152  Error("Handle", "problems enabling '%s' - cannot continue", kPROOF_BenchDataSelPar);
153  return -1;
154  }
155  // Check
156  if (!TClass::GetClass(selName)) {
157  Error("Handle", "failed to load '%s'", selName.Data());
158  return -1;
159  }
160  }
161 
162  // Add map in the input list
163  fcmap->SetName("PROOF_FilesToProcess");
164  fProof->AddInput(fcmap);
165 
166  // Set parameters for processing
167  TString oldpack;
168  if (TProof::GetParameter(fProof->GetInputList(), "PROOF_Packetizer", oldpack) != 0) oldpack = "";
169  fProof->SetParameter("PROOF_Packetizer", "TPacketizerFile");
170 
171  // Process
172  fProof->AddInput(type);
173  fProof->Process(selName, (Long64_t) fc->GetNFiles());
174  if (fProof->GetInputList()) fProof->GetInputList()->Remove(type);
175 
176  // Restore parameters
177  if (!oldpack.IsNull())
178  fProof->SetParameter("PROOF_Packetizer", oldpack);
179  else
180  fProof->DeleteParameters("PROOF_Packetizer");
181 
182  // Cleanup
183  fProof->GetInputList()->Remove(fcmap);
184  delete fcmap;
185  delete fc;
186 
187  // Done
188  return 0;
189 }