CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FWCore/Catalog/src/InputFileCatalog.cc

Go to the documentation of this file.
00001 
00002 //
00004 
00005 #include "FWCore/Catalog/interface/InputFileCatalog.h"
00006 
00007 #include "FWCore/Utilities/interface/Exception.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 
00010 #include <boost/algorithm/string.hpp>
00011 
00012 namespace edm {
00013 
00014   InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, bool useLFNasPFNifLFNnotFound) :
00015     logicalFileNames_(fileNames),
00016     fileNames_(fileNames),
00017     fallbackFileNames_(fileNames.size()),
00018     fileCatalogItems_(),
00019     fileLocator_(),
00020     overrideFileLocator_(),
00021     fallbackFileLocator_(),
00022     overrideFallbackFileLocator_() {
00023 
00024     init(override, "", useLFNasPFNifLFNnotFound);
00025   }
00026 
00027   InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, std::string const& overrideFallback, bool useLFNasPFNifLFNnotFound) :
00028     logicalFileNames_(fileNames),
00029     fileNames_(fileNames),
00030     fallbackFileNames_(fileNames.size()),
00031     fileCatalogItems_(),
00032     fileLocator_(),
00033     overrideFileLocator_(),
00034     fallbackFileLocator_(),
00035     overrideFallbackFileLocator_() {
00036 
00037     init(override, overrideFallback, useLFNasPFNifLFNnotFound);
00038   }
00039 
00040   InputFileCatalog::~InputFileCatalog() {}
00041 
00042   void InputFileCatalog::init(std::string const& inputOverride, std::string const& inputOverrideFallback, bool useLFNasPFNifLFNnotFound) {
00043 
00044     fileCatalogItems_.reserve(fileNames_.size());
00045     typedef std::vector<std::string>::iterator iter;
00046     for(iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end(), ft = fallbackFileNames_.begin();
00047         it != itEnd; ++it, ++lt, ++ft) {
00048       boost::trim(*it);
00049       if (it->empty()) {
00050         throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
00051           << "An empty string specified in the fileNames parameter for input source.\n";
00052       }
00053       if (isPhysical(*it)) {
00054         if(it->back() == ':') {
00055           throw Exception(errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
00056             << "An empty physical file name specified in the fileNames parameter for input source.\n";
00057         }
00058         // Clear the LFN.
00059         lt->clear();
00060       } else {
00061         if (!fileLocator_) {
00062           fileLocator_.reset(new FileLocator("", false));
00063         }
00064         if (!overrideFileLocator_ && !inputOverride.empty()) {
00065           overrideFileLocator_.reset(new FileLocator(inputOverride, false));
00066         }
00067         if (!fallbackFileLocator_) {
00068           try {
00069             fallbackFileLocator_.reset(new FileLocator("", true));
00070           } catch (cms::Exception const& e) {
00071             // No valid fallback locator is OK too.
00072           }
00073         }
00074         if (!overrideFallbackFileLocator_ && !inputOverrideFallback.empty()) {
00075           overrideFallbackFileLocator_.reset(new FileLocator(inputOverrideFallback, true));
00076         }
00077         boost::trim(*lt);
00078         findFile(*it, *ft, *lt, useLFNasPFNifLFNnotFound);
00079       }
00080       fileCatalogItems_.push_back(FileCatalogItem(*it, *lt, *ft));
00081     }
00082   }
00083 
00084   void InputFileCatalog::findFile(std::string& pfn, std::string& fallbackPfn, std::string const& lfn, bool useLFNasPFNifLFNnotFound) {
00085     if (overrideFileLocator_) {
00086       pfn = overrideFileLocator_->pfn(lfn);
00087       if (pfn.empty()) {
00088         pfn = fileLocator_->pfn(lfn);
00089       }
00090     } else {
00091       pfn = fileLocator_->pfn(lfn);
00092     }
00093     if (pfn.empty() && useLFNasPFNifLFNnotFound) {
00094       pfn = lfn;
00095     }
00096     // Empty PFN will be found by caller.
00097 
00098     if (overrideFallbackFileLocator_) {
00099       fallbackPfn = overrideFallbackFileLocator_->pfn(lfn);
00100       if (fallbackFileLocator_ && fallbackPfn.empty()) {
00101         fallbackPfn = fallbackFileLocator_->pfn(lfn);
00102       }
00103     } else if (fallbackFileLocator_) {
00104       fallbackPfn = fallbackFileLocator_->pfn(lfn);
00105       // Empty fallback PFN is OK.
00106     }
00107   }
00108 }