ATLAS Offline Software
Loading...
Searching...
No Matches
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
15
16#include <deque>
17#include <TSystem.h>
21
22//
23// method implementations
24//
25
26namespace 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 = std::move(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);
60 for (std::deque<std::string>::iterator file = files.begin(),
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}
#define RCU_ASSERT(x)
Definition Assert.h:222
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
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
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
This module defines a variety of assert style macros.
Definition Assert.cxx:26
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
TFile * file