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 129 of file PathResolver.cxx.

129  {
130 #ifdef XAOD_STANDALONE
131  static thread_local asg::AsgMessaging asgMsg("PathResolver");
132 #else
133  static asg::AsgMessaging asgMsg ATLAS_THREAD_SAFE ("PathResolver");
134 #endif
135 #ifndef XAOD_ANALYSIS
138 #else
139  asgMsg.msg().setLevel(m_level);
140 #endif
141  return asgMsg;
142 }

◆ find_calib_directory()

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

Definition at line 295 of file PathResolver.cxx.

296 {
297  checkForDev(asgMsg(), logical_file_name);
298 
299  std::string out = PathResolver::find_directory (logical_file_name, "CALIBPATH");
300  if (out.empty()) {
301  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
302  }
303  return out;
304 }

◆ find_calib_file()

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

Definition at line 273 of file PathResolver.cxx.

274 {
275  checkForDev(asgMsg(), logical_file_name);
276 
277  if (logical_file_name.starts_with("root://")) {
278  //xrootd access .. try to open file ...
279  std::unique_ptr<TFile> fTmp{TFile::Open(logical_file_name.c_str())};
280  if (!fTmp || fTmp->IsZombie()) {
281  msg(MSG::WARNING) << "Could not open " << logical_file_name << endmsg;
282  return {};
283  }
284  return logical_file_name;
285  }
286 
287  std::string out = PathResolver::find_file (logical_file_name, "CALIBPATH");
288  if (out.empty()) {
289  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
290  }
291  return out;
292 }

◆ 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 250 of file PathResolver.cxx.

252 {
253  const char* path_list = std::getenv(search_path.c_str());
254  if(path_list == nullptr) {
255  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
256  return {};
257  }
258 
259  return find_directory_from_list(logical_file_name, path_list);
260 }

◆ 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 263 of file PathResolver.cxx.

265 {
266  std::string result;
267  PR_find(logical_file_name, search_list, fs::file_type::directory, result);
268 
269  return result;
270 }

◆ 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 221 of file PathResolver.cxx.

222  {
223 
224 #ifndef XAOD_ANALYSIS
225  if (logical_file_name.starts_with('/')) {
226  msg(MSG::ERROR) << "Use of an absolute file name: " << logical_file_name << endmsg;
227  }
228 #endif
229 
230  const char* path_list = std::getenv(search_path.c_str());
231  if (path_list == nullptr) {
232  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
233  return {};
234  }
235 
236  return find_file_from_list(logical_file_name, path_list);
237 }

◆ 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 240 of file PathResolver.cxx.

242 {
243  std::string result;
244  PR_find (logical_file_name, search_list, fs::file_type::regular, result);
245 
246  return result;
247 }

◆ 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 148 of file PathResolver.cxx.

149  {
150 
151  // expand filename before finding
152  TString tmpString(logical_file_name);
153  gSystem->ExpandPathName(tmpString);
154 
155  fs::path file(tmpString.Data());
156  fs::path locationToDownloadTo = "."; // will replace with first search location
157 
158  // First always search for filename as given in local directory
159  const std::string searchPath = std::format("./{}{}", path_separator, search_list);
160 
161  // iterate through search list
162  for (const auto& r : searchPath | std::views::split(path_separator)) {
163  std::string_view path(r.begin(), r.end());
164  const bool is_http = path.starts_with("http//");
165  if( (is_http || path.starts_with("https//")) &&
166  file_type==fs::file_type::regular && std::getenv("PATHRESOLVER_ALLOWHTTPDOWNLOAD") ) { // only http download files, not directories
167 
168  // Try to do an http download to the local location.
169  // Need to restore the proper http protocol (cannot use ":" in search paths)
170  const std::string fileToDownload = std::format("{}://{}/{}", is_http ? "http" : "https",
171  path.substr(6), file.string());
172 
173  const fs::path targetPath = locationToDownloadTo / file;
174  fs::path targetDir = targetPath;
175  targetDir.remove_filename();
176  msg(MSG::DEBUG) << "Attempting http download of " << fileToDownload << " to " << targetDir << endmsg;
177 
178  if (!is_directory(targetDir)) {
179  msg(MSG::DEBUG) << "Creating directory " << targetDir << endmsg;
180  if(!fs::create_directories(targetDir)) {
181  msg(MSG::ERROR) << "Unable to create directories to write file to " << targetDir << endmsg;
182  return false;
183  }
184  }
185 
186  if (!download_file(fileToDownload, targetPath, asgMsg())) {
187  msg(MSG::WARNING) << "Unable to download file " << fileToDownload << endmsg;
188  } else {
189  msg(MSG::DEBUG) << "Successfully downloaded " << fileToDownload << endmsg;
190  result = targetPath;
191  return true;
192  }
193 
194  } else if (locationToDownloadTo==".") {
195  // Prefer first non-pwd location (usually local build area) for downloading to.
196  fs::path dummyFile = fs::path(path) / "._pathresolver_dummy";
197  std::ofstream ofs(dummyFile); // check if writable
198  if (ofs.is_open()) {
199  locationToDownloadTo = path;
200  ofs.close();
201  fs::remove(dummyFile);
202  }
203  }
204 
205  fs::path fp = path / file;
206  try {
207  if (fs::status(fp).type() == file_type) {
208  result = fs::absolute(fp).string();
209  return true;
210  }
211  } catch (const fs::filesystem_error&) {
212  // file not accessible or does not exist
213  }
214 
215  }
216 
217  return false; // not found
218 }

◆ 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 307 of file PathResolver.cxx.

307  {
308  m_level = level;
309 }

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:273
beamspotman.r
def r
Definition: beamspotman.py:672
PathResolver::asgMsg
static asg::AsgMessaging & asgMsg()
Definition: PathResolver.cxx:129
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:250
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:295
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:240
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:148
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:263
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
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:221
DEBUG
#define DEBUG
Definition: page_access.h:11
PathResolver::setOutputLevel
static void setOutputLevel(MSG::Level level)
Definition: PathResolver.cxx:307
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