LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
TrivialFileTransfer_service.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 
8 #include "fhiclcpp/fwd.h"
9 
10 #include <fstream>
11 #include <string>
12 
13 using namespace std;
14 
16 
17 namespace art {
18 
19  namespace {
20  string const fileURI{"file://"};
21  } // unnamed namespace
22 
24  // Configuration
25  public:
26  struct Config {};
28  // Special Member Functions
29  public:
31  TrivialFileTransfer(Parameters const& pset);
34  TrivialFileTransfer& operator=(TrivialFileTransfer const&);
36  // Implementation -- Required by base class
37  private:
38  int doTranslateToLocalFilename(std::string const& uri,
39  std::string& fileFQname) override;
40  };
41 
42  TrivialFileTransfer::~TrivialFileTransfer() = default;
43 
44  TrivialFileTransfer::TrivialFileTransfer(
46  {}
47 
48  TrivialFileTransfer::TrivialFileTransfer(TrivialFileTransfer const&) =
49  default;
50 
51  TrivialFileTransfer::TrivialFileTransfer(TrivialFileTransfer&&) = default;
52 
53  TrivialFileTransfer& TrivialFileTransfer::operator=(
54  TrivialFileTransfer const&) = default;
55 
56  TrivialFileTransfer& TrivialFileTransfer::operator=(TrivialFileTransfer&&) =
57  default;
58 
59  int
60  TrivialFileTransfer::doTranslateToLocalFilename(string const& uri,
61  string& fileFQname)
62  {
63  if (uri.substr(0, 7) != fileURI) {
64  // Unexpected protocol: pass through.
65  fileFQname = uri;
67  }
69  fileFQname = "";
70  if (uri.substr(0, 7) != fileURI) {
72  return stat;
73  }
74  string inFileName{uri.substr(7)};
75  ifstream infile{inFileName};
76  if (!infile) {
78  return stat;
79  }
80  fileFQname = inFileName;
82  return stat;
83  // Implementation plan details -- alternatives not chosen:
84  // x We could merely return the file name (the URI with file:// stripped
85  // off).
86  // Since the SAM developers may look at this file as a template for their
87  // real GeneralFileTransfer service, it is perhaps better to do the work
88  // of making a copy into a designated area.
89  // x We merely strip the file:// from the URI; this adhoc class is not
90  // beefed
91  // up to deal with genuine web access.
92  // x An alternative would be to embed the last part of the file FQname into
93  // the
94  // scratch file name, to try to maintain traceability in case things
95  // break.
96  }
97 
98 } // namespace art
99 
102  SHARED)
103 
STL namespace.
Definition: MVAAlg.h:12
#define DECLARE_ART_SERVICE_INTERFACE_IMPL(svc, iface, scope)
#define SUCCESS
Definition: DBScan3DAlg.h:39
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)