ATLAS Offline Software
Locate.cxx
Go to the documentation of this file.
1 //
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Please feel free to contact me (krumnack@iastate.edu) for bug
7 // reports, feature suggestions, praise and complaints.
8 
9 
10 //
11 // includes
12 //
13 
14 #include <RootCoreUtils/Locate.h>
15 
16 #include <deque>
17 #include <TSystem.h>
18 #include <RootCoreUtils/Assert.h>
20 #include <RootCoreUtils/ThrowMsg.h>
21 
22 //
23 // method implementations
24 //
25 
26 namespace RCU
27 {
28  std::string locate (const std::string& locations)
29  {
30  std::deque<std::string> files;
31  {
32  std::string::size_type pos = 0, pos2 = 0;
33  while ((pos2 = locations.find ("::", pos)) != std::string::npos)
34  {
35  files.push_back (locations.substr (pos, pos2 - pos));
36  pos = pos2 + 2;
37  }
38  files.push_back (locations.substr (pos));
39  }
40  std::string name;
41  {
42  for (std::deque<std::string>::const_iterator file = files.begin(),
43  end = files.end(); file != end; ++ file)
44  {
45  std::string::size_type split = file->rfind ('/');
46  if (split == std::string::npos)
47  RCU_THROW_MSG ("file name " + *file + " does not contain a \"/\"");
48  std::string myname = file->substr (split + 1);
49  if (myname.empty())
50  RCU_THROW_MSG ("file name " + *file + " should not end with a \"/\"");
51  if (name.empty())
52  name = myname;
53  else if (name != myname)
54  RCU_THROW_MSG ("inconsistent file names " + name + " and " + myname);
55  }
56  }
57  RCU_ASSERT (!name.empty());
58 
59  files.push_front ("$ROOTCOREBIN/data/RootCoreUtils/download/" + name);
61  end = files.end(); file != end; ++ file)
62  {
63  TString myfile = *file;
64  gSystem->ExpandPathName (myfile);
65  *file = myfile.Data();
66  }
67 
68  for (std::deque<std::string>::const_iterator file = files.begin(),
69  end = files.end(); file != end; ++ file)
70  {
71  if (file->find ("http://") == 0)
72  {
73  try
74  {
75  Shell::exec ("$ROOTCOREDIR/scripts/download.sh " + Shell::quote (*file) + " " + Shell::quote (files[0]));
76  return files[0];
77  } catch (...)
78  {
79  // rationale: ignoring all exceptions, since we might have
80  // more locations to try
81  }
82  } else
83  {
84  if (gSystem->AccessPathName (file->c_str()) == 0)
85  {
86  return *file;
87  }
88  }
89  }
90  RCU_THROW_MSG ("failed to find file at " + locations);
91  return ""; // compiler dummy
92  }
93 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
RCU
This module defines a variety of assert style macros.
Definition: Assert.cxx:26
ShellExec.h
Assert.h
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
file
TFile * file
Definition: tile_monitor.h:29
Locate.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ThrowMsg.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
RCU::Shell::exec
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition: ShellExec.cxx:29
RCU::locate
std::string locate(const std::string &locations)
effects: find the file with the given name from a list of locations separated by "::".
Definition: Locate.cxx:28
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
RCU::Shell::quote
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition: ShellExec.cxx:75
Trk::split
@ split
Definition: LayerMaterialProperties.h:38