Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Types | 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 Types

enum  SearchPathStatus { Ok, EnvironmentVariableUndefined, UnknownDirectory }
 
enum  SearchType { LocalSearch, RecursiveSearch }
 
enum  PR_file_type { PR_regular_file, PR_directory }
 

Public Member Functions

 PathResolver ()
 

Static Public Member Functions

static std::string find_file (const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
 
static std::string find_file_from_list (const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
 
static std::string find_directory (const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
 
static std::string find_directory_from_list (const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
 
static SearchPathStatus check_search_path (const std::string &search_path)
 
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 std::string FindCalibFile (const std::string &logical_file_name)
 
static std::string FindCalibDirectory (const std::string &logical_file_name)
 
static void SetOutputLevel (int lvl)
 

Static Private Member Functions

static bool PR_find (const std::string &logical_file_name, const std::string &search_list, PR_file_type file_type, SearchType search_type, std::string &result)
 
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 14 of file PathResolver.h.

Member Enumeration Documentation

◆ PR_file_type

Enumerator
PR_regular_file 
PR_directory 

Definition at line 31 of file PathResolver.h.

31  {
34  } PR_file_type;

◆ SearchPathStatus

Enumerator
Ok 
EnvironmentVariableUndefined 
UnknownDirectory 

Definition at line 18 of file PathResolver.h.

◆ SearchType

Enumerator
LocalSearch 
RecursiveSearch 

Definition at line 25 of file PathResolver.h.

26  {
29  } SearchType;

Constructor & Destructor Documentation

◆ PathResolver()

PathResolver::PathResolver ( )

Definition at line 94 of file PathResolver.cxx.

94 { }

Member Function Documentation

◆ asgMsg()

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

In AnalysisBase this method is not available

Definition at line 96 of file PathResolver.cxx.

96  {
97 #ifdef XAOD_STANDALONE
98  static thread_local asg::AsgMessaging asgMsg("PathResolver");
99 #else
100  static asg::AsgMessaging asgMsg ATLAS_THREAD_SAFE ("PathResolver");
101 #endif
102 #ifndef XAOD_ANALYSIS
105 #else
106  asgMsg.msg().setLevel(m_level);
107 #endif
108  return asgMsg;
109 }

◆ check_search_path()

PathResolver::SearchPathStatus PathResolver::check_search_path ( const std::string &  search_path)
static
  • search_path the name of a path-like environment variable
Returns
the result of the verification. Can be one of Ok, EnvironmentVariableUndefined, UnknownDirectory

Definition at line 348 of file PathResolver.cxx.

349 {
350  std::string path_list = gSystem->Getenv(search_path.c_str());
351  if ( path_list.empty() )
353 
354  vector<string> spv;
355  boost::split( spv, path_list, boost::is_any_of( path_separator ), boost::token_compress_on);
356  vector<string>::iterator itr=spv.begin();
357 
358  try {
359  for (; itr!= spv.end(); ++itr) {
360  bf::path pp(*itr);
361  if (!is_directory(pp)) {
362  return (UnknownDirectory);
363  }
364  }
365  } catch(const bf::filesystem_error& /*err*/) {
366  return (UnknownDirectory);
367  }
368 
369  return ( Ok );
370 }

◆ find_calib_directory()

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

Definition at line 413 of file PathResolver.cxx.

414 {
415  checkForDev(asgMsg(), logical_file_name);
416  //expand filename before finding
417  TString tmpString(logical_file_name);
418  gSystem->ExpandPathName(tmpString);
419  std::string expandedFileName(tmpString.Data());
420  boost::algorithm::trim(expandedFileName);
421  std::string out = PathResolver::find_directory (expandedFileName, "CALIBPATH");
422  if(out=="") msg(MSG::WARNING) <<"Could not locate " << logical_file_name << endmsg;
423  return out;
424 }

◆ find_calib_file()

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

Definition at line 384 of file PathResolver.cxx.

385 {
386  checkForDev(asgMsg(), logical_file_name);
387  //expand filename before finding ..
388  TString tmpString(logical_file_name);
389  gSystem->ExpandPathName(tmpString);
390  if(tmpString.BeginsWith("root://")) {
391  //xrootd access .. try to open file ...
392  TFile* fTmp = TFile::Open(tmpString);
393  if(!fTmp || fTmp->IsZombie()) {
394  msg(MSG::WARNING) << "Could not open " << logical_file_name << endmsg;
395  tmpString = "";
396  }
397 
398  if(fTmp) {
399  fTmp->Close();
400  delete fTmp;
401  }
402 
403  return tmpString.Data();
404  }
405  std::string expandedFileName(tmpString.Data());
406  //strip any spaces off of the name
407  boost::algorithm::trim(expandedFileName);
408  std::string out = PathResolver::find_file (expandedFileName, "CALIBPATH");
409  if(out=="") msg(MSG::WARNING) <<"Could not locate " << logical_file_name << endmsg;
410  return out;
411 }

◆ find_directory()

string PathResolver::find_directory ( const std::string &  logical_file_name,
const std::string &  search_path,
SearchType  search_type = LocalSearch 
)
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
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located directory or empty string if not found

Definition at line 307 of file PathResolver.cxx.

310 {
311  std::string path_list;
312 
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;
317  path_list = ""; //this will allow search in pwd ... maybe we should throw exception though!
318  }
319  else { path_list = envVarVal; }
320 #else
321  System::getEnv(search_path, path_list);
322 #endif
323 
324  return (find_directory_from_list (logical_file_name, path_list, search_type));
325 }

◆ find_directory_from_list()

string PathResolver::find_directory_from_list ( const std::string &  logical_file_name,
const std::string &  search_list,
SearchType  search_type = LocalSearch 
)
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
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located directory or empty string if not found

Definition at line 330 of file PathResolver.cxx.

333 {
334  std::string result;
335 
336  if (!PR_find (logical_file_name, search_list, PR_directory, search_type, result))
337  {
338  result = "";
339  }
340 
341  return (result);
342 }

◆ find_file()

string PathResolver::find_file ( const std::string &  logical_file_name,
const std::string &  search_path,
SearchType  search_type = LocalSearch 
)
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
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located file or empty string if not found

Definition at line 251 of file PathResolver.cxx.

253  {
254  //std::cout << "finding file: " <<logical_file_name << " in path=" << search_path);
255 
256  std::string path_list;
257 
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;
262  path_list = ""; //this will allow search in pwd ... maybe we should throw exception though!
263  }
264  else { path_list = envVarVal; }
265 #else
266  System::getEnv(search_path, path_list);
267 #endif
268 
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;
272  }
273 #endif
274 
275  return (find_file_from_list (logical_file_name, path_list, search_type));
276 }

◆ find_file_from_list()

std::string PathResolver::find_file_from_list ( const std::string &  logical_file_name,
const std::string &  search_list,
SearchType  search_type = LocalSearch 
)
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
  • search_type characterizes the type of search. Can be either LocalSearch or RecursiveSearch
Returns
the physical name of the located file or empty string if not found

Definition at line 281 of file PathResolver.cxx.

284 {
285  std::string result("");
286 
287 
288 
289  /* bool found = */
290  PR_find (logical_file_name, search_list, PR_regular_file, search_type, result);
291 
292  // The following functionality was in the original PathResolver, but I believe
293  // that it's WRONG. It extracts the filename of the requested item, and searches
294  // for that if the preceding search fails. i.e., if you're looking for "B/a.txt",
295  // and that fails, it will look for just "a.txt" in the search list.
296 
297  // if (! found && lfn.filename() != lfn ) {
298  // result = "";
299  // PR_find (lfn.filename(), search_list, PR_regular_file, search_type, result);
300  // }
301 
302  return (result);
303 }

◆ FindCalibDirectory()

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

Definition at line 109 of file PathResolver.h.

109 { return find_calib_directory(logical_file_name); }

◆ FindCalibFile()

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

Definition at line 108 of file PathResolver.h.

108 { return find_calib_file(logical_file_name); }

◆ msg() [1/2]

static MsgStream& PathResolver::msg ( )
inlinestaticprivate

Definition at line 120 of file PathResolver.h.

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

◆ msg() [2/2]

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

Definition at line 121 of file PathResolver.h.

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

◆ msgLvl()

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

Definition at line 119 of file PathResolver.h.

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

◆ PR_find()

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

Definition at line 122 of file PathResolver.cxx.

124  {
125 
126  std::string trimmed_logical_file_name = logical_file_name;
127  boost::algorithm::trim(trimmed_logical_file_name); //trim again for extra safety
128 
129  bf::path file( trimmed_logical_file_name );
130 
131  bool found(false);
132 
133  // look for file as specified first
134 
135  try {
136  if ( ( file_type == PR_regular_file && is_regular_file( file ) ) ||
137  ( file_type == PR_directory && is_directory( file ) ) ) {
138  result = bf::system_complete(file).string();
139  return true;
140  }
141  } catch (const bf::filesystem_error& /*err*/) {
142  }
143 
144  // assume that "." is always part of the search path, so check locally first
145 
146  try {
147  bf::path local = bf::initial_path() / file;
148  if ( ( file_type == PR_regular_file && is_regular_file( local ) ) ||
149  ( file_type == PR_directory && is_directory( local ) ) ) {
150  result = bf::system_complete(file).string();
151  return true;
152  }
153  } catch (const bf::filesystem_error& /*err*/) {
154  }
155 
156  std::string locationToDownloadTo = "."; //will replace with first search location
157 
158  // iterate through search list
159  vector<string> spv;
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 ) {
163 
164  if( itr->find("http//")==0 && file_type==PR_regular_file && gSystem->Getenv("PATHRESOLVER_ALLOWHTTPDOWNLOAD") ) { //only http download files, not directories
165  //try to do an http download to the local location
166  //restore the proper http protocal (had to remove for sake of env var splitting)
167  std::string addr = "http://"; addr += itr->substr(6,itr->length());
168  bf::path lp = locationToDownloadTo/file;
169  bf::path lpd = lp; lpd.remove_filename();
170  msg(MSG::DEBUG) <<"Attempting http download of " << addr << "/" << file.string() << " to " << lp << endmsg;
171 
172  if(!is_directory(lpd)) {
173  msg(MSG::DEBUG) <<" Creating directory: " << lpd << endmsg;
174  if(!boost::filesystem::create_directories(lpd)) {
175  msg(MSG::DEBUG) <<"Unable to create directories to write file to : " << lp << endmsg;
176  continue;
177  //throw std::runtime_error("Unable to download calibration file");
178  }
179  }
180  std::string fileToDownload = addr + "/" + file.string();
181  std::string targetPath = locationToDownloadTo+"/"+file.string();
182  //disable error output from root while attempting to download
183  // FIXME: Disabling errors now commented out because it is not
184  // thread-safe. Needs changes in ROOT.
185  //long errLevel = gErrorIgnoreLevel;
186  //gErrorIgnoreLevel = kError+1;
187  if(!TFile::Cp(fileToDownload.c_str(),targetPath.c_str(), false)) {
188  msg(MSG::WARNING) <<"Unable to download file : " << fileToDownload << endmsg;
189  } else {
190  msg(MSG::DEBUG) <<"Successfully downloaded " << fileToDownload << endmsg;
191  result = (locationToDownloadTo+"/"+file.string()).c_str();
192  //gErrorIgnoreLevel=errLevel;
193  return true;
194  }
195  //gErrorIgnoreLevel=errLevel;
196  } else if(locationToDownloadTo=="." && itr->find("/afs/cern.ch/atlas/www/")==std::string::npos) { //don't let it ever download back to the www area!
197  //prefer first non-pwd location for downloading to. But must be fully accessible. This should be the local InstallArea in cmt
198  FILE *fp = std::fopen((*itr+"/._pathresolver_dummy").c_str(), "a+");
199  if(fp!=NULL) {
200  locationToDownloadTo=*itr;
201  std::fclose(fp);
202  (void)std::remove((*itr+"/._pathresolver_dummy").c_str());
203  }
204  }
205 
206  //std::cout << "searching path: " << *itr);
207 
208  bf::path fp = *itr / file;
209 
210  try {
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();
214  return true;
215  }
216  } catch (const bf::filesystem_error& /*err*/) {
217  }
218 
219 
220  // if recursive searching requested, drill down
221  if (search_type == PathResolver::RecursiveSearch &&
222  is_directory( bf::path(*itr) ) ) {
223 
224  bf::recursive_directory_iterator end_itr;
225  try {
226  for ( bf::recursive_directory_iterator ritr( *itr );
227  ritr != end_itr; ++ritr) {
228 
229  // skip if not a directory
230  if (! is_directory( bf::path(*ritr) ) ) { continue; }
231 
232  bf::path fp2 = bf::path(*ritr) / file;
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();
236  return true;
237  }
238  }
239  } catch (const bf::filesystem_error& /*err*/) {
240  }
241  }
242 
243  }
244 
245  return found;
246 }

