CMS 3D CMS Logo

InputFileCatalog.cc

Go to the documentation of this file.
00001 
00002 //
00003 // $Id: InputFileCatalog.cc,v 1.6 2008/04/25 13:48:18 eulisse Exp $
00004 //
00005 // Original Author: Luca Lista
00006 // Current Author: Bill Tanenbaum
00007 //
00009 
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 
00012 #include "FWCore/Catalog/interface/InputFileCatalog.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FileCatalog/URIParser.h"
00015 #include "FileCatalog/IFCAction.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 #include "FWCore/Catalog/interface/SiteLocalConfig.h"
00018 
00019 #include <boost/algorithm/string.hpp>
00020 
00021 namespace edm {
00022   InputFileCatalog::InputFileCatalog(ParameterSet const& pset,
00023                                      PoolCatalog & poolcat,
00024                                      std::string const& namesParameter,
00025                                      bool canBeEmpty, bool noThrow) :
00026     FileCatalog(poolcat),
00027     logicalFileNames_(canBeEmpty ?
00028         pset.getUntrackedParameter<std::vector<std::string> >(namesParameter, std::vector<std::string>()) :
00029         pset.getUntrackedParameter<std::vector<std::string> >(namesParameter)),
00030     fileNames_(logicalFileNames_),
00031     fileCatalogItems_() {
00032 
00033     if (logicalFileNames_.empty()) {
00034       if (canBeEmpty) return;
00035       throw edm::Exception(edm::errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
00036           << "Empty '" << namesParameter << "' parameter specified for input source.\n";
00037     }
00038     // Starting the catalog will write a catalog out if it does not exist.
00039     // So, do not start (or even read) the catalog unless it is needed.
00040 
00041     fileCatalogItems_.reserve(fileNames_.size());
00042     typedef std::vector<std::string>::iterator iter;
00043     for(iter it = fileNames_.begin(), lt = logicalFileNames_.begin(), itEnd = fileNames_.end();
00044         it != itEnd; ++it, ++lt) {
00045       boost::trim(*it);
00046       if (it->empty()) {
00047         throw edm::Exception(edm::errors::Configuration, "InputFileCatalog::InputFileCatalog()\n")
00048           << "An empty string specified in '" << namesParameter << "' parameter for input source.\n";
00049       }
00050       if (isPhysical(*it)) {
00051         lt->clear();
00052       } else {
00053         boost::trim(*lt);
00054         if (!active()) {
00055           // Protect against handling the catalog twice.
00056           // There is only one catalog, so there is no need
00057           // to support multiple different catalogs.
00058           if (catalog().nReadCatalogs() == 0) {
00059             // Add the override catalog, if specified in the pset.
00060             std::string overriderUrl = pset.getUntrackedParameter<std::string>("overrideCatalog", std::string());
00061            if (!overriderUrl.empty ())
00062             {  
00063               pool::URIParser overriderParser(overriderUrl); 
00064               overriderParser.parse();
00065               catalog().addReadCatalog(overriderParser.contactstring());
00066             }
00067             // For reading use the catalog specified in the site-local config file
00068             url() = Service<edm::SiteLocalConfig>()->dataCatalog();
00069             pool::URIParser parser(url());
00070             parser.parse();
00071 
00072            catalog().addReadCatalog(parser.contactstring());
00073            catalog().connect();
00074 
00075             catalog().start();
00076             setActive();
00077           }
00078         }
00079         findFile(*it, *lt, noThrow);
00080       }
00081       fileCatalogItems_.push_back(FileCatalogItem(*it, *lt));
00082     }
00083   }
00084 
00085   InputFileCatalog::~InputFileCatalog() {}
00086 
00087   void InputFileCatalog::findFile(std::string & pfn, std::string const& lfn, bool noThrow) {
00088     pool::FClookup action;
00089     catalog().setAction(action);
00090     pool::FileCatalog::FileID fid;
00091     action.lookupFileByLFN(lfn, fid);
00092     if (fid == pool::FileCatalog::FileID()) {
00093       if (noThrow) {
00094         pfn.clear();
00095       } else {
00096         throw cms::Exception("LogicalFileNameNotFound", "FileCatalog::findFile()\n")
00097           << "Logical file name '" << lfn << "' was not found in the file catalog.\n"
00098           << "If you wanted a local file, you forgot the 'file:' prefix\n"
00099           << "before the file name in your configuration file.\n";
00100       }
00101     } else {
00102       std::string fileType;
00103       action.lookupBestPFN(fid, pool::FileCatalog::READ, pool::FileCatalog::SEQUENTIAL, pfn, fileType);
00104       if (pfn.empty() && !noThrow) {
00105         throw cms::Exception("LogicalFileNameNotFound", "FileCatalog::findFile()\n")
00106           << "Logical file name '" << lfn << "' was not found in the file catalog.\n"
00107           << "If you wanted a local file, you forgot the 'file:' prefix\n"
00108           << "before the file name in your configuration file.\n";
00109       }
00110     }
00111   }
00112 }

Generated on Tue Jun 9 17:35:18 2009 for CMSSW by  doxygen 1.5.4