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
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::InputFileCatalog::isPhysical
static bool isPhysical(std::string const &name)
Definition: InputFileCatalog.h:43
edm::InputFileCatalog::~InputFileCatalog
~InputFileCatalog()
Definition: InputFileCatalog.cc:24
edm::InputFileCatalog::findFile
void findFile(std::string const &lfn, std::vector< std::string > &pfns, bool useLFNasPFNifLFNnotFound)
Definition: InputFileCatalog.cc:86
edm::InputFileCatalog::fileCatalogItems_
std::vector< FileCatalogItem > fileCatalogItems_
Definition: InputFileCatalog.h:50
edm::InputFileCatalog::fileNames
std::vector< std::string > fileNames(unsigned iCatalog) const
Definition: InputFileCatalog.cc:26
edm::InputFileCatalog::fileLocators_
std::vector< edm::propagate_const< std::unique_ptr< FileLocator > > > fileLocators_
Definition: InputFileCatalog.h:53
InputFileCatalog.h
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
edm::InputFileCatalog::fileNames_
std::vector< std::string > fileNames_
Definition: InputFileCatalog.h:49
EDMException.h
Service.h
edm::InputFileCatalog::init
void init(std::string const &override, bool useLFNasPFNifLFNnotFound)
Definition: InputFileCatalog.cc:35
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Service
Definition: Service.h:30
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::InputFileCatalog::overrideFileLocator_
edm::propagate_const< std::unique_ptr< FileLocator > > overrideFileLocator_
Definition: InputFileCatalog.h:51
edm::InputFileCatalog::InputFileCatalog
InputFileCatalog(std::vector< std::string > const &fileNames, std::string const &override, bool useLFNasPFNifLFNnotFound=false)
Definition: InputFileCatalog.cc:17
edm::InputFileCatalog::logicalFileNames_
std::vector< std::string > logicalFileNames_
Definition: InputFileCatalog.h:48
Exception
Definition: hltDiff.cc:246
edm::FileCatalogItem
Definition: InputFileCatalog.h:18
Exception.h
LaserTracksInput_cfi.fileNames
fileNames
Definition: LaserTracksInput_cfi.py:8
cms::Exception
Definition: Exception.h:70
trim
static void trim(std::string &s)
Definition: DTCCablingMapProducer.cc:67
edm::errors::Configuration
Definition: EDMException.h:36
SiteLocalConfig.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37