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 #include <iostream>
16 
17 namespace edm {
18 
19  InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames,
20  std::string const& override,
21  bool useLFNasPFNifLFNnotFound,
22  edm::CatalogType catType)
23  : logicalFileNames_(fileNames), fileNames_(fileNames), fileCatalogItems_(), overrideFileLocator_() {
24  init(override, useLFNasPFNifLFNnotFound, catType);
25  }
26 
28 
29  std::vector<std::string> InputFileCatalog::fileNames(unsigned iCatalog) const {
30  std::vector<std::string> tmp;
31  tmp.reserve(fileCatalogItems_.size());
32  for (auto const& item : fileCatalogItems_) {
33  tmp.push_back(item.fileName(iCatalog));
34  }
35  return tmp;
36  }
37 
38  void InputFileCatalog::init(std::string const& inputOverride,
39  bool useLFNasPFNifLFNnotFound,
40  edm::CatalogType catType) {
41  typedef std::vector<std::string>::iterator iter;
42 
43  if (!overrideFileLocator_ && !inputOverride.empty()) {
44  if (catType == edm::CatalogType::TrivialCatalog) {
46  std::make_unique<FileLocator>(inputOverride); // propagate_const<T> has no reset() function
47  } else if (catType == edm::CatalogType::RucioCatalog) {
48  //now make a struct from input string
49  std::vector<std::string> tmps;
50  boost::algorithm::split(tmps, inputOverride, boost::is_any_of(std::string(",")));
51  if (tmps.size() != 5) {
52  cms::Exception ex("FileCatalog");
53  ex << "Trying to override input file catalog but invalid input override string " << inputOverride
54  << " (Should be site,subSite,storageSite,volume,protocol)";
55  ex.addContext("Calling edm::InputFileCatalog::init()");
56  throw ex;
57  }
58 
59  edm::CatalogAttributes inputOverride_struct(
60  tmps[0], tmps[1], tmps[2], tmps[3], tmps[4]); //site, subSite,storageSite,volume,protocol
61 
63  std::make_unique<FileLocator>(inputOverride_struct); // propagate_const<T> has no reset() function
64  }
65  }
66 
67  Service<SiteLocalConfig> localconfservice;
68  if (!localconfservice.isAvailable()) {
69  cms::Exception ex("FileCatalog");
70  ex << "edm::SiteLocalConfigService is not available";
71  ex.addContext("Calling edm::InputFileCatalog::init()");
72  throw ex;
73  }
74 
75  if (catType == edm::CatalogType::TrivialCatalog) {
76  std::vector<std::string> const& tmp_dataCatalogs = localconfservice->trivialDataCatalogs();
77  if (!fileLocators_trivalCatalog_.empty())
79 
80  //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 trivialDataCatalogs() of SiteLocalConfigService
81  fileLocators_trivalCatalog_.push_back(std::make_unique<FileLocator>(tmp_dataCatalogs.front()));
82 
83  for (auto it = tmp_dataCatalogs.begin() + 1; it != tmp_dataCatalogs.end(); ++it) {
84  try {
85  fileLocators_trivalCatalog_.push_back(std::make_unique<FileLocator>(*it));
86  } catch (cms::Exception const& e) {
87  continue;
88  }
89  }
90  } else if (catType == edm::CatalogType::RucioCatalog) {
91  std::vector<edm::CatalogAttributes> const& tmp_dataCatalogs = localconfservice->dataCatalogs();
92  if (!fileLocators_.empty())
93  fileLocators_.clear();
94  //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() of SiteLocalConfigService
95  fileLocators_.push_back(std::make_unique<FileLocator>(tmp_dataCatalogs.front()));
96  for (auto it = tmp_dataCatalogs.begin() + 1; it != tmp_dataCatalogs.end(); ++it) {
97  try {
98  fileLocators_.push_back(std::make_unique<FileLocator>(*it));
99  } catch (cms::Exception const& e) {
100  continue;
101  }
102  }
103  } else {
104  cms::Exception ex("FileCatalog");
105  ex << "Undefined catalog type";
106  ex.addContext("Calling edm::InputFileCatalog::init()");
107  throw ex;
108  }
109 
110  for (iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(); it != itEnd;
111  ++it, ++lt) {
112  boost::trim(*it);
113  std::vector<std::string> pfns;
114  if (it->empty()) {
115  cms::Exception ex("FileCatalog");
116  ex << "An empty string specified in the fileNames parameter for input source";
117  ex.addContext("Calling edm::InputFileCatalog::init()");
118  throw ex;
119  }
120  if (isPhysical(*it)) {
121  if (it->back() == ':') {
122  cms::Exception ex("FileCatalog");
123  ex << "An empty physical file name specified in the fileNames parameter for input source";
124  ex.addContext("Calling edm::InputFileCatalog::init()");
125  throw ex;
126  }
127  pfns.push_back(*it);
128  // Clear the LFN.
129  lt->clear();
130  } else {
131  boost::trim(*lt);
132  findFile(*lt, pfns, useLFNasPFNifLFNnotFound, catType);
133  }
134 
135  fileCatalogItems_.push_back(FileCatalogItem(pfns, *lt));
136  }
137  }
138 
140  std::vector<std::string>& pfns,
141  bool useLFNasPFNifLFNnotFound,
142  edm::CatalogType catType) {
143  if (overrideFileLocator_) {
144  pfns.push_back(overrideFileLocator_->pfn(lfn, catType));
145  } else {
146  if (catType == edm::CatalogType::TrivialCatalog) {
147  for (auto const& locator : fileLocators_trivalCatalog_) {
148  std::string pfn = locator->pfn(lfn, edm::CatalogType::TrivialCatalog);
149  if (pfn.empty() && useLFNasPFNifLFNnotFound)
150  pfns.push_back(lfn);
151  else
152  pfns.push_back(pfn);
153  }
154  } else if (catType == edm::CatalogType::RucioCatalog) {
155  for (auto const& locator : fileLocators_) {
156  std::string pfn = locator->pfn(lfn, edm::CatalogType::RucioCatalog);
157  if (pfn.empty() && useLFNasPFNifLFNnotFound)
158  pfns.push_back(lfn);
159  else
160  pfns.push_back(pfn);
161  }
162  } else {
163  cms::Exception ex("FileCatalog");
164  ex << "Undefined catalog type";
165  ex.addContext("Calling edm::InputFileCatalog::findFile()");
166  throw ex;
167  }
168  }
169 
170  // Empty PFN will be found by caller.
171  }
172 
173 } // namespace edm
void findFile(std::string const &lfn, std::vector< std::string > &pfns, bool useLFNasPFNifLFNnotFound, edm::CatalogType catType)
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, edm::CatalogType catType)
InputFileCatalog(std::vector< std::string > const &fileNames, std::string const &override, bool useLFNasPFNifLFNnotFound=false, edm::CatalogType catType=edm::CatalogType::RucioCatalog)
std::vector< edm::propagate_const< std::unique_ptr< FileLocator > > > fileLocators_trivalCatalog_
void addContext(std::string const &context)
Definition: Exception.cc:165
HLT enums.
edm::propagate_const< std::unique_ptr< FileLocator > > overrideFileLocator_
bool isAvailable() const
Definition: Service.h:40
tmp
align.sh
Definition: createJobs.py:716
std::vector< std::string > logicalFileNames_