CMS 3D CMS Logo

InputFileCatalog.cc
Go to the documentation of this file.
1 //
4 
6 
9 
12 
13 #include <boost/algorithm/string.hpp>
14 
15 namespace edm {
16 
17  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames,
18  std::string const& override,
19  bool useLFNasPFNifLFNnotFound)
20  : logicalFileNames_(fileNames), fileNames_(fileNames), fileCatalogItems_(), overrideFileLocator_() {
21  init(override, useLFNasPFNifLFNnotFound);
22  }
23 
25 
26  std::vector<std::string> InputFileCatalog::fileNames(unsigned iCatalog) const {
27  std::vector<std::string> tmp;
28  tmp.reserve(fileCatalogItems_.size());
29  for (auto const& item : fileCatalogItems_) {
30  tmp.push_back(item.fileName(iCatalog));
31  }
32  return tmp;
33  }
34 
35  void InputFileCatalog::init(std::string const& inputOverride, bool useLFNasPFNifLFNnotFound) {
36  typedef std::vector<std::string>::iterator iter;
37 
38  if (!overrideFileLocator_ && !inputOverride.empty()) {
40  std::make_unique<FileLocator>(inputOverride); // propagate_const<T> has no reset() function
41  }
42 
43  Service<SiteLocalConfig> localconfservice;
44  if (!localconfservice.isAvailable())
45  throw cms::Exception("TrivialFileCatalog", "edm::SiteLocalConfigService is not available");
46 
47  std::vector<std::string> const& tmp_dataCatalogs = localconfservice->dataCatalogs();
48  if (!fileLocators_.empty())
49  fileLocators_.clear();
50 
51  //require the first file locator to success so obvious mistakes in data catalogs, typos for example, can be catched early. Note that tmp_dataCatalogs is not empty at this point. The protection is done inside the dataCatalogs() above
52  fileLocators_.push_back(std::make_unique<FileLocator>(tmp_dataCatalogs.front()));
53 
54  for (auto it = tmp_dataCatalogs.begin() + 1; it != tmp_dataCatalogs.end(); ++it) {
55  try {
56  fileLocators_.push_back(std::make_unique<FileLocator>(*it));
57  } catch (cms::Exception const& e) {
58  continue;
59  }
60  }
61 
62  for (iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(); it != itEnd;
63  ++it, ++lt) {
64  boost::trim(*it);
65  std::vector<std::string> pfns;
66  if (it->empty()) {
67  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
68  << "An empty string specified in the fileNames parameter for input source.\n";
69  }
70  if (isPhysical(*it)) {
71  if (it->back() == ':') {
72  throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
73  << "An empty physical file name specified in the fileNames parameter for input source.\n";
74  }
75  pfns.push_back(*it);
76  // Clear the LFN.
77  lt->clear();
78  } else {
79  boost::trim(*lt);
80  findFile(*lt, pfns, useLFNasPFNifLFNnotFound);
81  }
82  fileCatalogItems_.push_back(FileCatalogItem(pfns, *lt));
83  }
84  }
85 
87  std::vector<std::string>& pfns,
88  bool useLFNasPFNifLFNnotFound) {
90  pfns.push_back(overrideFileLocator_->pfn(lfn));
91  } else {
92  for (auto const& locator : fileLocators_) {
93  std::string pfn = locator->pfn(lfn);
94  if (pfn.empty() && useLFNasPFNifLFNnotFound)
95  pfns.push_back(lfn);
96  else
97  pfns.push_back(pfn);
98  }
99  }
100 
101  // Empty PFN will be found by caller.
102  }
103 
104 } // namespace edm
void findFile(std::string const &lfn, std::vector< std::string > &pfns, bool useLFNasPFNifLFNnotFound)
std::vector< std::string > fileNames(unsigned iCatalog) const
std::vector< FileCatalogItem > fileCatalogItems_
static void trim(std::string &s)
std::vector< std::string > fileNames_
std::vector< edm::propagate_const< std::unique_ptr< FileLocator > > > fileLocators_
static bool isPhysical(std::string const &name)
void init(std::string const &override, bool useLFNasPFNifLFNnotFound)
HLT enums.
edm::propagate_const< std::unique_ptr< FileLocator > > overrideFileLocator_
bool isAvailable() const
Definition: Service.h:40
InputFileCatalog(std::vector< std::string > const &fileNames, std::string const &override, bool useLFNasPFNifLFNnotFound=false)
tmp
align.sh
Definition: createJobs.py:716
std::vector< std::string > logicalFileNames_