KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVDMS.cpp
1//Created by KVClassFactory on Thu Oct 18 10:38:52 2012
2//Author: John Frankland
3
4#include "KVDMS.h"
5#include "TSystem.h"
6#include "TList.h"
7#include "TObjArray.h"
8#include "TObjString.h"
9#include "TROOT.h"
10#include "Riostream.h"
11
12#include "KVUniqueNameList.h"
13
14using namespace std;
15
17
18
19
21
22KVDMS::KVDMS(const Char_t* name, const Char_t* title)
23 : KVBase(name, title)
24{
25 // Default ctor with name and title
26}
27
28
29
31
33{
34}
35
36
37
47
48Bool_t KVDMS::buildCommand(const Char_t* scmd, const Char_t* args, Option_t* opts)
49{
50 // scmd = one of the DMS commands (init, ls, get, etc.)
51 // args = (optional) list of arguments for command (filename, etc.)
52 // opts = (optional) list of options for command
53 // If the command give in 'scmd' is found in the path specified by the
54 // user's PATH environment variables, this method returns kTRUE and
55 // private member variables fexec and fcmd will hold the full path to
56 // the executable and the full command line to pass to gSystem->Exec.
57 // If executable is not found, returns kFALSE.
58
59 fexec = scmd;
60 if (!FindExecutable(fexec)) {
61 fexec = "";
62 fcmd = "";
63 return kFALSE;
64 }
65 fcmd = fexec + " ";
66 fcmd += opts;
67 fcmd += " ";
68 fcmd += args;
69 return kTRUE;
70}
71
72
73
78
80{
81 // Execute last command initialised with buildCommand() and return
82 // the value given by the operating system.
83 // Returns -1 if no command has been defined.
84
85 if (fcmd == "") return -1;
86 return gSystem->Exec(fcmd.Data());
87}
88
89
90
94
96{
97 // Execute last command initialised with buildCommand() and return
98 // the value given by the operating system in a string.
99
100 if (fcmd == "") return TString("");
102 return fout;
103}
104
105
106
110
112{
113 // 'line' is a line in a directory listing
114 // This method should return kTRUE if the line corresponds to a container
115
116 return (line.BeginsWith("C-"));
117}
118
119
120
126
128{
129 // Create and fill TList with info (name, size, modification date)
130 // on all files & containers in current directory
131 // (default) or in given directory.
132 // TList is filled with DMSFile_t objects which belong to the list, list must be deleted after use.
133
134 longlist(directory);
135 if (fout == "") {
136 Error("GetListing", "Unknown directory %s", directory);
137 return 0;
138 }
139
140 TObjArray* toks = fout.Tokenize("\n");
142 list->SetOwner(kTRUE);
143 list->SetName(((TObjString*)(*toks)[0])->String().Remove(TString::kBoth, ' ').Data());
144 for (int i = 1; i < toks->GetEntries(); i++) {
145 TString tmp = ((TObjString*)(*toks)[i])->String().Remove(TString::kBoth, ' ');
146 DMSFile_t* f = new DMSFile_t;
147 if (IsContainer(tmp)) { // container
148 f->SetName(gSystem->BaseName(tmp.Data()));
149 f->SetIsContainer();
150 }
151 else {
152 ExtractFileInfos(tmp, f);
153 }
154 list->Add(f);
155 }
156 delete toks;
157 return list;
158}
159
160
161
165
167{
168 // Returns kTRUE if 'path' exists (file or directory, absolute or relative pathname).
169 // If so, KVDMSFile_t object will be filled with information on file/container
170
172 TString dirname = gSystem->DirName(path);
173 if (DirectoryContains(filename.Data(), dirname.Data())) {
174 longlist(path);
175 fout.Remove(TString::kBoth, ' ');
176 fs.SetName(filename.Data());
177 if (IsContainer(fout)) { // container
178 fs.SetIsContainer();
179 }
180 else {
182 }
183 return kTRUE;
184 }
185 return kFALSE;
186}
187
188
189
194
196{
197 // Create and fill TList with just the names of files & containers in current directory
198 // (default) or in given directory.
199 // TList is filled with DMSFile_t objects which belong to the list, list must be deleted after use.
200
201 list(directory);
202 if (fout == "") {
203 Error("GetListing", "Unknown directory %s", directory);
204 return 0;
205 }
206
207 TObjArray* toks = fout.Tokenize("\n");
208 TList* list = new TList;
209 list->SetOwner(kTRUE);
210 list->SetName(((TObjString*)(*toks)[0])->String().Remove(TString::kBoth, ' ').Data());
211 for (int i = 1; i < toks->GetEntries(); i++) {
212 TString tmp = ((TObjString*)(*toks)[i])->String().Remove(TString::kBoth, ' ');
213 DMSFile_t* f = new DMSFile_t;
214 if (IsContainer(tmp)) { // container
215 f->SetName(gSystem->BaseName(tmp.Data()));
216 f->SetIsContainer();
217 }
218 else {
219 f->SetName(tmp.Data());
220 }
221 list->Add(f);
222 }
223 delete toks;
224 return list;
225}
226
227
228
232
233Bool_t KVDMS::DirectoryContains(const Char_t* name, const Char_t* directory)
234{
235 // Returns true if the current directory (default) or the given directory
236 // contains a file or a container with given name.
237
238 TList* list = GetListing(directory);
239 if (!list)
240 return kFALSE;
241 Bool_t ok = list->FindObject(name);
242 delete list;
243 return ok;
244}
245
246
248
249
250// DMSFile_t
251//
252// Describes Data Management System file/container attributes
254
255
256
258
259void DMSFile_t::ls(Option_t* /*opt*/) const
260{
261 // List file/container attributes
262
264 if (IsContainer())
265 cout << GetName() << "/" << endl;
266 else
267 cout << GetName() << "\t" << GetSize() << "\t" << GetModTime().AsString() << endl;
268}
269
270
int Int_t
#define f(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
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 fs
char name[80]
R__EXTERN TSystem * gSystem
Base class for KaliVeda framework.
Definition KVBase.h:142
static Bool_t FindExecutable(TString &exec, const Char_t *path="$(PATH)")
Definition KVBase.cpp:1001
Abstract base class for interfaces to Data Management Systems (SRB, IRODS, etc.)
Definition KVDMS.h:60
virtual ~KVDMS()
Definition KVDMS.cpp:32
virtual TString longlist(const Char_t *directory="")=0
virtual Bool_t GetPathInfo(const Char_t *path, DMSFile_t &fs)
Definition KVDMS.cpp:166
TString fcmd
string holding full path to command line with arguments
Definition KVDMS.h:62
TString fexec
string holding full path to executable
Definition KVDMS.h:61
virtual void ExtractFileInfos(TString &, DMSFile_t *) const =0
TString pipeCommand()
Definition KVDMS.cpp:95
virtual Bool_t DirectoryContains(const Char_t *name, const Char_t *directory="")
Definition KVDMS.cpp:233
TString fout
string holding results of command
Definition KVDMS.h:63
virtual TList * GetListing(const Char_t *directory="")
Definition KVDMS.cpp:195
Int_t execCommand()
Definition KVDMS.cpp:79
Bool_t buildCommand(const Char_t *scmd, const Char_t *args="", Option_t *opts="")
Definition KVDMS.cpp:48
virtual Bool_t IsContainer(TString &) const
Definition KVDMS.cpp:111
virtual KVUniqueNameList * GetFullListing(const Char_t *directory="")
Definition KVDMS.cpp:127
virtual TString list(const Char_t *directory="")=0
Optimised list in which named objects can only be placed once.
Int_t GetEntries() const override
virtual void Error(const char *method, const char *msgfmt,...) const
static void IndentLevel()
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
TString & Remove(EStripType s, char c)
virtual const char * DirName(const char *pathname)
virtual Int_t Exec(const char *shellcmd)
virtual const char * BaseName(const char *pathname)
virtual TString GetFromPipe(const char *command)
TLine * line
const char * String
ClassImp(TPyArg)