Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
@ kWritePermission
Definition TSystem.h:46
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:4807
EFileType
File type.
Definition TFile.h:202
@ kLocal
Definition TFile.h:202
@ kFile
Definition TFile.h:202
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:4990
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:578
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
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.
void RemoveFile(const char *fn)
Physically remove the file 'fn'.
void SlaveBegin(TTree *) override
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'.
Bool_t Process(Long64_t entry) override
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
void CopyFile(const char *fn)
Copy file 'fn' to fDestDir.
TList * fInput
List of objects available during processing.
Definition TSelector.h:41
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:380
Bool_t IsNull() const
Definition TString.h:418
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:2356
virtual int mkdir(const char *name, Bool_t recursive=kFALSE)
Make a file system directory.
Definition TSystem.cxx:893
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:1283
virtual const char * BaseName(const char *pathname)
Base name of a file name. Base name of /user/root is root.
Definition TSystem.cxx:921
virtual int Unlink(const char *name)
Unlink, i.e.
Definition TSystem.cxx:1368
A TTree represents a columnar dataset.
Definition TTree.h:79
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
Definition TUrl.cxx:390
void SetAnchor(const char *anchor)
Definition TUrl.h:86
const char * GetFileAndOptions() const
Return the file and its options (the string specified behind the ?).
Definition TUrl.cxx:504
const char * GetFile() const
Definition TUrl.h:69
const char * GetProtocol() const
Definition TUrl.h:64
const Int_t n
Definition legend1.C:16