◆ SetOutputLevel()

static void PathResolver::SetOutputLevel ( int  lvl)
inlinestatic

Definition at line 110 of file PathResolver.h.

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

◆ setOutputLevel()

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

Definition at line 426 of file PathResolver.cxx.

426  {
427  m_level = level;
428 }

Member Data Documentation

◆ m_level

std::atomic< MSG::Level > PathResolver::m_level =MSG::INFO
staticprivate

Definition at line 117 of file PathResolver.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
PathResolver::find_calib_file
static std::string find_calib_file(const std::string &logical_file_name)
Definition: PathResolver.cxx:384
PathResolver::EnvironmentVariableUndefined
@ EnvironmentVariableUndefined
Definition: PathResolver.h:21
PathResolver::asgMsg
static asg::AsgMessaging & asgMsg()
Definition: PathResolver.cxx:96
PathResolver::SearchType
SearchType
Definition: PathResolver.h:26
PathResolver::RecursiveSearch
@ RecursiveSearch
Definition: PathResolver.h:28
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
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
PathResolver::Ok
@ Ok
Definition: PathResolver.h:20
PathResolver::find_calib_directory
static std::string find_calib_directory(const std::string &logical_file_name)
Definition: PathResolver.cxx:413
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
PathResolver::m_level
static std::atomic< MSG::Level > m_level
Definition: PathResolver.h:117
PathResolver::find_directory
static std::string find_directory(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:307
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
PathResolver::LocalSearch
@ LocalSearch
Definition: PathResolver.h:27
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:120
PathResolver::PR_directory
@ PR_directory
Definition: PathResolver.h:33
trigmenu_modify_prescale_json.fp
fp
Definition: trigmenu_modify_prescale_json.py:53
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
file
TFile * file
Definition: tile_monitor.h:29
PathResolver::PR_find
static bool PR_find(const std::string &logical_file_name, const std::string &search_list, PR_file_type file_type, SearchType search_type, std::string &result)
Definition: PathResolver.cxx:122
PathResolver::find_file_from_list
static std::string find_file_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:281
PathResolver::SearchPathStatus
SearchPathStatus
Definition: PathResolver.h:19
InDetDD::local
@ local
Definition: InDetDD_Defs.h:16
PathResolver::find_directory_from_list
static std::string find_directory_from_list(const std::string &logical_file_name, const std::string &search_list, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:330
asg::AsgMessaging
Class mimicking the AthMessaging class from the offline software.
Definition: AsgMessaging.h:40
PathResolver::PR_file_type
PR_file_type
Definition: PathResolver.h:31
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
PathResolver::PR_regular_file
@ PR_regular_file
Definition: PathResolver.h:32
athena.path_list
list path_list
Definition: athena.py:93
DEBUG
#define DEBUG
Definition: page_access.h:11
GRLStrUtil::trim
void trim(std::string &input)
Definition: StrUtil.cxx:12
PathResolver::setOutputLevel
static void setOutputLevel(MSG::Level level)
Definition: PathResolver.cxx:426
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
PathResolver::UnknownDirectory
@ UnknownDirectory
Definition: PathResolver.h:22