ATLAS Offline Software
Loading...
Searching...
No Matches
Locate.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7//
8// includes
9//
10
12
13#include <deque>
14#include <TSystem.h>
18
19//
20// method implementations
21//
22
23namespace RCU
24{
25 std::string locate (const std::string& locations)
26 {
27 std::deque<std::string> files;
28 {
29 std::string::size_type pos = 0, pos2 = 0;
30 while ((pos2 = locations.find ("::", pos)) != std::string::npos)
31 {
32 files.push_back (locations.substr (pos, pos2 - pos));
33 pos = pos2 + 2;
34 }
35 files.push_back (locations.substr (pos));
36 }
37 std::string name;
38 {
39 for (std::deque<std::string>::const_iterator file = files.begin(),
40 end = files.end(); file != end; ++ file)
41 {
42 std::string::size_type split = file->rfind ('/');
43 if (split == std::string::npos)
44 RCU_THROW_MSG ("file name " + *file + " does not contain a \"/\"");
45 std::string myname = file->substr (split + 1);
46 if (myname.empty())
47 RCU_THROW_MSG ("file name " + *file + " should not end with a \"/\"");
48 if (name.empty())
49 name = std::move(myname);
50 else if (name != myname)
51 RCU_THROW_MSG ("inconsistent file names " + name + " and " + myname);
52 }
53 }
54 RCU_ASSERT (!name.empty());
55
56 files.push_front ("$ROOTCOREBIN/data/RootCoreUtils/download/" + name);
57 for (std::deque<std::string>::iterator file = files.begin(),
58 end = files.end(); file != end; ++ file)
59 {
60 TString myfile = *file;
61 gSystem->ExpandPathName (myfile);
62 *file = myfile.Data();
63 }
64
65 for (std::deque<std::string>::const_iterator file = files.begin(),
66 end = files.end(); file != end; ++ file)
67 {
68 if (file->find ("http://") == 0)
69 {
70 try
71 {
72 Shell::exec ("$ROOTCOREDIR/scripts/download.sh " + Shell::quote (*file) + " " + Shell::quote (files[0]));
73 return files[0];
74 } catch (...)
75 {
76 // rationale: ignoring all exceptions, since we might have
77 // more locations to try
78 }
79 } else
80 {
81 if (gSystem->AccessPathName (file->c_str()) == 0)
82 {
83 return *file;
84 }
85 }
86 }
87 RCU_THROW_MSG ("failed to find file at " + locations);
88 return ""; // compiler dummy
89 }
90}
#define RCU_ASSERT(x)
Definition Assert.h:217
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:52
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition ShellExec.cxx:26
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:72
This module defines a variety of assert style macros.
Definition Assert.cxx:23
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:25
TFile * file