CMS 3D CMS Logo

MCDBSource.cc File Reference

#include <iostream>
#include <utility>
#include <string>
#include <boost/regex.hpp>
#include "mcdb.hpp"
#include "FWCore/Framework/interface/InputSourceMacros.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Run.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
#include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
#include "GeneratorInterface/LHEInterface/interface/LHEReader.h"
#include "LHESource.h"

Go to the source code of this file.

Classes

class  MCDBSource

Functions

static edm::ParameterSet augmentPSetFromMCDB (const edm::ParameterSet &params)
 DEFINE_ANOTHER_FWK_INPUT_SOURCE (MCDBSource)
static std::pair< std::vector
< std::string >, unsigned int
getFileURLs (const edm::ParameterSet &params)


Function Documentation

static edm::ParameterSet augmentPSetFromMCDB ( const edm::ParameterSet params  )  [static]

Definition at line 108 of file MCDBSource.cc.

References edm::ParameterSet::addUntrackedParameter(), getFileURLs(), and HLT_VtxMuL3::result.

00109 {
00110         // note that this is inherently ugly, but the only way to
00111         // pass the file URLs to ExternalInputSource, as the MCDB client
00112         // is nothing but an MCDB to URL converter
00113         // all modified parameters are untracked, so the provenance is
00114         // unchanged
00115 
00116         std::pair<std::vector<std::string>, unsigned int> result =
00117                                                         getFileURLs(params);
00118 
00119         edm::ParameterSet newParams = params;
00120         newParams.addUntrackedParameter<std::vector<std::string> >(
00121                                                 "fileNames", result.first);
00122         newParams.addUntrackedParameter<unsigned int>(
00123                                                 "seekEvent", result.second);
00124 
00125         return newParams;
00126 }

DEFINE_ANOTHER_FWK_INPUT_SOURCE ( MCDBSource   ) 

static std::pair<std::vector<std::string>, unsigned int> getFileURLs ( const edm::ParameterSet params  )  [static]

Definition at line 32 of file MCDBSource.cc.

References lat::endl(), file, filter, cmssw-higgs-4mu::firstEvent, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), path(), prot, and MCDBSource_SingleTop_tW_10TeV_cff::supportedProtocols.

Referenced by augmentPSetFromMCDB().

00033 {
00034         unsigned int articleId = params.getParameter<unsigned int>("articleID");
00035 
00036         edm::LogInfo("Generator|LHEInterface")
00037                 << "Reading article id " << articleId << " from MCDB."
00038                 << std::endl;
00039 
00040         mcdb::MCDB mcdb;
00041 
00042         mcdb::Article article = mcdb.getArticle(articleId);
00043 
00044         edm::LogInfo("Generator|LHEInterface")
00045                 << "Title: " << article.title() << std::endl
00046                 << "First author: " << article.authors()[0].firstName() << " "
00047                 << article.authors()[0].lastName() << std::endl
00048                 << "Number of authors: " << article.authors().size() << std::endl
00049                 << "Abstract: " << article.abstract() << std::endl
00050                 << "Generator: " << article.generator().name()
00051                 << ", " << article.generator().version() << std::endl
00052                 << "Number of files: " << article.files().size() << std::endl
00053                 << "Files: " << std::endl;
00054 
00055         std::vector<std::string> supportedProtocols = 
00056                 params.getParameter< std::vector<std::string> >(
00057                                                         "supportedProtocols");
00058 
00059         boost::regex filter(params.getUntrackedParameter<std::string>(
00060                                                         "filter", "\\.lhef?$"),
00061                             boost::regex_constants::normal |
00062                             boost::regex_constants::icase);
00063 
00064         unsigned int firstEvent =
00065                 params.getUntrackedParameter<unsigned int>("seekEvent", 0);
00066 
00067         std::vector<std::string> fileURLs;
00068         for(std::vector<mcdb::File>::iterator file = article.files().begin();
00069             file != article.files().end(); ++file) {
00070                 std::string fileURL;
00071                 for(std::vector<std::string>::const_iterator prot =
00072                                                 supportedProtocols.begin();
00073                     prot != supportedProtocols.end(); ++prot) {
00074                         for(std::vector<std::string>::const_iterator path =
00075                                                         file->paths().begin();
00076                             path != file->paths().end(); ++path) {
00077                                 if (path->substr(0, prot->length() + 1) ==
00078                                     *prot + ":") {
00079                                         fileURL = *path;
00080                                         break;
00081                                 }
00082                         }
00083                         if (!fileURL.empty())
00084                                 break;
00085                 }
00086 
00087                 if (fileURL.empty())
00088                         throw cms::Exception("Generator|LHEInterface")
00089                                 << "MCDB did not contain any URLs with"
00090                                    " supported protocols for at least one"
00091                                    " file." << std::endl;
00092 
00093                 if (!boost::regex_search(fileURL, filter))
00094                         continue;
00095 
00096                 int nEvents = file->eventsNumber();
00097                 if ((int)firstEvent > nEvents) {
00098                         firstEvent -= nEvents;
00099                         continue;
00100                 }
00101 
00102                 fileURLs.push_back(fileURL);
00103         }
00104 
00105         return std::make_pair(fileURLs, firstEvent);
00106 }


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