1 |
#include <log4cxx/logger.h> |
2 |
#include <YFile.h> |
3 |
|
4 |
using namespace log4cxx; |
5 |
using namespace yngn; |
6 |
using namespace yngn::util; |
7 |
using namespace yngn::YException; |
8 |
|
9 |
TFile *YFile::yfile = 0; |
10 |
static LoggerPtr logger = Logger::getLogger(_T("yngn.util.YFile")); |
11 |
|
12 |
/** |
13 |
* Open/copy a file from remote (rfio) or local path. |
14 |
* This solution have been implemented mainly because the CASTOR system could have performance problem in |
15 |
* case of interactive file opening: the use of the "copy" flag, allow the minimum change for the existing |
16 |
* softwares. |
17 |
* @param url Path to the database to be used. |
18 |
* @param options Path to the database to be used. |
19 |
* @param copy Flag to define if the file have to be copied on a specified path or not. Default si false. |
20 |
* @param path Where to copy the file. Default is local. |
21 |
*/ |
22 |
TFile* YFile::Open(const char *url, const char* options, bool copy, const char *path) throw (YNotExistingFileException, YSystemCommandException) { |
23 |
const char *name; |
24 |
if ((copy) && (strlen(strstr(url, "rfio:/")) > 0)){ |
25 |
char cmd[999]; |
26 |
//Here do the copy of the remote file |
27 |
if (copy){ |
28 |
strcpy (cmd,"rfcp "); |
29 |
strcat (cmd,url+5); |
30 |
strcat (cmd," "); |
31 |
strcat (cmd, path); |
32 |
if (system(cmd) == 0) throw YSystemCommandException(cmd); |
33 |
name = strrchr(url,'/'); |
34 |
} |
35 |
} else { |
36 |
name = url; |
37 |
} |
38 |
yfile = TFile::Open(name, options); |
39 |
if (yfile == 0) throw YNotExistingFileException(url); |
40 |
return yfile; |
41 |
} |