13 #include "eckit/filesystem/PathName.h"
14 #include "eckit/log/Timer.h"
15 #include "eckit/config/Resource.h"
20 using namespace eckit;
31 string dhsHome (::getenv(
"DHSHOME") ? ::getenv(
"DHSHOME")
32 : ::getenv(
"TEST_DHSHOME") ? ::getenv(
"TEST_DHSHOME")
36 throw UserError(
"expandTilde: DHSHOME or TEST_DHSHOME must be set");
38 if (s.size() && s[0] ==
'~')
39 return dhsHome +
"/" + s.substr(1);
48 string prestageScript;
49 if (r.find(
"odbServerPrestageScript") != r.end())
51 vector<string> odbServerPrestageScripts (r.at(
"odbServerPrestageScript"));
52 if (odbServerPrestageScripts.size() > 1)
53 throw UserError(
"odbServerPrestageScript must be one value at most");
54 if (odbServerPrestageScripts.size() == 1)
55 prestageScript = odbServerPrestageScripts[0];
57 if (prestageScript.size() == 0)
58 prestageScript = string(Resource<string>(
"$ODB_SERVER_PRESTAGE_SCRIPT",
""));
59 if (prestageScript.size() == 0)
60 prestageScript = string(Resource<string>(
"odbServerPrestageScript",
""));
68 if (prestageScript.size() == 0)
71 Timer timer(
"Prestage " + fileName);
73 cmd << prestageScript <<
" " << fileName;
74 Log::debug() <<
"Calling prestage script: '" << cmd.str() <<
"'" << endl;
75 int rc (::system(cmd.str().c_str()));
78 ss <<
"prestage command '" << cmd.str() <<
"' failed (return code: " <<
rc <<
")";
80 throw SeriousBug(ss.str());
88 std::vector<eckit::PathName> r;
99 ASSERT(files.size() > 0);
100 for (
size_t i (0);
i < files.size(); ++
i)
104 if (PathName(p).exists())
106 Log::info() <<
"FileCollector::collectFile: FOUND " << p << endl;
109 Log::info() <<
"FileCollector::collectFile: NOT found " << p << endl;
116 ss <<
"File " << relativePath <<
" found in more than one root directory: " <<
foundFiles;
117 throw UserError(ss.str());
129 product(0, keywords, request, map<string,string>());
133 const vector<string>& keywords,
134 const map<
string, vector<string> >& request,
135 const map<string,string>& combination)
137 if (k == keywords.size())
140 const string& keyword (keywords[k]);
141 const vector<string>& values (request.find(keyword)->second);
142 for (
size_t i (0);
i < values.size(); ++
i)
144 map<string,string> newCombination(combination);
145 newCombination[keyword] = values[
i];
146 product(k + 1, keywords, request, newCombination);
std::vector< std::string > foundFiles() const
void product(size_t k, const std::vector< std::string > &keywords, const std::map< std::string, std::vector< std::string > > &, const std::map< std::string, std::string > &)
std::vector< std::string > allFound_
void findFiles(const std::vector< std::string > &, const std::map< std::string, std::vector< std::string > > &)
std::vector< eckit::PathName > foundFilesAsPathNames() const
virtual void collectFile(const std::map< std::string, std::vector< std::string > > &, const std::map< std::string, std::string > &values)
const FileMapper & mapper_
static std::string expandTilde(const std::string &s)
std::string prestageScriptPath(const std::map< std::string, std::vector< std::string > > &r) const
eckit::MultiHandle & multiHandle_
void prestage(const std::map< std::string, std::vector< std::string > > &, const std::string &fileName)
FileCollector(const FileMapper &, eckit::MultiHandle &)
std::vector< std::string > encode(const std::map< std::string, std::string > &values) const
std::string encodeRelative(const std::map< std::string, std::string > &values) const