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

70  {
71 #ifdef XAOD_STANDALONE
72  static thread_local asg::AsgMessaging asgMsg("PathResolver");
73 #else
74  static asg::AsgMessaging asgMsg ATLAS_THREAD_SAFE ("PathResolver");
75 #endif
76 #ifndef XAOD_ANALYSIS
79 #else
80  asgMsg.msg().setLevel(m_level);
81 #endif
82  return asgMsg;
83 }

◆ find_calib_directory()

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

Definition at line 236 of file PathResolver.cxx.

237 {
238  checkForDev(asgMsg(), logical_file_name);
239 
240  std::string out = PathResolver::find_directory (logical_file_name, "CALIBPATH");
241  if (out.empty()) {
242  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
243  }
244  return out;
245 }

◆ find_calib_file()

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

Definition at line 214 of file PathResolver.cxx.

215 {
216  checkForDev(asgMsg(), logical_file_name);
217 
218  if (logical_file_name.starts_with("root://")) {
219  //xrootd access .. try to open file ...
220  std::unique_ptr<TFile> fTmp{TFile::Open(logical_file_name.c_str())};
221  if (!fTmp || fTmp->IsZombie()) {
222  msg(MSG::WARNING) << "Could not open " << logical_file_name << endmsg;
223  return {};
224  }
225  return logical_file_name;
226  }
227 
228  std::string out = PathResolver::find_file (logical_file_name, "CALIBPATH");
229  if (out.empty()) {
230  msg(MSG::WARNING) << "Could not locate " << logical_file_name << endmsg;
231  }
232  return out;
233 }

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

193 {
194  const char* path_list = std::getenv(search_path.c_str());
195  if(path_list == nullptr) {
196  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
197  return {};
198  }
199 
200  return find_directory_from_list(logical_file_name, path_list);
201 }

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

206 {
207  std::string result;
208  PR_find(logical_file_name, search_list, fs::file_type::directory, result);
209 
210  return result;
211 }

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

163  {
164 
165 #ifndef XAOD_ANALYSIS
166  if (logical_file_name.starts_with('/')) {
167  msg(MSG::ERROR) << "Use of an absolute file name: " << logical_file_name << endmsg;
168  }
169 #endif
170 
171  const char* path_list = std::getenv(search_path.c_str());
172  if (path_list == nullptr) {
173  msg(MSG::ERROR) << search_path << " environment variable not defined!" << endmsg;
174  return {};
175  }
176 
177  return find_file_from_list(logical_file_name, path_list);
178 }

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

183 {
184  std::string result;
185  PR_find (logical_file_name, search_list, fs::file_type::regular, result);
186 
187  return result;
188 }

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

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

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

248  {
249  m_level = level;
250 }

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:214
beamspotman.r
def r
Definition: beamspotman.py:676
PathResolver::asgMsg
static asg::AsgMessaging & asgMsg()
Definition: PathResolver.cxx:70
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:191
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:236
plotting.yearwise_luminosity.absolute
absolute
Definition: yearwise_luminosity.py:29
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
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:181
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:80
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:89
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:204
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:162
DEBUG
#define DEBUG
Definition: page_access.h:11
PathResolver::setOutputLevel
static void setOutputLevel(MSG::Level level)
Definition: PathResolver.cxx:248
merge.status
status
Definition: merge.py:17
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
Trk::split
@ split
Definition: LayerMaterialProperties.h:38