LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
TrivialFileTransfer_service.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 #include <cerrno>
6 #include <cstdlib>
7 #include <fstream>
8 #include <iterator>
9 
10 using namespace art;
11 using namespace std;
13 
14 namespace {
15  std::string const fileURI{"file://"};
16 }
17 
20 {}
21 
22 int
24  std::string& fileFQname)
25 {
26  if (uri.substr(0, 7) != fileURI) {
27  fileFQname = uri; // Unexpected protocol: pass through.
29  }
30 
32  fileFQname = "";
33  std::string inFileName;
34  if (stripURI(uri, inFileName) != 0) {
36  return stat;
37  }
38 
39  ifstream infile{inFileName.c_str()};
40  if (!infile) {
42  return stat;
43  }
44  fileFQname = inFileName;
46  return stat;
47  // Implementation plan details -- alternatives not chosen:
48  // x We could merely return the file name (the URI with file:// stripped off).
49  // Since the SAM developers may look at this file as a template for their
50  // real GeneralFileTransfer service, it is perhaps better to do the work of
51  // making a copy into a designated area.
52  // x We merely strip the file:// from the URI; this adhoc class is not beefed
53  // up to deal with genuine web access.
54  // x An alternative would be to embed the last part of the file FQname into
55  // the
56  // scratch file name, to try to maintain traceability in case things break.
57 }
58 
59 int
60 art::TrivialFileTransfer::stripURI(std::string const& uri,
61  std::string& inFileName) const
62 {
63  if (uri.substr(0, 7) != fileURI) {
64  inFileName = "";
65  return 1;
66  }
67  inFileName = uri.substr(7);
68  return 0;
69 }
70 
71 int
72 art::TrivialFileTransfer::copyFile(std::ifstream& in, std::ofstream& out) const
73 {
74  std::copy(std::istream_iterator<char>{in},
75  std::istream_iterator<char>{},
76  std::ostream_iterator<char>{out});
77  return 0;
78 }
79 
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
STL namespace.
int doTranslateToLocalFilename(std::string const &uri, std::string &fileFQname) override
int copyFile(std::ifstream &in, std::ofstream &out) const
ifstream in
Definition: comparison.C:7
int stripURI(std::string const &uri, std::string &inFileName) const
HLT enums.
TrivialFileTransfer(Parameters const &pset)