Logo ROOT  
Reference Guide
TSelHandleDataSet.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 TSelHandleDataSet
13\ingroup proofbench
14
15PROOF selector for file cache release.
16List of files to be cleaned for each node is provided by client.
17
18*/
19
20#define TSelHandleDataSet_cxx
21
22#include "TSelHandleDataSet.h"
23
24#include "TDSet.h"
25#include "TEnv.h"
26#include "TFile.h"
27#include "TMap.h"
28#include "TParameter.h"
29#include "TProofBenchTypes.h"
30#include "TSystem.h"
31#include "TUrl.h"
32#include "errno.h"
33#include <unistd.h>
34#include <fcntl.h>
35
36
38
39////////////////////////////////////////////////////////////////////////////////
40/// Init the type from the input parameters
41
43{
44
45 TObject *o = fInput->FindObject("PROOF_Benchmark_HandleDSType");
46 if (o) fType = dynamic_cast<TPBHandleDSType *>(o);
47
48 TNamed *n = dynamic_cast<TNamed *>(fInput->FindObject("PROOF_Benchmark_DestDir"));
49 if (n) {
50 fDestDir = n->GetTitle();
52 // Create the directory
53 if (gSystem->mkdir(fDestDir, kTRUE) != 0) {
54 fDestDir = "";
55 Error("SlaveBegin", "could not create dir '%s'", fDestDir.Data());
56 } else {
58 fDestDir = "";
59 Error("SlaveBegin", "dir '%s' is not writable by this process", fDestDir.Data());
60 } else {
61 Info("SlaveBegin", "dir '%s' successfully created", fDestDir.Data());
62 }
63 }
64 }
65 }
66
67 // Use default if nothing found in the input list
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Release the memory cache associated with file 'fn'.
73
75{
76#if defined(R__LINUX)
77 TString filename(fn);
78 Int_t fd;
79 fd = open(filename.Data(), O_RDONLY);
80 if (fd > -1) {
81 fdatasync(fd);
82 posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED);
83 close(fd);
84 Info("ReleaseCache", "file cache for file '%s' cleaned ...", filename.Data());
85 } else {
86 Error("ReleaseCache", "cannot open file '%s' for cache clean up; errno=%d",
87 filename.Data(), errno);
88 }
89#else
90 Info("ReleaseCache", "dummy function: file '%s' untouched ...", fn);
91#endif
92 // Done
93 return;
94}
95
96////////////////////////////////////////////////////////////////////////////////
97/// Check the memory cache associated with file 'fn'.
98
99void TSelHandleDataSet::CheckCache(const char * /*fn*/)
100{
101 Warning("CheckCache", "cache checker not implemented yet");
102 // Done
103 return;
104}
105
106////////////////////////////////////////////////////////////////////////////////
107/// Physically remove the file 'fn'.
108
110{
112 if (gSystem->Unlink(fn) != 0) {
113 Error("RemoveFile", "problems removing file '%s' ...", fn);
114 } else {
115 if (!gSystem->AccessPathName(fn))
116 Warning("RemoveFile", "'unlink' returned success but the file still exists ('%s')", fn);
117 }
118 } else {
119 if (!gSystem->AccessPathName(fn)) {
120 Error("RemoveFile", "file '%s' cannot removed by this process", fn);
121 } else {
122 Error("RemoveFile", "file '%s' does not exists", fn);
123 }
124 }
125 // Done
126 return;
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Copy file 'fn' to fDestDir
131
132void TSelHandleDataSet::CopyFile(const char *fn)
133{
134 // Check if we have a destination dir
135 if (fDestDir.IsNull()) {
136 Error("CopyFile", "destination dir undefined: file '%s' not copied", fn);
137 return;
138 }
139
140 TString basefn = gSystem->BaseName(TUrl(fn, kTRUE).GetFile());
141 TString dst = TString::Format("%s/%s", fDestDir.Data(), basefn.Data());
142 if (!TFile::Cp(fn, dst.Data())) {
143 Error("CopyFile", "problems copying file '%s' to '%s'", fn, dst.Data());
144 return;
145 }
146 Info("CopyFile", "file '%s' created ...", dst.Data());
147
148 // Done
149 return;
150}
151
152////////////////////////////////////////////////////////////////////////////////
153/// The Process() function is called for each entry in the tree (or possibly
154/// keyed object in the case of PROOF) to be processed. The entry argument
155/// specifies which entry in the currently loaded tree is to be processed.
156/// It can be passed to either TTree::GetEntry() or TBranch::GetEntry()
157/// to read either all or the required parts of the data. When processing
158/// keyed objects with PROOF, the object is already loaded and is available
159/// via the fObject pointer.
160///
161/// This function should contain the "body" of the analysis. It can contain
162/// simple or elaborate selection criteria, run algorithms on the data
163/// of the event and typically fill histograms.
164
166{
167 // WARNING when a selector is used with a TChain, you must use
168 // the pointer to the current TTree to call GetEntry(entry).
169 // The entry is always the local entry number in the current tree.
170 // Assuming that fChain is the pointer to the TChain being processed,
171 // use fChain->GetTree()->GetEntry(entry).
172
173 TDSetElement *fCurrent = 0;
174 TPair *elemPair = 0;
175 if (fInput && (elemPair = dynamic_cast<TPair *>
176 (fInput->FindObject("PROOF_CurrentElement")))) {
177 if ((fCurrent = dynamic_cast<TDSetElement *>(elemPair->Value()))) {
178 Info("Process", "entry %lld: file: '%s'", entry, fCurrent->GetName());
179 } else {
180 Error("Process", "entry %lld: no file specified!", entry);
181 return kFALSE;
182 }
183 }
184
185 // Resolve the file type; this also adjusts names for Xrd based systems
186 TUrl url(fCurrent->GetName());
187 url.SetAnchor(0);
188 TString lfname = gEnv->GetValue("Path.Localroot", "");
189 TFile::EFileType type = TFile::GetType(url.GetUrl(), "", &lfname);
190 if (type == TFile::kLocal &&
191 strcmp(url.GetProtocol(),"root") && strcmp(url.GetProtocol(),"xrd"))
192 lfname = url.GetFileAndOptions();
193
195 // Release the file cache
196 if (type == TFile::kLocal) {
197 ReleaseCache(lfname);
198 } else if (type == TFile::kFile) {
199 ReleaseCache(url.GetFile());
200 } else {
201 Error("Process",
202 "attempt to call ReleaseCache for a non-local file: '%s'", url.GetUrl());
203 }
204 } else if (fType->GetType() == TPBHandleDSType::kCheckCache) {
205 // Check the file cache
206 if (type == TFile::kLocal) {
207 CheckCache(lfname);
208 } else if (type == TFile::kFile) {
209 CheckCache(url.GetFile());
210 } else {
211 Error("Process",
212 "attempt to call CheckCache for a non-local file: '%s'", url.GetUrl());
213 }
215 // Remove the file
217 } else if (fType->GetType() == TPBHandleDSType::kCopyFiles) {
218 // Copy file
220 } else {
221 // Type unknown
222 Warning("Process", "type: %d is unknown", fType->GetType());
223 }
224
225 return kTRUE;
226}
227
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
int type
Definition: TGX11.cxx:120
@ kWritePermission
Definition: TSystem.h:47
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
Manages an element of a TDSet.
Definition: TDSet.h:66
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
static EFileType GetType(const char *name, Option_t *option="", TString *prefix=nullptr)
Resolve the file type as a function of the protocol field in 'name'.
Definition: TFile.cxx:4637
EFileType
File type.
Definition: TFile.h:189
@ kLocal
Definition: TFile.h:189
@ kFile
Definition: TFile.h:189
virtual Bool_t Cp(const char *dst, Bool_t progressbar=kTRUE, UInt_t buffersize=1000000)
Allows to copy this file to the dst URL.
Definition: TFile.cxx:4820
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:575
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Mother of all ROOT objects.
Definition: TObject.h:37
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:854
EHandleDSType GetType() const
Class used by TMap to store (key,value) pairs.
Definition: TMap.h:102
TObject * Value() const
Definition: TMap.h:121
PROOF selector for file cache release.
virtual Bool_t Process(Long64_t entry)
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
void RemoveFile(const char *fn)
Physically remove the file 'fn'.
virtual void SlaveBegin(TTree *)
Init the type from the input parameters.
TPBHandleDSType * fType
void ReleaseCache(const char *fn)
Release the memory cache associated with file 'fn'.
void CheckCache(const char *fn)
Check the memory cache associated with file 'fn'.
void CopyFile(const char *fn)
Copy file 'fn' to fDestDir.
TList * fInput
List of objects available during processing.
Definition: TSelector.h:43
Basic string class.
Definition: TString.h:131
const char * Data() const
Definition: TString.h:364
Bool_t IsNull() const
Definition: TString.h:402
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition: TString.cxx:2311
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition: TSystem.cxx:914
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
Definition: TSystem.cxx:1287
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition: TSystem.cxx:942
virtual int Unlink(const char *name)
Unlink, i.e.
Definition: TSystem.cxx:1372
A TTree represents a columnar dataset.
Definition: TTree.h:72
This class represents a WWW compatible URL.
Definition: TUrl.h:35
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition: TUrl.cxx:385
void SetAnchor(const char *anchor)
Definition: TUrl.h:88
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition: TUrl.cxx:499
const char * GetFile() const
Definition: TUrl.h:71
const char * GetProtocol() const
Definition: TUrl.h:66
const Int_t n
Definition: legend1.C:16