CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/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 noThrow) :
00015     logicalFileNames_(fileNames),
00016     fileNames_(fileNames),
00017     fallbackFileNames_(fileNames.size()),
00018     fileCatalogItems_(),
00019     fileLocator_(),
00020     overrideFileLocator_(),
00021     fallbackFileLocator_(),
00022     overrideFallbackFileLocator_() {
00023 
00024     init(fileNames, override, "", noThrow);
00025   }
00026 
00027   InputFileCatalog::InputFileCatalog(std::vector<std::string> const& fileNames, std::string const& override, std::string const& overrideFallback, bool noThrow) :
00028     logicalFileNames_(fileNames),
00029     fileNames_(fileNames),
00030     fallbackFileNames_(fileNames.size()),
00031     fileCatalogItems_(),
00032     fileLocator_(),
00033     overrideFileLocator_(),
00034     fallbackFileLocator_(),
00035     overrideFallbackFileLocator_() {
00036 
00037     init(fileNames, override, overrideFallback, noThrow);
00038   }
00039 
00040   InputFileCatalog::~InputFileCatalog() {}
00041 
00042   void InputFileCatalog::init(std::vector<std::string> const& fileNames, std::string const& inputOverride, std::string const& inputOverrideFallback, bool noThrow) {
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         // Clear the LFN.
00055         lt->clear();
00056       } else {
00057         if (!fileLocator_) {
00058           fileLocator_.reset(new FileLocator("", false));
00059         }
00060         if (!overrideFileLocator_ && !inputOverride.empty()) {
00061           overrideFileLocator_.reset(new FileLocator(inputOverride, false));
00062         }
00063         if (!fallbackFileLocator_) {
00064           try {
00065             fallbackFileLocator_.reset(new FileLocator("", true));
00066           } catch (cms::Exception const& e) {
00067             // No valid fallback locator is OK too.
00068           }
00069         }
00070         if (!overrideFallbackFileLocator_ && !inputOverrideFallback.empty()) {
00071           overrideFallbackFileLocator_.reset(new FileLocator(inputOverrideFallback, true));
00072         }
00073         boost::trim(*lt);
00074         findFile(*it, *ft, *lt, noThrow);
00075       }
00076       fileCatalogItems_.push_back(FileCatalogItem(*it, *lt, *ft));
00077     }
00078   }
00079 
00080   void InputFileCatalog::findFile(std::string& pfn, std::string& fallbackPfn, std::string const& lfn, bool noThrow) {
00081     if (overrideFileLocator_) {
00082       pfn = overrideFileLocator_->pfn(lfn);
00083       if (pfn.empty()) {
00084         pfn = fileLocator_->pfn(lfn);
00085       }
00086     } else {
00087       pfn = fileLocator_->pfn(lfn);
00088     }
00089     if (pfn.empty()) {
00090       if (!noThrow) {
00091         throw cms::Exception("LogicalFileNameNotFound", "FileCatalog::findFile()\n")
00092           << "Logical file name '" << lfn << "' was not found in the file catalog.\n"
00093           << "If you wanted a local file, you forgot the 'file:' prefix\n"
00094           << "before the file name in your configuration file.\n";
00095       }
00096       pfn = lfn;
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 }