LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
art::InputFileCatalog Class Reference

#include "InputFileCatalog.h"

Inheritance diagram for art::InputFileCatalog:
art::FileCatalog

Classes

struct  Config
 

Public Member Functions

 InputFileCatalog (fhicl::TableFragment< Config > const &config)
 
virtual ~InputFileCatalog ()=default
 
std::vector< FileCatalogItem > const & fileCatalogItems () const
 
FileCatalogItem const & currentFile () const
 
size_t currentIndex () const
 
bool getNextFile (int attempts=5)
 
bool hasNextFile (int attempts=5)
 
void rewind ()
 
void rewindTo (size_t index)
 
bool isSearchable ()
 
bool empty () const
 
void finish ()
 
std::vector< std::string > const & fileSources () const
 
void commitCatalog ()
 
std::string & url ()
 
std::string const & url () const
 
void setActive ()
 
bool active () const
 

Static Public Member Functions

static bool isPhysical (std::string const &name)
 

Static Public Attributes

static constexpr size_t indexEnd {std::numeric_limits<size_t>::max()}
 

Private Member Functions

bool retrieveNextFile (FileCatalogItem &item, int attempts, bool transferOnly=false)
 
FileCatalogStatus retrieveNextFileFromCacheOrService (FileCatalogItem &item)
 
FileCatalogStatus transferNextFile (FileCatalogItem &item)
 

Private Attributes

std::vector< std::string > fileSources_
 
std::vector< FileCatalogItemfileCatalogItems_ {{}}
 
FileCatalogItem nextItem_ {}
 
size_t fileIdx_ {indexEnd}
 
size_t maxIdx_ {}
 
bool searchable_ {false}
 
bool nextFileProbed_ {false}
 
bool hasNextFile_ {false}
 
ServiceHandle< CatalogInterfaceci_
 
ServiceHandle< FileTransferft_
 

Detailed Description

Definition at line 33 of file InputFileCatalog.h.

Constructor & Destructor Documentation

art::InputFileCatalog::InputFileCatalog ( fhicl::TableFragment< Config > const &  config)
explicit

Definition at line 19 of file InputFileCatalog.cc.

References art::errors::CatalogServiceError, ci_, fileCatalogItems_, fileSources_, and searchable_.

21  : fileSources_{config().namesParameter()}
22  {
23 
24  if (fileSources_.empty()) {
26  "InputFileCatalog::InputFileCatalog()\n")
27  << "Empty '" << config().namesParameter.name()
28  << "' parameter specified for input source.\n";
29  }
30 
31  // Configure FileDelivery service
32  ci_->configure(fileSources_);
33  searchable_ = ci_->isSearchable();
34 
35  if (searchable_)
36  fileCatalogItems_.resize(fileSources_.size());
37  }
std::vector< std::string > fileSources_
ServiceHandle< CatalogInterface > ci_
std::vector< FileCatalogItem > fileCatalogItems_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
virtual art::InputFileCatalog::~InputFileCatalog ( )
virtualdefault

Member Function Documentation

bool art::FileCatalog::active ( ) const
inlineinherited

Definition at line 113 of file FileCatalog.h.

114  {
115  return active_;
116  }
void art::FileCatalog::commitCatalog ( )
inlineinherited

Definition at line 90 of file FileCatalog.h.

91  {}
FileCatalogItem const & art::InputFileCatalog::currentFile ( ) const

Definition at line 40 of file InputFileCatalog.cc.

References fileCatalogItems_, fileIdx_, indexEnd, art::errors::LogicError, and maxIdx_.

Referenced by finish(), and art::RootInputFileSequence::initFile().

41  {
42  if (fileIdx_ == indexEnd) {
43  throw art::Exception(
45  "Cannot access the current file while the file catalog is empty!");
46  }
47  assert(fileIdx_ <= maxIdx_);
49  }
static constexpr size_t indexEnd
std::vector< FileCatalogItem > fileCatalogItems_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
size_t art::InputFileCatalog::currentIndex ( ) const

Definition at line 52 of file InputFileCatalog.cc.

References fileIdx_.

Referenced by art::RootInputFileSequence::initFile(), and art::RootInputFileSequence::previousFile().

53  {
54  return fileIdx_;
55  }
bool art::InputFileCatalog::empty ( void  ) const
inline

Definition at line 58 of file InputFileCatalog.h.

