7 #ifndef XAOD_STANDALONE
8 #include "GaudiKernel/System.h"
18 #include <boost/algorithm/string/split.hpp>
19 #include <boost/algorithm/string.hpp>
20 #include <boost/algorithm/string/classification.hpp>
21 #include <boost/filesystem.hpp>
30 namespace bf = boost::filesystem;
34 enum class DevAreaResponse {
42 const std::string pathResolverEnvVar =
"PATHRESOLVER_DEVAREARESPONSE";
43 DevAreaResponse getDevAreaResponse(
44 const std::string&
varname = pathResolverEnvVar)
48 std::string envstr(
env);
49 #define TRYSTR(string) if (envstr == #string) return DevAreaResponse::string
57 throw std::runtime_error(
58 varname +
" set to '" + envstr +
"', not sure what to do. "
59 "Option are DEFAULT, THROW, INFO, WARNING, ERROR, or SILENT");
63 const std::string& logical_file_name,
64 const std::string& envvar = pathResolverEnvVar) {
65 DevAreaResponse dev_area_response = getDevAreaResponse(envvar);
67 if(logical_file_name.compare(0, 4,
"dev/")==0 &&
68 dev_area_response != DevAreaResponse::SILENT)
70 auto level = MSG::ERROR;
74 switch(dev_area_response) {
80 asgmsg.
msg(
level) <<
"Locating dev file " << logical_file_name <<
". Do not let this propagate to a release" <<
endmsg;
81 if (dev_area_response == DevAreaResponse::THROW) {
82 throw std::runtime_error(
83 "dev area file " + logical_file_name +
" is not allowed! "
84 "to override this error set the environment variable " +
85 envvar +
" to SILENT, DEFAULT, INFO, WARNING, or ERROR");
91 static const char*
const path_separator =
",:";
97 #ifdef XAOD_STANDALONE
102 #ifndef XAOD_ANALYSIS
104 asgMsg.setLevel(m_level);
106 asgMsg.msg().setLevel(m_level);
126 std::string trimmed_logical_file_name = logical_file_name;
136 if ( ( file_type == PR_regular_file && is_regular_file(
file ) ) ||
137 ( file_type == PR_directory && is_directory(
file ) ) ) {
141 }
catch (
const bf::filesystem_error& ) {
148 if ( ( file_type == PR_regular_file && is_regular_file(
local ) ) ||
149 ( file_type == PR_directory && is_directory(
local ) ) ) {
153 }
catch (
const bf::filesystem_error& ) {
156 std::string locationToDownloadTo =
".";
160 split(spv, search_list, boost::is_any_of( path_separator), boost::token_compress_on);
161 for (vector<string>::const_iterator itr = spv.begin();
162 itr != spv.end(); ++itr ) {
164 if( itr->find(
"http//")==0 && file_type==PR_regular_file && gSystem->Getenv(
"PATHRESOLVER_ALLOWHTTPDOWNLOAD") ) {
167 std::string addr =
"http://"; addr += itr->substr(6,itr->length());
169 bf::path lpd = lp; lpd.remove_filename();
172 if(!is_directory(lpd)) {
174 if(!boost::filesystem::create_directories(lpd)) {
180 std::string fileToDownload = addr +
"/" +
file.string();
181 std::string targetPath = locationToDownloadTo+
"/"+
file.string();
187 if(!TFile::Cp(fileToDownload.c_str(),targetPath.c_str(),
false)) {
188 msg(MSG::WARNING) <<
"Unable to download file : " << fileToDownload <<
endmsg;
191 result = (locationToDownloadTo+
"/"+
file.string()).c_str();
196 }
else if(locationToDownloadTo==
"." && itr->find(
"/afs/cern.ch/atlas/www/")==std::string::npos) {
198 FILE *
fp = std::fopen((*itr+
"/._pathresolver_dummy").c_str(),
"a+");
200 locationToDownloadTo=*itr;
202 (void)
std::remove((*itr+
"/._pathresolver_dummy").c_str());
211 if ( ( file_type == PR_regular_file && is_regular_file(
fp ) ) ||
212 ( file_type == PR_directory && is_directory(
fp ) ) ) {
213 result = bf::system_complete(
fp).string();
216 }
catch (
const bf::filesystem_error& ) {
224 bf::recursive_directory_iterator end_itr;
226 for ( bf::recursive_directory_iterator ritr( *itr );
227 ritr != end_itr; ++ritr) {
230 if (! is_directory(
bf::path(*ritr) ) ) {
continue; }
233 if ( ( file_type == PR_regular_file && is_regular_file( fp2 ) ) ||
234 ( file_type == PR_directory && is_directory( fp2 ) ) ) {
235 result = bf::system_complete( fp2 ).string();
239 }
catch (
const bf::filesystem_error& ) {
252 const std::string& search_path,
258 #ifdef XAOD_STANDALONE
259 const char* envVarVal = gSystem->Getenv(search_path.c_str());
260 if(envVarVal == NULL) {
261 msg(MSG::WARNING) <<search_path.c_str() <<
" environment variable not defined!" <<
endmsg;
269 #ifndef XAOD_ANALYSIS
270 if (!logical_file_name.empty() && logical_file_name[0]==
'/') {
271 msg(MSG::ERROR) <<
"Use of an absolute file name: " << logical_file_name <<
endmsg;
275 return (find_file_from_list (logical_file_name,
path_list, search_type));
282 const std::string& search_list,
290 PR_find (logical_file_name, search_list, PR_regular_file, search_type,
result);
308 const std::string& search_path,
313 #ifdef XAOD_STANDALONE
314 const char* envVarVal = gSystem->Getenv(search_path.c_str());
315 if(envVarVal == NULL) {
316 msg(MSG::WARNING) <<search_path.c_str() <<
" environment variable not defined!" <<
endmsg;
324 return (find_directory_from_list (logical_file_name,
path_list, search_type));
331 const std::string& search_list,
336 if (!PR_find (logical_file_name, search_list, PR_directory, search_type,
result))
350 std::string
path_list = gSystem->Getenv(search_path.c_str());
352 return (EnvironmentVariableUndefined);
359 for (; itr!= spv.end(); ++itr) {
361 if (!is_directory(pp)) {
362 return (UnknownDirectory);
365 }
catch(
const bf::filesystem_error& ) {
366 return (UnknownDirectory);
386 checkForDev(asgMsg(), logical_file_name);
388 TString tmpString(logical_file_name);
389 gSystem->ExpandPathName(tmpString);
390 if(tmpString.BeginsWith(
"root://")) {
392 TFile* fTmp = TFile::Open(tmpString);
393 if(!fTmp || fTmp->IsZombie()) {
394 msg(MSG::WARNING) <<
"Could not open " << logical_file_name <<
endmsg;
403 return tmpString.Data();
405 std::string expandedFileName(tmpString.Data());
409 if(
out==
"")
msg(MSG::WARNING) <<
"Could not locate " << logical_file_name <<
endmsg;
415 checkForDev(asgMsg(), logical_file_name);
417 TString tmpString(logical_file_name);
418 gSystem->ExpandPathName(tmpString);
419 std::string expandedFileName(tmpString.Data());
422 if(
out==
"")
msg(MSG::WARNING) <<
"Could not locate " << logical_file_name <<
endmsg;