ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
PathResolver Class Reference

#include <PathResolver.h>

Collaboration diagram for PathResolver:

Public Member Functions

 PathResolver ()=default
 

Static Public Member Functions

static std::string find_file (const std::string &logical_file_name, const std::string &search_path)
 
static std::string find_file_from_list (const std::string &logical_file_name, const std::string &search_list)
 
static std::string find_directory (const std::string &logical_file_name, const std::string &search_path)
 
static std::string find_directory_from_list (const std::string &logical_file_name, const std::string &search_list)
 
static std::string find_calib_file (const std::string &logical_file_name)
 
static std::string find_calib_directory (const std::string &logical_file_name)
 
static void setOutputLevel (MSG::Level level)
 
static void SetOutputLevel (int lvl)
 
static std::string FindCalibFile (const std::string &logical_file_name)
 
static std::string FindCalibDirectory (const std::string &logical_file_name)
 

Static Private Member Functions

static bool PR_find (const std::string &logical_file_name, const std::string &search_list, std::filesystem::file_type file_type, std::string &result)
 Main private search method used by all public methods. More...
 
static bool msgLvl (const MSG::Level lvl)
 
static MsgStream & msg ()
 
static MsgStream & msg (const MSG::Level lvl)
 
static asg::AsgMessagingasgMsg ()
 

Static Private Attributes

static std::atomic< MSG::Level > m_level {MSG::INFO}
 

Detailed Description

Definition at line 15 of file PathResolver.h.

Constructor & Destructor Documentation

◆ PathResolver()

PathResolver::PathResolver ( )
default

Member Function Documentation

◆ asgMsg()

asg::AsgMessaging & PathResolver::asgMsg ( )
staticprivate

In AnalysisBase this method is not available

Definition at line 79 of file PathResolver.cxx.

79  {
80 #ifdef XAOD_STANDALONE
81  static thread_local asg::AsgMessaging asgMsg("PathResolver");
82 #else
83  static asg::AsgMessaging asgMsg ATLAS_THREAD_SAFE ("PathResolver");
84 #endif
85 #ifndef XAOD_ANALYSIS
88 #else
89  asgMsg.msg().setLevel(m_level);
90 #endif
91  return asgMsg;
92 }

◆ find_calib_directory()

std::string PathResolver::find_calib_directory ( const std::string &  logical_file_name)
static

Definition at line 257 of file PathResolver.cxx.

258 {
259  checkForDev(asgMsg(), logical_file_name);
260 
261  std::string out = PathResolver::find_directory (logical_file_name, "CALIBPATH");
262  if (out.empty()) {
263  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
264  }
265  return out;
266 }

◆ find_calib_file()

std::string PathResolver::find_calib_file ( const std::string &  logical_file_name)
static

Definition at line 235 of file PathResolver.cxx.

236 {
237  checkForDev(asgMsg(), logical_file_name);
238 
239  if (logical_file_name.starts_with("root://")) {
240  //xrootd access .. try to open file ...
241  std::unique_ptr<TFile> fTmp{TFile::Open(logical_file_name.c_str())};
242  if (!fTmp || fTmp->IsZombie()) {
243  msg(MSG::WARNING) << "Could not open " << logical_file_name << endmsg;
244  return {};
245  }
246  return logical_file_name;
247  }
248 
249  std::string out = PathResolver::find_file (logical_file_name, "CALIBPATH");
250  if (out.empty()) {
251  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
252  }
253  return out;
254 }

◆ find_directory()

std::string PathResolver::find_directory ( const std::string &  logical_file_name,
const std::string &  search_path 
)
static
  • logical_file_name the name of the directory to locate in the search path
  • search_path the name of a path-like environment variable
Returns
the physical name of the located directory or empty string if not found

Definition at line 212 of file PathResolver.cxx.

214 {
215  const char* path_list = std::getenv(search_path.c_str());
216  if(path_list == nullptr) {
217  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
218  return {};
219  }
220 
221  return find_directory_from_list(logical_file_name, path_list);
222 }

◆ find_directory_from_list()

std::string PathResolver::find_directory_from_list ( const std::string &  logical_file_name,
const std::string &  search_list 
)
static
  • logical_file_name the name of the directory to locate in the search path
  • search_list the prioritized list of possible locations separated by the usual path separator
Returns
the physical name of the located directory or empty string if not found

Definition at line 225 of file PathResolver.cxx.

227 {
228  std::string result;
229  PR_find(logical_file_name, search_list, fs::file_type::directory, result);
230 
231  return result;
232 }

