Go to the documentation of this file.00001 #include <iostream>
00002 #include <utility>
00003 #include <string>
00004
00005 #include <boost/regex.hpp>
00006
00007 #include "mcdb.hpp"
00008
00009 #include "FWCore/Framework/interface/InputSourceMacros.h"
00010 #include "FWCore/Framework/interface/MakerMacros.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/Run.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
00017 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
00018 #include "GeneratorInterface/LHEInterface/interface/LHEReader.h"
00019
00020 #include "LHESource.h"
00021
00022 using namespace lhef;
00023
00024 class MCDBSource : public LHESource {
00025 public:
00026 explicit MCDBSource(const edm::ParameterSet ¶ms,
00027 const edm::InputSourceDescription &desc);
00028 virtual ~MCDBSource();
00029 };
00030
00031 static std::pair<std::vector<std::string>, unsigned int>
00032 getFileURLs(const edm::ParameterSet ¶ms)
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.getUntrackedParameter< 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>("skipEvents", 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 (nEvents > 0 && (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 }
00107
00108 static edm::ParameterSet augmentPSetFromMCDB(const edm::ParameterSet ¶ms)
00109 {
00110
00111
00112
00113
00114
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 "skipEvents", result.second);
00124
00125 return newParams;
00126 }
00127
00128 MCDBSource::MCDBSource(const edm::ParameterSet ¶ms,
00129 const edm::InputSourceDescription &desc) :
00130 LHESource(augmentPSetFromMCDB(params), desc)
00131 {
00132 }
00133
00134 MCDBSource::~MCDBSource()
00135 {
00136 }
00137
00138 DEFINE_FWK_INPUT_SOURCE(MCDBSource);