CMS 3D CMS Logo

InputFileCatalog.cc
Go to the documentation of this file.
1 //
4 
6 
9 
10 #include <boost/algorithm/string.hpp>
11 
12 namespace edm {
13 
14  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, bool useLFNasPFNifLFNnotFound) :
15  logicalFileNames_(fileNames),
16  fileNames_(fileNames),
17  fallbackFileNames_(fileNames.size()),
18  fileCatalogItems_(),
19  fileLocator_(),
20  overrideFileLocator_(),
21  fallbackFileLocator_(),
22  overrideFallbackFileLocator_() {
23 
24  init(override, "", useLFNasPFNifLFNnotFound);
25  }
26 
27  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, std::string const& overrideFallback, bool useLFNasPFNifLFNnotFound) :
28  logicalFileNames_(fileNames),
29  fileNames_(fileNames),
30  fallbackFileNames_(fileNames.size()),
32  fileLocator_(),
36 
37  init(override, overrideFallback, useLFNasPFNifLFNnotFound);
38  }
39 
41 
42  void InputFileCatalog::init(std::string const& inputOverride, std::string const& inputOverrideFallback, bool useLFNasPFNifLFNnotFound) {
43 
44  fileCatalogItems_.reserve(fileNames_.size());
45  typedef std::vector<std::string>::iterator iter;
46  for(iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(), ft = fallbackFileNames_.begin();
47  it != itEnd; ++it, ++lt, ++ft) {
48  boost::trim(*it);
49  if (it->empty()) {
50  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
51  << "An empty string specified in the fileNames parameter for input source.\n";
52  }
53  if (isPhysical(*it)) {
54  if(it->back() == ':') {
55  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
56  << "An empty physical file name specified in the fileNames parameter for input source.\n";
57  }
58  // Clear the LFN.
59  lt->clear();
60  } else {
61  if (!fileLocator_) {
62  fileLocator_ = std::make_unique<FileLocator>("", false); // propagate_const<T> has no reset() function
63  }
64  if (!overrideFileLocator_ && !inputOverride.empty()) {
65  overrideFileLocator_ = std::make_unique<FileLocator>(inputOverride, false); // propagate_const<T> has no reset() function
66  }
67  if (!fallbackFileLocator_) {
68  try {
69  fallbackFileLocator_ = std::make_unique<FileLocator>("", true); // propagate_const<T> has no reset() function
70  } catch (cms::Exception const& e) {
71  // No valid fallback locator is OK too.
72  }
73  }
74  if (!overrideFallbackFileLocator_ && !inputOverrideFallback.empty()) {
75  overrideFallbackFileLocator_ = std::make_unique<FileLocator>(inputOverrideFallback, true); // propagate_const<T> has no reset() function
76  }
77  boost::trim(*lt);
78  findFile(*it, *ft, *lt, useLFNasPFNifLFNnotFound);
79  }
80  fileCatalogItems_.push_back(FileCatalogItem(*it, *lt, *ft));
81  }
82  }
83 
84  void InputFileCatalog::findFile(std::string& pfn, std::string& fallbackPfn, std::string const& lfn, bool useLFNasPFNifLFNnotFound) {
86  pfn = overrideFileLocator_->pfn(lfn);
87  if (pfn.empty()) {
88  pfn = fileLocator_->pfn(lfn);
89  }
90  } else {
91  pfn = fileLocator_->pfn(lfn);
92  }
93  if (pfn.empty() && useLFNasPFNifLFNnotFound) {
94  pfn = lfn;
95  }
96  // Empty PFN will be found by caller.
97 
99  fallbackPfn = overrideFallbackFileLocator_->pfn(lfn);
100  if (fallbackFileLocator_ && fallbackPfn.empty()) {
101  fallbackPfn = fallbackFileLocator_->pfn(lfn);
102  }
103  } else if (fallbackFileLocator_) {
104  fallbackPfn = fallbackFileLocator_->pfn(lfn);
105  // Empty fallback PFN is OK.
106  }
107  }
108 }
size
Write out results.
std::vector< FileCatalogItem > fileCatalogItems_
std::vector< std::string > fileNames_
static bool isPhysical(std::string const &name)
edm::propagate_const< std::unique_ptr< FileLocator > > fileLocator_
std::vector< std::string > fallbackFileNames_
edm::propagate_const< std::unique_ptr< FileLocator > > overrideFallbackFileLocator_
edm::propagate_const< std::unique_ptr< FileLocator > > fallbackFileLocator_
std::vector< std::string > const & fileNames() const
HLT enums.
edm::propagate_const< std::unique_ptr< FileLocator > > overrideFileLocator_
void init(std::string const &override, std::string const &overrideFallback, bool useLFNasPFNifLFNnotFound)
InputFileCatalog(std::vector< std::string > const &fileNames, std::string const &override, bool useLFNasPFNifLFNnotFound=false)
std::vector< std::string > logicalFileNames_
void findFile(std::string &pfn, std::string &fallbackPfn, std::string const &lfn, bool useLFNasPFNifLFNnotFound)