◆ find_file()

std::string PathResolver::find_file ( const std::string &  logical_file_name,
const std::string &  search_path 
)
static
  • logical_file_name the name of the file to locate in the search path
  • search_path the name of a path-like environment variable
Returns
the physical name of the located file or empty string if not found

Definition at line 183 of file PathResolver.cxx.

184  {
185 
186 #ifndef XAOD_ANALYSIS
187  if (logical_file_name.starts_with('/')) {
188  msg(MSG::ERROR) << "Use of an absolute file name: " << logical_file_name << endmsg;
189  }
190 #endif
191 
192  const char* path_list = std::getenv(search_path.c_str());
193  if (path_list == nullptr) {
194  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
195  return {};
196  }
197 
198  return find_file_from_list(logical_file_name, path_list);
199 }

◆ find_file_from_list()

std::string PathResolver::find_file_from_list ( const std::string &  logical_file_name,
const std::string &  search_list 
)
static
  • logical_file_name the name of the file to locate in the search path
  • search_list the prioritized list of possible locations separated by the usual path separator
Returns
the physical name of the located file or empty string if not found

Definition at line 202 of file PathResolver.cxx.

204 {
205  std::string result;
206  PR_find (logical_file_name, search_list, fs::file_type::regular, result);
207 
208  return result;
209 }

◆ FindCalibDirectory()

static std::string PathResolver::FindCalibDirectory ( const std::string &  logical_file_name)
inlinestatic

Definition at line 64 of file PathResolver.h.

64 { return find_calib_directory(logical_file_name); }

◆ FindCalibFile()

static std::string PathResolver::FindCalibFile ( const std::string &  logical_file_name)
inlinestatic

Definition at line 63 of file PathResolver.h.

63 { return find_calib_file(logical_file_name); }

◆ msg() [1/2]

static MsgStream& PathResolver::msg ( )
inlinestaticprivate

Definition at line 73 of file PathResolver.h.

73 { return asgMsg().msg(); }

◆ msg() [2/2]

static MsgStream& PathResolver::msg ( const MSG::Level  lvl)
inlinestaticprivate

Definition at line 74 of file PathResolver.h.

74 { return asgMsg().msg(lvl); }

◆ msgLvl()

static bool PathResolver::msgLvl ( const MSG::Level  lvl)
inlinestaticprivate

Definition at line 72 of file PathResolver.h.

72 { return asgMsg().msgLvl(lvl); }

◆ PR_find()

bool PathResolver::PR_find ( const std::string &  logical_file_name,
const std::string &  search_list,
std::filesystem::file_type  file_type,
std::string &  result 
)
staticprivate

Main private search method used by all public methods.

Definition at line 98 of file PathResolver.cxx.

99  {
100 
101  // expand filename before finding
102  TString tmpString(logical_file_name);
103  gSystem->ExpandPathName(tmpString);
104 
105  fs::path file(tmpString.Data());
106  fs::path locationToDownloadTo = "."; // will replace with first search location
107 
108  // First always search for filename as given in local directory
109  const std::string searchPath = std::format("./{}{}", path_separator, search_list);
110 
111  // iterate through search list
112  for (const auto r : searchPath | std::views::split(path_separator)) {
113  std::string_view path(r.begin(), r.end());
114  const bool is_http = path.starts_with("http//");
115  if( (is_http || path.starts_with("https//")) &&
116  file_type==fs::file_type::regular && std::getenv("PATHRESOLVER_ALLOWHTTPDOWNLOAD") ) { // only http download files, not directories
117 
118  // Try to do an http download to the local location.
119  // Need to restore the proper http protocol (cannot use ":" in search paths)
120  const std::string fileToDownload = std::format("{}://{}/{}", is_http ? "http" : "https",
121  path.substr(6), file.string());
122 
123  const fs::path targetPath = locationToDownloadTo / file;
124  fs::path targetDir = targetPath;
125  targetDir.remove_filename();
126  msg(MSG::DEBUG) << "Attempting http download of " << fileToDownload << " to " << targetDir << endmsg;
127 
128  if (!is_directory(targetDir)) {
129  msg(MSG::DEBUG) << "Creating directory " << targetDir << endmsg;
130  if(!fs::create_directories(targetDir)) {
131  msg(MSG::ERROR) << "Unable to create directories to write file to " << targetDir << endmsg;
132  return false;
133  }
134  }
135 
136  if (!TFile::Cp(fileToDownload.c_str(), targetPath.c_str(), false)) {
137  msg(MSG::INFO) << "Unable to download file "
138  << fileToDownload
139  << " with ROOT, falling back to command line tools"
140  << endmsg;
141  if (download_with_curl(fileToDownload, targetPath)) {
142  msg(MSG::INFO) << "Successfully curled " << fileToDownload << endmsg;
143  result = targetPath;
144  return true;
145  } else {
146  msg(MSG::WARNING) << "Unable to download file "
147  << fileToDownload
148  << endmsg;
149  }
150  } else {
151  msg(MSG::DEBUG) << "Successfully downloaded " << fileToDownload << endmsg;
152  result = targetPath;
153  return true;
154  }
155 
156  } else if (locationToDownloadTo==".") {
157  // Prefer first non-pwd location (usually local build area) for downloading to.
158  fs::path dummyFile = fs::path(path) / "._pathresolver_dummy";
159  std::ofstream ofs(dummyFile); // check if writable
160  if (ofs.is_open()) {
161  locationToDownloadTo = path;
162  ofs.close();
163  fs::remove(dummyFile);
164  }
165  }
166 
167  fs::path fp = path / file;
168  try {
169  if (fs::status(fp).type() == file_type) {
170  result = fs::absolute(fp).string();
171  return true;
172  }
173  } catch (const fs::filesystem_error&) {
174  // file not accessible or does not exist
175  }
176 
177  }
178 
179  return false; // not found
180 }