59  {
60  return fileCatalogItems_.empty();
61  }
std::vector< FileCatalogItem > fileCatalogItems_
std::vector<FileCatalogItem> const& art::InputFileCatalog::fileCatalogItems ( ) const
inline

Definition at line 42 of file InputFileCatalog.h.

Referenced by art::RootInputFileSequence::fileCatalogItems().

43  {
44  return fileCatalogItems_;
45  }
std::vector< FileCatalogItem > fileCatalogItems_
std::vector<std::string> const& art::InputFileCatalog::fileSources ( ) const
inline

Definition at line 64 of file InputFileCatalog.h.

Referenced by art::RootInputFileSequence::RootInputFileSequence().

65  {
66  return fileSources_;
67  }
std::vector< std::string > fileSources_
void art::InputFileCatalog::finish ( )

Definition at line 256 of file InputFileCatalog.cc.

References ci_, art::CONSUMED, currentFile(), fileCatalogItems_, fileIdx_, and indexEnd.

Referenced by art::RootInputFileSequence::closeFile_(), and retrieveNextFile().

257  {
258  if (fileIdx_ != indexEnd // there is a current file
259  && !currentFile().skipped() // not skipped
260  && !currentFile().consumed()) // not consumed
261  {
262  ci_->updateStatus(currentFile().uri(), FileDisposition::CONSUMED);
263  fileCatalogItems_[fileIdx_].consume();
264  }
265  }
static constexpr size_t indexEnd
ServiceHandle< CatalogInterface > ci_
FileCatalogItem const & currentFile() const
std::vector< FileCatalogItem > fileCatalogItems_
bool art::InputFileCatalog::getNextFile ( int  attempts = 5)

Definition at line 58 of file InputFileCatalog.cc.

References fileCatalogItems_, fileIdx_, hasNextFile_, indexEnd, maxIdx_, nextFileProbed_, nextItem_, retrieveNextFile(), and searchable_.

Referenced by art::RootInputFileSequence::nextFile(), art::RootInputFileSequence::readIt(), art::RootInputFileSequence::RootInputFileSequence(), and art::RootInputFileSequence::seekToEvent().

59  {
60  // get next file from FileDelivery service
61  // and give it to currentFile_ object
62  // returns false if theres no more file
63  //
64  // If hasNextFile() has been called prior to
65  // getNextFile(), it does not actually go fetch
66  // the next file from FileDelivery service,
67  // instead, it advances the iterator by one and
68  // make the "hidden" next file current.
69 
71  return false;
72 
73  if ((nextFileProbed_ && hasNextFile_) ||
74  retrieveNextFile(nextItem_, attempts)) {
75  nextFileProbed_ = false;
76  fileIdx_ =
77  (fileIdx_ == indexEnd) ? 0 : (searchable_ ? (fileIdx_ + 1) : 0);
78  if (fileIdx_ > maxIdx_)
79  maxIdx_ = fileIdx_;
81  return true;
82  }
83 
84  return false;
85  }
static constexpr size_t indexEnd
bool retrieveNextFile(FileCatalogItem &item, int attempts, bool transferOnly=false)
std::vector< FileCatalogItem > fileCatalogItems_
FileCatalogItem nextItem_
bool art::InputFileCatalog::hasNextFile ( int  attempts = 5)

Definition at line 88 of file InputFileCatalog.cc.

References hasNextFile_, nextFileProbed_, nextItem_, and retrieveNextFile().

Referenced by art::RootInputFileSequence::getNextItemType().

89  {
90  // A probe. It tries(and actually does) retreive
91  // the next file from the FileDelivery service. But
92  // does not advance the current file pointer
93  if (nextFileProbed_)
94  return hasNextFile_;
95 
97  nextFileProbed_ = true;
98 
99  return hasNextFile_;
100  }
bool retrieveNextFile(FileCatalogItem &item, int attempts, bool transferOnly=false)
FileCatalogItem nextItem_
static bool art::FileCatalog::isPhysical ( std::string const &  name)
inlinestaticinherited

Definition at line 93 of file FileCatalog.h.

Referenced by transferNextFile().

94  {
95  return (name.empty() || name.find(':') != std::string::npos);
96  }
bool art::InputFileCatalog::isSearchable ( )
inline
bool art::InputFileCatalog::retrieveNextFile ( FileCatalogItem item,
int  attempts,
bool  transferOnly = false 
)
private

