8 #pragma warning(disable:4996)
16 #include <boost/algorithm/string/split.hpp>
17 #include <boost/algorithm/string/classification.hpp>
18 #include <boost/filesystem.hpp>
20 namespace bf = boost::filesystem;
24 static const char* path_separator =
",;";
26 static const char* path_separator =
",:";
48 PR_find(
const bf::path&
file,
const string& search_list,
49 PR_file_type file_type, PathResolver::SearchType search_type,
58 ( file_type ==
PR_directory && is_directory( file ) ) ) {
59 result = bf::system_complete(file).string();
62 }
catch (bf::filesystem_error ) {
70 ( file_type ==
PR_directory && is_directory( local ) ) ) {
71 result = bf::system_complete(file).string();
74 }
catch (bf::filesystem_error ) {
80 split(spv, search_list, boost::is_any_of( path_separator), boost::token_compress_on);
81 for (vector<string>::const_iterator itr = spv.begin();
82 itr != spv.end(); ++itr ) {
89 result = bf::system_complete(fp).string();
92 }
catch (bf::filesystem_error ) {
97 if (search_type == PathResolver::RecursiveSearch &&
100 bf::recursive_directory_iterator end_itr;
102 for ( bf::recursive_directory_iterator ritr( *itr );
103 ritr != end_itr; ++ritr) {
106 if (! is_directory(
bf::path(*ritr) ) ) {
continue; }
110 ( file_type ==
PR_directory && is_directory( fp2 ) ) ) {
111 result = bf::system_complete( fp2 ).string();
115 }
catch (bf::filesystem_error ) {
127 PathResolver::find_file(
const std::string& logical_file_name,
128 const std::string& search_path,
131 std::string path_list;
134 return (find_file_from_list (logical_file_name, path_list, search_type));
140 PathResolver::find_file_from_list (
const std::string& logical_file_name,
141 const std::string& search_list,
144 std::string result(
"");
166 string PathResolver::find_directory (
const std::string& logical_file_name,
167 const std::string& search_path,
170 std::string path_list;
173 return (find_directory_from_list (logical_file_name, path_list, search_type));
179 PathResolver::find_directory_from_list (
const std::string& logical_file_name,
180 const std::string& search_list,
185 if (!PR_find (logical_file_name, search_list,
PR_directory, search_type, result))
197 PathResolver::check_search_path (
const std::string& search_path)
199 std::string path_list;
201 return (EnvironmentVariableUndefined);
204 boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on);
205 vector<string>::iterator itr=spv.begin();
208 for (; itr!= spv.end(); ++itr) {
210 if (!is_directory(pp)) {
211 return (UnknownDirectory);
214 }
catch(bf::filesystem_error ) {
215 return (UnknownDirectory);
225 return PathResolver::find_file (logical_file_name,
"XMLPATH");
230 return PathResolver::find_file (logical_file_name,
"DATAPATH");
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
GAUDI_API std::string PathResolverFindXMLFile(const std::string &logical_file_name)
GAUDI_API std::string PathResolverFindDataFile(const std::string &logical_file_name)
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram