Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:36

0001 //////////////////////////////////////////////////////////////////////
0002 //
0003 //////////////////////////////////////////////////////////////////////
0004 
0005 #include "FWCore/Catalog/interface/InputFileCatalog.h"
0006 
0007 #include "FWCore/ServiceRegistry/interface/Service.h"
0008 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
0009 
0010 #include "FWCore/Utilities/interface/Exception.h"
0011 #include "FWCore/Utilities/interface/EDMException.h"
0012 
0013 #include <boost/algorithm/string.hpp>
0014 
0015 namespace edm {
0016 
0017   InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames,
0018                                      std::string const& override,
0019                                      bool useLFNasPFNifLFNnotFound)
0020       : logicalFileNames_(fileNames), fileNames_(fileNames), fileCatalogItems_(), overrideFileLocator_() {
0021     init(override, useLFNasPFNifLFNnotFound);
0022   }
0023 
0024   InputFileCatalog::~InputFileCatalog() {}
0025 
0026   std::vector<std::string> InputFileCatalog::fileNames(unsigned iCatalog) const {
0027     std::vector<std::string> tmp;
0028     tmp.reserve(fileCatalogItems_.size());
0029     for (auto const& item : fileCatalogItems_) {
0030       tmp.push_back(item.fileName(iCatalog));
0031     }
0032     return tmp;
0033   }
0034 
0035   void InputFileCatalog::init(std::string const& inputOverride, bool useLFNasPFNifLFNnotFound) {
0036     typedef std::vector<std::string>::iterator iter;
0037 
0038     if (!overrideFileLocator_ && !inputOverride.empty()) {
0039       overrideFileLocator_ =
0040           std::make_unique<FileLocator>(inputOverride);  // propagate_const<T> has no reset() function
0041     }
0042 
0043     Service<SiteLocalConfig> localconfservice;
0044     if (!localconfservice.isAvailable())
0045       throw cms::Exception("TrivialFileCatalog", "edm::SiteLocalConfigService is not available");
0046 
0047     std::vector<std::string> const& tmp_dataCatalogs = localconfservice->dataCatalogs();
0048     if (!fileLocators_.empty())
0049       fileLocators_.clear();
0050 
0051     //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
0052     fileLocators_.push_back(std::make_unique<FileLocator>(tmp_dataCatalogs.front()));
0053 
0054     for (auto it = tmp_dataCatalogs.begin() + 1; it != tmp_dataCatalogs.end(); ++it) {
0055       try {
0056         fileLocators_.push_back(std::make_unique<FileLocator>(*it));
0057       } catch (cms::Exception const& e) {
0058         continue;
0059       }
0060     }
0061 
0062     for (iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(); it != itEnd;
0063          ++it, ++lt) {
0064       boost::trim(*it);
0065       std::vector<std::string> pfns;
0066       if (it->empty()) {
0067         throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
0068             << "An empty string specified in the fileNames parameter for input source.\n";
0069       }
0070       if (isPhysical(*it)) {
0071         if (it->back() == ':') {
0072           throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
0073               << "An empty physical file name specified in the fileNames parameter for input source.\n";
0074         }
0075         pfns.push_back(*it);
0076         // Clear the LFN.
0077         lt->clear();
0078       } else {
0079         boost::trim(*lt);
0080         findFile(*lt, pfns, useLFNasPFNifLFNnotFound);
0081       }
0082       fileCatalogItems_.push_back(FileCatalogItem(pfns, *lt));
0083     }
0084   }
0085 
0086   void InputFileCatalog::findFile(std::string const& lfn,
0087                                   std::vector<std::string>& pfns,
0088                                   bool useLFNasPFNifLFNnotFound) {
0089     if (overrideFileLocator_) {
0090       pfns.push_back(overrideFileLocator_->pfn(lfn));
0091     } else {
0092       for (auto const& locator : fileLocators_) {
0093         std::string pfn = locator->pfn(lfn);
0094         if (pfn.empty() && useLFNasPFNifLFNnotFound)
0095           pfns.push_back(lfn);
0096         else
0097           pfns.push_back(pfn);
0098       }
0099     }
0100 
0101     // Empty PFN will be found by caller.
0102   }
0103 
0104 }  // namespace edm