Definition at line 103 of file InputFileCatalog.cc.

References ci_, art::errors::Configuration, art::DELIVERY_ERROR, finish(), art::NO_MORE_FILES, retrieveNextFileFromCacheOrService(), art::SKIPPED, art::SUCCESS, art::TRANSFER_ERROR, transferNextFile(), art::TRANSFERRED, and art::FileCatalogItem::uri().

Referenced by getNextFile(), and hasNextFile().

106  {
107 
108  // Tell the service the current opened file (if theres one) is consumed
109  finish();
110 
111  // retrieve (deliver and transfer) next file from service
112  // or, do the transfer only
113  FileCatalogStatus status;
114  if (transferOnly) {
115  status = transferNextFile(item);
116  } else {
117  status = retrieveNextFileFromCacheOrService(item);
118  }
119 
120  if (status == FileCatalogStatus::SUCCESS) {
121  // mark the file as transferred
122  ci_->updateStatus(item.uri(), FileDisposition::TRANSFERRED);
123  return true;
124  }
125 
126  if (status == FileCatalogStatus::NO_MORE_FILES) {
127  return false;
128  }
129 
130  if (status == FileCatalogStatus::DELIVERY_ERROR) {
131  if (attempts <= 1) {
133  "InputFileCatalog::retreiveNextFile()\n")
134  << "Delivery error encountered after reaching maximum number of "
135  "attemtps!";
136  } else {
137  return retrieveNextFile(item, attempts - 1, false);
138  }
139  }
140 
141  if (status == FileCatalogStatus::TRANSFER_ERROR) {
142  if (attempts <= 1) {
143  // if we end up with a transfer error, the method returns
144  // with a true flag and empty filename. Weired enough, but
145  // the next file does exist we just cannot retrieve it. Therefore
146  // we notify the service that the file has been skipped
147  ci_->updateStatus(item.uri(), FileDisposition::SKIPPED);
148  return true;
149  } else {
150  return retrieveNextFile(item, attempts - 1, true);
151  }
152  }
153 
154  // should never reach here
155  assert(0);
156  return false;
157  }
FileCatalogStatus retrieveNextFileFromCacheOrService(FileCatalogItem &item)
bool retrieveNextFile(FileCatalogItem &item, int attempts, bool transferOnly=false)
ServiceHandle< CatalogInterface > ci_
FileCatalogStatus
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
FileCatalogStatus transferNextFile(FileCatalogItem &item)
FileCatalogStatus art::InputFileCatalog::retrieveNextFileFromCacheOrService ( FileCatalogItem item)
private

Definition at line 160 of file InputFileCatalog.cc.

References ci_, art::DELIVERY_ERROR, fileCatalogItems_, fileIdx_, maxIdx_, art::NO_MORE_FILES, art::SUCCESS, and transferNextFile().

Referenced by retrieveNextFile().

161  {
162  // Try to get it from cached files
163  if (fileIdx_ < maxIdx_) {
164  item = fileCatalogItems_[fileIdx_ + 1];
166  }
167 
168  // Try to get it from the service
169  std::string uri;
170  double wait = 0.0;
171 
172  // get file delivered
173  int result = ci_->getNextFileURI(uri, wait);
174 
175  if (result == FileDeliveryStatus::NO_MORE_FILES)
177 
178  if (result != FileDeliveryStatus::SUCCESS)
180 
181  item = FileCatalogItem("", "", uri);
182 
183  // get file transfered
184  return transferNextFile(item);
185  }
ServiceHandle< CatalogInterface > ci_
std::vector< FileCatalogItem > fileCatalogItems_
FileCatalogStatus transferNextFile(FileCatalogItem &item)
void art::InputFileCatalog::rewind ( )

Definition at line 224 of file InputFileCatalog.cc.

References fileIdx_, art::errors::LogicError, and searchable_.

Referenced by art::RootInputFileSequence::rewind_().

225  {
226  if (!searchable_) {
228  "InputFileCatalog::rewind()\n")
229  << "A non-searchable catalog is not allowed to rewind!";
230  }
231  fileIdx_ = 0;
232  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::InputFileCatalog::rewindTo ( size_t  index)

Definition at line 235 of file InputFileCatalog.cc.

References fileIdx_, art::errors::InvalidNumber, art::errors::LogicError, maxIdx_, and searchable_.