◆ SetOutputLevel()

static void PathResolver::SetOutputLevel ( int  lvl)
inlinestatic

Definition at line 61 of file PathResolver.h.

61 { setOutputLevel(MSG::Level(lvl)); }

◆ setOutputLevel()

void PathResolver::setOutputLevel ( MSG::Level  level)
static

Definition at line 269 of file PathResolver.cxx.

269  {
270  m_level = level;
271 }

Member Data Documentation

◆ m_level

std::atomic<MSG::Level> PathResolver::m_level {MSG::INFO}
inlinestaticprivate

Definition at line 71 of file PathResolver.h.


The documentation for this class was generated from the following files:
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:235
beamspotman.r
def r
Definition: beamspotman.py:674
PathResolver::asgMsg
static asg::AsgMessaging & asgMsg()
Definition: PathResolver.cxx:79
get_generator_info.result
result
Definition: get_generator_info.py:21
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
asg::AsgMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level of the object.
Definition: AsgMessaging.cxx:41
vtune_athena.format
format
Definition: vtune_athena.py:14
PathResolver::find_directory
static std::string find_directory(const std::string &logical_file_name, const std::string &search_path)
Definition: PathResolver.cxx:212
pool_uuid.regular
bool regular
Definition: pool_uuid.py:103
PathResolver::find_calib_directory
static std::string find_calib_directory(const std::string &logical_file_name)
Definition: PathResolver.cxx:257
plotting.yearwise_luminosity.absolute
absolute
Definition: yearwise_luminosity.py:29
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
PathResolver::find_file_from_list
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list)
Definition: PathResolver.cxx:202
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
AthMessaging::setLevel
void setLevel(MSG::Level lvl)
Change the current logging level.
Definition: AthMessaging.cxx:28
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
PathResolver::msg
static MsgStream & msg()
Definition: PathResolver.h:73
DeMoScan.directory
string directory
Definition: DeMoScan.py:78
PathResolver::PR_find
static bool PR_find(const std::string &logical_file_name, const std::string &search_list, std::filesystem::file_type file_type, std::string &result)
Main private search method used by all public methods.
Definition: PathResolver.cxx:98
trigmenu_modify_prescale_json.fp
fp
Definition: trigmenu_modify_prescale_json.py:53
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
PathResolver::find_directory_from_list
static std::string find_directory_from_list(const std::string &logical_file_name, const std::string &search_list)
Definition: PathResolver.cxx:225
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
file
TFile * file
Definition: tile_monitor.h:29
PathResolver::m_level
static std::atomic< MSG::Level > m_level
Definition: PathResolver.h:71
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
athena.path_list
list path_list
Definition: athena.py:93
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path)
Definition: PathResolver.cxx:183
DEBUG
#define DEBUG
Definition: page_access.h:11
PathResolver::setOutputLevel
static void setOutputLevel(MSG::Level level)
Definition: PathResolver.cxx:269
merge.status
status
Definition: merge.py:16
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
Trk::split
@ split
Definition: LayerMaterialProperties.h:38