LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
TrivialFileDelivery_service.cc
Go to the documentation of this file.
3 #include <cerrno>
4 #include <cstdlib>
5 #include <fstream>
6 using namespace art;
7 using namespace std;
9 
10 namespace {
11  void
12  throwIfFileNotExist(char const* fname)
13  {
14  std::ifstream f(fname);
15  if (!f) {
16  // Throw here, otherwise we don't know what file we couldn't find.
18  << "Input file not found: " << fname << ".\n";
19  }
20  }
21 }
22 
25 {}
26 
27 void
28 art::TrivialFileDelivery::doConfigure(std::vector<std::string> const& items)
29 {
30  fileList = items;
31  nextFile = fileList.begin();
32  endOfFiles = fileList.end();
33 }
34 
35 int
36 art::TrivialFileDelivery::doGetNextFileURI(std::string& uri, double& waitTime)
37 {
38  FileDeliveryStatus stat;
39  if (nextFile == endOfFiles) {
41  return stat;
42  }
43  auto pos = nextFile->find("://"); // Look for protocol.
44  if (pos == std::string::npos) { // Bare filename.
45  throwIfFileNotExist(nextFile->c_str());
46  uri = prependFileDesignation(*nextFile);
47  } else if (nextFile->substr(0, pos) == "file") { // file://
48  throwIfFileNotExist(nextFile->c_str() + pos + 3);
49  uri = *nextFile;
50  } else { // Unknown URI.
51  uri = *nextFile;
52  }
53  waitTime = 0.0;
55  ++nextFile;
56  return stat;
57 }
58 
59 // The remaining doXXX methods are trivial in this class, ignoring the XXX
60 // events. The real SAMProtocol concrete class might have real work in these.
61 void
63 {}
64 void
66 {}
67 void
69  ParameterSet const&)
70 {}
71 void
73  std::string const&)
74 {}
75 void
77  EventID const&,
78  HLTGlobalStatus const&)
79 {}
80 
81 bool
83 {
84  return true;
85 }
86 void
88 {
89  nextFile = fileList.begin();
90 }
91 
92 // helper functions
93 std::vector<std::string>
95 {
96  auto const& p = pset.get<ParameterSet>("source");
97  return p.get<std::vector<std::string>>("fileNames");
98  // TODO -- How do we properly throw if either source or fileNames is absent?
99  // get() does throw, but is it the right throw and should we be catching it?
100 }
101 
102 std::string
104 {
105  std::string const s{"file://"};
106  return s + name;
107 }
108 
Float_t s
Definition: plot.C:23
void doConfigure(std::vector< std::string > const &items) override
void doOutputFileOpened(std::string const &module_label) override
std::vector< std::string > extractFileListFromPset(fhicl::ParameterSet const &pset)
FileDisposition
#define DEFINE_ART_SERVICE_INTERFACE_IMPL(svc, iface)
std::string prependFileDesignation(std::string const &name) const
STL namespace.
TFile f
Definition: plotHisto.C:6
void doOutputModuleInitiated(std::string const &module_label, fhicl::ParameterSet const &pset) override
TrivialFileDelivery(Parameters const &config)
T get(std::string const &key) const
Definition: ParameterSet.h:231
void doOutputFileClosed(std::string const &module_label, std::string const &file) override
void doEventSelected(std::string const &module_label, EventID const &event_id, HLTGlobalStatus const &acceptance_info) override
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
HLT enums.
int doGetNextFileURI(std::string &uri, double &waitTime) override
void doUpdateStatus(std::string const &uri, FileDisposition status) override