Referenced by art::RootInputFileSequence::previousFile(), art::RootInputFileSequence::readIt(), and art::RootInputFileSequence::seekToEvent().

236  {
237  // rewind to a previous file location in the catalog
238  // service is not rewinded. only usable when FileDeliveryService::
239  // areFilesPersistent() is true
240  if (!searchable_) {
242  "InputFileCatalog::rewindTo()\n")
243  << "A non-searchable catalog is not allowed to rewind!";
244  }
245 
246  if (index > maxIdx_) {
248  "InputFileCatalog::rewindTo()\n")
249  << "Index " << index << " is out of range!";
250  }
251 
252  fileIdx_ = index;
253  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
void art::FileCatalog::setActive ( )
inlineinherited

Definition at line 108 of file FileCatalog.h.

109  {
110  active_ = true;
111  }
FileCatalogStatus art::InputFileCatalog::transferNextFile ( FileCatalogItem item)
private

Definition at line 188 of file InputFileCatalog.cc.

References art::errors::Configuration, art::FileCatalogItem::fileName(), ft_, art::FileCatalog::isPhysical(), art::FileCatalogItem::logicalFileName(), art::FileCatalogItem::skip(), art::SUCCESS, art::TRANSFER_ERROR, and art::FileCatalogItem::uri().

Referenced by retrieveNextFile(), and retrieveNextFileFromCacheOrService().

189  {
190 
191  std::string pfn;
192 
193  int result = ft_->translateToLocalFilename(item.uri(), pfn);
194 
195  if (result != FileTransferStatus::SUCCESS) {
196  item.fileName("");
197  item.logicalFileName("");
198  item.skip();
200  }
201 
202  // successfully retrieved the file
203  std::string lfn = pfn;
204 
205  boost::trim(pfn);
206 
207  if (pfn.empty()) {
208  throw art::Exception(
210  "InputFileCatalog::retrieveNextFileFromCacheService()\n")
211  << "An empty string specified in parameter for input source.\n";
212  }
213 
214  if (isPhysical(pfn)) {
215  lfn.clear();
216  }
217 
218  item.fileName(pfn);
219  item.logicalFileName(lfn);
221  }
ServiceHandle< FileTransfer > ft_
static bool isPhysical(std::string const &name)
Definition: FileCatalog.h:93
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string& art::FileCatalog::url ( )
inlineinherited

Definition at line 98 of file FileCatalog.h.

Referenced by art::RootInputFileSequence::initFile().

99  {
100  return url_;
101  }
std::string url_
Definition: FileCatalog.h:119
std::string const& art::FileCatalog::url ( ) const
inlineinherited

Definition at line 103 of file FileCatalog.h.

104  {
105  return url_;
106  }
std::string url_
Definition: FileCatalog.h:119

Member Data Documentation

ServiceHandle<CatalogInterface> art::InputFileCatalog::ci_
private
std::vector<FileCatalogItem> art::InputFileCatalog::fileCatalogItems_ {{}}
private
size_t art::InputFileCatalog::fileIdx_ {indexEnd}
private
std::vector<std::string> art::InputFileCatalog::fileSources_
private

Definition at line 78 of file InputFileCatalog.h.

Referenced by InputFileCatalog().

ServiceHandle<FileTransfer> art::InputFileCatalog::ft_
private

Definition at line 88 of file InputFileCatalog.h.

Referenced by transferNextFile().

bool art::InputFileCatalog::hasNextFile_ {false}
private

Definition at line 85 of file InputFileCatalog.h.

Referenced by getNextFile(), and hasNextFile().

constexpr size_t art::InputFileCatalog::indexEnd {std::numeric_limits<size_t>::max()}
static
size_t art::InputFileCatalog::maxIdx_ {}
private
bool art::InputFileCatalog::nextFileProbed_ {false}
private

Definition at line 84 of file InputFileCatalog.h.

Referenced by getNextFile(), and hasNextFile().

FileCatalogItem art::InputFileCatalog::nextItem_ {}
private

Definition at line 80 of file InputFileCatalog.h.

Referenced by getNextFile(), and hasNextFile().

bool art::InputFileCatalog::searchable_ {false}
private

Definition at line 83 of file InputFileCatalog.h.

Referenced by getNextFile(), InputFileCatalog(), rewind(), and rewindTo().


The documentation for this class was generated from the following files: