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,
15  std::string const& override,
16  bool useLFNasPFNifLFNnotFound)
17  : logicalFileNames_(fileNames),
18  fileNames_(fileNames),
19  fallbackFileNames_(fileNames.size()),
20  fileCatalogItems_(),
21  fileLocator_(),
22  overrideFileLocator_(),
23  fallbackFileLocator_(),
24  overrideFallbackFileLocator_() {
25  init(override, "", useLFNasPFNifLFNnotFound);
26  }
27 
28  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames,
29  std::string const& override,
30  std::string const& overrideFallback,
31  bool useLFNasPFNifLFNnotFound)
32  : logicalFileNames_(fileNames),
33  fileNames_(fileNames),
34  fallbackFileNames_(fileNames.size()),
36  fileLocator_(),
40  init(override, overrideFallback, useLFNasPFNifLFNnotFound);
41  }
42 
44 
45  void InputFileCatalog::init(std::string const& inputOverride,
46  std::string const& inputOverrideFallback,
47  bool useLFNasPFNifLFNnotFound) {
48  fileCatalogItems_.reserve(fileNames_.size());
49  typedef std::vector<std::string>::iterator iter;
50  for (iter it = fileNames_.begin(),
51  lt = logicalFileNames_.begin(),
52  itEnd = fileNames_.end(),
53  ft = fallbackFileNames_.begin();
54  it != itEnd;
55  ++it, ++lt, ++ft) {
56  boost::trim(*it);
57  if (it->empty()) {
58  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
59  << "An empty string specified in the fileNames parameter for input source.\n";
60  }
61  if (isPhysical(*it)) {
62  if (it->back() == ':') {
63  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
64  << "An empty physical file name specified in the fileNames parameter for input source.\n";
65  }
66  // Clear the LFN.
67  lt->clear();
68  } else {
69  if (!fileLocator_) {
70  fileLocator_ = std::make_unique<FileLocator>("", false); // propagate_const<T> has no reset() function
71  }
72  if (!overrideFileLocator_ && !inputOverride.empty()) {
74  std::make_unique<FileLocator>(inputOverride, false); // propagate_const<T> has no reset() function
75  }
76  if (!fallbackFileLocator_) {
77  try {
79  std::make_unique<FileLocator>("", true); // propagate_const<T> has no reset() function
80  } catch (cms::Exception const& e) {
81  // No valid fallback locator is OK too.
82  }
83  }
84  if (!overrideFallbackFileLocator_ && !inputOverrideFallback.empty()) {
86  std::make_unique<FileLocator>(inputOverrideFallback, true); // propagate_const<T> has no reset() function
87  }
88  boost::trim(*lt);
89  findFile(*it, *ft, *lt, useLFNasPFNifLFNnotFound);
90  }
91  fileCatalogItems_.push_back(FileCatalogItem(*it, *lt, *ft));
92  }
93  }
94 
96  std::string& fallbackPfn,
97  std::string const& lfn,
98  bool useLFNasPFNifLFNnotFound) {
100  pfn = overrideFileLocator_->pfn(lfn);
101  if (pfn.empty()) {
102  pfn = fileLocator_->pfn(lfn);
103  }
104  } else {
105  pfn = fileLocator_->pfn(lfn);
106  }
107  if (pfn.empty() && useLFNasPFNifLFNnotFound) {
108  pfn = lfn;
109  }
110  // Empty PFN will be found by caller.
111 
113  fallbackPfn = overrideFallbackFileLocator_->pfn(lfn);
114  if (fallbackFileLocator_ && fallbackPfn.empty()) {
115  fallbackPfn = fallbackFileLocator_->pfn(lfn);
116  }
117  } else if (fallbackFileLocator_) {
118  fallbackPfn = fallbackFileLocator_->pfn(lfn);
119  // Empty fallback PFN is OK.
120  }
121  }
122 } // namespace edm
size
Write out results.
std::vector< FileCatalogItem > fileCatalogItems_
static void trim(std::string &s)
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)