InputFileCatalog.h
Go to the documentation of this file.
1 #ifndef art_Framework_IO_Catalog_InputFileCatalog_h
2 #define art_Framework_IO_Catalog_InputFileCatalog_h
3 
4 // ======================================================================
5 //
6 // Class InputFileCatalog. Services to manage InputFile catalog
7 //
8 // ======================================================================
9 
16 
17 #include <string>
18 #include <vector>
19 
20 // ----------------------------------------------------------------------
21 
22 namespace art {
23  enum class FileCatalogStatus {
24  SUCCESS,
28  };
29 
30  class InputFileCatalog : public FileCatalog {
31  public:
32  struct Config {
33  fhicl::Sequence<std::string> namesParameter{fhicl::Name("fileNames")};
34  };
35 
37  virtual ~InputFileCatalog() = default;
38  std::size_t
39  size() const
40  {
41  return fileCatalogItems_.size();
42  }
43  FileCatalogItem const& currentFile() const;
44  size_t currentIndex() const;
45  bool getNextFile(int attempts = 5);
46  bool hasNextFile(int attempts = 5);
47  void rewind();
48  void rewindTo(size_t index);
49  bool
51  {
52  return searchable_;
53  }
54  bool
55  empty() const
56  {
57  return fileCatalogItems_.empty();
58  }
59  void finish(); // Dispose of the current file.
60  std::vector<std::string> const&
61  fileSources() const
62  {
63  return fileSources_;
64  }
65 
66  static constexpr size_t indexEnd{std::numeric_limits<size_t>::max()};
67 
68  private:
69  bool retrieveNextFile(FileCatalogItem& item,
70  int attempts,
71  bool transferOnly = false);
72  FileCatalogStatus retrieveNextFileFromCacheOrService(FileCatalogItem& item);
73  FileCatalogStatus transferNextFile(FileCatalogItem& item);
74 
75  std::vector<std::string> fileSources_;
76  std::vector<FileCatalogItem> fileCatalogItems_{{}}; // seed with one item
77  FileCatalogItem nextItem_{};
78  size_t fileIdx_{indexEnd};
79  size_t maxIdx_{};
80  bool searchable_{false}; // update value after the service gets configured
81  bool nextFileProbed_{false};
82  bool hasNextFile_{false};
83 
86  }; // InputFileCatalog
87 
88 } // namespace art
89 
90 // ======================================================================
91 
92 #endif /* art_Framework_IO_Catalog_InputFileCatalog_h */
93 
94 // Local Variables:
95 // mode: c++
96 // End:
std::vector< std::string > fileSources_
ChannelGroupService::Name Name
ServiceHandle< FileTransfer > ft_
ServiceHandle< CatalogInterface > ci_
FileCatalogStatus
static Config * config
Definition: config.cpp:1054
static int max(int a, int b)
std::vector< std::string > const & fileSources() const
std::size_t size() const